pxt-ev3/sim/state/gyro.ts
Peli de Halleux 374bbb8304
Drift-compensated angle in gyro (#931)
* compute angle based on undrifted rate

* add is calibrating function

* fix integrator

* added example

* docs

* poll faster
2019-10-01 10:11:58 -07:00

37 lines
728 B
TypeScript

namespace pxsim {
export const enum GyroSensorMode {
None = -1,
Angle = 0,
Rate = 1,
}
export class GyroSensorNode extends UartSensorNode {
id = NodeType.GyroSensor;
private rate: number = 0;
constructor(port: number) {
super(port);
}
getDeviceType() {
return DAL.DEVICE_TYPE_GYRO;
}
setRate(rate: number) {
rate = rate | 0;
if (this.rate != rate) {
this.rate = rate;
this.setChangedState();
}
}
getRate() {
return this.rate;
}
getValue() {
return this.getRate();
}
}
}