![](/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:
- 104:750d7e13137d
- Parent:
- 99:7030e9790b1d
- Child:
- 105:663b73bb2f81
diff -r 4a37d19e8fcc -r 750d7e13137d main.cpp --- a/main.cpp Thu Oct 22 14:26:08 2015 +0000 +++ b/main.cpp Fri Oct 23 12:17:29 2015 +0000 @@ -14,28 +14,37 @@ #include "debug.h" #include "emg.h" -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, servoTick; +volatile bool switches_go=false, debug_go=false, motor_go=false, emg_go=false, safety_go=false, servo_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 servo_activate(){servo_go=true;}; -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 -const int normalize = 1; // Constant for mode switching for program readability -bool mode = normalize; // Set program mode +const double emgCall = 0.005; // Set EMG sampling period +const double motorCall = 0.005; // Set motor control period global so it can be used for speed. +const double servoCall = 0.025; // Set servo control speed +const int sample = 0; // Constant for mode switching for program readability +const int normalize = 1; // Constant for mode switching for program readability +bool mode = sample; // Set program mode + int main(){ - motorInit(); + wait_ms(2000); + motorsEnable = true; + //motorInit(); // calibrateMotors(); // start motor calibration - - EMGTick.attach(&emg_activate, 0.005f); - switchesTick.attach(&switches_activate, 0.02f); - debugTick.attach(&debug_activate, 0.03f); + blueLed.write(1),redLed.write(1),greenLed.write(1); + servo.pulsewidth(0.0015); // Set servo to zero position + + //EMGTick.attach(&emg_activate, emgCall); + //switchesTick.attach(&switches_activate, 0.02f); + //debugTick.attach(&debug_activate, 0.03f); motorTick.attach(&motor_activate, motorCall); + servoTick.attach(&servo_activate, servoCall); safetyTick.attach(&safety_activate, 0.001f); while (true) { @@ -52,6 +61,14 @@ emg_go=false; readEMG(); } + if(motor_go){ + motor_go=false; + motorControl(); + } + if(servo_go){ + servo_go=false; + servoControl(); + } if(switches_go){ switches_go=false; checkSwitches(); @@ -60,10 +77,6 @@ debug_go=false; debugProcess(); } - if(motor_go){ - motor_go=false; - motorControl(); - } } } } \ No newline at end of file