bring back speed
This commit is contained in:
parent
3c86ae286f
commit
92178f3371
@ -53,19 +53,21 @@
|
|||||||
"motors.Motor.clearCount": "Clears the motor count",
|
"motors.Motor.clearCount": "Clears the motor count",
|
||||||
"motors.Motor.count": "Gets motor step 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": "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|unit": "the meaning of the value",
|
||||||
"motors.Motor.move|param|value": "the move quantity, eg: 2",
|
"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.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": "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.setBrake|param|brake": "a value indicating if the motor should break when off",
|
||||||
"motors.Motor.setReversed": "Reverses the motor polarity",
|
"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.speed": "Gets motor actual speed.",
|
||||||
"motors.Motor.sync": "Synchronizes a follower motor to this motor",
|
"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.sync|param|follower": "the motor that follows this motor commands, eg: motors.largeC",
|
||||||
"motors.Motor.tachoCount": "Gets motor tacho count.",
|
"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": "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|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|unit": "the meaning of the value",
|
||||||
"motors.Motor.turn|param|value": "the move quantity, eg: 2",
|
"motors.Motor.turn|param|value": "the move quantity, eg: 2",
|
||||||
|
@ -40,15 +40,15 @@
|
|||||||
"control.raiseEvent|block": "raise event|from %src|with value %value",
|
"control.raiseEvent|block": "raise event|from %src|with value %value",
|
||||||
"control|block": "control",
|
"control|block": "control",
|
||||||
"motors.Motor.count|block": "`icons.motorLarge` %motor|count",
|
"motors.Motor.count|block": "`icons.motorLarge` %motor|count",
|
||||||
"motors.Motor.move|block": "move `icons.motorLarge` %motor|for %value|%unit",
|
"motors.Motor.move|block": "move `icons.motorLarge` %motor|for %value|%unit|at %speed|%",
|
||||||
"motors.Motor.power|block": "power `icons.motorLarge` %motor|%on",
|
|
||||||
"motors.Motor.reset|block": "reset `icons.motorLarge` %motor",
|
"motors.Motor.reset|block": "reset `icons.motorLarge` %motor",
|
||||||
"motors.Motor.setBrake|block": "set `icons.motorLarge` %motor|brake %brake",
|
"motors.Motor.setBrake|block": "set `icons.motorLarge` %motor|brake %brake",
|
||||||
"motors.Motor.setReversed|block": "set `icons.motorLarge` %motor|reversed %reversed",
|
"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.speed|block": "`icons.motorLarge` %motor|speed",
|
||||||
"motors.Motor.sync|block": "sync `icons.motorLarge` %motor|with `icons.motorLarge` %follower",
|
"motors.Motor.sync|block": "sync `icons.motorLarge` %motor|with `icons.motorLarge` %follower",
|
||||||
"motors.Motor.tachoCount|block": "`icons.motorLarge` %motor|tacho count",
|
"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.largeMotorA|block": "large A",
|
||||||
"motors.largeMotorB|block": "large B",
|
"motors.largeMotorB|block": "large B",
|
||||||
"motors.largeMotorC|block": "large C",
|
"motors.largeMotorC|block": "large C",
|
||||||
|
@ -91,7 +91,6 @@ namespace motors {
|
|||||||
private _large: boolean;
|
private _large: boolean;
|
||||||
|
|
||||||
private _initialized: boolean;
|
private _initialized: boolean;
|
||||||
private _speed: number;
|
|
||||||
private _brake: boolean;
|
private _brake: boolean;
|
||||||
private _follower: Motor; //
|
private _follower: Motor; //
|
||||||
|
|
||||||
@ -100,7 +99,6 @@ namespace motors {
|
|||||||
this._port = port;
|
this._port = port;
|
||||||
this._large = large;
|
this._large = large;
|
||||||
this._brake = false;
|
this._brake = false;
|
||||||
this._speed = 50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private __init() {
|
private __init() {
|
||||||
@ -113,18 +111,21 @@ namespace motors {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Turns the motor on or off at the current speed
|
* Sets the speed of the motor.
|
||||||
* @param on true if the motor should be on
|
* @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
|
//% on.fieldEditor=toggleonoff
|
||||||
//% weight=99 blockGap=8
|
//% weight=99 blockGap=8
|
||||||
power(on: boolean) {
|
//% speed.min=-100 speed.max=100
|
||||||
if (!this._speed || !on) { // always stop
|
setSpeed(speed: number) {
|
||||||
|
this.__init();
|
||||||
|
speed = Math.clamp(-100, 100, speed >> 0);
|
||||||
|
if (!speed) { // always stop
|
||||||
this.stop();
|
this.stop();
|
||||||
} else {
|
} else {
|
||||||
if (this._follower) this.setSpeedSync(this._speed);
|
if (this._follower) this.setSpeedSync(speed);
|
||||||
else this.setSpeedSingle(this._speed);
|
else this.setSpeedSingle(speed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,21 +150,21 @@ namespace motors {
|
|||||||
* @param unit the meaning of the value
|
* @param unit the meaning of the value
|
||||||
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
|
* @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
|
//% weight=98
|
||||||
//% speed.min=-100 speed.max=100
|
//% speed.min=-100 speed.max=100
|
||||||
move(value: number, unit: MoveUnit) {
|
move(value: number, unit: MoveUnit, speed: number) {
|
||||||
this.output(value, unit, 0);
|
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();
|
this.__init();
|
||||||
if (!this._speed) {
|
speed = Math.clamp(-100, 100, speed >> 0);
|
||||||
|
if (!speed) {
|
||||||
this.stop();
|
this.stop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
turnRatio = Math.clamp(-200, 200, turnRatio >> 0);
|
turnRatio = Math.clamp(-200, 200, turnRatio >> 0);
|
||||||
|
|
||||||
let useSteps: boolean;
|
let useSteps: boolean;
|
||||||
let stepsOrTime: number;
|
let stepsOrTime: number;
|
||||||
switch (unit) {
|
switch (unit) {
|
||||||
@ -185,7 +186,7 @@ namespace motors {
|
|||||||
syncMotors(this._port | this._follower._port, {
|
syncMotors(this._port | this._follower._port, {
|
||||||
useSteps: useSteps,
|
useSteps: useSteps,
|
||||||
stepsOrTime: stepsOrTime,
|
stepsOrTime: stepsOrTime,
|
||||||
speed: this._speed,
|
speed: speed,
|
||||||
turnRatio: turnRatio,
|
turnRatio: turnRatio,
|
||||||
useBrake: this._brake
|
useBrake: this._brake
|
||||||
})
|
})
|
||||||
@ -195,7 +196,7 @@ namespace motors {
|
|||||||
step1: 0,
|
step1: 0,
|
||||||
step2: stepsOrTime,
|
step2: stepsOrTime,
|
||||||
step3: 0,
|
step3: 0,
|
||||||
speed: this._speed,
|
speed: speed,
|
||||||
useBrake: this._brake
|
useBrake: this._brake
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -218,6 +219,7 @@ namespace motors {
|
|||||||
//% brake.fieldEditor=toggleonoff
|
//% brake.fieldEditor=toggleonoff
|
||||||
//% weight=60 blockGap=8
|
//% weight=60 blockGap=8
|
||||||
setBrake(brake: boolean) {
|
setBrake(brake: boolean) {
|
||||||
|
this.__init();
|
||||||
this._brake = brake;
|
this._brake = brake;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,11 +314,11 @@ namespace motors {
|
|||||||
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
|
* @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
|
* @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
|
//% weight=9 blockGap=8
|
||||||
//% turnRatio.min=-200 turnRatio=200
|
//% turnRatio.min=-200 turnRatio=200
|
||||||
turn(value: number, unit: MoveUnit, turnRatio: number) {
|
turn(value: number, unit: MoveUnit, speed: number, turnRatio: number) {
|
||||||
this.output(value, unit, turnRatio);
|
this.output(value, unit, speed, turnRatio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user