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.h@15:a4bbdde8ed69, 2017-04-25 (annotated)
- Committer:
- simplyellow
- Date:
- Tue Apr 25 20:54:15 2017 +0000
- Revision:
- 15:a4bbdde8ed69
- Parent:
- 14:fd6090cddc2e
- Child:
- 16:6530f62dd28b
added more comments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pvela | 6:5cc6a9b6f60e | 1 | /** |
pvela | 6:5cc6a9b6f60e | 2 | * @file DumpTruck.h |
pvela | 6:5cc6a9b6f60e | 3 | * |
simplyellow | 10:cf77da9be0b8 | 4 | * @brief DumpTruck class integrates multiple sensors into one API. |
pvela | 6:5cc6a9b6f60e | 5 | * |
pvela | 6:5cc6a9b6f60e | 6 | * @author Terrabots Team |
pvela | 6:5cc6a9b6f60e | 7 | * |
pvela | 6:5cc6a9b6f60e | 8 | */ |
pvela | 6:5cc6a9b6f60e | 9 | |
Josahty | 0:6942f0e2198c | 10 | #ifndef MBED_DUMP_TRUCK_H |
Josahty | 0:6942f0e2198c | 11 | #define MBED_DUMP_TRUCK_H |
simplyellow | 10:cf77da9be0b8 | 12 | |
Josahty | 0:6942f0e2198c | 13 | #include "mbed.h" |
simplyellow | 10:cf77da9be0b8 | 14 | #include "Tracker.h" |
simplyellow | 10:cf77da9be0b8 | 15 | //#include "IMU.h" |
simplyellow | 10:cf77da9be0b8 | 16 | #include "Motor.h" |
simplyellow | 12:502cf4fc6d98 | 17 | #include "nRF24L01P.h" //Transceiver library |
simplyellow | 10:cf77da9be0b8 | 18 | #include "SRF05.h" |
simplyellow | 14:fd6090cddc2e | 19 | #include "commands.h" |
simplyellow | 13:112b6543909a | 20 | |
simplyellow | 12:502cf4fc6d98 | 21 | #define TRANSFER_SIZE 8 |
simplyellow | 12:502cf4fc6d98 | 22 | |
simplyellow | 14:fd6090cddc2e | 23 | |
simplyellow | 10:cf77da9be0b8 | 24 | // ADD SWITCHES & ULTRASONIC SENSOR implementation |
Josahty | 0:6942f0e2198c | 25 | |
pvela | 7:dd3a7dcc5c84 | 26 | /** |
pvela | 7:dd3a7dcc5c84 | 27 | * @class DumpTruck |
pvela | 7:dd3a7dcc5c84 | 28 | * |
simplyellow | 10:cf77da9be0b8 | 29 | * @brief Interface for controlling a Dump truck. |
pvela | 7:dd3a7dcc5c84 | 30 | */ |
simplyellow | 10:cf77da9be0b8 | 31 | |
Josahty | 0:6942f0e2198c | 32 | class DumpTruck { |
Josahty | 0:6942f0e2198c | 33 | public: |
pvela | 6:5cc6a9b6f60e | 34 | /** |
simplyellow | 10:cf77da9be0b8 | 35 | * Constructor for the Tracker object. |
pvela | 6:5cc6a9b6f60e | 36 | * |
simplyellow | 10:cf77da9be0b8 | 37 | * @param[in] truckId The dump truck's identifier |
pvela | 6:5cc6a9b6f60e | 38 | */ |
Josahty | 0:6942f0e2198c | 39 | DumpTruck(int truckId); |
pvela | 6:5cc6a9b6f60e | 40 | |
simplyellow | 12:502cf4fc6d98 | 41 | /* |
simplyellow | 15:a4bbdde8ed69 | 42 | * Process command, parsing it and calling the associated function. |
simplyellow | 13:112b6543909a | 43 | */ |
simplyellow | 13:112b6543909a | 44 | void processCommand(); |
simplyellow | 13:112b6543909a | 45 | |
simplyellow | 13:112b6543909a | 46 | /* |
simplyellow | 15:a4bbdde8ed69 | 47 | * Send not acknowledge to base station. |
simplyellow | 13:112b6543909a | 48 | */ |
simplyellow | 13:112b6543909a | 49 | |
simplyellow | 13:112b6543909a | 50 | void sendNack(); |
simplyellow | 13:112b6543909a | 51 | |
simplyellow | 13:112b6543909a | 52 | /* |
simplyellow | 15:a4bbdde8ed69 | 53 | * Send acknowledge to base station. |
simplyellow | 13:112b6543909a | 54 | */ |
simplyellow | 13:112b6543909a | 55 | |
simplyellow | 13:112b6543909a | 56 | void sendAck(); |
simplyellow | 13:112b6543909a | 57 | |
simplyellow | 13:112b6543909a | 58 | /* |
simplyellow | 15:a4bbdde8ed69 | 59 | * Initialize transceiver and other miscellaneous devices. |
simplyellow | 12:502cf4fc6d98 | 60 | */ |
simplyellow | 12:502cf4fc6d98 | 61 | void startComms(); |
simplyellow | 12:502cf4fc6d98 | 62 | |
simplyellow | 12:502cf4fc6d98 | 63 | /* |
simplyellow | 12:502cf4fc6d98 | 64 | * Receive a command from base station. |
simplyellow | 12:502cf4fc6d98 | 65 | */ |
simplyellow | 12:502cf4fc6d98 | 66 | void getCommand(); |
simplyellow | 12:502cf4fc6d98 | 67 | |
simplyellow | 12:502cf4fc6d98 | 68 | /* |
simplyellow | 12:502cf4fc6d98 | 69 | * Send important data back to the base station. |
simplyellow | 12:502cf4fc6d98 | 70 | */ |
simplyellow | 12:502cf4fc6d98 | 71 | void reportData(); |
simplyellow | 12:502cf4fc6d98 | 72 | |
simplyellow | 10:cf77da9be0b8 | 73 | // motor functions |
simplyellow | 10:cf77da9be0b8 | 74 | /* |
simplyellow | 10:cf77da9be0b8 | 75 | * Drive a certain distance at a desired speed. |
simplyellow | 10:cf77da9be0b8 | 76 | */ |
simplyellow | 14:fd6090cddc2e | 77 | void driveDistance();// frontMotor |
simplyellow | 10:cf77da9be0b8 | 78 | /* |
simplyellow | 10:cf77da9be0b8 | 79 | * Drive at a desired speed. |
pvela | 6:5cc6a9b6f60e | 80 | */ |
simplyellow | 14:fd6090cddc2e | 81 | void drive(); |
simplyellow | 10:cf77da9be0b8 | 82 | /* |
simplyellow | 10:cf77da9be0b8 | 83 | * Turn the rear wheels a certain angle. |
pvela | 6:5cc6a9b6f60e | 84 | */ |
simplyellow | 14:fd6090cddc2e | 85 | void turn(); // turnMotor |
simplyellow | 10:cf77da9be0b8 | 86 | /* |
simplyellow | 10:cf77da9be0b8 | 87 | * Move the dump truck's bed up/down a certain angle. |
pvela | 6:5cc6a9b6f60e | 88 | */ |
simplyellow | 14:fd6090cddc2e | 89 | void moveBed(); // bedMotor |
simplyellow | 10:cf77da9be0b8 | 90 | /* |
simplyellow | 10:cf77da9be0b8 | 91 | * Stop driving. |
simplyellow | 10:cf77da9be0b8 | 92 | */ |
simplyellow | 14:fd6090cddc2e | 93 | void stopDrive(); // all Motors |
simplyellow | 13:112b6543909a | 94 | |
simplyellow | 13:112b6543909a | 95 | /* |
simplyellow | 13:112b6543909a | 96 | * Stop turning. |
simplyellow | 13:112b6543909a | 97 | */ |
simplyellow | 14:fd6090cddc2e | 98 | void stopTurn(); // all Motors |
simplyellow | 15:a4bbdde8ed69 | 99 | |
simplyellow | 15:a4bbdde8ed69 | 100 | /* |
simplyellow | 15:a4bbdde8ed69 | 101 | * Stop all motors if an object comes within range of the |
simplyellow | 15:a4bbdde8ed69 | 102 | * ultrasonic sensor |
simplyellow | 15:a4bbdde8ed69 | 103 | */ |
simplyellow | 15:a4bbdde8ed69 | 104 | void detectStop(); |
simplyellow | 13:112b6543909a | 105 | |
simplyellow | 13:112b6543909a | 106 | /* |
simplyellow | 13:112b6543909a | 107 | * Stop bed. |
simplyellow | 13:112b6543909a | 108 | */ |
simplyellow | 14:fd6090cddc2e | 109 | void stopBed(); // all Motors |
pvela | 6:5cc6a9b6f60e | 110 | |
simplyellow | 10:cf77da9be0b8 | 111 | // ultrasonic functions |
simplyellow | 10:cf77da9be0b8 | 112 | /* |
simplyellow | 10:cf77da9be0b8 | 113 | * Read from the ultrasonic sensor and determine the dump truck's |
simplyellow | 10:cf77da9be0b8 | 114 | * proximity from objects. |
pvela | 6:5cc6a9b6f60e | 115 | */ |
simplyellow | 10:cf77da9be0b8 | 116 | bool detect(); // returns bool for object too close |
simplyellow | 13:112b6543909a | 117 | |
simplyellow | 13:112b6543909a | 118 | int txDataCnt; |
simplyellow | 13:112b6543909a | 119 | int rxDataCnt; |
simplyellow | 13:112b6543909a | 120 | char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; |
simplyellow | 13:112b6543909a | 121 | char acked[TRANSFER_SIZE]; |
simplyellow | 13:112b6543909a | 122 | char nacked[TRANSFER_SIZE]; |
simplyellow | 13:112b6543909a | 123 | bool received; |
simplyellow | 14:fd6090cddc2e | 124 | int numCommands; |
simplyellow | 14:fd6090cddc2e | 125 | int commandValue; |
simplyellow | 14:fd6090cddc2e | 126 | typedef void (DumpTruck::*funcArray)(void); |
simplyellow | 14:fd6090cddc2e | 127 | funcArray commArr[sizeof(commands)/sizeof(*commands)]; |
simplyellow | 15:a4bbdde8ed69 | 128 | float zeroAngle; |
simplyellow | 15:a4bbdde8ed69 | 129 | bool interrupted; |
simplyellow | 14:fd6090cddc2e | 130 | |
simplyellow | 14:fd6090cddc2e | 131 | protected: |
simplyellow | 10:cf77da9be0b8 | 132 | Tracker *track; |
simplyellow | 10:cf77da9be0b8 | 133 | //IMU *bed; |
simplyellow | 10:cf77da9be0b8 | 134 | Motor *frontMotor; |
simplyellow | 10:cf77da9be0b8 | 135 | Motor *turnMotor; |
simplyellow | 10:cf77da9be0b8 | 136 | Motor *bedMotor; |
simplyellow | 12:502cf4fc6d98 | 137 | nRF24L01P *nrf; //Transceiver *nrf; |
simplyellow | 10:cf77da9be0b8 | 138 | SRF05 *srf; |
simplyellow | 15:a4bbdde8ed69 | 139 | AnalogIn *pot; |
simplyellow | 10:cf77da9be0b8 | 140 | |
simplyellow | 10:cf77da9be0b8 | 141 | // add direct control for motor, switch, and ultrasonic sensor. |
simplyellow | 10:cf77da9be0b8 | 142 | |
Josahty | 0:6942f0e2198c | 143 | int truckNumber; |
simplyellow | 10:cf77da9be0b8 | 144 | |
simplyellow | 10:cf77da9be0b8 | 145 | // motor variables |
simplyellow | 10:cf77da9be0b8 | 146 | float speed; // drive |
simplyellow | 10:cf77da9be0b8 | 147 | float distance; // drive |
simplyellow | 10:cf77da9be0b8 | 148 | float potAngle; // turn |
simplyellow | 10:cf77da9be0b8 | 149 | float bedAngle; // bed |
simplyellow | 10:cf77da9be0b8 | 150 | |
simplyellow | 10:cf77da9be0b8 | 151 | // bed-specific variables |
simplyellow | 10:cf77da9be0b8 | 152 | bool switchState; // BusIn the two limit switches |
simplyellow | 10:cf77da9be0b8 | 153 | |
simplyellow | 10:cf77da9be0b8 | 154 | // ultrasonic-specific variables |
simplyellow | 10:cf77da9be0b8 | 155 | bool tooClose; |
simplyellow | 10:cf77da9be0b8 | 156 | float proximity; |
simplyellow | 12:502cf4fc6d98 | 157 | |
simplyellow | 13:112b6543909a | 158 | /*int txDataCnt; |
simplyellow | 12:502cf4fc6d98 | 159 | int rxDataCnt; |
simplyellow | 12:502cf4fc6d98 | 160 | char txData[TRANSFER_SIZE], rxData[TRANSFER_SIZE]; |
simplyellow | 13:112b6543909a | 161 | bool received;*/ |
Josahty | 0:6942f0e2198c | 162 | }; |
simplyellow | 5:dc4cf6cc24b3 | 163 | #endif |