committed by
Sam El-Husseini
parent
4133828a10
commit
2e0a34c99b
@ -22,6 +22,15 @@ To properly reset the gyro, the brick must remain still (undistrurbed) while the
|
||||
|
||||
## ~
|
||||
|
||||
## Calibration states
|
||||
|
||||
Calibration happens in the following phases and each phase is tracked by the brick status light.
|
||||
|
||||
* **orange**: sensor initialization. This phase ensures that the sensor is in the desired mode and ready to collect data.
|
||||
* **orange pulse**: data collection. Light information is being collected, move the sensor over the various light sources to detect.
|
||||
* **green**: calibration success. The calibration data has been saved.
|
||||
* **red flash**: sensor failure. We were unable to connect to the sensor.
|
||||
|
||||
## Example
|
||||
Set the brick on a flat surface. Reset `gyro 2` and tilt the brick slighly. Reset it again while it's still tilted. Lay the brick down flat again and display the angle measurement.
|
||||
|
||||
@ -36,4 +45,4 @@ brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
## See also
|
||||
|
||||
[angle](/reference/sensors/gyro/angle), [rate](/reference/sensors/gyro/rate)
|
||||
[angle](/reference/sensors/gyro/angle), [rate](/reference/sensors/gyro/rate)
|
||||
|
@ -92,6 +92,9 @@ namespace sensors {
|
||||
reset(): void {
|
||||
if (this.calibrating) return; // already in calibration mode
|
||||
|
||||
const statusLight = brick.statusLight(); // save current status light
|
||||
brick.setStatusLight(StatusLight.Orange);
|
||||
|
||||
this.calibrating = true;
|
||||
// may be triggered by a button click,
|
||||
// give time for robot to settle
|
||||
@ -101,9 +104,22 @@ namespace sensors {
|
||||
// switch back to the desired mode
|
||||
this.setMode(this.mode);
|
||||
// wait till sensor is live
|
||||
pauseUntil(() => this.isActive());
|
||||
pauseUntil(() => this.isActive(), 5000);
|
||||
|
||||
// check sensor is ready
|
||||
if (!this.isActive()) {
|
||||
brick.setStatusLight(StatusLight.RedFlash); // didn't work
|
||||
pause(2000);
|
||||
brick.setStatusLight(statusLight); // restore previous light
|
||||
return;
|
||||
}
|
||||
|
||||
// give it a bit of time to init
|
||||
pause(1000)
|
||||
|
||||
// calibrating
|
||||
brick.setStatusLight(StatusLight.OrangePulse);
|
||||
|
||||
// compute drift
|
||||
this._drift = 0;
|
||||
if (this.mode == GyroSensorMode.Rate) {
|
||||
@ -113,6 +129,11 @@ namespace sensors {
|
||||
}
|
||||
this._drift /= 200;
|
||||
}
|
||||
|
||||
brick.setStatusLight(StatusLight.Green); // success
|
||||
pause(1000);
|
||||
brick.setStatusLight(statusLight); // resture previous light
|
||||
|
||||
// and we're done
|
||||
this.calibrating = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user