![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Code to run the microcontrollers on the R5 competition bot
Dependencies: LineSensors mbed
DriveController.h@2:d0ce8e26cbc4, 2014-10-03 (annotated)
- Committer:
- Hypna
- Date:
- Fri Oct 03 03:48:39 2014 +0000
- Revision:
- 2:d0ce8e26cbc4
- Parent:
- 1:fa6eb0c33b2f
- Child:
- 3:0d7687b6ef14
a little more
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Hypna | 0:e60f22c1d573 | 1 | #ifndef DRIVECONTROLLER_H |
Hypna | 0:e60f22c1d573 | 2 | #define DRIVECONTROLLER_H |
Hypna | 0:e60f22c1d573 | 3 | #include "mbed.h" |
Hypna | 0:e60f22c1d573 | 4 | |
Hypna | 0:e60f22c1d573 | 5 | enum Direction |
Hypna | 0:e60f22c1d573 | 6 | { |
Hypna | 2:d0ce8e26cbc4 | 7 | North, South, East, West; |
Hypna | 2:d0ce8e26cbc4 | 8 | }; |
Hypna | 2:d0ce8e26cbc4 | 9 | |
Hypna | 2:d0ce8e26cbc4 | 10 | struct Command |
Hypna | 2:d0ce8e26cbc4 | 11 | { |
Hypna | 2:d0ce8e26cbc4 | 12 | Direction direction = NORTH; |
Hypna | 2:d0ce8e26cbc4 | 13 | int distance; |
Hypna | 0:e60f22c1d573 | 14 | }; |
Hypna | 0:e60f22c1d573 | 15 | |
Hypna | 0:e60f22c1d573 | 16 | class DriveController |
Hypna | 0:e60f22c1d573 | 17 | { |
Hypna | 0:e60f22c1d573 | 18 | private: |
Hypna | 2:d0ce8e26cbc4 | 19 | DigitalOut wheels[4] = {{PTC1}, {PTC2}, {PTE29}, {PTE30}}; |
Hypna | 2:d0ce8e26cbc4 | 20 | |
Hypna | 2:d0ce8e26cbc4 | 21 | DigitalIn sensors[24] = {{PTC7}, {PTC0}, {PTC3}, {PTC4}, {PTC5}, {PTC6}, {PTC10}, {PTC11}, {PTC9}, |
Hypna | 2:d0ce8e26cbc4 | 22 | {PTC8}, {PTA5}, {PTA4}, {PTA12}, {PTD4}, {PTA2}, {PTA1}, {PTC12}, {PTC13}, {PTC16}, {PTC17}, |
Hypna | 2:d0ce8e26cbc4 | 23 | {PTD2}, {PTD0}, {PTD5}, {PTD13}}; |
Hypna | 2:d0ce8e26cbc4 | 24 | |
Hypna | 2:d0ce8e26cbc4 | 25 | bool sensorStates[24] = {false}; |
Hypna | 2:d0ce8e26cbc4 | 26 | |
Hypna | 2:d0ce8e26cbc4 | 27 | Direction orientation; |
Hypna | 0:e60f22c1d573 | 28 | |
Hypna | 2:d0ce8e26cbc4 | 29 | Command command; |
Hypna | 0:e60f22c1d573 | 30 | |
Hypna | 2:d0ce8e26cbc4 | 31 | void move(); |
Hypna | 2:d0ce8e26cbc4 | 32 | void getCommand(); |
Hypna | 2:d0ce8e26cbc4 | 33 | void rotate(); |
Hypna | 2:d0ce8e26cbc4 | 34 | void forward(); |
Hypna | 0:e60f22c1d573 | 35 | void readSensors(); |
Hypna | 2:d0ce8e26cbc4 | 36 | double calculateError(); |
Hypna | 2:d0ce8e26cbc4 | 37 | bool intersection(); |
Hypna | 0:e60f22c1d573 | 38 | |
Hypna | 0:e60f22c1d573 | 39 | public: |
Hypna | 2:d0ce8e26cbc4 | 40 | DriveController(); |
Hypna | 0:e60f22c1d573 | 41 | void go(); |
Hypna | 0:e60f22c1d573 | 42 | }; |
Hypna | 0:e60f22c1d573 | 43 | |
Hypna | 0:e60f22c1d573 | 44 | #endif |