... | ... | @@ -23,7 +23,7 @@ Our plan is to follow the exercises exactly as described, testing the the differ |
|
|
|
|
|
### LEGO vehicle that exhibits a single behavior
|
|
|
|
|
|
We first build the robot with a bumper, an ultrasonic sensor and a light sensor. The construction can be seen in Figure 1. We then ran the program AvoidFigure9_3.java [3], which were given to us in the exercisers, the robots behaviour is to avoid obstacles using the ultrasonic sensor.
|
|
|
We first build the robot with a bumper, an ultrasonic sensor and a light sensor. The construction can be seen in Figure 1. We then ran the program `AvoidFigure9_3.java` [3], which were given to us in the exercisers, the robots behaviour is to avoid obstacles using the ultrasonic sensor.
|
|
|
The robot does this by measuring the distance to the obstacles in front of it. if the distance value goes below a threshold (in this case 30) meaning that the robot senses an obstacle immediately in front of it. it checks for an alternate route by first turning left measuring the distance to obstacles in that direction and then turning right, past its original position and measuring the distance to obstacles to that side, it will then move to the side which have the largest distance, as that would be the better option.
|
|
|
|
|
|
![The robot we built for this exercise. At the bottom you see the bumper connected to the two touch sensors. Above it are the light sensor on the left and the ultrasonic sensor on the right.](http://i.imgur.com/8W0lOMJl.jpg)
|
... | ... | @@ -50,15 +50,15 @@ For the delay we have used some experimented numbers. This means that the values |
|
|
[Video link of Robot backing and turning 180 degree.](https://www.youtube.com/watch?v=lRW77bRqaFs)[5]
|
|
|
|
|
|
### Behaviors as concurrent threads
|
|
|
For this section the goal was to experiment with and observe the behavior of the robot while running the program $RobotFigure9_9.java$. This program implements the Avoid, Follow and Cruise behaviors along with an arbitration mechanism which are all based on suggestions from [6]. We have used two touch sensors, an ultrasonic sensor and a light sensor with our robot, which is a bit different than the build in [6] as they use an IR detector instead an ultrasonic sensor, though they both serve the same purpose.
|
|
|
For this section the goal was to experiment with and observe the behavior of the robot while running the program `RobotFigure9_9.java`. This program implements the Avoid, Follow and Cruise behaviors along with an arbitration mechanism which are all based on suggestions from [6]. We have used two touch sensors, an ultrasonic sensor and a light sensor with our robot, which is a bit different than the build in [6] as they use an IR detector instead an ultrasonic sensor, though they both serve the same purpose.
|
|
|
|
|
|
When running the program we observed the car’s behavior and what conditions triggered them. The first thing we noticed was that the car drove straight ahead if no obstacles were in its way. If an obstacle got in its way the car would look to both sides and go towards the side with the most room left. The final behaviour we observed was that the car would go towards bright light by again looking left and right and continue towards the side with the brightest light.
|
|
|
When running the program we observed the car’s behavior and what conditions triggered them. The first thing we noticed was that the car drove straight ahead if no obstacles were in its way. If an obstacle got in its way the car would look to both sides and go towards the side with the most room left. The final behavior we observed was that the car would go towards bright light by again looking left and right and continue towards the side with the brightest light.
|
|
|
|
|
|
Moving on to the conditions that triggered those behaviors we will start Avoid. Based on our observations this behavior was triggered when the car moved within a certain distance to an obstacle. The condition resulting in the Follow behavior was a more difficult to determine just by observing the car. Sometimes the behavior would never happen when using the car in a uniformly lit environment. Based on that we concluded that the car would have to spot an increase in light to trigger the behavior. The Cruise behavior was simply a fallback for when none of the other conditions were met.
|
|
|
|
|
|
To get to know the exact triggers for each behavior we looked into the three classes $Avoid.java$, $Follow.java$ and $Cruise.java$.
|
|
|
The Avoid class implements the same behavior as in the previous program $AvoidFigure9_3.java$ where the car will stop when reading a distance less than or equal to a fixed threshold of 30 cm. Next it will turn left, measure the distance, turn right and then measure again to determine which direction have the most space. If the left side had the most space then the car will turn towards the left side again otherwise it will keep pointing to the right before the next iteration of the control loop.
|
|
|
The Follow class uses the light sensor to measure an initial light threshold which is used throughout the entire running time of the program to determine if the car should follow the light or not. As long as the light readings are less than or equal to the threshold then no actions is taken. This is why the car could drive around a room without ever performing the Follow behaviour. If a reading is above the threshold, the car will stop, turn left and measure the light then turn to the right and measure again. The difference between those values are then used to control the power levels of the motors to make the car move in the direction of the light for a while.
|
|
|
To get to know the exact triggers for each behavior we looked into the three classes `Avoid.java`, `Follow.java` and `Cruise.java`.
|
|
|
The Avoid class implements the same behavior as in the previous program `AvoidFigure9_3.java` where the car will stop when reading a distance less than or equal to a fixed threshold of 30 cm. Next it will turn left, measure the distance, turn right and then measure again to determine which direction have the most space. If the left side had the most space then the car will turn towards the left side again otherwise it will keep pointing to the right before the next iteration of the control loop.
|
|
|
The Follow class uses the light sensor to measure an initial light threshold which is used throughout the entire running time of the program to determine if the car should follow the light or not. As long as the light readings are less than or equal to the threshold then no actions is taken. This is why the car could drive around a room without ever performing the Follow behavior. If a reading is above the threshold, the car will stop, turn left and measure the light then turn to the right and measure again. The difference between those values are then used to control the power levels of the motors to make the car move in the direction of the light for a while.
|
|
|
The Cruise class have no triggers as it simply drives forward at a fixed speed forever.
|
|
|
|
|
|
### Add an Escape behavior
|
... | ... | @@ -74,7 +74,7 @@ while (true) { |
|
|
if(r.nextBoolean()) {
|
|
|
car.forward(0, power);
|
|
|
Delay.msDelay(ms);
|
|
|
} else {
|
|
|
} else {
|
|
|
car.forward(power, 0);
|
|
|
Delay.msDelay(ms);
|
|
|
}
|
... | ... | |