![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Code to drive Team 1's robot for the 2016 R5 robotics competition.
Dependencies: mbed navigation R5_StepperDrive LongRangeSensor DistanceSensor scanner Gripper ColorSensor
r5driver.cpp@7:056f78006270, 2015-10-30 (annotated)
- Committer:
- j_j205
- Date:
- Fri Oct 30 15:33:50 2015 +0000
- Revision:
- 7:056f78006270
- Parent:
- 3:72b652325643
- Child:
- 9:a956ba674cea
updated navigation with completed dijkstra's algo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
j_j205 | 7:056f78006270 | 1 | #include "navigation.h" |
j_j205 | 7:056f78006270 | 2 | #include "stdint.h" |
j_j205 | 2:3b162e764c9d | 3 | #include "mbed.h" |
j_j205 | 0:a3c39d3359ac | 4 | |
j_j205 | 0:a3c39d3359ac | 5 | Serial pc(USBTX, USBRX); |
j_j205 | 0:a3c39d3359ac | 6 | |
j_j205 | 0:a3c39d3359ac | 7 | int main() |
j_j205 | 0:a3c39d3359ac | 8 | { |
j_j205 | 0:a3c39d3359ac | 9 | pc.baud(115200); |
j_j205 | 0:a3c39d3359ac | 10 | |
j_j205 | 7:056f78006270 | 11 | Navigation r5nav(10); |
j_j205 | 7:056f78006270 | 12 | pc.printf("Navigation Object Created\n\n"); |
j_j205 | 7:056f78006270 | 13 | wait(0.1); |
j_j205 | 1:1958e6db41fc | 14 | |
j_j205 | 7:056f78006270 | 15 | // loading map |
j_j205 | 7:056f78006270 | 16 | r5nav.addGraphNode(0, 1, 18, 0); |
j_j205 | 7:056f78006270 | 17 | r5nav.addGraphNode(1, 0, 18, 180); |
j_j205 | 7:056f78006270 | 18 | r5nav.addGraphNode(1, 2, 7, 0); |
j_j205 | 7:056f78006270 | 19 | r5nav.addGraphNode(1, 3, 1, 90); |
j_j205 | 7:056f78006270 | 20 | r5nav.addGraphNode(2, 1, 72, 180); |
j_j205 | 7:056f78006270 | 21 | r5nav.addGraphNode(3, 1, 13, 270); |
j_j205 | 7:056f78006270 | 22 | r5nav.addGraphNode(3, 4, 12, 180); |
j_j205 | 7:056f78006270 | 23 | r5nav.addGraphNode(3, 5, 23, 0); |
j_j205 | 7:056f78006270 | 24 | r5nav.addGraphNode(4, 3, 12, 0); |
j_j205 | 7:056f78006270 | 25 | r5nav.addGraphNode(5, 3, 23, 180); |
j_j205 | 7:056f78006270 | 26 | r5nav.addGraphNode(5, 6, 37, 0); |
j_j205 | 7:056f78006270 | 27 | r5nav.addGraphNode(5, 8, 12, 90); |
j_j205 | 7:056f78006270 | 28 | r5nav.addGraphNode(6, 5, 37, 180); |
j_j205 | 7:056f78006270 | 29 | r5nav.addGraphNode(6, 7, 12, 0); |
j_j205 | 7:056f78006270 | 30 | r5nav.addGraphNode(7, 6, 12, 180); |
j_j205 | 7:056f78006270 | 31 | r5nav.addGraphNode(8, 5, 12, 270); |
j_j205 | 7:056f78006270 | 32 | r5nav.addGraphNode(8, 9, 35, 180); |
j_j205 | 7:056f78006270 | 33 | r5nav.addGraphNode(9, 8, 35, 0); |
j_j205 | 7:056f78006270 | 34 | |
j_j205 | 7:056f78006270 | 35 | const uint16_t YELLOW_VICTIM = 7; |
j_j205 | 7:056f78006270 | 36 | const uint16_t RED_VICTIM = 9; |
j_j205 | 7:056f78006270 | 37 | const uint16_t YELLOW_DROP_ZONE = 4; |
j_j205 | 7:056f78006270 | 38 | const uint16_t RED_DROP_ZONE = 2; |
j_j205 | 1:1958e6db41fc | 39 | |
j_j205 | 7:056f78006270 | 40 | pc.printf("Size of graph is %i\n", r5nav.graphSize() ); |
j_j205 | 7:056f78006270 | 41 | wait(0.1); |
j_j205 | 7:056f78006270 | 42 | |
j_j205 | 7:056f78006270 | 43 | r5nav.getShortestPath(YELLOW_VICTIM); |
j_j205 | 7:056f78006270 | 44 | pc.printf("\nDistance from 0 to YELLOW_VICTIM: %i\n", r5nav.getMinDist(YELLOW_VICTIM) ); |
j_j205 | 7:056f78006270 | 45 | pc.printf("Route:\n"); |
j_j205 | 7:056f78006270 | 46 | r5nav.printRoute(pc); |
j_j205 | 7:056f78006270 | 47 | r5nav.setVertex(YELLOW_VICTIM); |
j_j205 | 7:056f78006270 | 48 | wait(0.1); |
j_j205 | 1:1958e6db41fc | 49 | |
j_j205 | 7:056f78006270 | 50 | r5nav.getShortestPath(YELLOW_DROP_ZONE); |
j_j205 | 7:056f78006270 | 51 | pc.printf("\nDistance from %i to YELLOW_DROP_ZONE: %i\n", r5nav.getVertex(), r5nav.getMinDist(YELLOW_DROP_ZONE) ); |
j_j205 | 7:056f78006270 | 52 | pc.printf("Route:\n"); |
j_j205 | 7:056f78006270 | 53 | r5nav.printRoute(pc); |
j_j205 | 7:056f78006270 | 54 | r5nav.setVertex(YELLOW_DROP_ZONE); |
j_j205 | 7:056f78006270 | 55 | wait(0.1); |
j_j205 | 1:1958e6db41fc | 56 | |
j_j205 | 7:056f78006270 | 57 | r5nav.getShortestPath(RED_VICTIM); |
j_j205 | 7:056f78006270 | 58 | pc.printf("\nDistance from %i to RED_VICTIM: %i\n", r5nav.getVertex(), r5nav.getMinDist(RED_VICTIM) ); |
j_j205 | 7:056f78006270 | 59 | pc.printf("Route:\n"); |
j_j205 | 7:056f78006270 | 60 | r5nav.printRoute(pc); |
j_j205 | 7:056f78006270 | 61 | r5nav.setVertex(RED_VICTIM); |
j_j205 | 7:056f78006270 | 62 | wait(0.1); |
j_j205 | 1:1958e6db41fc | 63 | |
j_j205 | 7:056f78006270 | 64 | r5nav.getShortestPath(RED_DROP_ZONE); |
j_j205 | 7:056f78006270 | 65 | pc.printf("\nDistance from %i to RED_DROP_ZONE: %i\n", r5nav.getVertex(), r5nav.getMinDist(RED_DROP_ZONE) ); |
j_j205 | 7:056f78006270 | 66 | pc.printf("Route:\n"); |
j_j205 | 7:056f78006270 | 67 | r5nav.printRoute(pc); |
j_j205 | 7:056f78006270 | 68 | r5nav.setVertex(RED_DROP_ZONE); |
j_j205 | 7:056f78006270 | 69 | wait(0.1); |
j_j205 | 0:a3c39d3359ac | 70 | |
j_j205 | 0:a3c39d3359ac | 71 | return 0; |
j_j205 | 1:1958e6db41fc | 72 | } |