![](/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
serialcom.cpp@130:2542f844ba1e, 2015-10-30 (annotated)
- Committer:
- annesteenbeek
- Date:
- Fri Oct 30 10:32:49 2015 +0100
- Revision:
- 130:2542f844ba1e
- Parent:
- 129:53d23eae7a6a
changes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
annesteenbeek | 124:f67ce69557db | 1 | #include "mbed.h" |
annesteenbeek | 125:749b8ce2e040 | 2 | #include "serialcom.h" |
annesteenbeek | 126:56866cefaa08 | 3 | //#include "MODSERIAL.h" |
annesteenbeek | 124:f67ce69557db | 4 | #include "config.h" |
annesteenbeek | 124:f67ce69557db | 5 | #include "PID.h" |
annesteenbeek | 125:749b8ce2e040 | 6 | #include "buttons.h" |
annesteenbeek | 124:f67ce69557db | 7 | #include <string> |
annesteenbeek | 124:f67ce69557db | 8 | |
annesteenbeek | 126:56866cefaa08 | 9 | Serial pc(USBTX, USBRX); |
annesteenbeek | 124:f67ce69557db | 10 | char buf[128]; |
annesteenbeek | 129:53d23eae7a6a | 11 | int transmitDOF; |
annesteenbeek | 129:53d23eae7a6a | 12 | bool EMGCalReady = false; |
annesteenbeek | 129:53d23eae7a6a | 13 | bool enableEMG = false; |
annesteenbeek | 129:53d23eae7a6a | 14 | bool startCalibration = false; |
annesteenbeek | 124:f67ce69557db | 15 | |
annesteenbeek | 126:56866cefaa08 | 16 | void serialInit(){ |
annesteenbeek | 126:56866cefaa08 | 17 | const int baudrate = 9600; |
annesteenbeek | 126:56866cefaa08 | 18 | redLed.write(1); // dim the leds |
annesteenbeek | 126:56866cefaa08 | 19 | blueLed.write(1); |
annesteenbeek | 126:56866cefaa08 | 20 | greenLed.write(1); |
annesteenbeek | 126:56866cefaa08 | 21 | |
annesteenbeek | 126:56866cefaa08 | 22 | pc.baud(baudrate); |
annesteenbeek | 126:56866cefaa08 | 23 | } |
annesteenbeek | 126:56866cefaa08 | 24 | |
annesteenbeek | 124:f67ce69557db | 25 | void serialCom(){ |
annesteenbeek | 127:831f03471efb | 26 | // Receiving |
annesteenbeek | 124:f67ce69557db | 27 | pc.scanf("%s", buf); |
annesteenbeek | 124:f67ce69557db | 28 | if(strcmp(buf,"ledRed")==0){ |
annesteenbeek | 125:749b8ce2e040 | 29 | redLed.write(!redLed.read()); |
annesteenbeek | 124:f67ce69557db | 30 | } |
annesteenbeek | 124:f67ce69557db | 31 | if(strcmp(buf,"ledBlue")==0){ |
annesteenbeek | 125:749b8ce2e040 | 32 | blueLed.write(!blueLed.read()); |
annesteenbeek | 124:f67ce69557db | 33 | } |
annesteenbeek | 124:f67ce69557db | 34 | if(strcmp(buf,"ledGreen")==0){ |
annesteenbeek | 125:749b8ce2e040 | 35 | greenLed.write(!greenLed.read()); |
annesteenbeek | 124:f67ce69557db | 36 | } |
annesteenbeek | 127:831f03471efb | 37 | if(strcmp(buf, "switchPump")==0){ |
annesteenbeek | 127:831f03471efb | 38 | enablePump = !enablePump; |
annesteenbeek | 127:831f03471efb | 39 | } |
annesteenbeek | 127:831f03471efb | 40 | if(strcmp(buf, "startCalibration")==0){ |
annesteenbeek | 127:831f03471efb | 41 | startCalibration = true; |
annesteenbeek | 127:831f03471efb | 42 | } |
annesteenbeek | 127:831f03471efb | 43 | if(strcmp(buf, "enableEMG")==0){ |
annesteenbeek | 127:831f03471efb | 44 | enableEMG = true; |
annesteenbeek | 129:53d23eae7a6a | 45 | usePotmeters = false; |
annesteenbeek | 127:831f03471efb | 46 | } |
annesteenbeek | 127:831f03471efb | 47 | if(strcmp(buf, "usePotmeters")==0){ |
annesteenbeek | 127:831f03471efb | 48 | usePotmeters = true; |
annesteenbeek | 129:53d23eae7a6a | 49 | enableEMG = false; |
annesteenbeek | 127:831f03471efb | 50 | } |
annesteenbeek | 127:831f03471efb | 51 | if(strcmp(buf, "controlAngle")==0){ |
annesteenbeek | 127:831f03471efb | 52 | controlAngle = true; |
annesteenbeek | 129:53d23eae7a6a | 53 | controlDirection = false; |
annesteenbeek | 127:831f03471efb | 54 | } |
annesteenbeek | 127:831f03471efb | 55 | if(strcmp(buf, "controlDirection")==0){ |
annesteenbeek | 127:831f03471efb | 56 | controlDirection = true; |
annesteenbeek | 129:53d23eae7a6a | 57 | controlAngle = false; |
annesteenbeek | 127:831f03471efb | 58 | } |
annesteenbeek | 128:c583aff5a7bf | 59 | |
annesteenbeek | 128:c583aff5a7bf | 60 | // Writers |
annesteenbeek | 128:c583aff5a7bf | 61 | pc.printf("enablePump %d\n", enablePump); |
annesteenbeek | 128:c583aff5a7bf | 62 | pc.printf("startCalibration %d\n", startCalibration); |
annesteenbeek | 128:c583aff5a7bf | 63 | pc.printf("enableEMG %d\n", enableEMG); |
annesteenbeek | 128:c583aff5a7bf | 64 | pc.printf("usePotmeters %d\n", usePotmeters); |
annesteenbeek | 128:c583aff5a7bf | 65 | pc.printf("controlAngle %d\n", controlAngle); |
annesteenbeek | 128:c583aff5a7bf | 66 | pc.printf("controlDirection %d\n", controlDirection); |
annesteenbeek | 128:c583aff5a7bf | 67 | pc.printf("calReady %d\n", calReady); |
annesteenbeek | 128:c583aff5a7bf | 68 | pc.printf("motorsEnable %d\n", motorsEnable); |
annesteenbeek | 128:c583aff5a7bf | 69 | pc.printf("EMGCalReady %d\n", EMGCalReady); |
annesteenbeek | 130:2542f844ba1e | 70 | pc.printf("Xpos %.3lf\n", Xpos); |
annesteenbeek | 130:2542f844ba1e | 71 | pc.printf("Ypos %.3lf\n", Ypos); |
annesteenbeek | 130:2542f844ba1e | 72 | pc.printf("motor1Pos %.3lf\n", motor1Pos); |
annesteenbeek | 130:2542f844ba1e | 73 | pc.printf("motor2Pos %.3lf\n", motor2Pos); |
annesteenbeek | 128:c583aff5a7bf | 74 | |
annesteenbeek | 128:c583aff5a7bf | 75 | // transmit correct DOF controller |
annesteenbeek | 129:53d23eae7a6a | 76 | if(usePotmeters){ |
annesteenbeek | 128:c583aff5a7bf | 77 | transmitDOF = actuatorState; // DOF controlled by buttons |
annesteenbeek | 128:c583aff5a7bf | 78 | }if(enableEMG){ |
annesteenbeek | 128:c583aff5a7bf | 79 | transmitDOF = DOF; // DOF controlled by EMG |
annesteenbeek | 128:c583aff5a7bf | 80 | } |
annesteenbeek | 128:c583aff5a7bf | 81 | pc.printf("DOF %i\n", transmitDOF); // DOF: 1=x 2=y 3=z |
annesteenbeek | 124:f67ce69557db | 82 | } |
annesteenbeek | 124:f67ce69557db | 83 |