differentiate large/medium motors

This commit is contained in:
Peli de Halleux 2017-10-27 00:09:00 -07:00
parent 6391620373
commit 95076f8f24
3 changed files with 65 additions and 26 deletions

View File

@ -58,9 +58,13 @@
"input.remoteButtonTopRight": "Remote top-right button.", "input.remoteButtonTopRight": "Remote top-right button.",
"output.Motor.off": "Power off the motor.", "output.Motor.off": "Power off the motor.",
"output.Motor.on": "Power on the motor.", "output.Motor.on": "Power on the motor.",
"output.Motor.onForTime": "Power on the motor for a specified number of milliseconds.", "output.Motor.onForAngle": "Powers on the motor for a specified number of milliseconds.",
"output.Motor.onForAngle|param|brake": "whether or not to use the brake",
"output.Motor.onForAngle|param|degrees": "the number of degrees to turn, eg: 90",
"output.Motor.onForAngle|param|power": "the motor power level from ``-100`` to ``100``, eg: 50",
"output.Motor.onForTime": "Powers on the motor for a specified number of milliseconds.",
"output.Motor.onForTime|param|brake": "whether or not to use the brake", "output.Motor.onForTime|param|brake": "whether or not to use the brake",
"output.Motor.onForTime|param|ms": "the number of milliseconds to turn the motor on, eg: 500", "output.Motor.onForTime|param|milliseconds": "the number of milliseconds to turn the motor on, eg: 500",
"output.Motor.onForTime|param|power": "the motor power level from ``-100`` to ``100``, eg: 50", "output.Motor.onForTime|param|power": "the motor power level from ``-100`` to ``100``, eg: 50",
"output.Motor.on|param|power": "the motor power level from ``-100`` to ``100``, eg: 50", "output.Motor.on|param|power": "the motor power level from ``-100`` to ``100``, eg: 50",
"output.Motor.setPower": "Sets the motor power level from ``-100`` to ``100``.", "output.Motor.setPower": "Sets the motor power level from ``-100`` to ``100``.",

View File

@ -83,14 +83,19 @@
"input.ultrasonic4|block": "ultrasonic sensor 4", "input.ultrasonic4|block": "ultrasonic sensor 4",
"input|block": "input", "input|block": "input",
"output.Motor.off|block": "%motor|OFF then brake %brake", "output.Motor.off|block": "%motor|OFF then brake %brake",
"output.Motor.onForTime|block": "%motor|ON at power %power|for %ms=timePicker|ms then brake %brake", "output.Motor.onForAngle|block": "%motor|ON at power %power|for %degrees|deg then brake %brake",
"output.Motor.onForTime|block": "%motor|ON at power %power|for %milliseconds=timePicker|ms then brake %brake",
"output.Motor.on|block": "%motor|ON at power %power", "output.Motor.on|block": "%motor|ON at power %power",
"output.Motor.setPower|block": "%motor|set power to %speed", "output.Motor.setPower|block": "%motor|set power to %speed",
"output.Motor.speed|block": "%motor|speed", "output.Motor.speed|block": "%motor|speed",
"output.motorA|block": "motor A", "output.largeMotorA|block": "large motor A",
"output.motorB|block": "motor B", "output.largeMotorB|block": "large motor B",
"output.motorC|block": "motor C", "output.largeMotorC|block": "large motor C",
"output.motorD|block": "motor D", "output.largeMotorD|block": "large motor D",
"output.mediumMotorA|block": "medium motor A",
"output.mediumMotorB|block": "medium motor B",
"output.mediumMotorC|block": "medium motor C",
"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|block": "output", "output|block": "output",

View File

@ -66,9 +66,11 @@ namespace output {
//% fixedInstances //% fixedInstances
export class Motor extends control.Component { export class Motor extends control.Component {
port: Output; port: Output;
constructor(port: Output) { large: boolean;
constructor(port: Output, large: boolean) {
super(); super();
this.port = port; this.port = port;
this.large = large;
} }
/** /**
@ -99,26 +101,42 @@ namespace output {
} }
/** /**
* Power on the motor for a specified number of milliseconds. * Powers on the motor for a specified number of milliseconds.
* @param motor the motor to turn on * @param motor the motor to turn on
* @param power the motor power level from ``-100`` to ``100``, eg: 50 * @param power the motor power level from ``-100`` to ``100``, eg: 50
* @param ms the number of milliseconds to turn the motor on, eg: 500 * @param milliseconds the number of milliseconds to turn the motor on, eg: 500
* @param brake whether or not to use the brake * @param brake whether or not to use the brake
*/ */
//% blockId=outputMotorOnForTime block="%motor|ON at power %power|for %ms=timePicker|ms then brake %brake" //% blockId=outputMotorOnForTime block="%motor|ON at power %power|for %milliseconds=timePicker|ms then brake %brake"
//% power.min=-100 power.max=100 //% power.min=-100 power.max=100
//% brake.fieldEditor=toggleonoff //% brake.fieldEditor=toggleonoff
//% weight=98 group="Motors" blockGap=8 //% weight=98 group="Motors" blockGap=8
onForTime(power: number, ms: number, brake = false) { onForTime(power: number, milliseconds: number, brake = false) {
step(this.port, { step(this.port, {
power, power,
step1: 0, step1: 0,
step2: ms, step2: milliseconds,
step3: 0, step3: 0,
useSteps: false, useSteps: false,
useBrake: brake useBrake: brake
}) })
loops.pause(ms); loops.pause(milliseconds);
}
/**
* Powers on the motor for a specified number of milliseconds.
* @param motor the motor to turn on
* @param power the motor power level from ``-100`` to ``100``, eg: 50
* @param degrees the number of degrees to turn, eg: 90
* @param brake whether or not to use the brake
*/
//% blockId=outputMotorOnForAngle block="%motor|ON at power %power|for %degrees|deg then brake %brake"
//% power.min=-100 power.max=100
//% degrees.min=-360 degrees.max=360
//% brake.fieldEditor=toggleonoff
//% weight=97 group="Motors" blockGap=8
onForAngle(power: number, degrees: number, brake = false) {
// TODO
} }
/** /**
@ -146,17 +164,29 @@ namespace output {
} }
} }
//% whenUsed fixedInstance block="motor B" //% whenUsed fixedInstance block="large motor A"
export const motorB = new Motor(Output.B); export const largeMotorA = new Motor(Output.A, true);
//% whenUsed fixedInstance block="motor C" //% whenUsed fixedInstance block="large motor B"
export const motorC = new Motor(Output.C); export const largeMotorB = new Motor(Output.B, true);
//% whenUsed fixedInstance block="motor A" //% whenUsed fixedInstance block="large motor C"
export const motorA = new Motor(Output.A); export const largeMotorC = new Motor(Output.C, true);
//% whenUsed fixedInstance block="motor D" //% whenUsed fixedInstance block="large motor D"
export const motorD = new Motor(Output.D); export const largeMotorD = new Motor(Output.D, true);
//% whenUsed fixedInstance block="medium motor A"
export const mediumMotorA = new Motor(Output.A, false);
//% whenUsed fixedInstance block="medium motor B"
export const mediumMotorB = new Motor(Output.B, false);
//% whenUsed fixedInstance block="medium motor C"
export const mediumMotorC = new Motor(Output.C, false);
//% whenUsed fixedInstance block="medium motor D"
export const mediumMotorD = new Motor(Output.D, false);
function reset(out: Output) { function reset(out: Output) {
let b = mkCmd(out, DAL.opOutputReset, 0) let b = mkCmd(out, DAL.opOutputReset, 0)