stop all motors

This commit is contained in:
Peli de Halleux 2017-10-27 02:52:42 -07:00
parent 712c2178d2
commit 05a8395028
3 changed files with 78 additions and 22 deletions

View File

@ -56,18 +56,24 @@
"input.remoteButtonCenter": "Remote beacon (center) button.", "input.remoteButtonCenter": "Remote beacon (center) button.",
"input.remoteButtonTopLeft": "Remote top-left button.", "input.remoteButtonTopLeft": "Remote top-left button.",
"input.remoteButtonTopRight": "Remote top-right button.", "input.remoteButtonTopRight": "Remote top-right button.",
"output.Motor.clearCount": "Clears the motor count",
"output.Motor.count": "Gets motor step count.",
"output.Motor.on": "Power on or off the motor.", "output.Motor.on": "Power on or off the motor.",
"output.Motor.reset": "Resets the motor.",
"output.Motor.setBrake": "Sets the automatic brake on or off when the motor is off", "output.Motor.setBrake": "Sets the automatic brake on or off when the motor is off",
"output.Motor.setBrake|param|brake": "a value indicating if the motor should break when off", "output.Motor.setBrake|param|brake": "a value indicating if the motor should break when off",
"output.Motor.setPower": "Sets the motor power level from ``-100`` to ``100``.", "output.Motor.setPower": "Sets the motor power level from ``-100`` to ``100``.",
"output.Motor.setPower|param|power": "the desired speed to use. eg: 50", "output.Motor.setPower|param|power": "the desired speed to use. eg: 50",
"output.Motor.setReversed": "Reverses the motor polarity",
"output.Motor.speed": "Gets motor actual speed.", "output.Motor.speed": "Gets motor actual speed.",
"output.Motor.tachoCount": "Gets motor tacho count.",
"output.createBuffer": "Create a new zero-initialized buffer.", "output.createBuffer": "Create a new zero-initialized buffer.",
"output.createBuffer|param|size": "number of bytes in the buffer", "output.createBuffer|param|size": "number of bytes in the buffer",
"output.pattern": "Pattern block.", "output.pattern": "Pattern block.",
"output.pattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green", "output.pattern|param|pattern": "the lights pattern to use. eg: LightsPattern.Green",
"output.setStatusLight": "Set lights.", "output.setStatusLight": "Set lights.",
"output.setStatusLight|param|pattern": "the lights pattern to use.", "output.setStatusLight|param|pattern": "the lights pattern to use.",
"output.stopAllMotors": "Stops all motors",
"screen.clear": "Clear screen and reset font to normal.", "screen.clear": "Clear screen and reset font to normal.",
"screen.doubleIcon": "Double size of an icon.", "screen.doubleIcon": "Double size of an icon.",
"screen.drawIcon": "Draw an icon on the screen.", "screen.drawIcon": "Draw an icon on the screen.",

View File

@ -82,10 +82,13 @@
"input.ultrasonic3|block": "ultrasonic sensor 3", "input.ultrasonic3|block": "ultrasonic sensor 3",
"input.ultrasonic4|block": "ultrasonic sensor 4", "input.ultrasonic4|block": "ultrasonic sensor 4",
"input|block": "input", "input|block": "input",
"output.Motor.count|block": "%motor|count",
"output.Motor.on|block": "%motor|%onOrOff", "output.Motor.on|block": "%motor|%onOrOff",
"output.Motor.setBrake|block": "%motor|set brake %brake", "output.Motor.setBrake|block": "%motor|set brake %brake",
"output.Motor.setPower|block": "%motor|set power to %speed", "output.Motor.setPower|block": "%motor|set power to %speed",
"output.Motor.setReversed|block": "%motor|set reversed %reversed",
"output.Motor.speed|block": "%motor|speed", "output.Motor.speed|block": "%motor|speed",
"output.Motor.tachoCount|block": "%motor|tacho count",
"output.largeMotorA|block": "large motor A", "output.largeMotorA|block": "large motor A",
"output.largeMotorB|block": "large motor B", "output.largeMotorB|block": "large motor B",
"output.largeMotorC|block": "large motor C", "output.largeMotorC|block": "large motor C",
@ -96,6 +99,7 @@
"output.mediumMotorD|block": "medium motor D", "output.mediumMotorD|block": "medium motor D",
"output.pattern|block": "%pattern", "output.pattern|block": "%pattern",
"output.setStatusLight|block": "set status light %pattern=led_pattern", "output.setStatusLight|block": "set status light %pattern=led_pattern",
"output.stopAllMotors|block": "stop all motors",
"output|block": "output", "output|block": "output",
"screen.print|block": "print %text| at x: %x| y: %y", "screen.print|block": "print %text| at x: %x| y: %y",
"screen.setPixel|block": "set pixel %on| at x: %x| y: %y", "screen.setPixel|block": "set pixel %on| at x: %x| y: %y",

View File

@ -63,6 +63,16 @@ namespace output {
reset(Output.ALL) reset(Output.ALL)
} }
/**
* Stops all motors
*/
//% blockId=motorStopAll block="stop all motors"
//% weight=10 group="Motors" blockGap=8
export function stopAllMotors() {
const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
writePWM(b)
}
//% fixedInstances //% fixedInstances
export class Motor extends control.Component { export class Motor extends control.Component {
private port: Output; private port: Output;
@ -82,8 +92,8 @@ namespace output {
* @param power the motor power level from ``-100`` to ``100``, eg: 50 * @param power the motor power level from ``-100`` to ``100``, eg: 50
*/ */
//% blockId=outputMotorOn block="%motor|%onOrOff" //% blockId=outputMotorOn block="%motor|%onOrOff"
//% weight=99 group="Motors" blockGap=8
//% onOrOff.fieldEditor=toggleonoff //% onOrOff.fieldEditor=toggleonoff
//% weight=99 group="Motors" blockGap=8
on(onOrOff: boolean = true) { on(onOrOff: boolean = true) {
if (onOrOff) { if (onOrOff) {
const b = mkCmd(this.port, DAL.opOutputStart, 0) const b = mkCmd(this.port, DAL.opOutputStart, 0)
@ -101,7 +111,7 @@ namespace output {
* @param power the desired speed to use. eg: 50 * @param power the desired speed to use. eg: 50
*/ */
//% blockId=motorSetPower block="%motor|set power to %speed" //% blockId=motorSetPower block="%motor|set power to %speed"
//% weight=60 group="Motors" blockGap=8 //% weight=62 group="Motors" blockGap=8
//% speed.min=-100 speed.max=100 //% speed.min=-100 speed.max=100
setPower(power: number) { setPower(power: number) {
const b = mkCmd(this.port, DAL.opOutputPower, 1) const b = mkCmd(this.port, DAL.opOutputPower, 1)
@ -115,20 +125,72 @@ namespace output {
*/ */
//% blockId=outputMotorSetBrakeMode block="%motor|set brake %brake" //% blockId=outputMotorSetBrakeMode block="%motor|set brake %brake"
//% brake.fieldEditor=toggleonoff //% brake.fieldEditor=toggleonoff
//% weight=60 group="Motors" //% weight=60 group="Motors" blockGap=8
setBrake(brake: boolean) { setBrake(brake: boolean) {
this.brake = brake; this.brake = brake;
} }
/**
* Reverses the motor polarity
*/
//% blockId=motorSetReversed block="%motor|set reversed %reversed"
//% reversed.fieldEditor=toggleonoff
//% weight=59 group="Motors"
setReversed(reversed: boolean) {
const b = mkCmd(this.port, DAL.opOutputPolarity, 1)
b.setNumber(NumberFormat.Int8LE, 2, reversed ? -1 : 1);
writePWM(b)
}
/** /**
* Gets motor actual speed. * Gets motor actual speed.
* @param motor the port which connects to the motor * @param motor the port which connects to the motor
*/ */
//% blockId=motorSpeed block="%motor|speed" //% blockId=motorSpeed block="%motor|speed"
//% weight=50 group="Motors" blockGap=8 //% weight=50 group="Motors" blockGap=8
speed() { speed(): number {
return getMotorData(this.port).actualSpeed; return getMotorData(this.port).actualSpeed;
} }
/**
* Gets motor step count.
* @param motor the port which connects to the motor
*/
//% blockId=motorCount block="%motor|count"
//% weight=49 group="Motors" blockGap=8
count(): number {
return getMotorData(this.port).count;
}
/**
* Gets motor tacho count.
* @param motor the port which connects to the motor
*/
//% blockId=motorTachoCount block="%motor|tacho count"
//% weight=48 group="Motors"
tachoCount(): number {
return getMotorData(this.port).tachoCount;
}
/**
* Clears the motor count
*/
clearCount() {
const b = mkCmd(this.port, DAL.opOutputClearCount, 0)
writePWM(b)
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
if (this.port & (1 << i)) {
motorMM.setNumber(NumberFormat.Int32LE, i * MotorDataOff.Size + MotorDataOff.TachoSensor, 0)
}
}
}
/**
* Resets the motor.
*/
reset() {
reset(this.port);
}
} }
//% whenUsed fixedInstance block="large motor A" //% whenUsed fixedInstance block="large motor A"
@ -160,16 +222,6 @@ namespace output {
writePWM(b) writePWM(b)
} }
function clearCount(out: Output) {
let b = mkCmd(out, DAL.opOutputClearCount, 0)
writePWM(b)
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
if (out & (1 << i)) {
motorMM.setNumber(NumberFormat.Int32LE, i * MotorDataOff.Size + MotorDataOff.TachoSensor, 0)
}
}
}
function outOffset(out: Output) { function outOffset(out: Output) {
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) { for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
if (out & (1 << i)) if (out & (1 << i))
@ -194,12 +246,6 @@ namespace output {
} }
} }
function setPolarity(out: Output, polarity: number) {
let b = mkCmd(out, DAL.opOutputPolarity, 1)
b.setNumber(NumberFormat.Int8LE, 2, Math.clamp(-1, 1, polarity))
writePWM(b)
}
interface StepOptions { interface StepOptions {
power?: number; power?: number;
speed?: number; // either speed or power has to be present speed?: number; // either speed or power has to be present