Motor pause until ready (#108)
* adding command to pause until ready * adding console API * adding ready support for motors * fix time output scale * fixing angle
This commit is contained in:
@ -51,10 +51,13 @@
|
||||
"control.raiseEvent": "Announce that an event happened to registered handlers.",
|
||||
"control.raiseEvent|param|src": "ID of the Component that generated the event",
|
||||
"control.raiseEvent|param|value": "Component specific code indicating the cause of the event.",
|
||||
"motors.Motor.isReady": "Returns a value indicating if the motor is still running a previous command.",
|
||||
"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.pauseUntilReady": "Pauses the execution until the previous command finished.",
|
||||
"motors.Motor.pauseUntilReady|param|timeOut": "optional maximum pausing time in milliseconds",
|
||||
"motors.Motor.reset": "Resets the motor(s).",
|
||||
"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",
|
||||
@ -62,10 +65,9 @@
|
||||
"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.stop": "Stops the motor(s).",
|
||||
"motors.SingleMotor.angle": "Gets motor ration angle.",
|
||||
"motors.SingleMotor.clearCount": "Clears the motor count",
|
||||
"motors.SingleMotor.count": "Gets motor step count.",
|
||||
"motors.SingleMotor.speed": "Gets motor actual speed.",
|
||||
"motors.SingleMotor.tachoCount": "Gets motor tacho count.",
|
||||
"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``",
|
||||
|
@ -13,8 +13,8 @@
|
||||
"LightsPattern.RedPulse|block": "Pulsing Red",
|
||||
"LightsPattern.Red|block": "Red",
|
||||
"MoveUnit.Degrees|block": "degrees",
|
||||
"MoveUnit.MilliSeconds|block": "milliseconds",
|
||||
"MoveUnit.Rotations|block": "rotations",
|
||||
"MoveUnit.Seconds|block": "seconds",
|
||||
"Output.AB|block": "A+B",
|
||||
"Output.AD|block": "A+D",
|
||||
"Output.ALL|block": "All",
|
||||
@ -44,12 +44,12 @@
|
||||
"control.raiseEvent|block": "raise event|from %src|with value %value",
|
||||
"control|block": "control",
|
||||
"motors.Motor.move|block": "move `icons.motorLarge` %motor|for %value|%unit|at %speed|%",
|
||||
"motors.Motor.pauseUntilReady|block": "%motor|pause until ready",
|
||||
"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.SingleMotor.count|block": "`icons.motorLarge` %motor|count",
|
||||
"motors.SingleMotor.angle|block": "`icons.motorLarge` %motor|angle",
|
||||
"motors.SingleMotor.speed|block": "`icons.motorLarge` %motor|speed",
|
||||
"motors.SingleMotor.tachoCount|block": "`icons.motorLarge` %motor|tacho count",
|
||||
"motors.SynchedMotorPair.steer|block": "steer %chassis|%steering|%|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",
|
||||
|
@ -30,8 +30,8 @@ enum MoveUnit {
|
||||
Rotations,
|
||||
//% block="degrees"
|
||||
Degrees,
|
||||
//% block="seconds"
|
||||
Seconds
|
||||
//% block="milliseconds"
|
||||
MilliSeconds
|
||||
}
|
||||
|
||||
namespace motors {
|
||||
@ -65,9 +65,9 @@ namespace motors {
|
||||
pwmMM.write(buf)
|
||||
}
|
||||
|
||||
function readPWM(buf: Buffer): void {
|
||||
function readPWM(buf: Buffer): number {
|
||||
init()
|
||||
pwmMM.read(buf);
|
||||
return pwmMM.read(buf);
|
||||
}
|
||||
|
||||
function mkCmd(out: Output, cmd: number, addSize: number) {
|
||||
@ -220,6 +220,27 @@ namespace motors {
|
||||
|
||||
this._move(useSteps, stepsOrTime, speed);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a value indicating if the motor is still running a previous command.
|
||||
*/
|
||||
//%
|
||||
isReady(): boolean {
|
||||
this.init();
|
||||
const r = readPWM(mkCmd(this._port, DAL.opOutputTest, 0))
|
||||
// 0 = ready, 1 = busy
|
||||
return r == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses the execution until the previous command finished.
|
||||
* @param timeOut optional maximum pausing time in milliseconds
|
||||
*/
|
||||
//% blockId=motorPauseUntilRead block="%motor|pause until ready"
|
||||
//% group="Motion"
|
||||
pauseUntilReady(timeOut: number = -1) {
|
||||
pauseUntil(() => this.isReady(), timeOut);
|
||||
}
|
||||
}
|
||||
|
||||
//% fixedInstances
|
||||
@ -248,7 +269,7 @@ namespace motors {
|
||||
b.setNumber(NumberFormat.Int8LE, 2, speed)
|
||||
writePWM(b)
|
||||
if (speed) {
|
||||
writePWM(mkCmd(this._port, DAL.opOutputStart, 0))
|
||||
writePWM(mkCmd(this._port, DAL.opOutputStart, 0))
|
||||
}
|
||||
}
|
||||
|
||||
@ -276,27 +297,15 @@ namespace motors {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets motor step count.
|
||||
* Gets motor ration angle.
|
||||
* @param motor the port which connects to the motor
|
||||
*/
|
||||
//% blockId=motorCount block="`icons.motorLarge` %motor|count"
|
||||
//% weight=71 blockGap=8
|
||||
//% group="Sensors"
|
||||
count(): number {
|
||||
this.init();
|
||||
return getMotorData(this._port).count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets motor tacho count.
|
||||
* @param motor the port which connects to the motor
|
||||
*/
|
||||
//% blockId=motorTachoCount block="`icons.motorLarge` %motor|tacho count"
|
||||
//% blockId=motorTachoCount block="`icons.motorLarge` %motor|angle"
|
||||
//% weight=70
|
||||
//% group="Sensors"
|
||||
tachoCount(): number {
|
||||
angle(): number {
|
||||
this.init();
|
||||
return getMotorData(this._port).tachoCount;
|
||||
return getMotorData(this._port).count;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user