![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
biorobotics group 19 , 2 november
Dependencies: HIDScope MODSERIAL PID QEI SigInterpreternovember2 biquadFilter mbed
Fork of Robot_controlv2 by
Diff: Controller.h
- Revision:
- 4:bfdcf3da7cff
- Parent:
- 2:6b913f93bc0b
- Child:
- 6:a4440eec3652
--- a/Controller.h Wed Oct 26 12:40:26 2016 +0000 +++ b/Controller.h Fri Oct 28 12:49:02 2016 +0000 @@ -1,16 +1,20 @@ +#include "SigInterpreter.h" + +SigInterpreter signal = SigInterpreter(); const double PI = 3.141592653589793; +//MODSERIAL pc(USBTX, USBRX); int xPulses = 0; // pulsecount -int x_max = 33068; +const int x_max = 33068; int yPulses = 0; -int y_max = 17640; +const int y_max = 17640; int prevXpulses = 0; int prevYpulses = 0; -double rMax; // maxAmplitude emg signal -double lMax; -double uMax; -double dMax; +double rMax = 0; // maxAmplitude emg signal +double lMax = 0; +double uMax = 0; +double dMax = 0; float motorValueX = 0; // requested speed float motorValueY = 0; @@ -31,9 +35,9 @@ double l = 0; double u = 0; double d = 0; -int i = 1; +int i = 0; -int SAMPLES_PER_AVERAGE = 10; +const int SAMPLES_PER_AVERAGE = 10; const int margin = 100; // margin pulses for calibration void calibrate(); @@ -46,46 +50,51 @@ void initMotors(); void initMotorvariables(); -SigInterpreter signal = SigInterpreter(); -PulseChecker pulses = PulseChecker(); +HIDScope scope(2); const float Kc = 0.0; const float Ti = 0.0; const float Td = 0.0; -float RATE = 0.01; // rate = interval motors will be updateed +const float RATE = 0.001; // rate = interval motors will be updateed + +int counter = 0; +int counter_motor = 0; PwmOut X_Magnitude(D5); // bind to horizontal motor DigitalOut X_Direction(D4); PID X_Controller(Kc, Ti, Td, RATE); +QEI X_Motor(D12 ,D13 ,NC, 64 ,QEI::X4_ENCODING); PwmOut Y_Magnitude(D6); // bind to Ytical motor DigitalOut Y_Direction(D7); PID Y_Controller(Kc, Ti, Td, RATE); +QEI Y_Motor(D14 ,D15 ,NC, 64 ,QEI::X4_ENCODING); -InterruptIn calibrateButton(D2); +//InterruptIn calibrateButton(D2); +DigitalIn button(D2); Ticker motorControl; -void setFlag(); -bool flag = true; -bool calibrateFlag = true; +void setUpdate_flag(); +volatile bool update_flag = false; +const int CW = true; -int CW = true; +DigitalOut led(LED_BLUE); void initMotors(){ - X_Magnitude.period_us(50); + X_Magnitude.period_ms(1); X_Magnitude.write(0.0); X_Direction.write(CW); - Y_Magnitude.period_us(50); + Y_Magnitude.period_ms(1); Y_Magnitude.write(0.0); Y_Direction.write(CW); } void initControllers(){ - X_Controller.setInputLimits(-90.0,90.0); // fiX_ me + X_Controller.setInputLimits(-1.0,1.0); // fiX_ me X_Controller.setOutputLimits(-1.0,1.0); X_Controller.setBias(0); - X_Controller.setMode(0); + X_Controller.setMode(0); // fix me - Y_Controller.setInputLimits(-90.0,90.0); // fix me + Y_Controller.setInputLimits(-1.0,1.0); // fix me Y_Controller.setOutputLimits(-1.0,1.0); Y_Controller.setBias(0); Y_Controller.setMode(0);