![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
control for robotic arm that can play chess using a granular gripper
Dependencies: Encoder mbed HIDScope Servo MODSERIAL
Fork of chessRobot by
Diff: main.cpp
- Revision:
- 115:d8d2968981f3
- Parent:
- 110:a6439e13be8b
- Child:
- 116:8b812e268b85
--- a/main.cpp Tue Oct 27 14:45:15 2015 +0000 +++ b/main.cpp Tue Oct 27 16:21:20 2015 +0100 @@ -16,14 +16,24 @@ int a =4; -Ticker switchesTick, debugTick, motorTick, EMGTick, safetyTick; -volatile bool switches_go=false, debug_go=false, motor_go=false, emg_go=false, safety_go=false; +Ticker switchesTick, debugTick, motorTick, EMGTick, safetyTick calibrateTick; +volatile bool switches_go=false, debug_go=false, motor_go=false, emg_go=false, safety_go=false, cal_go=false; void switches_activate(){switches_go=true;}; void debug_activate(){debug_go=true;}; void motor_activate(){motor_go=true;}; void emg_activate(){emg_go=true;}; void safety_activate(){safety_go=true;}; +void calibration_activate(){cal_go=true;}; + +void tickerAttach(){ + calibrateTick.detach(&calibration_activate); // stop calibration ticker + EMGTick.attach(&emg_activate, 0.005f); + switchesTick.attach(&switches_activate, 0.02f); + debugTick.attach(&debug_activate, 0.03f); + motorTick.attach(&motor_activate, motorCall); + safetyTick.attach(&safety_activate, 0.001f); +} double motorCall = 0.01; // set motor frequency global so it can be used for speed. const int sample = 0; // Constant for mode switching for program readability @@ -32,16 +42,20 @@ bool calReady = false; // flag for calibration ready int main(){ - motorInit(); - calReady = calibrateMotors(); // start motor calibration - - EMGTick.attach(&emg_activate, 0.005f); - switchesTick.attach(&switches_activate, 0.02f); - debugTick.attach(&debug_activate, 0.03f); - motorTick.attach(&motor_activate, motorCall); - safetyTick.attach(&safety_activate, 0.001f); + motorInit(); + calibrateTick.attach(&calibration_activate, motorCall); while (true) { + if(cal_go){ + cal_go=false; + calReady = calibrateMotors(); + } + + if(calReady && !tickersActivated){ // when done with calibration, start tickers + tickerAttach(); + tickersActivated = true; + } + if(emg_go){ emg_go=false; readEMG();