Tank fixes (#892)
* fixing turnration computation * updated tank computation * fix rendering glitch * restore tank computation * rounding errors
This commit is contained in:
parent
0de8a84de2
commit
277c9903bb
@ -86,6 +86,51 @@ for (let i = 0; i < 4; i++) {
|
|||||||
motors.stopAll()
|
motors.stopAll()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Steer tester
|
||||||
|
|
||||||
|
This program lets you change the values of speed and turn ratio with the buttons.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
let speed = 0;
|
||||||
|
let turnRatio = 0;
|
||||||
|
|
||||||
|
brick.showString(`steer tester`, 1)
|
||||||
|
brick.showString(`connect motors BC`, 7)
|
||||||
|
brick.showString(`up/down for speed`, 8)
|
||||||
|
brick.showString(`left/right for turn ratio`, 9)
|
||||||
|
|
||||||
|
forever(function () {
|
||||||
|
brick.showString(`motor B speed ${motors.largeB.speed()}%`, 4)
|
||||||
|
brick.showString(`motor C speed ${motors.largeC.speed()}%`, 5)
|
||||||
|
pause(100)
|
||||||
|
})
|
||||||
|
|
||||||
|
function updateSteer() {
|
||||||
|
motors.largeBC.steer(turnRatio, speed);
|
||||||
|
brick.showString(`speed ${speed}%`, 2)
|
||||||
|
brick.showString(`turnRatio ${turnRatio}`, 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
speed += 10
|
||||||
|
updateSteer()
|
||||||
|
})
|
||||||
|
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
speed -= 10
|
||||||
|
updateSteer()
|
||||||
|
})
|
||||||
|
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
turnRatio -= 10
|
||||||
|
updateSteer()
|
||||||
|
})
|
||||||
|
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
turnRatio += 10
|
||||||
|
updateSteer()
|
||||||
|
})
|
||||||
|
|
||||||
|
updateSteer()
|
||||||
|
```
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
[tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)
|
[tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)
|
@ -82,6 +82,51 @@ pause(5000)
|
|||||||
motors.stopAll()
|
motors.stopAll()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Tank tester
|
||||||
|
|
||||||
|
This program lets you change the tank values using the brick buttons
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
let tankB = 0;
|
||||||
|
let tankC = 0;
|
||||||
|
|
||||||
|
brick.showString(`tank tester`, 1)
|
||||||
|
brick.showString(`connect motors BC`, 7)
|
||||||
|
brick.showString(`up/down for tank B`, 8)
|
||||||
|
brick.showString(`left/right for tank C`, 9)
|
||||||
|
|
||||||
|
forever(function () {
|
||||||
|
brick.showString(`motor B speed ${motors.largeB.speed()}%`, 4)
|
||||||
|
brick.showString(`motor C speed ${motors.largeC.speed()}%`, 5)
|
||||||
|
pause(100)
|
||||||
|
})
|
||||||
|
|
||||||
|
function updateTank() {
|
||||||
|
brick.showString(`tank A: ${tankB}%`, 2)
|
||||||
|
brick.showString(`tank B: ${tankC}%`, 3)
|
||||||
|
motors.largeBC.tank(tankB, tankC);
|
||||||
|
}
|
||||||
|
|
||||||
|
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
tankB += 10
|
||||||
|
updateTank();
|
||||||
|
})
|
||||||
|
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
tankB -= 10
|
||||||
|
updateTank();
|
||||||
|
})
|
||||||
|
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
tankC += 10
|
||||||
|
updateTank();
|
||||||
|
})
|
||||||
|
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||||
|
tankC -= 10
|
||||||
|
updateTank();
|
||||||
|
})
|
||||||
|
|
||||||
|
updateTank();
|
||||||
|
```
|
||||||
|
|
||||||
## See also
|
## See also
|
||||||
|
|
||||||
[steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)
|
[steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)
|
@ -129,7 +129,7 @@ namespace sensors.internal {
|
|||||||
|
|
||||||
let nonActivated = 0;
|
let nonActivated = 0;
|
||||||
function detectDevices() {
|
function detectDevices() {
|
||||||
control.dmesg(`detect devices (${nonActivated} na)`)
|
//control.dmesg(`detect devices (${nonActivated} na)`)
|
||||||
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
||||||
let numChanged = 0;
|
let numChanged = 0;
|
||||||
const uartSensors: SensorInfo[] = [];
|
const uartSensors: SensorInfo[] = [];
|
||||||
@ -198,7 +198,7 @@ namespace sensors.internal {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
control.dmesg(`detect devices done`)
|
//control.dmesg(`detect devices done`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Sensor extends control.Component {
|
export class Sensor extends control.Component {
|
||||||
|
@ -561,10 +561,12 @@ namespace motors {
|
|||||||
speedRight = Math.clamp(-100, 100, speedRight >> 0);
|
speedRight = Math.clamp(-100, 100, speedRight >> 0);
|
||||||
|
|
||||||
const speed = Math.abs(speedLeft) > Math.abs(speedRight) ? speedLeft : speedRight;
|
const speed = Math.abs(speedLeft) > Math.abs(speedRight) ? speedLeft : speedRight;
|
||||||
const turnRatio = speedLeft == speed
|
let turnRatio = speedLeft == speed
|
||||||
? (100 - speedRight / speedLeft * 100)
|
? speedLeft == 0 ? 0 : (100 - speedRight / speedLeft * 100)
|
||||||
: (speedLeft / speedRight * 100 - 100);
|
: speedRight == 0 ? 0 : (speedLeft / speedRight * 100 - 100);
|
||||||
|
turnRatio = Math.floor(turnRatio);
|
||||||
|
|
||||||
|
//control.dmesg(`tank ${speedLeft} ${speedRight} => ${turnRatio} ${speed}`)
|
||||||
this.steer(turnRatio, speed, value, unit);
|
this.steer(turnRatio, speed, value, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ namespace pxsim {
|
|||||||
delete this.speedCmd;
|
delete this.speedCmd;
|
||||||
delete this.speedCmdValues;
|
delete this.speedCmdValues;
|
||||||
delete this._synchedMotor;
|
delete this._synchedMotor;
|
||||||
|
this.setChangedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
clearSyncCmd() {
|
clearSyncCmd() {
|
||||||
@ -184,11 +185,13 @@ namespace pxsim {
|
|||||||
case DAL.opOutputStepSync:
|
case DAL.opOutputStepSync:
|
||||||
case DAL.opOutputTimeSync: {
|
case DAL.opOutputTimeSync: {
|
||||||
const otherMotor = this._synchedMotor;
|
const otherMotor = this._synchedMotor;
|
||||||
if (otherMotor.port < this.port) // handled in other motor code
|
|
||||||
break;
|
|
||||||
|
|
||||||
const speed = this.speedCmdValues[0];
|
const speed = this.speedCmdValues[0];
|
||||||
const turnRatio = this.speedCmdValues[1];
|
const turnRatio = this.speedCmdValues[1];
|
||||||
|
// if turnratio is negative, right motor at power level
|
||||||
|
// right motor -> this.port > otherMotor.port
|
||||||
|
if (Math.sign(this.port - otherMotor.port)
|
||||||
|
== Math.sign(turnRatio))
|
||||||
|
break; // handled in other motor code
|
||||||
const stepsOrTime = this.speedCmdValues[2];
|
const stepsOrTime = this.speedCmdValues[2];
|
||||||
const brake = this.speedCmdValues[3];
|
const brake = this.speedCmdValues[3];
|
||||||
const dstep = this.speedCmd == DAL.opOutputTimeSync
|
const dstep = this.speedCmd == DAL.opOutputTimeSync
|
||||||
@ -204,12 +207,7 @@ namespace pxsim {
|
|||||||
|
|
||||||
// turn ratio is a bit weird to interpret
|
// turn ratio is a bit weird to interpret
|
||||||
// see https://communities.theiet.org/blogs/698/1706
|
// see https://communities.theiet.org/blogs/698/1706
|
||||||
if (turnRatio < 0) {
|
otherMotor.speed = this.speed * (100 - Math.abs(turnRatio)) / 100;
|
||||||
otherMotor.speed = speed;
|
|
||||||
this.speed *= (100 + turnRatio) / 100;
|
|
||||||
} else {
|
|
||||||
otherMotor.speed = this.speed * (100 - turnRatio) / 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
// clamp
|
// clamp
|
||||||
this.speed = Math.max(-100, Math.min(100, this.speed >> 0));
|
this.speed = Math.max(-100, Math.min(100, this.speed >> 0));
|
||||||
|
Loading…
Reference in New Issue
Block a user