control for robotic arm that can play chess using a granular gripper
Dependencies: Encoder mbed HIDScope Servo MODSERIAL
Fork of chessRobot by
Revision 126:56866cefaa08, committed 2015-10-29
- Comitter:
- annesteenbeek
- Date:
- Thu Oct 29 20:06:41 2015 +0000
- Parent:
- 125:749b8ce2e040
- Child:
- 127:831f03471efb
- Commit message:
- working led switching
Changed in this revision
--- a/config.h Thu Oct 29 17:41:10 2015 +0000 +++ b/config.h Thu Oct 29 20:06:41 2015 +0000 @@ -12,6 +12,7 @@ #define button1Pin D0 #define button2Pin D1 +#define pumpPin D3 // Servo #define servoPin D9
--- a/main.cpp Thu Oct 29 17:41:10 2015 +0000 +++ b/main.cpp Thu Oct 29 20:06:41 2015 +0000 @@ -31,7 +31,7 @@ debugTick.attach(&debug_activate, motorCall); motorTick.attach(&motor_activate, motorCall); safetyTick.attach(&safety_activate, 0.001f); - serialTick.attach(&serial_activate, 0.05f); + } double motorCall = 0.01; // set motor frequency global so it can be used for speed. @@ -47,10 +47,21 @@ int main(){ + serialInit(); + serialTick.attach(&serial_activate, 0.1f); // initialze serial communication first motorInit(); - calReady = true; // calibrateMotors(); + + + while (true) { + + calReady = calibrateMotors(); + + if(serial_go){ + serial_go=false; + serialCom(); + } if(calReady && !tickersActivated){ // when done with calibration, start tickers tickerAttach(); @@ -82,10 +93,7 @@ motor_go=false; motorControl(); } - if(serial_go){ - serial_go=false; - serialCom(); - } + } } } \ No newline at end of file
--- a/serialcom.cpp Thu Oct 29 17:41:10 2015 +0000 +++ b/serialcom.cpp Thu Oct 29 20:06:41 2015 +0000 @@ -1,24 +1,38 @@ #include "mbed.h" #include "serialcom.h" -#include "MODSERIAL.h" +//#include "MODSERIAL.h" #include "config.h" #include "PID.h" #include "buttons.h" #include <string> -MODSERIAL pc(USBTX, USBRX); +Serial pc(USBTX, USBRX); +DigitalOut pumpSwitch(pumpPin); char buf[128]; +void serialInit(){ + const int baudrate = 9600; + redLed.write(1); // dim the leds + blueLed.write(1); + greenLed.write(1); + + pc.baud(baudrate); + } + void serialCom(){ pc.scanf("%s", buf); if(strcmp(buf,"ledRed")==0){ redLed.write(!redLed.read()); + pc.printf("received data\n"); + pumpSwitch.write(!pumpSwitch.read()); } if(strcmp(buf,"ledBlue")==0){ blueLed.write(!blueLed.read()); + pc.printf("received data\n"); } if(strcmp(buf,"ledGreen")==0){ greenLed.write(!greenLed.read()); + pc.printf("received data\n"); } }
--- a/serialcom.h Thu Oct 29 17:41:10 2015 +0000 +++ b/serialcom.h Thu Oct 29 20:06:41 2015 +0000 @@ -14,5 +14,6 @@ extern DigitalOut blueLed; void serialCom(); +void serialInit(); #endif \ No newline at end of file