Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • L LEGO
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • René Søndergaard Nilsson
  • LEGO
  • Wiki
  • Lesson 8 Journal 2

Lesson 8 Journal 2 · Changes

Page history
Add plateau pilot stuff authored May 04, 2015 by René Nilsson's avatar René Nilsson
Show whitespace changes
Inline Side-by-side
Lesson-8-Journal-2.markdown
View page @ 1f034664
......@@ -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 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
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.
......
Clone repository
  • Lesson 1
  • Lesson 2
  • Lesson 3
  • Lesson 4
  • Lesson 5
  • Lesson 6
  • Lesson 7
  • Lesson 8 Journal 2
  • Lesson 8
  • Lesson 9
  • Lesson10
  • Lesson11
  • Home