Drift-compensated angle in gyro (#931)
* compute angle based on undrifted rate * add is calibrating function * fix integrator * added example * docs * poll faster
This commit is contained in:
BIN
docs/static/tutorials/drifter.png
vendored
Normal file
BIN
docs/static/tutorials/drifter.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
34
docs/tutorials/drifter.md
Normal file
34
docs/tutorials/drifter.md
Normal file
@ -0,0 +1,34 @@
|
||||
# Drifter
|
||||
|
||||
Use this program to try out the gyro sensor and the effect of drifting.
|
||||
|
||||
```typescript
|
||||
// this loop shows the rate, angle and drift of the robot
|
||||
forever(() => {
|
||||
brick.showValue("rate", sensors.gyro2.rate(), 1)
|
||||
brick.showValue("angle", sensors.gyro2.angle(), 2)
|
||||
brick.showValue("drift", sensors.gyro2.drift(), 3)
|
||||
})
|
||||
// this loop shows wheter the sensor is calibrating
|
||||
forever(() => {
|
||||
brick.showString(sensors.gyro2.isCalibrating() ? "calibrating..." : "", 4)
|
||||
})
|
||||
// instructions on how to use the buttons
|
||||
brick.showString("ENTER: calibrate", 7)
|
||||
brick.showString(" (reset+drift)", 8)
|
||||
brick.showString("LEFT: reset", 9)
|
||||
brick.showString("RIGHT: compute drift", 10)
|
||||
|
||||
// enter -> calibrate
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
sensors.gyro2.calibrate()
|
||||
})
|
||||
// right -> compute drift
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
sensors.gyro2.computeDrift()
|
||||
})
|
||||
// left -> reset
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
sensors.gyro2.reset()
|
||||
})
|
||||
```
|
@ -15,5 +15,11 @@
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/move-straight-with-gyro",
|
||||
"imageUrl":"/static/tutorials/move-straight-with-gyro.png"
|
||||
}, {
|
||||
"name": "Drifter",
|
||||
"description": "Explore how the gyro is drifting",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/drifter",
|
||||
"imageUrl":"/static/tutorials/drifter.png"
|
||||
}]
|
||||
```
|
Reference in New Issue
Block a user