Add reading motor speed data (untested)
This commit is contained in:
parent
b0145cf378
commit
d42117a2a5
@ -101,11 +101,39 @@ namespace output {
|
|||||||
writePWM(b)
|
writePWM(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*export function getSpeed(out: Output): number {
|
export function clearCount(out: Output) {
|
||||||
let b = mkCmd(out, DAL.opOutputSpeed, 0)
|
let b = mkCmd(out, DAL.opOutputClearCount, 0)
|
||||||
readPWM(b)
|
writePWM(b)
|
||||||
return b.getNumber(NumberFormat.Int16LE, 1)
|
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||||
}*/
|
if (out & (1 << i)) {
|
||||||
|
motorMM.setNumber(NumberFormat.Int32LE, i * MotorDataOff.Size + MotorDataOff.TachoSensor, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function outOffset(out: Output) {
|
||||||
|
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||||
|
if (out & (1 << i))
|
||||||
|
return i * MotorDataOff.Size
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface MotorData {
|
||||||
|
actualSpeed: number; // -100..+100
|
||||||
|
tachoCount: number;
|
||||||
|
count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
// only a single output at a time
|
||||||
|
export function getMotorData(out: Output): MotorData {
|
||||||
|
let buf = motorMM.slice(outOffset(out), MotorDataOff.Size)
|
||||||
|
return {
|
||||||
|
actualSpeed: buf.getNumber(NumberFormat.Int8LE, MotorDataOff.Speed),
|
||||||
|
tachoCount: buf.getNumber(NumberFormat.Int32LE, MotorDataOff.TachoCounts),
|
||||||
|
count: buf.getNumber(NumberFormat.Int32LE, MotorDataOff.TachoSensor),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set motor speed.
|
* Set motor speed.
|
||||||
|
Loading…
Reference in New Issue
Block a user