ft. button press reset
Dependencies: mbed
Fork of BeaconDemo_RobotCodeNew by
Diff: programs.cpp
- Revision:
- 19:b5788427db67
- Parent:
- 16:976a1d0ea897
- Child:
- 22:3643fc1c82b6
--- a/programs.cpp Thu Feb 23 09:51:40 2017 +0000 +++ b/programs.cpp Wed Mar 01 15:23:47 2017 +0000 @@ -725,6 +725,59 @@ } +// mock flocking program + +void mockFlocking() +{ + float left_motor_speed = 0.5; + float right_motor_speed = 0.5; + char buffer[255]; + + + if (reflected_sensor_data[0] > 300){ + left_motor_speed = -0.5; + set_left_motor_speed(left_motor_speed); + set_right_motor_speed(right_motor_speed); + } + else if (reflected_sensor_data[7] > 300){ + right_motor_speed = -0.5; + set_left_motor_speed(left_motor_speed); + set_right_motor_speed(right_motor_speed); + } + else if (robot_id == 1) { + display.clear_display(); + display.set_position(0,0); + display.write_string("my Id is 1!"); + float left_motor_speed = 0.3; + float right_motor_speed = 0.3; + int turnChance = rand() %100; + if (turnChance < 20) { + left_motor_speed = 0; + } else if (turnChance > 80) { + right_motor_speed = 0; + } + + set_left_motor_speed(left_motor_speed); + set_right_motor_speed(right_motor_speed); + } + else { + + if (abs(robots_heading[1]) > 40 && robots_found[1] == 1) { + time_based_turn_degrees(1, robots_heading[1], 1); + sprintf(buffer,"%d > 40", robots_heading[1]); + display.clear_display(); + display.set_position(0,0); + display.write_string(buffer); + } + else { + //used for time based turn instead of location based + set_left_motor_speed(left_motor_speed); + set_right_motor_speed(right_motor_speed); + } + } + +} + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// generic_program - Framework for building typical programs