Biorobotics
/
Controller
Controller futhers (PI)
Diff: main.cpp
- Revision:
- 9:ea9d35838861
- Parent:
- 8:998f4575089b
- Child:
- 10:3796b6a6c239
--- a/main.cpp Mon Oct 19 09:12:17 2015 +0000 +++ b/main.cpp Tue Oct 27 10:30:54 2015 +0000 @@ -5,8 +5,9 @@ QEI wheel (PTC10, PTC11, NC, 624); // Pin for counting (analog in) // Define pin for motor control -DigitalOut directionPin(D4); -PwmOut PWM(D5); +DigitalOut directionPin_one(D4); +PwmOut PWM_one(D5); + DigitalIn buttonccw(PTA4); DigitalIn buttoncw(PTC6); @@ -54,12 +55,12 @@ } // To make a new setpoint -double making_setpoint(double direction){ +double making_setpoint(double direction, double setpoint){ if ( cw == direction){ - setpoint = setpoint + (pulses_per_revolution/40000); + setpoint = setpoint + (pulses_per_revolution/400000); } if ( ccw == direction){ - setpoint = setpoint - (pulses_per_revolution/40000); + setpoint = setpoint - (pulses_per_revolution/400000); } return(setpoint); @@ -75,7 +76,7 @@ return PI_output; } // Next task, measure the error and apply the output to the plant -void motor1_Controller() +void motor1_Controller(DigitalOut directionPin, PwmOut PWM, QEI &wheel, double setpoint) { double reference = setpoint; // setpoint is in pulses double position = wheel.getPulses(); @@ -116,7 +117,7 @@ // to make the motor move if(flag_motor) { flag_motor = false; - motor1_Controller(); + motor1_Controller(directionPin, PWM, wheel, setpoint); } if(flag_pcprint) { @@ -127,10 +128,10 @@ // Pussing buttons to get input signal if(buttoncw.read() == Buttoncw_pressed){ - setpoint = making_setpoint(cw); + setpoint = making_setpoint(cw, setpoint); } -if(buttonccw.read() == Buttonccw_pressed) { - setpoint = making_setpoint(ccw); + if(buttonccw.read() == Buttonccw_pressed) { + setpoint = making_setpoint(ccw, setpoint); } }