Tank fixes (#892)
* fixing turnration computation * updated tank computation * fix rendering glitch * restore tank computation * rounding errors
This commit is contained in:
		@@ -86,6 +86,51 @@ for (let i = 0; i < 4; i++) {
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
[tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)
 | 
			
		||||
@@ -82,6 +82,51 @@ pause(5000)
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
[steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)
 | 
			
		||||
		Reference in New Issue
	
	Block a user