NXP cup car code made by Pascal. "stable" version apr. 2016
Dependencies: mbed FRDM-TFC PIDcontroller FreescaleIAP Vision MMA8451Q MotorControl
Diff: main.cpp
- Revision:
- 2:eb79d6e3f701
- Parent:
- 1:5402c62ad487
- Child:
- 3:c21068661635
diff -r 5402c62ad487 -r eb79d6e3f701 main.cpp --- a/main.cpp Tue Jul 04 19:24:29 2017 +0000 +++ b/main.cpp Wed Jul 05 20:31:26 2017 +0000 @@ -53,7 +53,7 @@ { } -void dataConversionRoutine() +void dataConvertionRoutine() { uint8_t mask; @@ -107,9 +107,9 @@ int main() { - //uint8_t i; + uint8_t i; uint8_t r,l; - float motorPWM,steering; + float motorPWM,steering,steeringFiltered; float pixelTarget; struct lineScanData lineData; uint32_t lastcount = 0; @@ -122,15 +122,19 @@ pc.baud(115200); debug.baud(115200); - convTicker.attach_us(&dataConversionRoutine, 2000); + // run convertion routine each 2ms + convTicker.attach_us(&dataConvertionRoutine, 2000); + // record data when convertion done TFC_ConvertionReadyCallback.attach(&saveADCMeas); batLevelTicker.attach(&updateBatteryLevel,0.2); + motors.setFixedPWMMode(); motors.setSpeedTargetValue(2.0); + motors.setPWM(0.45); steeringPID.setReference(0); - steeringPID.setCoefficients(2,0,0); + steeringPID.setCoefficients(1.5,0,0); steeringPID.setOutputLimits(-0.6,0.6); while(1) @@ -168,7 +172,10 @@ // new - applySteeringCommand(steeringPID.processNewValue(steering)); + steeringFiltered = steeringPID.processNewValue(steering); + applySteeringCommand(steeringFiltered); + motorPWM = 0.6-abs(steeringFiltered)/2.0; + motors.setPWM(motorPWM); motors.processTasks(); //motorPWM = TFC_ReadPot(0); @@ -183,13 +190,6 @@ t.reset(); t.start(); - //lineScanLightAdjust((uint16_t*)TFC_LineScanImage0); - lineData = lineScanProcess((uint16_t*)TFC_LineScanImage0); - pixelTarget = (lineData.leftEdgeIndex+lineData.rightEdgeIndex)/2.0; - steering = getSteeringValue(pixelTarget); - - applySteeringCommand(steeringFilter(steering)); - // stop calculation time measurement t.stop();