Puppet Master System / Mbed 2 deprecated Robot_Puppet_EndDevice_Final

Dependencies:   Motor mbed

Fork of Robot_Puppet_EndDevice by Puppet Master System

Committer:
bstrickland9
Date:
Sun Apr 29 16:59:11 2018 +0000
Revision:
1:06beb0d8958a
Parent:
0:a66bf82d70ed
Final Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fyousuf3 0:a66bf82d70ed 1 // test code, this demonstrates working motor drivers.
fyousuf3 0:a66bf82d70ed 2 // full reverse to full stop, dynamicaly brake and switch off.
fyousuf3 0:a66bf82d70ed 3 #include "mbed.h"
fyousuf3 0:a66bf82d70ed 4 #include "Motor.h"
bstrickland9 1:06beb0d8958a 5 Motor B(p23, p6, p5); // pwm, fwd, rev, can brake //right?
bstrickland9 1:06beb0d8958a 6 Motor A(p24, p7, p8); // pwm, fwd, rev, can brake //left?
fyousuf3 0:a66bf82d70ed 7
fyousuf3 0:a66bf82d70ed 8
fyousuf3 0:a66bf82d70ed 9 //End Device Setup for XBEE End Device
fyousuf3 0:a66bf82d70ed 10 Serial xbee2(p9,p10);
fyousuf3 0:a66bf82d70ed 11 DigitalOut rst1(p11);
fyousuf3 0:a66bf82d70ed 12
fyousuf3 0:a66bf82d70ed 13 //Movement Indicators
fyousuf3 0:a66bf82d70ed 14 DigitalOut myled1(LED1);
fyousuf3 0:a66bf82d70ed 15 DigitalOut myled2(LED2);
bstrickland9 1:06beb0d8958a 16 DigitalOut myled3(LED3);
bstrickland9 1:06beb0d8958a 17 DigitalOut myled4(LED4);
bstrickland9 1:06beb0d8958a 18
bstrickland9 1:06beb0d8958a 19 //debug
bstrickland9 1:06beb0d8958a 20 Serial pc(USBTX, USBRX);
fyousuf3 0:a66bf82d70ed 21
fyousuf3 0:a66bf82d70ed 22 // Default Value for command to wait
fyousuf3 0:a66bf82d70ed 23 char command = 'W';
fyousuf3 0:a66bf82d70ed 24
fyousuf3 0:a66bf82d70ed 25 int main() {
fyousuf3 0:a66bf82d70ed 26 rst1 = 0; //Set reset pin to 0
fyousuf3 0:a66bf82d70ed 27 myled1 = 0;
fyousuf3 0:a66bf82d70ed 28 myled2 = 0;
fyousuf3 0:a66bf82d70ed 29 myled3 = 0;
fyousuf3 0:a66bf82d70ed 30 myled4 = 0;
fyousuf3 0:a66bf82d70ed 31 wait_ms(1);
fyousuf3 0:a66bf82d70ed 32 rst1 = 1; //Set reset pin to 1
fyousuf3 0:a66bf82d70ed 33 wait_ms(1);
fyousuf3 0:a66bf82d70ed 34
fyousuf3 0:a66bf82d70ed 35 while (1){
fyousuf3 0:a66bf82d70ed 36 if(xbee2.readable()) {//if new command readable
fyousuf3 0:a66bf82d70ed 37 command = xbee2.getc();
fyousuf3 0:a66bf82d70ed 38 //pc.printf("Command: %c\n\r",command);
fyousuf3 0:a66bf82d70ed 39 }
fyousuf3 0:a66bf82d70ed 40
bstrickland9 1:06beb0d8958a 41 // pc.printf("%c",command);
bstrickland9 1:06beb0d8958a 42 // pc.printf("\n\r");
bstrickland9 1:06beb0d8958a 43
fyousuf3 0:a66bf82d70ed 44 switch (command){
fyousuf3 0:a66bf82d70ed 45 case 'A': // Move back speed 1
fyousuf3 0:a66bf82d70ed 46 A.speed(-0.5);
fyousuf3 0:a66bf82d70ed 47 B.speed(-0.5);
fyousuf3 0:a66bf82d70ed 48
fyousuf3 0:a66bf82d70ed 49 myled1 = 1;
fyousuf3 0:a66bf82d70ed 50 myled2 = 0;
fyousuf3 0:a66bf82d70ed 51 myled3 = 0;
fyousuf3 0:a66bf82d70ed 52 myled4 = 0;
fyousuf3 0:a66bf82d70ed 53
bstrickland9 1:06beb0d8958a 54 //wait(0.5);
fyousuf3 0:a66bf82d70ed 55 break;
fyousuf3 0:a66bf82d70ed 56 case 'B': // Move back speed 2
fyousuf3 0:a66bf82d70ed 57 A.speed(-1);
fyousuf3 0:a66bf82d70ed 58 B.speed(-1);
fyousuf3 0:a66bf82d70ed 59
fyousuf3 0:a66bf82d70ed 60 myled1 = 1;
fyousuf3 0:a66bf82d70ed 61 myled2 = 0;
fyousuf3 0:a66bf82d70ed 62 myled3 = 0;
fyousuf3 0:a66bf82d70ed 63 myled4 = 0;
fyousuf3 0:a66bf82d70ed 64
bstrickland9 1:06beb0d8958a 65 //wait(0.5);
fyousuf3 0:a66bf82d70ed 66 break;
fyousuf3 0:a66bf82d70ed 67 case 'C': // Move right speed 1
fyousuf3 0:a66bf82d70ed 68 A.speed(0.5);
fyousuf3 0:a66bf82d70ed 69 B.speed(0);
fyousuf3 0:a66bf82d70ed 70
fyousuf3 0:a66bf82d70ed 71 myled1 = 0;
fyousuf3 0:a66bf82d70ed 72 myled2 = 1;
fyousuf3 0:a66bf82d70ed 73 myled3 = 0;
fyousuf3 0:a66bf82d70ed 74 myled4 = 0;
fyousuf3 0:a66bf82d70ed 75
bstrickland9 1:06beb0d8958a 76 //wait(0.5);
fyousuf3 0:a66bf82d70ed 77 break;
fyousuf3 0:a66bf82d70ed 78 case 'D': // Move right speed 2
fyousuf3 0:a66bf82d70ed 79 A.speed(1);
fyousuf3 0:a66bf82d70ed 80 B.speed(0);
fyousuf3 0:a66bf82d70ed 81
fyousuf3 0:a66bf82d70ed 82 myled1 = 0;
fyousuf3 0:a66bf82d70ed 83 myled2 = 1;
fyousuf3 0:a66bf82d70ed 84 myled3 = 0;
fyousuf3 0:a66bf82d70ed 85 myled4 = 0;
fyousuf3 0:a66bf82d70ed 86
bstrickland9 1:06beb0d8958a 87 //wait(0.5);
fyousuf3 0:a66bf82d70ed 88 break;
fyousuf3 0:a66bf82d70ed 89 case 'E': // Move forward speed 1
fyousuf3 0:a66bf82d70ed 90 A.speed(0.5);
fyousuf3 0:a66bf82d70ed 91 B.speed(0.5);
fyousuf3 0:a66bf82d70ed 92
fyousuf3 0:a66bf82d70ed 93 myled1 = 0;
fyousuf3 0:a66bf82d70ed 94 myled2 = 0;
fyousuf3 0:a66bf82d70ed 95 myled3 = 1;
fyousuf3 0:a66bf82d70ed 96 myled4 = 0;
fyousuf3 0:a66bf82d70ed 97
bstrickland9 1:06beb0d8958a 98 //wait(0.5);
fyousuf3 0:a66bf82d70ed 99 break;
fyousuf3 0:a66bf82d70ed 100 case 'F': // Move forward speed 2
fyousuf3 0:a66bf82d70ed 101 A.speed(1);
fyousuf3 0:a66bf82d70ed 102 B.speed(1);
fyousuf3 0:a66bf82d70ed 103
fyousuf3 0:a66bf82d70ed 104 myled1 = 0;
fyousuf3 0:a66bf82d70ed 105 myled2 = 0;
fyousuf3 0:a66bf82d70ed 106 myled3 = 1;
fyousuf3 0:a66bf82d70ed 107 myled4 = 0;
fyousuf3 0:a66bf82d70ed 108
bstrickland9 1:06beb0d8958a 109 //wait(0.5);
fyousuf3 0:a66bf82d70ed 110 break;
fyousuf3 0:a66bf82d70ed 111 case 'G': // Move left speed 1
fyousuf3 0:a66bf82d70ed 112 A.speed(0);
fyousuf3 0:a66bf82d70ed 113 B.speed(0.5);
fyousuf3 0:a66bf82d70ed 114
fyousuf3 0:a66bf82d70ed 115 myled1 = 0;
fyousuf3 0:a66bf82d70ed 116 myled2 = 0;
fyousuf3 0:a66bf82d70ed 117 myled3 = 0;
fyousuf3 0:a66bf82d70ed 118 myled4 = 1;
fyousuf3 0:a66bf82d70ed 119
bstrickland9 1:06beb0d8958a 120 //wait(0.5);
fyousuf3 0:a66bf82d70ed 121 break;
fyousuf3 0:a66bf82d70ed 122 case 'H': // Move left speed 2
fyousuf3 0:a66bf82d70ed 123 A.speed(0);
fyousuf3 0:a66bf82d70ed 124 B.speed(1);
fyousuf3 0:a66bf82d70ed 125
fyousuf3 0:a66bf82d70ed 126 myled1 = 0;
fyousuf3 0:a66bf82d70ed 127 myled2 = 0;
fyousuf3 0:a66bf82d70ed 128 myled3 = 0;
fyousuf3 0:a66bf82d70ed 129 myled4 = 1;
fyousuf3 0:a66bf82d70ed 130
bstrickland9 1:06beb0d8958a 131 //wait(0.5);
fyousuf3 0:a66bf82d70ed 132 break;
fyousuf3 0:a66bf82d70ed 133 case 'I': // Stop
bstrickland9 1:06beb0d8958a 134 A.speed(0.0);
bstrickland9 1:06beb0d8958a 135 B.speed(0.0);
fyousuf3 0:a66bf82d70ed 136
fyousuf3 0:a66bf82d70ed 137 myled1 = 1;
fyousuf3 0:a66bf82d70ed 138 myled2 = 1;
fyousuf3 0:a66bf82d70ed 139 myled3 = 1;
fyousuf3 0:a66bf82d70ed 140 myled4 = 1;
bstrickland9 1:06beb0d8958a 141 break;
fyousuf3 0:a66bf82d70ed 142
bstrickland9 1:06beb0d8958a 143 //wait(0.5);
fyousuf3 0:a66bf82d70ed 144
fyousuf3 0:a66bf82d70ed 145 case 'W': // Stop if nothing else is coming in
bstrickland9 1:06beb0d8958a 146 A.speed(0.0);
bstrickland9 1:06beb0d8958a 147 B.speed(0.0);
fyousuf3 0:a66bf82d70ed 148
fyousuf3 0:a66bf82d70ed 149 myled1 = 0;
fyousuf3 0:a66bf82d70ed 150 myled2 = 0;
fyousuf3 0:a66bf82d70ed 151 myled3 = 0;
fyousuf3 0:a66bf82d70ed 152 myled4 = 0;
bstrickland9 1:06beb0d8958a 153 //wait(0.5);
fyousuf3 0:a66bf82d70ed 154
fyousuf3 0:a66bf82d70ed 155 }
fyousuf3 0:a66bf82d70ed 156 }
fyousuf3 0:a66bf82d70ed 157 }