Source code for Active Aerodynamics and Drag Reduction System
Dependencies: mbed Servo mbed-rtos LSM9DS1_Library_cal MPL3115A2
Revision 5:295fe3425a73, committed 2020-04-24
- Comitter:
- skiley6
- Date:
- Fri Apr 24 15:24:30 2020 +0000
- Parent:
- 4:8442a7d55f23
- Child:
- 6:38cc8e010406
- Commit message:
- Added Temperature and made sure everything works. Temp is in Main thread;
Changed in this revision
MPL3115A2.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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MPL3115A2.lib Fri Apr 24 15:24:30 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/sophtware/code/MPL3115A2/#7c7c1ea6fc33
--- a/main.cpp Thu Apr 23 20:05:58 2020 +0000 +++ b/main.cpp Fri Apr 24 15:24:30 2020 +0000 @@ -2,6 +2,7 @@ #include "rtos.h" #include "Servo.h" #include "LSM9DS1.h" +#include "MPL3115A2.h" #define PI 3.14159 // Used in IMU code #define DECLINATION -4.94 // Declination (degrees) in Atlanta,GA (Used in IMU code) @@ -15,6 +16,9 @@ RawSerial blue(p13,p14); // bluetooth Serial pc(USBTX, USBRX); // tx, rx +I2C i2c(p28, p27); // sda, scl +MPL3115A2 sensor(&i2c, &pc); + //BusOut myled(LED1,LED2,LED3,LED4); //bluetooth debugging DigitalOut led1(LED1); DigitalOut led2(LED2); @@ -24,13 +28,15 @@ //THREADS Thread blueRXThread; Thread blueTXThread; -Thread sensorThread; +Thread IMUThread; Thread servoThread; // VARIABLE DECLARATIONS volatile float YawRate; volatile float roll; -volatile float midTemp; + +Temperature t; + enum statetype {Off = 0, Testing, DRS_Active, Active_Yaw, Active_Roll}; volatile statetype servoState = Off; @@ -230,15 +236,19 @@ blue.printf("....................Mode: DRS ACTIVATED....................\n"); break; case Active_Yaw: - blue.printf("Mode: ACTIVE-YAW.......YawRate: %3.0f deg/s........\n", YawRate); + //blue.printf("Mode: ACTIVE-YAW....Yaw:%3.0f deg/s....", YawRate); + blue.printf("Mode: ACTIVE-YAW....Yaw:%3.0f deg/s....T:%sF\n", YawRate, t.print()); break; case Active_Roll: - blue.printf("Mode: ACTIVE-ROLL..........roll: %3.0f deg...............\n", roll); + //blue.printf("Mode: ACTIVE-ROLL....Roll: %3.0f deg....", roll); + blue.printf("Mode: ACTIVE-ROLL....Roll: %3.0f deg....T:%sF\n", roll, t.print()); break; default: break; } + + //blue.printf("Temp: %sºF, Pressure: %sPa\r\n", t.print(),p.print()); Thread::wait(200); } } @@ -252,38 +262,26 @@ return roll_t; } + // IMU - read and display magnetometer, gyroscope, acceleration values -void getSensorData() +void getIMUData() { + while(1) { while(!IMU.gyroAvailable()); IMU.readGyro(); IMU.readAccel(); - //IMU.readTemp(); + YawRate = IMU.calcGyro(IMU.gz); roll = getRoll(IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.az)); - //midTemp = (25.0 + IMU.temperature/16.0) * (9/5) + 32; //get into C then into F + + + //sensor.readTemperature(&t); + //sensor.readPressure(&p); + Thread::wait(50); } - - /* - while(!IMU.magAvailable(X_AXIS)); - IMU.readMag(); - while(!IMU.accelAvailable()); - IMU.readAccel(); - while(!IMU.gyroAvailable()); - IMU.readGyro(); - pc.printf(" X axis Y axis Z axis\n\r"); - pc.printf("gyro: %9f %9f %9f in deg/s\n\r", IMU.calcGyro(IMU.gx), IMU.calcGyro(IMU.gy), IMU.calcGyro(IMU.gz)); - pc.printf("accel: %9f %9f %9f in Gs\n\r", IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az)); - pc.printf("mag: %9f %9f %9f in gauss\n\r", IMU.calcMag(IMU.mx), IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); - printAttitude(IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.ay), IMU.calcAccel(IMU.az), IMU.calcMag(IMU.mx),IMU.calcMag(IMU.my), IMU.calcMag(IMU.mz)); - - zAccel = IMU.calcAccel(IMU.az);//setting global variable for storage of z-Axis acceleration - yAccel = IMU.calcAccel(IMU.ay); - xAccel = IMU.calcAccel(IMU.ax); - */ } void setServos() @@ -480,11 +478,24 @@ int main() { + //init temp sensor + sensor.init(); + // Offsets for Dacula, GA + sensor.setOffsetAltitude(83); + sensor.setOffsetTemperature(20); + sensor.setOffsetPressure(-32); + + sensor.setModeStandby(); + sensor.setModeBarometer(); + sensor.setModeActive(); + // initialise IMU IMU.begin(); if (!IMU.begin()) { pc.printf("Failed to communicate with LSM9DS1.\n"); } + + //IMU.calibrate(1); //IMU.calibrateMag(0); @@ -492,10 +503,11 @@ blueRXThread.start(blueRX); blueTXThread.start(blueTX); - sensorThread.start(getSensorData); + IMUThread.start(getIMUData); servoThread.start(setServos); while(1) { - + sensor.readTemperature(&t); + Thread::wait(1000); } }