Motor sync support in simulator (#159)

* parse sync motor command

* better sim support

* sync support

* fixing tank
This commit is contained in:
Peli de Halleux
2018-01-02 16:20:00 -08:00
committed by GitHub
parent 1bc93013e6
commit c35dbdd38f
6 changed files with 4758 additions and 19 deletions

View File

@ -77,7 +77,7 @@
"motors.MotorBase.stop": "Stops the motor(s).",
"motors.SynchedMotorPair.steer": "Turns the motor and the follower motor by a number of rotations",
"motors.SynchedMotorPair.steer|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.SynchedMotorPair.steer|param|steering": "the ratio of power sent to the follower motor, from ``-100`` to ``100``",
"motors.SynchedMotorPair.steer|param|turnRatio": "the ratio of power sent to the follower motor, from ``-200`` to ``200``, eg: 100",
"motors.SynchedMotorPair.steer|param|unit": "the meaning of the value",
"motors.SynchedMotorPair.steer|param|value": "the move quantity, eg: 2",
"motors.SynchedMotorPair.tank": "The Move Tank block can make a robot drive forward, backward, turn, or stop. \nUse the Move Tank block for robot vehicles that have two Large Motors, \nwith one motor driving the left side of the vehicle and the other the right side. \nYou can make the two motors go at different speeds or in different directions \nto make your robot turn.",

View File

@ -54,7 +54,7 @@
"motors.MotorBase.setBrake|block": "set %motor|brake %brake",
"motors.MotorBase.setReversed|block": "set %motor|reversed %reversed",
"motors.MotorBase.setSpeed|block": "set speed of %motor|to %speed|%",
"motors.SynchedMotorPair.steer|block": "steer %chassis|%steering|%|at speed %speed|%|by %value|%unit",
"motors.SynchedMotorPair.steer|block": "steer %chassis|%turnRatio|%|at speed %speed|%|by %value|%unit",
"motors.SynchedMotorPair.tank|block": "tank %chassis|left %speedLeft|%|right %speedRight|%|by %value|%unit",
"motors.largeAB|block": "large A+B",
"motors.largeAD|block": "large A+D",

View File

@ -14,7 +14,7 @@ enum Output {
//% block="C+D"
CD = Output.C | Output.D,
//% block="A+D"
AD = Output.B | Output.C,
AD = Output.A | Output.D,
//% block="All"
ALL = 0x0f
}
@ -439,17 +439,17 @@ namespace motors {
/**
* Turns the motor and the follower motor by a number of rotations
* @param turnRatio the ratio of power sent to the follower motor, from ``-200`` to ``200``, eg: 100
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
* @param value the move quantity, eg: 2
* @param unit the meaning of the value
* @param steering the ratio of power sent to the follower motor, from ``-100`` to ``100``
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
*/
//% blockId=motorPairTurn block="steer %chassis|%steering|%|at speed %speed|%|by %value|%unit"
//% blockId=motorPairTurn block="steer %chassis|%turnRatio|%|at speed %speed|%|by %value|%unit"
//% weight=9 blockGap=8
//% steering.min=-100 steering=100
//% turnRatio.min=-200 turnRatio=200
//% inlineInputMode=inline
//% group="Chassis"
steer(steering: number, speed: number, value: number, unit: MoveUnit) {
steer(turnRatio: number, speed: number, value: number, unit: MoveUnit) {
this.init();
speed = Math.clamp(-100, 100, speed >> 0);
if (!speed) {
@ -457,7 +457,7 @@ namespace motors {
return;
}
const turnRatio = Math.clamp(-200, 200, steering + 100 >> 0);
turnRatio = Math.clamp(-200, 200, turnRatio >> 0);
let useSteps: boolean;
let stepsOrTime: number;
switch (unit) {
@ -470,7 +470,7 @@ namespace motors {
useSteps = true;
break;
default:
stepsOrTime = value;
stepsOrTime = value >> 0;
useSteps = false;
break;
}
@ -502,10 +502,10 @@ namespace motors {
//% inlineInputMode=inline
//% group="Chassis"
tank(speedLeft: number, speedRight: number, value: number, unit: MoveUnit) {
speedLeft = Math.clamp(speedLeft >> 0, -100, 100);
speedRight = Math.clamp(speedRight >> 0, -100, 100);
const steering = (speedRight * 100 / speedLeft) >> 0;
this.steer(speedLeft, steering, value, unit);
speedLeft = Math.clamp(-100, 100, speedLeft >> 0);
speedRight = Math.clamp(-100, 100, speedRight >> 0);
const turnRatio = speedLeft == 0 ? 0 : speedRight / speedLeft * 100;
this.steer(turnRatio, speedLeft, value, unit);
}
/**