Robotic Construction Vehicle

Dependencies:   mbed

Committer:
alipford3
Date:
Wed Dec 10 03:50:14 2014 +0000
Revision:
0:8aab3120e540
Robotic Construction Vehicle

Who changed what in which revision?

UserRevisionLine numberNew contents of line
alipford3 0:8aab3120e540 1 #include "mbed.h"
alipford3 0:8aab3120e540 2
alipford3 0:8aab3120e540 3 //ZigBee
alipford3 0:8aab3120e540 4 Serial xbee(p28, p27);
alipford3 0:8aab3120e540 5 DigitalOut rst(p29);
alipford3 0:8aab3120e540 6 int myData;
alipford3 0:8aab3120e540 7
alipford3 0:8aab3120e540 8 //Left Motors
alipford3 0:8aab3120e540 9 DigitalOut enLeft(p7);
alipford3 0:8aab3120e540 10 DigitalOut ctrlLeft(p11);
alipford3 0:8aab3120e540 11 PwmOut pwrLeft(p23);
alipford3 0:8aab3120e540 12
alipford3 0:8aab3120e540 13 //Right Motors
alipford3 0:8aab3120e540 14 DigitalOut enRight(p8);
alipford3 0:8aab3120e540 15 DigitalOut ctrlRight(p12);
alipford3 0:8aab3120e540 16 PwmOut pwrRight(p24);
alipford3 0:8aab3120e540 17
alipford3 0:8aab3120e540 18 //Arm Motors
alipford3 0:8aab3120e540 19 DigitalOut enArm(p5);
alipford3 0:8aab3120e540 20 DigitalOut ctrlArm(p9);
alipford3 0:8aab3120e540 21 PwmOut pwrArm(p21);
alipford3 0:8aab3120e540 22
alipford3 0:8aab3120e540 23 //Bucket Motors
alipford3 0:8aab3120e540 24 DigitalOut enBucket(p6);
alipford3 0:8aab3120e540 25 DigitalOut ctrlBucket(p10);
alipford3 0:8aab3120e540 26 PwmOut pwrBucket(p22);
alipford3 0:8aab3120e540 27
alipford3 0:8aab3120e540 28 DigitalOut myled1(LED1);
alipford3 0:8aab3120e540 29 DigitalOut myled2(LED2);
alipford3 0:8aab3120e540 30 DigitalOut myled3(LED3);
alipford3 0:8aab3120e540 31 DigitalOut myled4(LED4);
alipford3 0:8aab3120e540 32
alipford3 0:8aab3120e540 33 int stop = 0;
alipford3 0:8aab3120e540 34
alipford3 0:8aab3120e540 35 int main() {
alipford3 0:8aab3120e540 36 // ZigBee Init
alipford3 0:8aab3120e540 37 xbee.baud(19200);
alipford3 0:8aab3120e540 38 rst = 0;
alipford3 0:8aab3120e540 39 wait_ms(1);
alipford3 0:8aab3120e540 40 rst = 1;
alipford3 0:8aab3120e540 41 wait_ms(1);
alipford3 0:8aab3120e540 42
alipford3 0:8aab3120e540 43 //Motor Enables
alipford3 0:8aab3120e540 44 enLeft = 0;
alipford3 0:8aab3120e540 45 enRight = 0;
alipford3 0:8aab3120e540 46 enArm = 0;
alipford3 0:8aab3120e540 47 enBucket = 0;
alipford3 0:8aab3120e540 48
alipford3 0:8aab3120e540 49 //Motor PWMs
alipford3 0:8aab3120e540 50 pwrLeft = 0.9;
alipford3 0:8aab3120e540 51 pwrRight = 0.9;
alipford3 0:8aab3120e540 52 pwrArm = 0.9;
alipford3 0:8aab3120e540 53 pwrBucket = 0.4;
alipford3 0:8aab3120e540 54
alipford3 0:8aab3120e540 55 while(1) {
alipford3 0:8aab3120e540 56
alipford3 0:8aab3120e540 57 myData = xbee.getc();
alipford3 0:8aab3120e540 58
alipford3 0:8aab3120e540 59 // Move Forward
alipford3 0:8aab3120e540 60 if(myData == '0'){
alipford3 0:8aab3120e540 61 myled1 = 1;
alipford3 0:8aab3120e540 62 stop = 0;
alipford3 0:8aab3120e540 63 while(stop != 1) {
alipford3 0:8aab3120e540 64 //Left Motors
alipford3 0:8aab3120e540 65 enLeft = 1;
alipford3 0:8aab3120e540 66 ctrlLeft = 1;
alipford3 0:8aab3120e540 67 //Right Motors
alipford3 0:8aab3120e540 68 enRight = 1;
alipford3 0:8aab3120e540 69 ctrlRight = 1;
alipford3 0:8aab3120e540 70 wait(1.5);
alipford3 0:8aab3120e540 71 stop = 1;
alipford3 0:8aab3120e540 72 }
alipford3 0:8aab3120e540 73 enLeft = 0;
alipford3 0:8aab3120e540 74 enRight = 0;
alipford3 0:8aab3120e540 75 myled1 = 0;
alipford3 0:8aab3120e540 76 }
alipford3 0:8aab3120e540 77
alipford3 0:8aab3120e540 78 // Move Backward
alipford3 0:8aab3120e540 79 else if(myData == '1'){
alipford3 0:8aab3120e540 80 stop = 0;
alipford3 0:8aab3120e540 81 while(stop != 1) {
alipford3 0:8aab3120e540 82 //Left Motors
alipford3 0:8aab3120e540 83 enLeft = 1;
alipford3 0:8aab3120e540 84 ctrlLeft = 0;
alipford3 0:8aab3120e540 85 //Right Motors
alipford3 0:8aab3120e540 86 enRight = 1;
alipford3 0:8aab3120e540 87 ctrlRight = 0;
alipford3 0:8aab3120e540 88 wait(1.5);
alipford3 0:8aab3120e540 89 stop = 1;
alipford3 0:8aab3120e540 90 }
alipford3 0:8aab3120e540 91 enLeft = 0;
alipford3 0:8aab3120e540 92 enRight = 0;
alipford3 0:8aab3120e540 93 }
alipford3 0:8aab3120e540 94
alipford3 0:8aab3120e540 95 //Turn Left
alipford3 0:8aab3120e540 96 else if(myData == '2') {
alipford3 0:8aab3120e540 97 stop = 0;
alipford3 0:8aab3120e540 98 while(stop != 1) {
alipford3 0:8aab3120e540 99 //Left Motors
alipford3 0:8aab3120e540 100 enLeft = 1;
alipford3 0:8aab3120e540 101 ctrlLeft = 0;
alipford3 0:8aab3120e540 102 //Right Motors
alipford3 0:8aab3120e540 103 enRight = 1;
alipford3 0:8aab3120e540 104 ctrlRight = 1;
alipford3 0:8aab3120e540 105 wait(1.5);
alipford3 0:8aab3120e540 106 stop = 1;
alipford3 0:8aab3120e540 107 }
alipford3 0:8aab3120e540 108 enLeft = 0;
alipford3 0:8aab3120e540 109 enRight = 0;
alipford3 0:8aab3120e540 110 }
alipford3 0:8aab3120e540 111
alipford3 0:8aab3120e540 112 //Turn Right
alipford3 0:8aab3120e540 113 else if(myData == '3') {
alipford3 0:8aab3120e540 114 stop = 0;
alipford3 0:8aab3120e540 115 while(stop != 1) {
alipford3 0:8aab3120e540 116 //Left Motors
alipford3 0:8aab3120e540 117 enLeft = 1;
alipford3 0:8aab3120e540 118 ctrlLeft = 1;
alipford3 0:8aab3120e540 119 //Right Motors
alipford3 0:8aab3120e540 120 enRight = 1;
alipford3 0:8aab3120e540 121 ctrlRight = 0;
alipford3 0:8aab3120e540 122 wait(1.5);
alipford3 0:8aab3120e540 123 stop = 1;
alipford3 0:8aab3120e540 124 }
alipford3 0:8aab3120e540 125 enLeft = 0;
alipford3 0:8aab3120e540 126 enRight = 0;
alipford3 0:8aab3120e540 127 }
alipford3 0:8aab3120e540 128
alipford3 0:8aab3120e540 129 //Arm Up
alipford3 0:8aab3120e540 130 else if(myData == '4') {
alipford3 0:8aab3120e540 131 stop = 0;
alipford3 0:8aab3120e540 132 while(stop != 1) {
alipford3 0:8aab3120e540 133 enArm = 1;
alipford3 0:8aab3120e540 134 ctrlArm = 1;
alipford3 0:8aab3120e540 135 wait(1);
alipford3 0:8aab3120e540 136 stop = 1;
alipford3 0:8aab3120e540 137 }
alipford3 0:8aab3120e540 138 enArm = 0;
alipford3 0:8aab3120e540 139 }
alipford3 0:8aab3120e540 140
alipford3 0:8aab3120e540 141 //Arm Down
alipford3 0:8aab3120e540 142 else if(myData == '5') {
alipford3 0:8aab3120e540 143 stop = 0;
alipford3 0:8aab3120e540 144 while(stop != 1) {
alipford3 0:8aab3120e540 145 enArm = 1;
alipford3 0:8aab3120e540 146 ctrlArm = 0;
alipford3 0:8aab3120e540 147 wait(1);
alipford3 0:8aab3120e540 148 stop = 1;
alipford3 0:8aab3120e540 149 }
alipford3 0:8aab3120e540 150 enArm = 0;
alipford3 0:8aab3120e540 151 }
alipford3 0:8aab3120e540 152
alipford3 0:8aab3120e540 153 //Bucket Out
alipford3 0:8aab3120e540 154 else if(myData == '6') {
alipford3 0:8aab3120e540 155 stop = 0;
alipford3 0:8aab3120e540 156 while(stop != 1) {
alipford3 0:8aab3120e540 157 enBucket = 1;
alipford3 0:8aab3120e540 158 ctrlBucket = 1;
alipford3 0:8aab3120e540 159 wait(0.5);
alipford3 0:8aab3120e540 160 stop = 1;
alipford3 0:8aab3120e540 161 }
alipford3 0:8aab3120e540 162 enBucket = 0;
alipford3 0:8aab3120e540 163 }
alipford3 0:8aab3120e540 164
alipford3 0:8aab3120e540 165 //Bucket In
alipford3 0:8aab3120e540 166 else if(myData == '7') {
alipford3 0:8aab3120e540 167 stop = 0;
alipford3 0:8aab3120e540 168 while(stop != 1) {
alipford3 0:8aab3120e540 169 enBucket = 1;
alipford3 0:8aab3120e540 170 ctrlBucket = 0;
alipford3 0:8aab3120e540 171 wait(0.5);
alipford3 0:8aab3120e540 172 stop = 1;
alipford3 0:8aab3120e540 173 }
alipford3 0:8aab3120e540 174 enBucket = 0;
alipford3 0:8aab3120e540 175 }
alipford3 0:8aab3120e540 176 }
alipford3 0:8aab3120e540 177 }