... | ... | @@ -114,34 +114,6 @@ switch (nextAction) { |
|
|
```
|
|
|
The FSM is responsible for performing all turns on the track using an instance of the `Car` class provided by the Arbiter. The methods of the `Car` class is described below. By letting the FSM control the stopping mechanism we avoid having a third behavior that uses the light sensor or an additional color sensor to detect when the LEGO car is in the green end zone.
|
|
|
|
|
|
The 180 degree rotation is implemented using the `rotate(degree)` method of the `NXTRegulatedMotor` as follows:
|
|
|
|
|
|
```java
|
|
|
public void Rotate180()
|
|
|
{
|
|
|
leftMotor.setSpeed((int)(getMaxSpeed()*0.7));
|
|
|
rightMotor.setSpeed((int)(getMaxSpeed()*0.7));
|
|
|
leftMotor.rotate(370,true);
|
|
|
rightMotor.rotate(-370,true);
|
|
|
leftMotor.waitComplete();
|
|
|
rightMotor.waitComplete();
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Each turn is hard coded by imposing a certain power to each motor in a fixed amount of time. The amount of power and the time interval is then adjusted according to manual inspection. Turning is different whether the robot is ascending or descending, and left and right turns are not implemented precisely symmetrical, because the left and right motors run slightly different. All turns follow the same pattern and is implemented as follows:
|
|
|
|
|
|
```java
|
|
|
public void TurnRightUp()
|
|
|
{
|
|
|
final int innerPower = 37;
|
|
|
final int outerPower = 100;
|
|
|
|
|
|
Forward(innerPower, outerPower);
|
|
|
|
|
|
Delay.msDelay(1350);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
The hardware setup is identical to previously.
|
|
|
|
|
|
The PlateauPilot performs an action every time a plateau is reached. This is sensed using the gyroscope. In the code snippet below the run function of the PlateauPilot is shown. This function sets the boolean ´isPlatueaReached´, which triggers the Arbiter to perform the next action, as described by the state machine above.
|
... | ... | @@ -221,7 +193,37 @@ The final construction is shown in the following figure. |
|
|
|
|
|
![Final constructionn](https://gitlab.au.dk/rene2014/lego/raw/master/Lesson8/Images/FinalCar.JPG)
|
|
|
|
|
|
A link to the final code is also found in the references section.
|
|
|
### Implementing turns
|
|
|
|
|
|
The 180 degree rotation is implemented using the `rotate(degree)` method of the `NXTRegulatedMotor` as follows:
|
|
|
|
|
|
```java
|
|
|
public void Rotate180()
|
|
|
{
|
|
|
leftMotor.setSpeed((int)(getMaxSpeed()*0.7));
|
|
|
rightMotor.setSpeed((int)(getMaxSpeed()*0.7));
|
|
|
leftMotor.rotate(370,true);
|
|
|
rightMotor.rotate(-370,true);
|
|
|
leftMotor.waitComplete();
|
|
|
rightMotor.waitComplete();
|
|
|
}
|
|
|
```
|
|
|
|
|
|
Each turn is hard coded by imposing a certain power to each motor in a fixed amount of time. The amount of power and the time interval is then adjusted according to manual inspection. Turning is different whether the robot is ascending or descending, and left and right turns are not implemented precisely symmetrical, because the left and right motors run slightly different. All turns follow the same pattern and is implemented as follows:
|
|
|
|
|
|
```java
|
|
|
public void TurnRightUp()
|
|
|
{
|
|
|
final int innerPower = 37;
|
|
|
final int outerPower = 100;
|
|
|
|
|
|
Forward(innerPower, outerPower);
|
|
|
|
|
|
Delay.msDelay(1350);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
A link to the final code is also found in the references section.
|
|
|
|
|
|
## Conclusion
|
|
|
|
... | ... | |