test angle measurement LSM6DS3

Dependencies:   ESC IMUfilter LSM6DS3 mbed

Files at this revision

API Documentation at this revision

Comitter:
rsmits
Date:
Wed Jan 17 19:52:07 2018 +0000
Child:
1:0e63617e1965
Commit message:
fix address, import IMUfilter

Changed in this revision

ESC.lib Show annotated file Show diff for this revision Revisions of this file
IMUfilter.lib Show annotated file Show diff for this revision Revisions of this file
LSM6DS3.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ESC.lib	Wed Jan 17 19:52:07 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/MatteoT/code/ESC/#735702ea5519
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IMUfilter.lib	Wed Jan 17 19:52:07 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/aberk/code/IMUfilter/#8a920397b510
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LSM6DS3.lib	Wed Jan 17 19:52:07 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/5hel2l2y/code/LSM6DS3/#ed14e6196255
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 17 19:52:07 2018 +0000
@@ -0,0 +1,106 @@
+#include "mbed.h"
+#include "esc.h" 
+#include "LSM6DS3.h"
+#include "IMUfilter.h"
+
+// refresh time. set to 500 for part 2 and 50 for part 4
+#define REFRESH_TIME_MS 1000
+
+const int   LSM6DS3_ADDRESS = 0xD4;
+int PERIOD = 20;
+//
+//float       MOTOR_PRINT; 
+Serial      pc(SERIAL_TX, SERIAL_RX); 
+ESC         MOTOR(PA_8, PERIOD);
+AnalogIn    PRESSURE_SENSOR(PA_0);
+//Ticker      UpdateScreen;
+LSM6DS3     imu(PF_0, PF_1, LSM6DS3_ADDRESS);
+
+//void screenUpdate();
+
+//Init Serial port and LSM6DS3 chip
+void setup()
+{
+    // Use the begin() function to initialize the LSM9DS0 library.
+    // You can either call it with no parameters (the easy way):
+    // SLEEP
+//    uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G,
+//                                imu.G_POWER_DOWN, imu.A_POWER_DOWN);
+    // LOWEST
+//    uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G,
+//                                imu.G_ODR_13_BW_0, imu.A_ODR_13);
+    // HIGHEST
+//    uint16_t status = imu.begin(imu.G_SCALE_2000DPS, imu.A_SCALE_8G,
+//                                imu.G_ODR_1660, imu.A_ODR_6660);
+                                
+    uint16_t status = imu.begin(imu.G_SCALE_245DPS, imu.A_SCALE_2G,
+                                imu.G_ODR_1660, imu.A_ODR_6660);
+ 
+    //Make sure communication is working
+    pc.printf("LSM6DS3 WHO_AM_I's returned: 0x%X\r\n", status);
+    pc.printf("Should be 0x69\r\n");
+}
+ 
+int main()
+{
+    MOTOR.setThrottle(0.0); 
+    bool started = false;
+    
+    while (true){
+        
+        if(PRESSURE_SENSOR > 0.9){
+            
+            if (not started){
+                setup();  //Setup sensor and Serial
+                pc.printf("\r\n------ LSM6DS3 Demo -----------\r\n");
+                started=true;
+            }
+ 
+            imu.readTemp();
+            pc.printf("Temp:\r\n");
+            pc.printf("TC: %2f\r\n", imu.temperature_c);
+            pc.printf("TF: %2f\r\n", imu.temperature_f);
+            
+            imu.readAccel();
+            pc.printf("Accel:\r\n");
+            pc.printf("AX: %2f\r\n", imu.ax);
+            pc.printf("AY: %2f\r\n", imu.ay);
+            pc.printf("AZ: %2f\r\n", imu.az);
+     
+            imu.readGyro();
+            pc.printf("Gyro:\r\n");
+            pc.printf("GX: %2f\r\n", imu.gx);
+            pc.printf("GY: %2f\r\n", imu.gy);
+            pc.printf("GZ: %2f\r\n\r\n", imu.gz);
+           
+            wait_ms(REFRESH_TIME_MS);
+        }
+        else {
+            started=false;
+        }
+    }
+}
+
+
+//int main() {
+//    
+//    UpdateScreen.attach(&screenUpdate, 1);
+//    MOTOR.setThrottle(0.0); // motor PWM speed
+//    UpdateScreen.attach(&screenUpdate, 1);
+//    
+//    while(1) {
+//        
+//        
+//        float angle = 0.0;
+//        
+//        MOTOR.setThrottle(angle);
+//        MOTOR_PRINT = MOTOR.getThrottle();
+//        MOTOR.pulse();
+//        wait_ms(PERIOD);
+//
+//    }
+//}
+//
+//void screenUpdate(){
+//    PC.printf("PWM: %f \r\n\n", MOTOR_PRINT);
+//}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 17 19:52:07 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7130f322cb7e
\ No newline at end of file