Example software of using the mbed-rtos to control a simple vehicle's on board computer
Dependencies: MCP23017 WattBob_TextLCD mbed-rtos mbed
Diff: main.cpp
- Revision:
- 6:572b9755f2c1
- Parent:
- 5:4f2a072ed289
- Child:
- 7:f09208f9a4f7
--- a/main.cpp Wed Mar 30 03:52:21 2016 +0000 +++ b/main.cpp Wed Mar 30 04:01:53 2016 +0000 @@ -93,16 +93,7 @@ PCConn.printf("B: %f\r\n",currentBrake); bool currentEngineState = rawParams.EngineState; rawParamsMutex.unlock(); - - SpeedMutex.unlock(); - float lastSpeed_copy = lastSpeed; - SpeedMutex.lock(); - // Calculate speed in m/s, convert to mph -// float Acc = ((lastSpeed_copy/2.23) + ((7*currentAccelerometer)*0.05)); -// float Dec = ((lastSpeed_copy/2.23) + ((7*currentBrake)*0.05)); -// -// newSpeed = (Acc - Dec)*2.23; #define MAX_SPEED 100 newSpeed = currentAccelerometer*MAX_SPEED*(1-currentBrake)*currentEngineState; @@ -114,16 +105,11 @@ speedParams.rawSpeed[speedParams.counter] = newSpeed; SpeedMutex.unlock(); - - lastSpeed = newSpeed; - + speedParams.counter = speedParams.counter++; - - - + } - // ============================================================================ // Control System Tasks // ============================================================================ @@ -211,13 +197,13 @@ void Task6_UpdateOdometer(void const *arg) -{ - totalDistance = 50; - +{ filteredParamsMutex.lock(); float currentAverageSpeed = filteredParams.AverageSpeed; filteredParamsMutex.unlock(); + totalDistance = totalDistance + (currentAverageSpeed*(0.5/3600)); + lcd -> cls(); lcd -> locate(0,0); lcd -> printf("Dist: %8.2f",totalDistance); @@ -318,6 +304,8 @@ speedParams.rawSpeed[2] = 0.0; filteredParams.AverageSpeed = 0.0; + + totalDistance = 0.0; }