fixing isReady query on motors (#197)
This commit is contained in:
@ -22,6 +22,10 @@ namespace pxsim {
|
||||
this.setLarge(large);
|
||||
}
|
||||
|
||||
isReady() {
|
||||
return !this.speedCmd;
|
||||
}
|
||||
|
||||
getSpeed() {
|
||||
return this.speed * (this.polarity == 0 ? -1 : 1);
|
||||
}
|
||||
@ -154,8 +158,21 @@ namespace pxsim {
|
||||
if (brake) this.speed = 0;
|
||||
this.clearSpeedCmd();
|
||||
}
|
||||
// send synched motor state
|
||||
otherMotor.speed = Math.floor(this.speed * turnRatio / 100);
|
||||
|
||||
// turn ratio is a bit weird to interpret
|
||||
// see https://communities.theiet.org/blogs/698/1706
|
||||
if (turnRatio < 0) {
|
||||
otherMotor.speed = speed;
|
||||
this.speed *= (100 + turnRatio) / 100;
|
||||
} else {
|
||||
otherMotor.speed = this.speed * (100 - turnRatio) / 100;
|
||||
}
|
||||
|
||||
// clamp
|
||||
this.speed = Math.max(-100, Math.min(100, this.speed >> 0));
|
||||
otherMotor.speed = Math.max(-100, Math.min(100, otherMotor.speed >> 0));;
|
||||
|
||||
// stop other motor if needed
|
||||
if (!this._synchedMotor)
|
||||
otherMotor.clearSpeedCmd();
|
||||
break;
|
||||
|
@ -12,10 +12,24 @@ namespace pxsim {
|
||||
data[i] = 0
|
||||
},
|
||||
read: buf => {
|
||||
let v = "vSIM"
|
||||
for (let i = 0; i < buf.data.length; ++i)
|
||||
buf.data[i] = v.charCodeAt(i) || 0
|
||||
console.log("pwm read");
|
||||
// console.log("pwm read");
|
||||
if (buf.data.length == 0) return 2;
|
||||
const cmd = buf.data[0];
|
||||
switch (cmd) {
|
||||
case DAL.opOutputTest:
|
||||
const port = buf.data[1];
|
||||
let r = 0;
|
||||
ev3board().getMotor(port)
|
||||
.filter(motor => !motor.isReady())
|
||||
.forEach(motor => r |= (1 << motor.port));
|
||||
pxsim.BufferMethods.setNumber(buf, BufferMethods.NumberFormat.UInt8LE, 2, r);
|
||||
break;
|
||||
default:
|
||||
let v = "vSIM"
|
||||
for (let i = 0; i < buf.data.length; ++i)
|
||||
buf.data[i] = v.charCodeAt(i) || 0
|
||||
break;
|
||||
}
|
||||
return buf.data.length
|
||||
},
|
||||
write: buf => {
|
||||
|
Reference in New Issue
Block a user