encoding 32bit angle into data buffer
This commit is contained in:
parent
7123bfecd3
commit
9cca35d49f
@ -19,9 +19,15 @@ namespace pxsim {
|
||||
console.log("motor before read");
|
||||
for (let port = 0; port < DAL.NUM_OUTPUTS; ++port) {
|
||||
const output = outputs[port];
|
||||
const speed = output ? Math.round(outputs[port].getSpeed()) : 0;
|
||||
const angle = output ? Math.round(outputs[port].getAngle()) : 0;
|
||||
const tsi = MotorDataOff.TachoSensor + port * MotorDataOff.Size;
|
||||
data[MotorDataOff.TachoCounts + port * MotorDataOff.Size] = 0; // Tacho count
|
||||
data[MotorDataOff.Speed + port * MotorDataOff.Size] = output ? outputs[port].getSpeed() : 0; // Speed
|
||||
data[MotorDataOff.TachoSensor + port * MotorDataOff.Size] = output ? outputs[port].getAngle() : 0; // Count
|
||||
data[MotorDataOff.Speed + port * MotorDataOff.Size] = speed; // Speed
|
||||
data[tsi] = angle & 0xff; // Count
|
||||
data[tsi + 1] = (angle >> 8) & 0xff; // Count
|
||||
data[tsi + 2] = (angle >> 16) & 0xff; // Count
|
||||
data[tsi + 3] = (angle >> 24) & 0xff; // Count
|
||||
}
|
||||
},
|
||||
read: buf => {
|
||||
|
@ -37,7 +37,7 @@ namespace pxsim {
|
||||
case DAL.opOutputStepSpeed: {
|
||||
// step speed
|
||||
const port = buf.data[1];
|
||||
const speed = buf.data[2];
|
||||
const speed = buf.data[2] << 24 >> 24; // signed byte
|
||||
// note that b[3] is padding
|
||||
const step1 = buf.data[4];
|
||||
const step2 = buf.data[5]; // angle
|
||||
@ -59,7 +59,7 @@ namespace pxsim {
|
||||
case DAL.opOutputSpeed: {
|
||||
// setSpeed
|
||||
const port = buf.data[1];
|
||||
const speed = buf.data[2];
|
||||
const speed = buf.data[2] << 24 >> 24; // signed byte
|
||||
const motors = ev3board().getMotor(port);
|
||||
motors.forEach(motor => motor.setSpeed(speed));
|
||||
return 2;
|
||||
|
@ -374,7 +374,7 @@ namespace pxsim.visuals {
|
||||
now = Date.now();
|
||||
delta = now - then;
|
||||
if (delta > interval) {
|
||||
then = now - (delta % interval);
|
||||
then = now;
|
||||
that.updateStateStep(delta);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user