bring back speed

This commit is contained in:
Peli de Halleux 2017-12-13 22:54:08 -08:00
parent 3c86ae286f
commit 92178f3371
3 changed files with 29 additions and 25 deletions

View File

@ -53,19 +53,21 @@
"motors.Motor.clearCount": "Clears the motor count",
"motors.Motor.count": "Gets motor step count.",
"motors.Motor.move": "Moves the motor by a number of rotations, degress or seconds",
"motors.Motor.move|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.Motor.move|param|unit": "the meaning of the value",
"motors.Motor.move|param|value": "the move quantity, eg: 2",
"motors.Motor.power": "Turns the motor on or off at the current speed",
"motors.Motor.power|param|on": "true if the motor should be on",
"motors.Motor.reset": "Resets the motor and clears any synchronization",
"motors.Motor.setBrake": "Sets the automatic brake on or off when the motor is off",
"motors.Motor.setBrake|param|brake": "a value indicating if the motor should break when off",
"motors.Motor.setReversed": "Reverses the motor polarity",
"motors.Motor.setSpeed": "Sets the speed of the motor.",
"motors.Motor.setSpeed|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.Motor.speed": "Gets motor actual speed.",
"motors.Motor.sync": "Synchronizes a follower motor to this motor",
"motors.Motor.sync|param|follower": "the motor that follows this motor commands, eg: motors.largeC",
"motors.Motor.tachoCount": "Gets motor tacho count.",
"motors.Motor.turn": "Turns the motor and the follower motor by a number of rotations",
"motors.Motor.turn|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.Motor.turn|param|turnRatio": "the ratio of power sent to the follower motor, from -200 to 200",
"motors.Motor.turn|param|unit": "the meaning of the value",
"motors.Motor.turn|param|value": "the move quantity, eg: 2",

View File

@ -40,15 +40,15 @@
"control.raiseEvent|block": "raise event|from %src|with value %value",
"control|block": "control",
"motors.Motor.count|block": "`icons.motorLarge` %motor|count",
"motors.Motor.move|block": "move `icons.motorLarge` %motor|for %value|%unit",
"motors.Motor.power|block": "power `icons.motorLarge` %motor|%on",
"motors.Motor.move|block": "move `icons.motorLarge` %motor|for %value|%unit|at %speed|%",
"motors.Motor.reset|block": "reset `icons.motorLarge` %motor",
"motors.Motor.setBrake|block": "set `icons.motorLarge` %motor|brake %brake",
"motors.Motor.setReversed|block": "set `icons.motorLarge` %motor|reversed %reversed",
"motors.Motor.setSpeed|block": "set speed of `icons.motorLarge` %motor|to %speed|%",
"motors.Motor.speed|block": "`icons.motorLarge` %motor|speed",
"motors.Motor.sync|block": "sync `icons.motorLarge` %motor|with `icons.motorLarge` %follower",
"motors.Motor.tachoCount|block": "`icons.motorLarge` %motor|tacho count",
"motors.Motor.turn|block": "turn `icons.motorLarge` %motor|by %value|%unit|turn %turnRadio",
"motors.Motor.turn|block": "turn `icons.motorLarge` %motor|by %value|%unit|at %speed|% turn %turnRadio",
"motors.largeMotorA|block": "large A",
"motors.largeMotorB|block": "large B",
"motors.largeMotorC|block": "large C",

View File

@ -91,7 +91,6 @@ namespace motors {
private _large: boolean;
private _initialized: boolean;
private _speed: number;
private _brake: boolean;
private _follower: Motor; //
@ -100,7 +99,6 @@ namespace motors {
this._port = port;
this._large = large;
this._brake = false;
this._speed = 50;
}
private __init() {
@ -113,18 +111,21 @@ namespace motors {
}
/**
* Turns the motor on or off at the current speed
* @param on true if the motor should be on
* Sets the speed of the motor.
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
*/
//% blockId=motorPower block="power `icons.motorLarge` %motor|%on"
//% blockId=motorPower block="set speed of `icons.motorLarge` %motor|to %speed|%"
//% on.fieldEditor=toggleonoff
//% weight=99 blockGap=8
power(on: boolean) {
if (!this._speed || !on) { // always stop
//% speed.min=-100 speed.max=100
setSpeed(speed: number) {
this.__init();
speed = Math.clamp(-100, 100, speed >> 0);
if (!speed) { // always stop
this.stop();
} else {
if (this._follower) this.setSpeedSync(this._speed);
else this.setSpeedSingle(this._speed);
if (this._follower) this.setSpeedSync(speed);
else this.setSpeedSingle(speed);
}
}
@ -149,21 +150,21 @@ namespace motors {
* @param unit the meaning of the value
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
*/
//% blockId=motorMove block="move `icons.motorLarge` %motor|for %value|%unit"
//% blockId=motorMove block="move `icons.motorLarge` %motor|for %value|%unit|at %speed|%"
//% weight=98
//% speed.min=-100 speed.max=100
move(value: number, unit: MoveUnit) {
this.output(value, unit, 0);
move(value: number, unit: MoveUnit, speed: number) {
this.output(value, unit, speed, 0);
}
private output(value: number, unit: MoveUnit, turnRatio: number) {
private output(value: number, unit: MoveUnit, speed: number, turnRatio: number) {
this.__init();
if (!this._speed) {
speed = Math.clamp(-100, 100, speed >> 0);
if (!speed) {
this.stop();
return;
}
turnRatio = Math.clamp(-200, 200, turnRatio >> 0);
let useSteps: boolean;
let stepsOrTime: number;
switch (unit) {
@ -185,7 +186,7 @@ namespace motors {
syncMotors(this._port | this._follower._port, {
useSteps: useSteps,
stepsOrTime: stepsOrTime,
speed: this._speed,
speed: speed,
turnRatio: turnRatio,
useBrake: this._brake
})
@ -195,7 +196,7 @@ namespace motors {
step1: 0,
step2: stepsOrTime,
step3: 0,
speed: this._speed,
speed: speed,
useBrake: this._brake
})
}
@ -218,6 +219,7 @@ namespace motors {
//% brake.fieldEditor=toggleonoff
//% weight=60 blockGap=8
setBrake(brake: boolean) {
this.__init();
this._brake = brake;
}
@ -312,11 +314,11 @@ namespace motors {
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
* @param turnRatio the ratio of power sent to the follower motor, from -200 to 200
*/
//% blockId=motorTurn block="turn `icons.motorLarge` %motor|by %value|%unit|turn %turnRadio"
//% blockId=motorTurn block="turn `icons.motorLarge` %motor|by %value|%unit|at %speed|% turn %turnRadio"
//% weight=9 blockGap=8
//% turnRatio.min=-200 turnRatio=200
turn(value: number, unit: MoveUnit, turnRatio: number) {
this.output(value, unit, turnRatio);
turn(value: number, unit: MoveUnit, speed: number, turnRatio: number) {
this.output(value, unit, speed, turnRatio);
}
}