... | @@ -111,6 +111,48 @@ Each turn is hard coded by imposing a certain power to each motor in a fixed amo |
... | @@ -111,6 +111,48 @@ Each turn is hard coded by imposing a certain power to each motor in a fixed amo |
|
|
|
|
|
The hardware setup is identical to previously.
|
|
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.
|
|
|
|
|
|
|
|
```java
|
|
|
|
public void run() {
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
int gyroVal = gyro.readValue();
|
|
|
|
double filteredVal = oldFilteredVal*alpha + gyroVal*(1-alpha);
|
|
|
|
oldFilteredVal = filteredVal;
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case idle: //starting in idle
|
|
|
|
if (filteredVal > gyroOffset + 40 && isAscending)
|
|
|
|
{
|
|
|
|
if(System.currentTimeMillis() > timePlateauReached + 2000) {
|
|
|
|
state = State.plateauReached;
|
|
|
|
isPlateauReached = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (gyroVal < gyroOffset - 40 && !isAscending)
|
|
|
|
{
|
|
|
|
if(System.currentTimeMillis() > timePlateauReached + 2000) {
|
|
|
|
state = State.plateauReached;
|
|
|
|
isPlateauReached = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case plateauReached:
|
|
|
|
if (!isPlateauReached) {
|
|
|
|
state = State.idle;
|
|
|
|
timePlateauReached = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
The gyro values are filtered with an exponential filter to remove unwanted spikes. If the filtered value is 40 degress/second above or below the offset, a plateau is either entered or left. In order not to trigger the next action when leaving a plateau a timing threshold is inserted. This ensures that at least two seconds passes between actions.
|
|
|
|
|
|
|
|
|
|
### Results
|
|
### Results
|
|
|
|
|
|
With the current setup the car is able to follow the black line on the first inclined path. However a problem arises in the plateau detection which is illustrated in the following figure.
|
|
With the current setup the car is able to follow the black line on the first inclined path. However a problem arises in the plateau detection which is illustrated in the following figure.
|
... | | ... | |