Added acceleration/deceleraiton setters for tacho motors

This commit is contained in:
Nathan Kellenicki 2020-05-23 18:33:04 -07:00
parent e526e32146
commit b219dcf60b
2 changed files with 36 additions and 8 deletions

View File

@ -57,11 +57,11 @@ export class AbsoluteMotor extends TachoMotor {
} }
let message; let message;
if (angle instanceof Array) { if (angle instanceof Array) {
message = Buffer.from([0x81, this.portId, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, 0x00]); message = Buffer.from([0x81, this.portId, 0x11, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, this.useProfile()]);
message.writeInt32LE(normalizeAngle(angle[0]), 4); message.writeInt32LE(normalizeAngle(angle[0]), 4);
message.writeInt32LE(normalizeAngle(angle[1]), 8); message.writeInt32LE(normalizeAngle(angle[1]), 8);
} else { } else {
message = Buffer.from([0x81, this.portId, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, 0x00]); message = Buffer.from([0x81, this.portId, 0x11, 0x0d, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, this.useProfile()]);
message.writeInt32LE(normalizeAngle(angle), 4); message.writeInt32LE(normalizeAngle(angle), 4);
} }
this.send(message); this.send(message);

View File

@ -12,6 +12,8 @@ import { mapSpeed } from "../utils";
export class TachoMotor extends BasicMotor { export class TachoMotor extends BasicMotor {
protected _brakeStyle: Consts.BrakingStyle = Consts.BrakingStyle.BRAKE; protected _brakeStyle: Consts.BrakingStyle = Consts.BrakingStyle.BRAKE;
public useAccelerationProfile: boolean = true;
public useDecelerationProfile: boolean = true;
constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.UNKNOWN) { constructor (hub: IDeviceInterface, portId: number, modeMap: {[event: string]: number} = {}, type: Consts.DeviceType = Consts.DeviceType.UNKNOWN) {
super(hub, portId, Object.assign({}, modeMap, ModeMap), type); super(hub, portId, Object.assign({}, modeMap, ModeMap), type);
@ -46,6 +48,19 @@ export class TachoMotor extends BasicMotor {
this._brakeStyle = style; this._brakeStyle = style;
} }
public setAccelerationTime (time: number, profile: number = 0x00) {
const message = Buffer.from([0x81, this.portId, 0x11, 0x05, 0x00, 0x00, profile]);
message.writeUInt16LE(time, 4);
this.send(message);
}
public setDecelerationTime (time: number, profile: number = 0x00) {
const message = Buffer.from([0x81, this.portId, 0x11, 0x06, 0x00, 0x00, profile]);
message.writeUInt16LE(time, 4);
this.send(message);
}
/** /**
* Set the motor speed. * Set the motor speed.
@ -69,16 +84,16 @@ export class TachoMotor extends BasicMotor {
let message; let message;
if (time !== undefined) { if (time !== undefined) {
if (speed instanceof Array) { if (speed instanceof Array) {
message = Buffer.from([0x81, this.portId, 0x11, 0x0a, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), 0x64, this._brakeStyle, 0x00]); message = Buffer.from([0x81, this.portId, 0x11, 0x0a, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), 0x64, this._brakeStyle, this.useProfile()]);
} else { } else {
message = Buffer.from([0x81, this.portId, 0x11, 0x09, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, 0x00]); message = Buffer.from([0x81, this.portId, 0x11, 0x09, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, this.useProfile()]);
} }
message.writeUInt16LE(time, 4); message.writeUInt16LE(time, 4);
} else { } else {
if (speed instanceof Array) { if (speed instanceof Array) {
message = Buffer.from([0x81, this.portId, 0x11, 0x08, mapSpeed(speed[0]), mapSpeed(speed[1]), 0x64, this._brakeStyle, 0x00]); message = Buffer.from([0x81, this.portId, 0x11, 0x08, mapSpeed(speed[0]), mapSpeed(speed[1]), 0x64, this.useProfile()]);
} else { } else {
message = Buffer.from([0x81, this.portId, 0x11, 0x07, mapSpeed(speed), 0x64, 0x03, 0x64, this._brakeStyle, 0x00]); message = Buffer.from([0x81, this.portId, 0x11, 0x07, mapSpeed(speed), 0x64, this.useProfile()]);
} }
} }
this.send(message); this.send(message);
@ -110,9 +125,9 @@ export class TachoMotor extends BasicMotor {
} }
let message; let message;
if (speed instanceof Array) { if (speed instanceof Array) {
message = Buffer.from([0x81, this.portId, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), 0x64, this._brakeStyle, 0x03]); message = Buffer.from([0x81, this.portId, 0x11, 0x0c, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed[0]), mapSpeed(speed[1]), 0x64, this._brakeStyle, this.useProfile()]);
} else { } else {
message = Buffer.from([0x81, this.portId, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, 0x03]); message = Buffer.from([0x81, this.portId, 0x11, 0x0b, 0x00, 0x00, 0x00, 0x00, mapSpeed(speed), 0x64, this._brakeStyle, this.useProfile()]);
} }
message.writeUInt32LE(degrees, 4); message.writeUInt32LE(degrees, 4);
this.send(message); this.send(message);
@ -122,6 +137,19 @@ export class TachoMotor extends BasicMotor {
}); });
} }
protected useProfile () {
let value = 0x00;
if (this.useAccelerationProfile) {
value += 0x01;
}
if (this.useDecelerationProfile) {
value += 0x02;
}
return value;
}
} }
export enum Mode { export enum Mode {