Tobis Programm forked to not destroy your golden files
Fork of Robocode by
source/positioning.cpp@33:8a98f8b9d859, 2017-03-20 (annotated)
- Committer:
- cittecla
- Date:
- Mon Mar 20 14:11:46 2017 +0000
- Revision:
- 33:8a98f8b9d859
- Parent:
- 18:a82994e67297
Something
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cittecla | 12:91c2e07d2b5b | 1 | /** |
cittecla | 12:91c2e07d2b5b | 2 | * Positioning function library |
cittecla | 12:91c2e07d2b5b | 3 | * Handels position of the Robot on the map |
cittecla | 12:91c2e07d2b5b | 4 | **/ |
cittecla | 33:8a98f8b9d859 | 5 | |
cittecla | 12:91c2e07d2b5b | 6 | #include "mbed.h" |
cittecla | 33:8a98f8b9d859 | 7 | #include "pathfinding.h" |
cittecla | 33:8a98f8b9d859 | 8 | #include "IRsensor.h" |
cittecla | 33:8a98f8b9d859 | 9 | |
cittecla | 33:8a98f8b9d859 | 10 | position current_pos; |
cittecla | 12:91c2e07d2b5b | 11 | |
cittecla | 33:8a98f8b9d859 | 12 | void get_current_pos() |
cittecla | 33:8a98f8b9d859 | 13 | { |
cittecla | 33:8a98f8b9d859 | 14 | return current_pos; |
cittecla | 33:8a98f8b9d859 | 15 | } |
cittecla | 33:8a98f8b9d859 | 16 | |
cittecla | 33:8a98f8b9d859 | 17 | void initial_positioning() |
cittecla | 33:8a98f8b9d859 | 18 | { |
cittecla | 33:8a98f8b9d859 | 19 | float last_dist_r = 1.0f; |
cittecla | 33:8a98f8b9d859 | 20 | float last_dist_f = 1.0f; |
cittecla | 33:8a98f8b9d859 | 21 | |
cittecla | 33:8a98f8b9d859 | 22 | int deg_r = 0; |
cittecla | 33:8a98f8b9d859 | 23 | int deg_l = 0; |
cittecla | 33:8a98f8b9d859 | 24 | |
cittecla | 33:8a98f8b9d859 | 25 | turn_straight_right(); |
cittecla | 33:8a98f8b9d859 | 26 | turn_straight_left(); |
cittecla | 12:91c2e07d2b5b | 27 | |
cittecla | 33:8a98f8b9d859 | 28 | while(last_dist_r > sensors[r]) { |
cittecla | 33:8a98f8b9d859 | 29 | turn_sensor_right(1); //turn sensor + 1 deg |
cittecla | 33:8a98f8b9d859 | 30 | wait(0.1f) |
cittecla | 33:8a98f8b9d859 | 31 | deg_r += 1; |
cittecla | 33:8a98f8b9d859 | 32 | last_dist_r = sensors[r]; |
cittecla | 33:8a98f8b9d859 | 33 | } |
cittecla | 33:8a98f8b9d859 | 34 | |
cittecla | 33:8a98f8b9d859 | 35 | while(last_dist_l > sensors[l]) { |
cittecla | 33:8a98f8b9d859 | 36 | turn_sensor_left(-1); //turn sensor - 1 deg |
cittecla | 33:8a98f8b9d859 | 37 | wait(0.1f) |
cittecla | 33:8a98f8b9d859 | 38 | deg_l += 1; |
cittecla | 33:8a98f8b9d859 | 39 | last_dist_l = sensors[l]; |
cittecla | 33:8a98f8b9d859 | 40 | } |
cittecla | 33:8a98f8b9d859 | 41 | |
cittecla | 33:8a98f8b9d859 | 42 | int deg_l_2=0; |
cittecla | 33:8a98f8b9d859 | 43 | turn_straight_left(); |
cittecla | 33:8a98f8b9d859 | 44 | last_dist_l = 0; |
cittecla | 33:8a98f8b9d859 | 45 | |
cittecla | 33:8a98f8b9d859 | 46 | while(last_dist_l < sensors[l]) { |
cittecla | 33:8a98f8b9d859 | 47 | turn_sensor_left(1); //turn sensor +1 deg (positiv = uhrzeigersinn) |
cittecla | 33:8a98f8b9d859 | 48 | wait(0.1f) |
cittecla | 33:8a98f8b9d859 | 49 | deg_l_2 += 1; |
cittecla | 33:8a98f8b9d859 | 50 | last_dist_l = sensors[l]; |
cittecla | 33:8a98f8b9d859 | 51 | } |
cittecla | 33:8a98f8b9d859 | 52 | |
cittecla | 33:8a98f8b9d859 | 53 | turn_straight_right(); |
cittecla | 33:8a98f8b9d859 | 54 | turn_straight_left(); |
cittecla | 33:8a98f8b9d859 | 55 | |
cittecla | 33:8a98f8b9d859 | 56 | wait(0.2f); |
cittecla | 33:8a98f8b9d859 | 57 | |
cittecla | 14:9e2ce5880fb0 | 58 | } |