... | ... | @@ -97,8 +97,58 @@ The trigger condition for the `Avoid` class is that the `frontDistance`, which i |
|
|
|
|
|
### Setup
|
|
|
|
|
|
The *Escape* behavior was implemented in java based on the IC description given in [4]. Note that the bumper on the back is not used in our design, since we did not have enough available sensor ports on the NXT.
|
|
|
A snippet of the main loop of the behavior is shown below.
|
|
|
The full source code can be found in [3].
|
|
|
|
|
|
```java
|
|
|
while (true)
|
|
|
{
|
|
|
// Check for bumps
|
|
|
bumpLeft = presLeft.isPressed();
|
|
|
bumpRight = presRight.isPressed();
|
|
|
|
|
|
// React to bumps
|
|
|
if( bumpLeft && bumpRight)
|
|
|
{
|
|
|
car.backward(power,power);
|
|
|
Delay.msDelay(msSmall);
|
|
|
|
|
|
car.forward(0,power);
|
|
|
Delay.msDelay(msLarge);
|
|
|
}
|
|
|
else if (bumpLeft)
|
|
|
{
|
|
|
car.forward(power,0);
|
|
|
Delay.msDelay(msLarge);
|
|
|
}
|
|
|
else if (bumpRight)
|
|
|
{
|
|
|
car.forward(0,power);
|
|
|
Delay.msDelay(msLarge);
|
|
|
}
|
|
|
// We do not use a bumper on the back
|
|
|
/*
|
|
|
else if (bumpBack)
|
|
|
{
|
|
|
car.forward(0,power);
|
|
|
Delay.msDelay(msSmall);
|
|
|
}
|
|
|
*/
|
|
|
else
|
|
|
{
|
|
|
// do nothing
|
|
|
car.noCommand();
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
The *Escape* behavior was added to the RobotFigure9_9.java program and started as a daemon thread, just as the other behaviors. The *Escape* behavior got the highest priority as dictated by [1].
|
|
|
|
|
|
### Results
|
|
|
|
|
|
In the video [Concurrent behavior:Escape], the escape behavior can be seen. In the video it is seen that the NXT behaves, just as the java program dictates. This is not a very effective escape behavior though. If the car bumps into something in the left side, it will turn right by increasing the power in the left motor. This turns out to be very ineffective, as shown in the video. In order to make the escape behavior work as intended, a right turn should probably be executed be the left motor driving forward AND the right motor driving backward! It is worth noting that the escape behavior in [4] was designed for a completely round robot and not for our Lego car, which means that our car might be more prone to get stuck.
|
|
|
If both bumpers are pressed, the car backs off a little and turn slightly to the left and drives forward again.
|
|
|
|
|
|
## Light turning motor
|
|
|
|
|
|
### Setup
|
... | ... | @@ -158,6 +208,8 @@ In this lesson we have worked with both single and concurrent behaviors. The sin |
|
|
|
|
|
[1] http://legolab.cs.au.dk/DigitalControl.dir/NXT/Lesson7.dir/Lesson.html
|
|
|
[2] Fred G. Martin, Robotic Explorations: A Hands-on Introduction to Engineering, Prentice Hall, 2001.
|
|
|
[3] https://gitlab.au.dk/rene2014/lego/tree/master/Lesson7/Programs
|
|
|
[4] Jones, Flynn, and Seiger, "Mobile Robots, Inspiration to Implementation", Second Edition, 1999.
|
|
|
|
|
|
### Videos
|
|
|
|
... | ... | |