... | ... | @@ -28,12 +28,30 @@ In this test the Lego car is mounted with two large wheels on the motors and a s |
|
|
|
|
|
By running the program provided the car acts as expected where it drives forward until the distance to an obstacle gets below the stop threshold. Afterwards by turning first to the left, then to the right and in both cases measuring the distance to the obstacle in front it determines in which direction the distance to the obstacle is largest and drives in that direction. The problem is that when the car approaches a corner the structure of the program makes it drive further and further into the corner until all distances (front, left and right) is below the stop threshold. In this situation the car stops and is stuck in the corner. This scenario is shown in the video "Single behavior" in the references section.
|
|
|
|
|
|
In order to cope with this a small fix is implemented. Whenever the all the distances is below the stop threshold the car drives backwards a performs a 180 degree turn. This scenario is shown in the video "Single behavior modified" in the references section.
|
|
|
In order to cope with this a small fix is implemented. Whenever the all the distances is below the stop threshold the car drives backwards a performs a 180 degree turn. This scenario is shown in the video "Single behavior modified" in the references section. The added code is seen in the code snippet below.
|
|
|
|
|
|
```java
|
|
|
if(leftDistance < stopThreshold &&
|
|
|
rightDistance < stopThreshold &&
|
|
|
frontDistance < stopThreshold)
|
|
|
{
|
|
|
car.backward(power, power);
|
|
|
Delay.msDelay(1000);
|
|
|
|
|
|
car.rotate(true, power);
|
|
|
Delay.msDelay(1550);
|
|
|
car.stop();
|
|
|
}
|
|
|
```
|
|
|
|
|
|
The full code is
|
|
|
|
|
|
## Concurrent behaviors
|
|
|
|
|
|
### Setup
|
|
|
|
|
|
The physical setup for this test is identical to the single behavior test.
|
|
|
|
|
|
### Results
|
|
|
|
|
|
|
... | ... | @@ -47,8 +65,37 @@ In order to cope with this a small fix is implemented. Whenever the all the dist |
|
|
|
|
|
### Setup
|
|
|
|
|
|
The physical base setup in this test is identical to previously tests. In order to detect light in both directions a horizontal motor has been added to avoid having the car turn in each direction. The light sensor has been removed from the front of the car and attached to the horizontal motor. The setup is seen in the following image.
|
|
|
|
|
|
[INSERT IMAGE]
|
|
|
|
|
|
A the class `Follow` is replaced by a new class called `FollowSensorTurn` which make use of the NXT motor abstraction to turn the light sensor. To ensure that the light sensor performs acurate turns the method `rotate()` is used. This method takes a value in degrees as input and then use the tachometer as feedback when turning the motor.
|
|
|
The structure of the code is similar to the Follow class. The light sensor is rotated 45 degrees the left, then to the right and in both cases a light value is acquired. FInially the light sensor is rotated to its initial position (pointing forward) and the power for the two main motors are calculated. The main part of the `FollowSensorTurn` class is shown in the code snippet below.
|
|
|
|
|
|
```java
|
|
|
// Get the light to the left
|
|
|
Motor.A.rotate(45);
|
|
|
leftLight = light.getLightValue();
|
|
|
|
|
|
// Get the light to the right
|
|
|
Motor.A.rotate(-90);
|
|
|
rightLight = light.getLightValue();
|
|
|
|
|
|
// Turn back to start position
|
|
|
Motor.A.rotate(45);
|
|
|
|
|
|
// Follow light for a while
|
|
|
delta = leftLight-rightLight;
|
|
|
car.forward(power-delta, power+delta);
|
|
|
Delay.msDelay(ms);
|
|
|
|
|
|
frontLight = light.getLightValue();
|
|
|
```
|
|
|
|
|
|
### Results
|
|
|
|
|
|
The result is seen
|
|
|
|
|
|
## SharedCar and Arbiter
|
|
|
|
|
|
### SharedCar
|
... | ... | @@ -77,3 +124,9 @@ In Fred Martins code, arrays are preallocated to be able to contain ten processe |
|
|
[Single behavior] - http://youtu.be/iFmBLXIuRiE
|
|
|
[Single behavior modified] - http://youtu.be/Xvs0y3kdMeA
|
|
|
|
|
|
[Concurrent behavior - Light turning motor] - http://youtu.be/SRYQU0VrlH0
|
|
|
|
|
|
### Code
|
|
|
|
|
|
[Single behavior] - https://gitlab.au.dk/rene2014/lego/tree/master/Lesson7/Programs/SingleBehavior
|
|
|
|