
ft. button press reset
Dependencies: mbed
Fork of BeaconDemo_RobotCodeNew by
Diff: beacon.cpp
- Revision:
- 10:1b09d4bb847b
- Parent:
- 9:085e090e1ec1
- Child:
- 11:7b3ee540ba56
--- a/beacon.cpp Mon Oct 26 11:16:05 2015 +0000 +++ b/beacon.cpp Mon Oct 26 23:58:08 2015 +0000 @@ -5,7 +5,6 @@ // Beacon.cpp - Functions for detecting the beacon and taking IR readings of the robots -#include "psiswarm.h" #include "main.h" int pulse_step = 1; //Pulse-step corresponds to which timeslot (0-9) is currently active, where beacon=0 and robots=2-8 @@ -17,7 +16,7 @@ Timeout ir_emitter_timeout; // Timeout for turning off the IR emitters after 40ms Timer beacon_debug_timer; // Timer for debug information only [remove later?] - +char show_ir_debug_info = 0; // Set to 1 to display (via PC) the list of IR readings & visible robots every timestep /// The locate beacon function samples the IR radiation from all 8 side sensors over a period of 1 second in [BEACON_PERIOD / 2.5] (20ms) blocks. /// The infrared beacon is set to give a 50ms burst of IR every 500ms. We should thus see in the sampled radiation 2 blocks @@ -264,7 +263,7 @@ //It then starts a timeout to run emitter_timeout_block after 40ms, which turns off the emitters void emitter_ticker_block(){ //If the time-step (-1) equals my ID, turn on my emitters for 40ms - if(pulse_step-1 == robot_id){ + if(pulse_step-1 == robot_id && disable_ir_emitters == 0){ IF_set_IR_emitter_output(0, 1); IF_set_IR_emitter_output(1, 1); ir_emitter_timeout.attach_us(emitter_timeout_block,(BEACON_PERIOD * 8)/10); @@ -321,7 +320,7 @@ } } } - display_ir_readings(); + if(show_ir_debug_info == 1)display_ir_readings(); } //Increment pulse step pulse_step++; @@ -361,6 +360,8 @@ int current_bearing = 360 - beacon_heading; //Now work out turn needed to face intended heading int target_turn = (bearing - current_bearing) % 360; + //Adjust to take 10% off turn, stops overshoot + target_turn = (target_turn * 9) / 10; if(target_turn > 180) target_turn -= 360; if(target_turn < -180) target_turn += 360; //We can't reliably turn more than 280 degrees per second, so set a limit for the turn to that