Main repository for dump truck API development in Spring 2017
Dependencies: Tracker mbed MotorV2 SRF05 nRF24L01P
Fork of DUMP_TRUCK_TEST_V1 by
Activities
This Week
If needed, please contact Milo Pan at mpan9@gatech.edu for rights and access to this repository.
DumpTruck.cpp@13:112b6543909a, 2017-04-13 (annotated)
- Committer:
- simplyellow
- Date:
- Thu Apr 13 17:32:44 2017 +0000
- Revision:
- 13:112b6543909a
- Parent:
- 12:502cf4fc6d98
- Child:
- 14:fd6090cddc2e
.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Josahty | 0:6942f0e2198c | 1 | #include "DumpTruck.h" |
Josahty | 0:6942f0e2198c | 2 | |
simplyellow | 13:112b6543909a | 3 | |
Josahty | 0:6942f0e2198c | 4 | DumpTruck::DumpTruck(int truckId) : truckNumber(truckId) { |
Josahty | 0:6942f0e2198c | 5 | truckNumber = truckId; |
simplyellow | 11:87f30625b213 | 6 | //track = new Tracker(p29, p30, p15); |
simplyellow | 10:cf77da9be0b8 | 7 | // PWM: 21, 22, 23 |
simplyellow | 10:cf77da9be0b8 | 8 | // DIR: 27, 28, 29 |
simplyellow | 11:87f30625b213 | 9 | frontMotor = new Motor(p23, p28); |
simplyellow | 13:112b6543909a | 10 | turnMotor = new Motor(p22, p29); |
simplyellow | 13:112b6543909a | 11 | bedMotor = new Motor(p23, p28); |
simplyellow | 10:cf77da9be0b8 | 12 | //bed = new IMU(@@@@@@@); |
simplyellow | 11:87f30625b213 | 13 | srf = new SRF05(p15, p16); //trigger, echo. |
simplyellow | 10:cf77da9be0b8 | 14 | tooClose = false; |
simplyellow | 13:112b6543909a | 15 | |
simplyellow | 12:502cf4fc6d98 | 16 | nrf = new nRF24L01P(p5, p6, p7, p8, p9, p10); // transceiver |
simplyellow | 12:502cf4fc6d98 | 17 | //transceiver set up, similar to one on base station code |
simplyellow | 12:502cf4fc6d98 | 18 | txDataCnt = 0; |
simplyellow | 12:502cf4fc6d98 | 19 | rxDataCnt = 0; |
simplyellow | 13:112b6543909a | 20 | received = false; |
simplyellow | 13:112b6543909a | 21 | |
simplyellow | 13:112b6543909a | 22 | void (*commands[2]); |
simplyellow | 13:112b6543909a | 23 | commands[0] = DumpTruck::stopBed; |
simplyellow | 13:112b6543909a | 24 | commands[1] = DumpTruck::stopDrive; |
simplyellow | 12:502cf4fc6d98 | 25 | } |
simplyellow | 12:502cf4fc6d98 | 26 | |
simplyellow | 12:502cf4fc6d98 | 27 | void DumpTruck::startComms() { |
simplyellow | 12:502cf4fc6d98 | 28 | nrf->powerUp(); |
simplyellow | 12:502cf4fc6d98 | 29 | printf( "nRF24L01+ Frequency : %d MHz\r\n", nrf->getRfFrequency() ); |
simplyellow | 12:502cf4fc6d98 | 30 | printf( "nRF24L01+ Output power : %d dBm\r\n", nrf->getRfOutputPower() ); |
simplyellow | 12:502cf4fc6d98 | 31 | printf( "nRF24L01+ Data Rate : %d kbps\r\n", nrf->getAirDataRate() ); |
simplyellow | 12:502cf4fc6d98 | 32 | printf( "nRF24L01+ TX Address : 0x%010llX\r\n", nrf->getTxAddress() ); |
simplyellow | 12:502cf4fc6d98 | 33 | printf( "nRF24L01+ RX Address : 0x%010llX\r\n", nrf->getRxAddress() ); |
simplyellow | 12:502cf4fc6d98 | 34 | nrf->setTransferSize( TRANSFER_SIZE ); |
simplyellow | 12:502cf4fc6d98 | 35 | nrf->setReceiveMode(); |
simplyellow | 12:502cf4fc6d98 | 36 | nrf->enable(); |
simplyellow | 13:112b6543909a | 37 | |
simplyellow | 13:112b6543909a | 38 | // fill acked array |
simplyellow | 13:112b6543909a | 39 | for(int i = 0; i < TRANSFER_SIZE; i++) { |
simplyellow | 13:112b6543909a | 40 | acked[i] = '0'; |
simplyellow | 13:112b6543909a | 41 | nacked[i] = '1'; |
simplyellow | 13:112b6543909a | 42 | } |
simplyellow | 13:112b6543909a | 43 | } |
simplyellow | 13:112b6543909a | 44 | |
simplyellow | 13:112b6543909a | 45 | void DumpTruck::sendAck() { |
simplyellow | 13:112b6543909a | 46 | printf("SEND acked\n\r"); |
simplyellow | 13:112b6543909a | 47 | wait(1); |
simplyellow | 13:112b6543909a | 48 | nrf->write(NRF24L01P_PIPE_P0, acked, TRANSFER_SIZE); |
simplyellow | 13:112b6543909a | 49 | printf("SENT\n\r"); |
simplyellow | 13:112b6543909a | 50 | } |
simplyellow | 13:112b6543909a | 51 | |
simplyellow | 13:112b6543909a | 52 | void DumpTruck::sendNack() { |
simplyellow | 13:112b6543909a | 53 | printf("SEND nacked\n\r"); |
simplyellow | 13:112b6543909a | 54 | wait(1); |
simplyellow | 13:112b6543909a | 55 | nrf->write(NRF24L01P_PIPE_P0, nacked, TRANSFER_SIZE); |
simplyellow | 13:112b6543909a | 56 | printf("SENT\n\r"); |
simplyellow | 12:502cf4fc6d98 | 57 | } |
simplyellow | 12:502cf4fc6d98 | 58 | |
simplyellow | 12:502cf4fc6d98 | 59 | void DumpTruck::getCommand() { |
simplyellow | 12:502cf4fc6d98 | 60 | //called at the end of each executable command |
simplyellow | 12:502cf4fc6d98 | 61 | //dump truck transceiver sends a code to base station, opening the channel |
simplyellow | 13:112b6543909a | 62 | //code is all 0's |
simplyellow | 13:112b6543909a | 63 | received = false; |
simplyellow | 13:112b6543909a | 64 | //acked to receive command |
simplyellow | 13:112b6543909a | 65 | sendAck(); |
simplyellow | 13:112b6543909a | 66 | //possibly implement kill switch/stop current action |
simplyellow | 12:502cf4fc6d98 | 67 | //code for receiving |
simplyellow | 12:502cf4fc6d98 | 68 | while(!received) { |
simplyellow | 13:112b6543909a | 69 | if (nrf->readable()) { |
simplyellow | 13:112b6543909a | 70 | // ...read the data into the receive buffer |
simplyellow | 12:502cf4fc6d98 | 71 | rxDataCnt = nrf->read(NRF24L01P_PIPE_P0, rxData, sizeof(rxData)); |
simplyellow | 13:112b6543909a | 72 | received = true; //after receiving command |
simplyellow | 13:112b6543909a | 73 | printf("received command\n\r"); |
simplyellow | 13:112b6543909a | 74 | processCommand(); |
simplyellow | 13:112b6543909a | 75 | } |
simplyellow | 13:112b6543909a | 76 | } |
simplyellow | 13:112b6543909a | 77 | } |
simplyellow | 12:502cf4fc6d98 | 78 | |
simplyellow | 13:112b6543909a | 79 | void DumpTruck::processCommand() { |
simplyellow | 13:112b6543909a | 80 | //strcmp(rxData,"on")==0 |
simplyellow | 13:112b6543909a | 81 | //perhaps have an array of all commands..?? |
simplyellow | 13:112b6543909a | 82 | //maybe commands.h is just the array |
simplyellow | 13:112b6543909a | 83 | //and the "on" becomes commands[k]? |
simplyellow | 13:112b6543909a | 84 | // real time driving |
simplyellow | 13:112b6543909a | 85 | switch(rxData) { |
simplyellow | 13:112b6543909a | 86 | case 1: |
simplyellow | 13:112b6543909a | 87 | sendAck(); |
simplyellow | 13:112b6543909a | 88 | printf("ack\n\r"); |
simplyellow | 13:112b6543909a | 89 | break; |
simplyellow | 13:112b6543909a | 90 | default: |
simplyellow | 13:112b6543909a | 91 | sendNack(); |
simplyellow | 13:112b6543909a | 92 | printf("nack\n\r"); |
simplyellow | 13:112b6543909a | 93 | break; |
simplyellow | 12:502cf4fc6d98 | 94 | } |
simplyellow | 13:112b6543909a | 95 | getCommand(); |
simplyellow | 12:502cf4fc6d98 | 96 | } |
simplyellow | 12:502cf4fc6d98 | 97 | |
simplyellow | 12:502cf4fc6d98 | 98 | void DumpTruck::reportData() { |
simplyellow | 12:502cf4fc6d98 | 99 | //should run last in main thread |
simplyellow | 10:cf77da9be0b8 | 100 | } |
simplyellow | 10:cf77da9be0b8 | 101 | |
simplyellow | 10:cf77da9be0b8 | 102 | void DumpTruck::driveDistance(float speed, float distance) { |
simplyellow | 10:cf77da9be0b8 | 103 | frontMotor->write(speed); |
simplyellow | 13:112b6543909a | 104 | getCommand(); |
simplyellow | 10:cf77da9be0b8 | 105 | } |
simplyellow | 10:cf77da9be0b8 | 106 | |
simplyellow | 10:cf77da9be0b8 | 107 | void DumpTruck::drive(float speed) { |
simplyellow | 10:cf77da9be0b8 | 108 | frontMotor->write(speed); |
simplyellow | 13:112b6543909a | 109 | getCommand(); |
Josahty | 0:6942f0e2198c | 110 | } |
Josahty | 0:6942f0e2198c | 111 | |
simplyellow | 10:cf77da9be0b8 | 112 | void DumpTruck::turn(float angle) { |
simplyellow | 13:112b6543909a | 113 | getCommand(); |
simplyellow | 10:cf77da9be0b8 | 114 | return; |
simplyellow | 10:cf77da9be0b8 | 115 | } |
simplyellow | 10:cf77da9be0b8 | 116 | |
simplyellow | 10:cf77da9be0b8 | 117 | void DumpTruck::moveBed(bool raise, float angle) { |
simplyellow | 13:112b6543909a | 118 | getCommand(); |
simplyellow | 10:cf77da9be0b8 | 119 | return; |
simplyellow | 10:cf77da9be0b8 | 120 | } |
simplyellow | 10:cf77da9be0b8 | 121 | |
simplyellow | 13:112b6543909a | 122 | void DumpTruck::stopDrive() { |
simplyellow | 11:87f30625b213 | 123 | frontMotor->write(0); |
simplyellow | 13:112b6543909a | 124 | getCommand(); |
simplyellow | 13:112b6543909a | 125 | } |
simplyellow | 13:112b6543909a | 126 | |
simplyellow | 13:112b6543909a | 127 | void DumpTruck::stopTurn() { |
simplyellow | 13:112b6543909a | 128 | turnMotor->write(0); |
simplyellow | 13:112b6543909a | 129 | getCommand(); |
simplyellow | 13:112b6543909a | 130 | } |
simplyellow | 13:112b6543909a | 131 | |
simplyellow | 13:112b6543909a | 132 | void DumpTruck::stopBed() { |
simplyellow | 13:112b6543909a | 133 | bedMotor->write(0); |
simplyellow | 13:112b6543909a | 134 | getCommand(); |
simplyellow | 10:cf77da9be0b8 | 135 | } |
simplyellow | 10:cf77da9be0b8 | 136 | |
simplyellow | 10:cf77da9be0b8 | 137 | bool DumpTruck::detect() { |
simplyellow | 10:cf77da9be0b8 | 138 | proximity = srf->read(); |
simplyellow | 11:87f30625b213 | 139 | if(proximity < 20) { //cm |
simplyellow | 10:cf77da9be0b8 | 140 | tooClose = true; |
simplyellow | 10:cf77da9be0b8 | 141 | } else { |
simplyellow | 10:cf77da9be0b8 | 142 | tooClose = false; |
simplyellow | 10:cf77da9be0b8 | 143 | } |
simplyellow | 10:cf77da9be0b8 | 144 | return tooClose; |
simplyellow | 10:cf77da9be0b8 | 145 | } |
Josahty | 0:6942f0e2198c | 146 | |
Josahty | 0:6942f0e2198c | 147 | |
Josahty | 3:cd6e2d7c7c9c | 148 | //void Calibrate(){} |
Josahty | 3:cd6e2d7c7c9c | 149 | |
Josahty | 3:cd6e2d7c7c9c | 150 | //void DumpTruck::drive() { |
Josahty | 3:cd6e2d7c7c9c | 151 | // // get desired distance and speed |
Josahty | 3:cd6e2d7c7c9c | 152 | // distance = 0; // placeholder |
Josahty | 3:cd6e2d7c7c9c | 153 | // // speed = 0.5; |
Josahty | 3:cd6e2d7c7c9c | 154 | // // distance = setTruckDistance(); |
Josahty | 3:cd6e2d7c7c9c | 155 | // speed = setTruckSpeed(); |
Josahty | 3:cd6e2d7c7c9c | 156 | // // terminal confirmation of distance and speed |
Josahty | 3:cd6e2d7c7c9c | 157 | // pc.printf("Truck will drive a distance of %f at a speed of %f\r\n",distance,speed); |
Josahty | 3:cd6e2d7c7c9c | 158 | // // insert while loop here which relates to distance travelled |
Josahty | 3:cd6e2d7c7c9c | 159 | // while(1) { |
Josahty | 3:cd6e2d7c7c9c | 160 | // // if the speed is greater than zero, go forward at specified speed |
Josahty | 3:cd6e2d7c7c9c | 161 | // if (speed >= 0) { |
Josahty | 3:cd6e2d7c7c9c | 162 | // DirPin = 1; |
Josahty | 3:cd6e2d7c7c9c | 163 | // DrivePin = speed; |
simplyellow | 10:cf77da9be0b8 | 164 | // } // else, go backwards at specified speed |
Josahty | 3:cd6e2d7c7c9c | 165 | // else { |
Josahty | 3:cd6e2d7c7c9c | 166 | // DirPin = 0; |
Josahty | 3:cd6e2d7c7c9c | 167 | // DrivePin = -1*speed; |
Josahty | 3:cd6e2d7c7c9c | 168 | // } |
Josahty | 3:cd6e2d7c7c9c | 169 | // } |
Josahty | 3:cd6e2d7c7c9c | 170 | // // stop motors |
Josahty | 3:cd6e2d7c7c9c | 171 | // // stop(); |
Josahty | 3:cd6e2d7c7c9c | 172 | // // calibrate motors |
Josahty | 3:cd6e2d7c7c9c | 173 | // Calibrate(); |
Josahty | 3:cd6e2d7c7c9c | 174 | // // |
Josahty | 3:cd6e2d7c7c9c | 175 | // travelled = 0; |
Josahty | 3:cd6e2d7c7c9c | 176 | //} |
Josahty | 3:cd6e2d7c7c9c | 177 | |
simplyellow | 10:cf77da9be0b8 | 178 | /*void DumpTruck::drive() { |
Josahty | 0:6942f0e2198c | 179 | // get desired distance and speed |
Josahty | 3:cd6e2d7c7c9c | 180 | // placeholder |
Josahty | 0:6942f0e2198c | 181 | // speed = 0.5; |
Josahty | 3:cd6e2d7c7c9c | 182 | //distance = 5.0; |
Josahty | 3:cd6e2d7c7c9c | 183 | distance = setTruckDistance(); |
Josahty | 0:6942f0e2198c | 184 | speed = setTruckSpeed(); |
Josahty | 0:6942f0e2198c | 185 | // terminal confirmation of distance and speed |
Josahty | 3:cd6e2d7c7c9c | 186 | pc.printf("Truck will drive a distance of %f inches at a speed of %f\r\n",distance,speed); |
Josahty | 0:6942f0e2198c | 187 | // insert while loop here which relates to distance travelled |
Josahty | 3:cd6e2d7c7c9c | 188 | travelled = getDistance(); |
Josahty | 3:cd6e2d7c7c9c | 189 | //pc.printf("Check 1: %f, %f\r\n", distance, travelled); |
simplyellow | 10:cf77da9be0b8 | 190 | while(travelled < distance) { |
Josahty | 3:cd6e2d7c7c9c | 191 | //pc.printf("Check 2:\r\n"); |
Josahty | 3:cd6e2d7c7c9c | 192 | travelled = getDistance(); |
Josahty | 3:cd6e2d7c7c9c | 193 | pc.printf("Travelling...: %f\n\r", (distance - travelled)); |
Josahty | 0:6942f0e2198c | 194 | // if the speed is greater than zero, go forward at specified speed |
Josahty | 0:6942f0e2198c | 195 | if (speed >= 0) { |
Josahty | 0:6942f0e2198c | 196 | DirPin = 1; |
Josahty | 0:6942f0e2198c | 197 | DrivePin = speed; |
simplyellow | 10:cf77da9be0b8 | 198 | } // else, go backwards at specified speed |
Josahty | 0:6942f0e2198c | 199 | else { |
Josahty | 0:6942f0e2198c | 200 | DirPin = 0; |
Josahty | 2:7811df5a6052 | 201 | DrivePin = -1*speed; |
Josahty | 3:cd6e2d7c7c9c | 202 | } |
Josahty | 0:6942f0e2198c | 203 | } |
Josahty | 3:cd6e2d7c7c9c | 204 | //pc.printf("Check 3:\r\n"); |
Josahty | 0:6942f0e2198c | 205 | // stop motors |
Josahty | 0:6942f0e2198c | 206 | // stop(); |
Josahty | 0:6942f0e2198c | 207 | // calibrate motors |
Josahty | 3:cd6e2d7c7c9c | 208 | //Calibrate(); |
Josahty | 0:6942f0e2198c | 209 | } |
Josahty | 0:6942f0e2198c | 210 | |
Josahty | 3:cd6e2d7c7c9c | 211 | |
Josahty | 3:cd6e2d7c7c9c | 212 | |
Josahty | 3:cd6e2d7c7c9c | 213 | |
Josahty | 3:cd6e2d7c7c9c | 214 | float DumpTruck::setTruckDistance(){ |
Josahty | 3:cd6e2d7c7c9c | 215 | // terminal prompt for distance |
Josahty | 3:cd6e2d7c7c9c | 216 | pc.printf("Please enter the truck distance:\r\n"); |
Josahty | 3:cd6e2d7c7c9c | 217 | // sets return value to given value |
Josahty | 4:2f1a0f628875 | 218 | //float input = pc.getc(); |
Josahty | 4:2f1a0f628875 | 219 | //input = input - 48; |
Josahty | 3:cd6e2d7c7c9c | 220 | // returns value |
Josahty | 4:2f1a0f628875 | 221 | //return input; |
simplyellow | 10:cf77da9be0b8 | 222 | |
Josahty | 4:2f1a0f628875 | 223 | char c; |
simplyellow | 10:cf77da9be0b8 | 224 | char buffer[128]; |
Josahty | 4:2f1a0f628875 | 225 | pc.gets(buffer, 4); |
Josahty | 4:2f1a0f628875 | 226 | float input = strtod(buffer,NULL); |
Josahty | 3:cd6e2d7c7c9c | 227 | return input; |
simplyellow | 10:cf77da9be0b8 | 228 | |
Josahty | 3:cd6e2d7c7c9c | 229 | } |
Josahty | 3:cd6e2d7c7c9c | 230 | |
Josahty | 0:6942f0e2198c | 231 | float DumpTruck::setTruckSpeed(){ |
Josahty | 4:2f1a0f628875 | 232 | // float mod = 0; |
Josahty | 4:2f1a0f628875 | 233 | // float div = 10; |
Josahty | 4:2f1a0f628875 | 234 | // pc.printf("Enter a direction - 1 = forward, 0 = backward:\r\n"); |
Josahty | 4:2f1a0f628875 | 235 | // float dir = pc.getc(); |
Josahty | 4:2f1a0f628875 | 236 | // while ((dir<48)||(dir>49)){ |
Josahty | 4:2f1a0f628875 | 237 | // pc.printf("Invalid input. Please enter a valid direction, 1 or 0: \r\n"); |
Josahty | 4:2f1a0f628875 | 238 | // dir = pc.getc(); |
Josahty | 4:2f1a0f628875 | 239 | // } |
Josahty | 4:2f1a0f628875 | 240 | // if (dir == 48) { |
Josahty | 4:2f1a0f628875 | 241 | // mod = -1; } |
Josahty | 4:2f1a0f628875 | 242 | // else { |
simplyellow | 10:cf77da9be0b8 | 243 | // mod = 1; } |
simplyellow | 10:cf77da9be0b8 | 244 | // |
Josahty | 4:2f1a0f628875 | 245 | // // terminal prompt for speed |
Josahty | 4:2f1a0f628875 | 246 | // pc.printf("Please enter a truck speed from 0-9 or F for full speed:\r\n"); |
Josahty | 4:2f1a0f628875 | 247 | // // sets return value to given value |
Josahty | 4:2f1a0f628875 | 248 | // float input = pc.getc(); |
Josahty | 4:2f1a0f628875 | 249 | // while ((input<48)||(input>57)){ |
Josahty | 4:2f1a0f628875 | 250 | // if((input == 70) || (input == 102)) { |
Josahty | 4:2f1a0f628875 | 251 | // input = 1; |
Josahty | 4:2f1a0f628875 | 252 | // input = input * mod; |
Josahty | 4:2f1a0f628875 | 253 | // return input; |
Josahty | 4:2f1a0f628875 | 254 | // } |
Josahty | 4:2f1a0f628875 | 255 | // pc.printf("Invalid input. Please enter a valid speed from 0-9 or F: \r\n"); |
Josahty | 4:2f1a0f628875 | 256 | // input = pc.getc(); |
Josahty | 4:2f1a0f628875 | 257 | // } |
Josahty | 4:2f1a0f628875 | 258 | // input = input - 48; |
Josahty | 4:2f1a0f628875 | 259 | // input = input * (1/div); |
Josahty | 4:2f1a0f628875 | 260 | // // returns value |
Josahty | 4:2f1a0f628875 | 261 | // input = input * mod; |
simplyellow | 10:cf77da9be0b8 | 262 | |
simplyellow | 10:cf77da9be0b8 | 263 | |
simplyellow | 10:cf77da9be0b8 | 264 | pc.printf("Enter a speed from -10 to +10:\r\n"); |
Josahty | 4:2f1a0f628875 | 265 | char c; |
simplyellow | 10:cf77da9be0b8 | 266 | char buffer[128]; |
Josahty | 4:2f1a0f628875 | 267 | pc.gets(buffer, 4); |
Josahty | 4:2f1a0f628875 | 268 | float input = strtod(buffer,NULL); |
simplyellow | 10:cf77da9be0b8 | 269 | |
Josahty | 4:2f1a0f628875 | 270 | while ((buffer[0] < 43) || (buffer[0] > 45)) { |
Josahty | 4:2f1a0f628875 | 271 | pc.printf("Invalid input. Please correct input and try again:\r\n"); |
Josahty | 4:2f1a0f628875 | 272 | setTruckSpeed(); |
Josahty | 4:2f1a0f628875 | 273 | } |
simplyellow | 10:cf77da9be0b8 | 274 | |
Josahty | 4:2f1a0f628875 | 275 | pc.printf("buffer[0]: %d\r\n",buffer[0]); |
Josahty | 4:2f1a0f628875 | 276 | pc.printf("buffer[1]: %d\r\n",buffer[1]); |
Josahty | 4:2f1a0f628875 | 277 | pc.printf("buffer[2]: %d\r\n",buffer[2]); |
Josahty | 4:2f1a0f628875 | 278 | input = input / 10; |
Josahty | 4:2f1a0f628875 | 279 | |
Josahty | 4:2f1a0f628875 | 280 | return input;} |
simplyellow | 10:cf77da9be0b8 | 281 | |
simplyellow | 10:cf77da9be0b8 | 282 | |
Josahty | 0:6942f0e2198c | 283 | void DumpTruck::stop(){ |
Josahty | 2:7811df5a6052 | 284 | pc.printf("Truck will now stop.\r\n"); |
Josahty | 0:6942f0e2198c | 285 | //stop motors |
Josahty | 0:6942f0e2198c | 286 | DrivePin = 0; |
Josahty | 0:6942f0e2198c | 287 | } |
simplyellow | 10:cf77da9be0b8 | 288 | |
Josahty | 3:cd6e2d7c7c9c | 289 | float DumpTruck::getDistance() { |
Josahty | 3:cd6e2d7c7c9c | 290 | //while(1){ |
Josahty | 3:cd6e2d7c7c9c | 291 | pulseCount = (float) wheel.getPulses(); |
Josahty | 3:cd6e2d7c7c9c | 292 | travelled = pulseCount*d/encoding/20/68; |
Josahty | 3:cd6e2d7c7c9c | 293 | wait(0.1); |
Josahty | 3:cd6e2d7c7c9c | 294 | //pc.printf("Inches travelled: %f\n\r", travelled); |
Josahty | 3:cd6e2d7c7c9c | 295 | return travelled; |
Josahty | 3:cd6e2d7c7c9c | 296 | //(pulse count / X * N) * (1 / PPI) |
simplyellow | 10:cf77da9be0b8 | 297 | |
Josahty | 3:cd6e2d7c7c9c | 298 | //} |
simplyellow | 10:cf77da9be0b8 | 299 | }*/ |
Josahty | 0:6942f0e2198c | 300 | |
simplyellow | 10:cf77da9be0b8 | 301 | //void DumpTruck::RotateTo() { |
Josahty | 0:6942f0e2198c | 302 | // pc.printf("Desired Angle: "); |
Josahty | 0:6942f0e2198c | 303 | // DesiredPivotAngle = pc.getc(); |
Josahty | 0:6942f0e2198c | 304 | // float CurrentPivotAngle = getPivotAngle(); |
Josahty | 0:6942f0e2198c | 305 | // Difference = DesiredPivotAngle-CurrentPivotAngle; |
Josahty | 0:6942f0e2198c | 306 | // if (Difference > limit) |
Josahty | 0:6942f0e2198c | 307 | // { |
Josahty | 0:6942f0e2198c | 308 | // PivotSpeed = setPivotSpeed(); |
Josahty | 0:6942f0e2198c | 309 | // pc.printf("Rotating to %s /n", DesiredPivotAngle); |
Josahty | 0:6942f0e2198c | 310 | // //Drive Motors |
Josahty | 0:6942f0e2198c | 311 | // } |
Josahty | 0:6942f0e2198c | 312 | // else |
Josahty | 0:6942f0e2198c | 313 | // {stop()} |
Josahty | 0:6942f0e2198c | 314 | // |
simplyellow | 10:cf77da9be0b8 | 315 | //} |
simplyellow | 10:cf77da9be0b8 | 316 | // |
simplyellow | 10:cf77da9be0b8 | 317 | //void DumpTruck::BedDown() { |
Josahty | 0:6942f0e2198c | 318 | // SwitchState = bool GetBedUpperSwitch(); |
Josahty | 0:6942f0e2198c | 319 | // if SwitchState |
Josahty | 0:6942f0e2198c | 320 | // {return 0;} |
Josahty | 0:6942f0e2198c | 321 | // else |
Josahty | 0:6942f0e2198c | 322 | // |
Josahty | 0:6942f0e2198c | 323 | // while(SwitchState == 0) |
Josahty | 0:6942f0e2198c | 324 | // { |
Josahty | 0:6942f0e2198c | 325 | // //driveMotor |
Josahty | 0:6942f0e2198c | 326 | // } |
Josahty | 0:6942f0e2198c | 327 | // calibrate(); |
simplyellow | 10:cf77da9be0b8 | 328 | // } |
Josahty | 0:6942f0e2198c | 329 | //void DumpTruck::LowerBed() { |
Josahty | 0:6942f0e2198c | 330 | // SwitchState = bool GetLowerUpperSwitch(); |
Josahty | 0:6942f0e2198c | 331 | // if SwitchState |
Josahty | 0:6942f0e2198c | 332 | // {return 0;} |
Josahty | 0:6942f0e2198c | 333 | // else |
Josahty | 0:6942f0e2198c | 334 | // |
Josahty | 0:6942f0e2198c | 335 | // while(SwitchState == 0) |
Josahty | 0:6942f0e2198c | 336 | // { |
Josahty | 0:6942f0e2198c | 337 | // //driveMotor |
Josahty | 0:6942f0e2198c | 338 | // } |
Josahty | 0:6942f0e2198c | 339 | // calibrate(); |
Josahty | 0:6942f0e2198c | 340 | // } |
Josahty | 0:6942f0e2198c | 341 | //} |
simplyellow | 10:cf77da9be0b8 | 342 | //void DumpTruck::raiseTo(int angle) { |
Josahty | 0:6942f0e2198c | 343 | // pc.printf("Desired Angle: "); |
Josahty | 0:6942f0e2198c | 344 | // DesiredBedAngle = pc.getc(); |
Josahty | 0:6942f0e2198c | 345 | // float CurrentBedAngle = getBedAngle(); |
Josahty | 0:6942f0e2198c | 346 | // Difference = DesiredBedAngle-CurrentBedAngle; |
Josahty | 0:6942f0e2198c | 347 | // if (Difference > limit) |
Josahty | 0:6942f0e2198c | 348 | // { |
Josahty | 0:6942f0e2198c | 349 | // BedSpeed = setBedSpeed(); |
Josahty | 0:6942f0e2198c | 350 | // pc.printf("Rotating to %s /n", DesiredBedAngle); |
Josahty | 0:6942f0e2198c | 351 | // //Drive Motors |
Josahty | 0:6942f0e2198c | 352 | // } |
Josahty | 0:6942f0e2198c | 353 | // else |
Josahty | 0:6942f0e2198c | 354 | // {stop()} |
simplyellow | 10:cf77da9be0b8 | 355 | //} |
Josahty | 0:6942f0e2198c | 356 | // |
Josahty | 0:6942f0e2198c | 357 | //float DumpTruck::getPivotAngle(){ |
Josahty | 0:6942f0e2198c | 358 | // float input = AnalogIn(x); |
Josahty | 0:6942f0e2198c | 359 | // return input |
Josahty | 0:6942f0e2198c | 360 | // } |
Josahty | 0:6942f0e2198c | 361 | //float DumpTruck::setPivotSpeed(){ |
Josahty | 0:6942f0e2198c | 362 | // pc.printf("Please enter the Pivot speed /n"); |
Josahty | 0:6942f0e2198c | 363 | // float input = pc.getc(); |
Josahty | 0:6942f0e2198c | 364 | // return input; |
Josahty | 0:6942f0e2198c | 365 | // } |
Josahty | 0:6942f0e2198c | 366 | // |
Josahty | 0:6942f0e2198c | 367 | //float DumpTruck::setBedSpeed(){ |
Josahty | 0:6942f0e2198c | 368 | // pc.printf("Please enter the Bed speed /n"); |
Josahty | 0:6942f0e2198c | 369 | // float input = pc.getc(); |
Josahty | 0:6942f0e2198c | 370 | // return input; |
Josahty | 0:6942f0e2198c | 371 | // } |
Josahty | 0:6942f0e2198c | 372 | //float DumpTruck::getBedAngle(){ |
Josahty | 0:6942f0e2198c | 373 | // float input = AnalogIn(x); // data from potentiometer |
Josahty | 0:6942f0e2198c | 374 | // return input; |
Josahty | 0:6942f0e2198c | 375 | // } |
simplyellow | 10:cf77da9be0b8 | 376 | // |