
Robot code for searching an object and charging at it.
Dependencies: HCSR04 Motor mbed
Diff: main.cpp
- Revision:
- 30:8a5570b2de68
- Parent:
- 29:977f47331d85
- Child:
- 32:775eec44ba4f
--- a/main.cpp Sun Jun 07 17:34:17 2015 +0000 +++ b/main.cpp Sun Jun 07 18:35:04 2015 +0000 @@ -33,7 +33,7 @@ // -1 - if line detected from the back // // reverse(speed) -// - reverses the robot with moveforwardspeed in same position +// - reverses the robot with forwardspeed in same position // // stop() // - stops the robot @@ -55,20 +55,27 @@ //Serial pc(USBTX, USBRX); // Global parameters -// Speed at which it move_forwards an object -// optimum value: 0.4 to 0.8 -float moveforwardspeed; -// Speed at which it rotates to find an object -// optimum value: 0.3 to 0.5 + +float forwardspeed; +float reversespeed; float searchspeed; -// Range of detection -// optimum value: 30 to 50 unsigned int range; void initialise() { - moveforwardspeed = 0.6; + // Each speed value can be set from 0 to 1 + + // Speed at which it moves forward + // optimum value: 0.5 to 0.8 + forwardspeed = 0.6; + // Speed at which it reverses + // optimum value: 0.4 to 0.6 + reversespeed = 0.5; + // Speed at which it rotates to find an object + // optimum value: 0.4 to 0.6 searchspeed = 0.5; + // Range of detection + // optimum value: 30 to 50 range = 30; // Wait for 5 seconds to move away from robot @@ -98,7 +105,7 @@ if (detect_o == 1) { - move_forward(moveforwardspeed); + move_forward(forwardspeed); while (true) { @@ -107,7 +114,7 @@ if(detect_l == 1 || detect_l == -1) { stop(); turn_led_right(); - reverse(searchspeed); + reverse(reversespeed); wait(1.5); detect_l = 0; break;