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:
- 127:831f03471efb
- Parent:
- 126:56866cefaa08
- Child:
- 128:c583aff5a7bf
diff -r 56866cefaa08 -r 831f03471efb main.cpp --- a/main.cpp Thu Oct 29 20:06:41 2015 +0000 +++ b/main.cpp Thu Oct 29 22:46:30 2015 +0100 @@ -8,12 +8,12 @@ */ #include "mbed.h" -#include "config.h" // settings and pin configurations -#include "actuators.h" -#include "buttons.h" -#include "debug.h" -#include "emg.h" -#include "serialcom.h" +#include "config.h" // settings and pin configurations +#include "actuators.h" // all the actuator related functions +#include "buttons.h" // reading switches and buttons +#include "debug.h" // HIDscope +#include "emg.h" // EMG +#include "serialcom.h" // Communication with web app Ticker switchesTick, debugTick, motorTick, EMGTick, safetyTick, serialTick; volatile bool switches_go=false, debug_go=false, motor_go=false, emg_go=false, safety_go=false, serial_go=false; @@ -26,73 +26,67 @@ void serial_activate(){serial_go=true;}; void tickerAttach(){ - EMGTick.attach(&emg_activate, 0.005f); switchesTick.attach(&switches_activate, 0.02f); - debugTick.attach(&debug_activate, motorCall); + // debugTick.attach(&debug_activate, motorCall); 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 -const int normalize = 1; // Constant for mode switching for program readability -bool mode = normalize; // Set program mode +const int sample = 0; // Constant for EMG mode switching +const int normalize = 1; // Constant for EMG mode switching +bool mode = normalize; bool tickersActivated = false; -bool calReady = false; // flag for calibration ready +bool calReady = false; // flag for motor calibration -bool usePotmeters = true; -bool controlAngle = false; -bool controlDirection = true; +bool usePotmeters = true; // flag for using the potmeters/EMG to control the system +bool controlAngle = false; // control the system using motor angles +bool controlDirection = true; // control the system using kinematics int main(){ serialInit(); serialTick.attach(&serial_activate, 0.1f); // initialze serial communication first + EMGTick.attach(&emg_activate, 0.005f); motorInit(); - - - while (true) { - - calReady = calibrateMotors(); - - if(serial_go){ + if(serial_go){ // communication between serial and the webpage serial_go=false; serialCom(); } - - if(calReady && !tickersActivated){ // when done with calibration, start tickers + if(startCalibration & !calReady){ // start calibration + calReady = calibrateMotors(); + } + if(emg_go){ + if(enableEMG){ + emg_go=false; + readEMG(); + } + } + if(calReady && !tickersActivated){ // when done with calibration, start rest of tickers tickerAttach(); tickersActivated = true; } - - if(emg_go){ - emg_go=false; - readEMG(); + if(safety_go){ + safety_go=false; + safety(); // springs at the side to constrain arm movement + } + if(switches_go){ + switches_go=false; + checkSwitches(); // read potmeters and buttons on the motor board } - if(mode==0){ // wait until EMG is done with calibration - if(safety_go){ - safety_go=false; - safety(); - } - if(emg_go){ - emg_go=false; - readEMG(); - } - if(switches_go){ - switches_go=false; - checkSwitches(); - } - if(debug_go){ - debug_go=false; - debugProcess(); - } - if(motor_go){ - motor_go=false; - motorControl(); - } + if(debug_go){ + debug_go=false; + debugProcess(); // send data to HIDscope + } + if(motor_go){ + motor_go=false; + motorControl(); // write data to the motors + } + + if(mode==0){ } }