Source code for Active Aerodynamics and Drag Reduction System
Dependencies: mbed Servo mbed-rtos LSM9DS1_Library_cal MPL3115A2
Revision 6:38cc8e010406, committed 2020-04-24
- Comitter:
- skiley6
- Date:
- Fri Apr 24 16:06:47 2020 +0000
- Parent:
- 5:295fe3425a73
- Commit message:
- Removed useless comments and made sure it compiles. This is able to be turned in currently
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 295fe3425a73 -r 38cc8e010406 main.cpp --- a/main.cpp Fri Apr 24 15:24:30 2020 +0000 +++ b/main.cpp Fri Apr 24 16:06:47 2020 +0000 @@ -115,7 +115,6 @@ if(cF > 0.5){ cF = 0.5; } - //Thread::wait(20); } else if(edit == editRear) { @@ -123,7 +122,6 @@ if(cR > 0.5){ cR = 0.5; } - //Thread::wait(20); } else{ cF += 0.05; @@ -135,7 +133,6 @@ if(cF > 0.5){ cF = 0.5; } - //Thread::wait(20); } } break; @@ -147,7 +144,6 @@ if(cF < 0){ cF = 0; } - //Thread::wait(20); } else if(edit == editRear) { @@ -155,7 +151,6 @@ if(cR < 0){ cR = 0; } - //Thread::wait(20); } else{ cF -= 0.05; @@ -167,7 +162,6 @@ if(cF < 0){ cF = 0; } - //Thread::wait(20); } } break; @@ -201,17 +195,9 @@ void blueTX() { - //float lastF = 0; - //float last R = 0; - //statetype lastState = Off; - //editState lastEdit = editALL; - //blue.printf("Mode: HOLD........||Front:%3.0f%%||........||Rear:%3.0f%%||\n", ceil(cF/0.5 * 100), ceil(cR/0.5 * 100)); - while(1) { - //Off = 0, Testing, DRS_Active, Active_Yaw, Active_Roll //Send data - switch (servoState) { case Off: @@ -236,23 +222,20 @@ blue.printf("....................Mode: DRS ACTIVATED....................\n"); break; case Active_Yaw: - //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....", 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); } } -// IMU - caluclate pitch and roll + +// Calculate roll float getRoll(float ax, float az) { float roll_t = atan2(ax, az); @@ -262,11 +245,9 @@ return roll_t; } - -// IMU - read and display magnetometer, gyroscope, acceleration values +// IMU - read IMU gyro and accel data for YawRate and roll void getIMUData() { - while(1) { while(!IMU.gyroAvailable()); @@ -276,34 +257,30 @@ YawRate = IMU.calcGyro(IMU.gz); roll = getRoll(IMU.calcAccel(IMU.ax), IMU.calcAccel(IMU.az)); - - //sensor.readTemperature(&t); - //sensor.readPressure(&p); - Thread::wait(50); } } +// calculate and set servo positions void setServos() { - uint32_t testSpeed = 20; - float testPrec = 0.05; - - + uint32_t testSpeed = 20; // thread wait length for movement + float testPrec = 0.05; // amount of movement per iteration + while(1) { switch(servoState) { - case Off: //close all flaps + case Off: //close all flaps to set angle servoFR = cF; servoFL = 1 - cF; servoRR = cR; servoRL = 1 - cR; - Thread::wait(250); //longer wait because of Off state + Thread::wait(250); //longer wait because only based on user input changes break; - case Testing: + case Testing: //TESTING Mode servoFR = 0; servoFL = 1; @@ -349,7 +326,7 @@ } servoState = Off; break; - case DRS_Active: + case DRS_Active: //DRS ACTIVE Mode, opens flaps to pre determined angle servoFR = 0.25; servoFL = 1 - 0.25; @@ -359,7 +336,7 @@ break; - case Active_Yaw: + case Active_Yaw: // ACTIVE YAW mode. automatically adjust flaps based on the speed at which the vehicle turns float tempFront = 0.0; float tempRear = 0.0; float newFront = 0.0; @@ -414,7 +391,7 @@ Thread::wait(25); break; - case Active_Roll: + case Active_Roll: // ACTIVE ROLL Mode. automatically set flaps based on how much the vehicle rolls tempFront = 0.0; tempRear = 0.0; newFront = 0.0; @@ -495,18 +472,19 @@ pc.printf("Failed to communicate with LSM9DS1.\n"); } - + // Can Calibrate IMU if issues arise. //IMU.calibrate(1); //IMU.calibrateMag(0); blue.baud(9600); //set baud rate for UART window + //START THREADS blueRXThread.start(blueRX); blueTXThread.start(blueTX); IMUThread.start(getIMUData); servoThread.start(setServos); - while(1) { + while(1) { sensor.readTemperature(&t); Thread::wait(1000); }