2017-12-18 22:04:17 +01:00
|
|
|
namespace pxsim {
|
2019-10-01 07:43:50 +02:00
|
|
|
export const enum GyroSensorMode {
|
2017-12-18 22:04:17 +01:00
|
|
|
None = -1,
|
|
|
|
Angle = 0,
|
|
|
|
Rate = 1,
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GyroSensorNode extends UartSensorNode {
|
|
|
|
id = NodeType.GyroSensor;
|
|
|
|
|
|
|
|
private angle: number = 0;
|
|
|
|
private rate: number = 0;
|
|
|
|
|
|
|
|
constructor(port: number) {
|
|
|
|
super(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
getDeviceType() {
|
|
|
|
return DAL.DEVICE_TYPE_GYRO;
|
|
|
|
}
|
|
|
|
|
|
|
|
setAngle(angle: number) {
|
2019-10-01 07:43:50 +02:00
|
|
|
angle = angle | 0;
|
2017-12-18 22:04:17 +01:00
|
|
|
if (this.angle != angle) {
|
|
|
|
this.angle = angle;
|
2017-12-19 23:20:35 +01:00
|
|
|
this.setChangedState();
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setRate(rate: number) {
|
2019-10-01 07:43:50 +02:00
|
|
|
rate = rate | 0;
|
2017-12-18 22:04:17 +01:00
|
|
|
if (this.rate != rate) {
|
|
|
|
this.rate = rate;
|
2017-12-19 23:20:35 +01:00
|
|
|
this.setChangedState();
|
2017-12-18 22:04:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getValue() {
|
|
|
|
return this.mode == GyroSensorMode.Angle ? this.angle :
|
|
|
|
this.mode == GyroSensorMode.Rate ? this.rate : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|