8) Avoiding Obstacles
The walking speed should now be automatically
regulated. As the ant gets closer to an obstacle, it
will gradually slow down.
By using "getSensor(L2)", for example, the
sensor value of the left mandible "L2" is
retrieved.
The measured value is divided by 8 and subtracted
from the maximum speed of 255.
By using "senseShadow(820, L1)", the sensor
value defined by "L1" is compared to a
threshold value (e.g., 820). If the threshold is
reached, the corresponding LED will light up.
You can specify 1 to 4 parameters for the
sensors. In this case, the sum of these sensor
values is compared to the threshold value.
This causes the "variAnt" to rotate one step to the
right when the left front leg "L1" is shaded, using
"stepBack(0,1)".
"senseShadow(900, L0, L2, R2)": However, if the
two mandibles (pincers) "L2, R2" or the left
antenna "L0" are shaded, the ant should take one
step back with "stepBack(1,4)" and then turn 3
steps (approximately 90°) to the right. Adjust the
parameters according to your needs.
void loop()
{
ant.update( );
ant.setSpeed(255 – ant.getSensor(L2)/8);
if(ant.senseShadow(820, L1))
ant.stepBack(0,1);
if(ant.senseShadow(820, R1))
ant.stepBack(1,0);
if(ant.senseShadow(900, L0, L2, R2))
ant.stepBack(1,4);
if(ant.senseShadow(900, R0, R2, L2))
ant.stepBack(4,1);
}
Need help?
Do you have a question about the variAnt and is the answer not in the manual?