motor controller with P velocity control
Dependencies: HIDScope PID QEI mbed EMG
Fork of PID_VelocityExample by
Diff: main.cpp
- Revision:
- 3:4c93be3a9010
- Parent:
- 2:b2ccd9f044bb
- Child:
- 4:be465e9a12cb
diff -r b2ccd9f044bb -r 4c93be3a9010 main.cpp --- a/main.cpp Thu Sep 24 11:20:14 2015 +0000 +++ b/main.cpp Thu Sep 24 11:25:06 2015 +0000 @@ -25,6 +25,7 @@ DigitalOut leftDirection(D4); QEI leftQei(D12, D13, NC, 624); PID leftController(Kc, Ti, Td, RATE); +AnalogIn pot1(A0); //------- // Files //------- @@ -43,6 +44,7 @@ volatile float leftVelocity = 0.0; //Velocity to reach. int goal = 3000; +float measure; //****************************************************************************/ // Prototypes @@ -82,11 +84,13 @@ endTimer.start(); //Set velocity set point. - leftController.setSetPoint(goal); + leftMotor.period_ms(0.1); //Run for 3 seconds. - while (endTimer.read() < 3.0){ + while (endTimer.read() < 10){ + measure = pot1.read()*10000; + leftController.setSetPoint(measure); leftPulses = leftQei.getPulses(); leftVelocity = (leftPulses - leftPrevPulses) / RATE; leftPrevPulses = leftPulses;