Tobis Programm forked to not destroy your golden files
Fork of Robocode by
source/Positioning.cpp@34:40d8d29b44b8, 2017-03-29 (annotated)
- Committer:
- cittecla
- Date:
- Wed Mar 29 12:10:32 2017 +0000
- Revision:
- 34:40d8d29b44b8
- Parent:
- source/positioning.cpp@33:8a98f8b9d859
- Child:
- 38:3526c36e4c73
update
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 | 34:40d8d29b44b8 | 7 | #include "Pathfinding.h" |
cittecla | 34:40d8d29b44b8 | 8 | #include "IRSensor.h" |
cittecla | 33:8a98f8b9d859 | 9 | |
cittecla | 33:8a98f8b9d859 | 10 | position current_pos; |
cittecla | 12:91c2e07d2b5b | 11 | |
cittecla | 34:40d8d29b44b8 | 12 | position get_current_pos() |
cittecla | 33:8a98f8b9d859 | 13 | { |
cittecla | 33:8a98f8b9d859 | 14 | return current_pos; |
cittecla | 33:8a98f8b9d859 | 15 | } |
cittecla | 34:40d8d29b44b8 | 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 | } |
cittecla | 34:40d8d29b44b8 | 59 | */ |