renaming 'set speed' to 'run' (#327)

This commit is contained in:
Peli de Halleux 2018-02-19 07:35:08 -08:00 committed by GitHub
parent 3b6cfed5b2
commit fad4ca98db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 177 additions and 177 deletions

View File

@ -67,7 +67,7 @@
* [set light](/reference/brick/set-status-light) * [set light](/reference/brick/set-status-light)
* [battery level](/reference/brick/battery-level) * [battery level](/reference/brick/battery-level)
* [Motors](/reference/motors) * [Motors](/reference/motors)
* [set speed](/reference/motors/motor/set-speed) * [run](/reference/motors/motor/run)
* [stop](/reference/motors/motor/stop) * [stop](/reference/motors/motor/stop)
* [reset](/reference/motors/motor/reset) * [reset](/reference/motors/motor/reset)
* [set brake](/reference/motors/motor/set-brake) * [set brake](/reference/motors/motor/set-brake)

View File

@ -8,12 +8,12 @@ You can program the @boardname@ using [Blocks](/blocks) or [JavaScript](/javascr
```blocks ```blocks
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => { brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
motors.largeA.setSpeed(50) motors.largeA.run(50)
}) })
``` ```
```typescript ```typescript
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => { brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
motors.largeA.setSpeed(50) motors.largeA.run(50)
}) })
``` ```
@ -34,6 +34,6 @@ The simulator has support for the LED screen, buttons, as well as compass, accel
```sim ```sim
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => { brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
motors.largeA.setSpeed(50) motors.largeA.run(50)
}) })
``` ```

View File

@ -5,6 +5,6 @@ let speed = 0;
sensors.touch1.onEvent(ButtonEvent.Pressed, function () { sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
if (speed < 100) if (speed < 100)
speed = speed + 10; speed = speed + 10;
motors.largeBC.setSpeed(speed); motors.largeBC.run(speed);
}) })
``` ```

View File

@ -5,11 +5,11 @@ let speed = 0;
sensors.touch1.onEvent(ButtonEvent.Pressed, function () { sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
if (speed < 100) if (speed < 100)
speed = speed + 10; speed = speed + 10;
motors.largeBC.setSpeed(speed); motors.largeBC.run(speed);
}) })
sensors.touch2.onEvent(ButtonEvent.Pressed, function () { sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
if (speed > -100) if (speed > -100)
speed = speed - 10; speed = speed - 10;
motors.largeBC.setSpeed(speed); motors.largeBC.run(speed);
}) })
``` ```

View File

@ -15,7 +15,7 @@ function accelerate() {
function update() { function update() {
brick.clearScreen() brick.clearScreen()
brick.showString("speed: " + speed, 1) brick.showString("speed: " + speed, 1)
motors.largeBC.setSpeed(speed) motors.largeBC.run(speed)
} }
sensors.touch2.onEvent(ButtonEvent.Pressed, function () { sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
accelerate() accelerate()

View File

@ -5,7 +5,7 @@ forever(function () {
music.playTone(440, sensors.ultrasonic4.distance()); music.playTone(440, sensors.ultrasonic4.distance());
pause(50) pause(50)
}) })
motors.largeBC.setSpeed(-20); motors.largeBC.run(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear); sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.largeBC.stop(); motors.largeBC.stop();
``` ```

View File

@ -7,7 +7,7 @@ forever(function () {
pause(50) pause(50)
} }
}) })
motors.largeBC.setSpeed(-20); motors.largeBC.run(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear); sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.largeBC.stop(); motors.largeBC.stop();
``` ```

View File

@ -4,7 +4,7 @@
let beep = false let beep = false
beep = true beep = true
control.runInParallel(function () { control.runInParallel(function () {
motors.largeBC.setSpeed(-20) motors.largeBC.run(-20)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear) sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
motors.largeBC.stop() motors.largeBC.stop()
beep = false beep = false

View File

@ -2,13 +2,13 @@
```blocks ```blocks
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () { brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
motors.largeBC.setSpeed(50) motors.largeBC.run(50)
sensors.touch1.pauseUntil(ButtonEvent.Pressed) sensors.touch1.pauseUntil(ButtonEvent.Pressed)
motors.largeBC.setSpeed(0) motors.largeBC.run(0)
pause(1000) pause(1000)
brick.setStatusLight(StatusLight.OrangeFlash) brick.setStatusLight(StatusLight.OrangeFlash)
motors.largeBC.setSpeed(-50) motors.largeBC.run(-50)
pause(2000) pause(2000)
motors.largeBC.setSpeed(0) motors.largeBC.run(0)
}) })
``` ```

View File

@ -3,13 +3,13 @@
```blocks ```blocks
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () { brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
sensors.touch1.pauseUntil(ButtonEvent.Pressed) sensors.touch1.pauseUntil(ButtonEvent.Pressed)
motors.largeBC.setSpeed(50) motors.largeBC.run(50)
sensors.touch2.pauseUntil(ButtonEvent.Pressed) sensors.touch2.pauseUntil(ButtonEvent.Pressed)
motors.largeBC.setSpeed(0) motors.largeBC.run(0)
pause(1000) pause(1000)
brick.setStatusLight(StatusLight.OrangeFlash) brick.setStatusLight(StatusLight.OrangeFlash)
motors.largeBC.setSpeed(-50) motors.largeBC.run(-50)
pause(2000) pause(2000)
motors.largeBC.setSpeed(0) motors.largeBC.run(0)
}) })
``` ```

View File

@ -5,15 +5,15 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
brick.showImage(images.eyesSleeping) brick.showImage(images.eyesSleeping)
sensors.touch1.pauseUntil(ButtonEvent.Pressed) sensors.touch1.pauseUntil(ButtonEvent.Pressed)
brick.showImage(images.eyesNeutral) brick.showImage(images.eyesNeutral)
motors.largeBC.setSpeed(50) motors.largeBC.run(50)
sensors.touch2.pauseUntil(ButtonEvent.Pressed) sensors.touch2.pauseUntil(ButtonEvent.Pressed)
brick.showImage(images.eyesTiredMiddle) brick.showImage(images.eyesTiredMiddle)
motors.largeBC.setSpeed(0) motors.largeBC.run(0)
pause(1000) pause(1000)
brick.setStatusLight(StatusLight.OrangeFlash) brick.setStatusLight(StatusLight.OrangeFlash)
brick.showImage(images.eyesDizzy) brick.showImage(images.eyesDizzy)
motors.largeBC.setSpeed(-50) motors.largeBC.run(-50)
pause(2000) pause(2000)
motors.largeBC.setSpeed(0) motors.largeBC.run(0)
}) })
``` ```

View File

@ -19,13 +19,13 @@ pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo) music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) { for (let d of drive) {
if (d == 1) { if (d == 1) {
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees) motors.largeC.run(50, 360, MoveUnit.Degrees)
} else if (d == 3) { } else if (d == 3) {
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees) motors.largeB.run(50, 360, MoveUnit.Degrees)
} else if (d == 4) { } else if (d == 4) {
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees) motors.largeBC.run(50, 360, MoveUnit.Degrees)
} else { } else {
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees) motors.largeBC.run(-50, 360, MoveUnit.Degrees)
} }
} }
music.playSoundEffectUntilDone(sounds.communicationGameOver) music.playSoundEffectUntilDone(sounds.communicationGameOver)

View File

@ -23,13 +23,13 @@ pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo) music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) { for (let d of drive) {
if (d == 1) { if (d == 1) {
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees) motors.largeC.run(50, 360, MoveUnit.Degrees)
} else if (d == 3) { } else if (d == 3) {
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees) motors.largeB.run(50, 360, MoveUnit.Degrees)
} else if (d == 4) { } else if (d == 4) {
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees) motors.largeBC.run(50, 360, MoveUnit.Degrees)
} else { } else {
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees) motors.largeBC.run(-50, 360, MoveUnit.Degrees)
} }
} }
music.playSoundEffectUntilDone(sounds.communicationGameOver) music.playSoundEffectUntilDone(sounds.communicationGameOver)

View File

@ -119,9 +119,9 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
controlSteering = 0 controlSteering = 0
oldControlDrive = controlDrive oldControlDrive = controlDrive
controlDrive = -10 controlDrive = -10
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees); motors.mediumC.run(30, 30, MoveUnit.Degrees);
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees); motors.mediumC.run(-30, 60, MoveUnit.Degrees);
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees); motors.mediumC.run(30, 30, MoveUnit.Degrees);
if (Math.randomRange(-1, 1) >= 1) { if (Math.randomRange(-1, 1) >= 1) {
controlSteering = 70 controlSteering = 70
} else { } else {
@ -149,8 +149,8 @@ sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
}) })
// apply power to motors // apply power to motors
function controlMotors() { function controlMotors() {
motors.largeA.setSpeed(power + controlSteering * 0.1) motors.largeA.run(power + controlSteering * 0.1)
motors.largeD.setSpeed(power - controlSteering * 0.1) motors.largeD.run(power - controlSteering * 0.1)
} }
sensors.color1.onColorDetected(ColorSensorColor.Yellow, function () { sensors.color1.onColorDetected(ColorSensorColor.Yellow, function () {
moods.middleLeft.show() moods.middleLeft.show()

View File

@ -137,8 +137,8 @@ forever(function () {
GM(); GM();
EQ(); EQ();
cntrl(); cntrl();
motors.largeA.setSpeed(lpwr) motors.largeA.run(lpwr)
motors.largeD.setSpeed(rpwr) motors.largeD.run(rpwr)
CHK() CHK()
let t2 = control.timer1.millis(); let t2 = control.timer1.millis();
let p = 5 - (t2 - t1); let p = 5 - (t2 - t1);
@ -196,9 +196,9 @@ forever(function () {
Cstr = 0; Cstr = 0;
oldDr = Cdrv; oldDr = Cdrv;
Cdrv = -10; Cdrv = -10;
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees); motors.mediumC.run(30, 30, MoveUnit.Degrees);
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees); motors.mediumC.run(-30, 60, MoveUnit.Degrees);
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees); motors.mediumC.run(30, 30, MoveUnit.Degrees);
if (Math.randomRange(-1, 1) >= 1) if (Math.randomRange(-1, 1) >= 1)
Cstr = 70; Cstr = 70;
else else

View File

@ -32,9 +32,9 @@ function MNRH() {
brick.setStatusLight(StatusLight.OrangePulse) brick.setStatusLight(StatusLight.OrangePulse)
while (!brick.buttonEnter.wasPressed()) { while (!brick.buttonEnter.wasPressed()) {
if (brick.buttonUp.wasPressed()) { if (brick.buttonUp.wasPressed()) {
motors.mediumC.setSpeed(-100); motors.mediumC.run(-100);
} else if (brick.buttonDown.wasPressed()) { } else if (brick.buttonDown.wasPressed()) {
motors.mediumC.setSpeed(100); motors.mediumC.run(100);
} else { } else {
motors.mediumC.stop(); motors.mediumC.stop();
} }
@ -83,20 +83,20 @@ function UP() {
if (motors.largeA.angle() > -50) { if (motors.largeA.angle() > -50) {
control.runInParallel(function () { control.runInParallel(function () {
motors.largeD.clearCounts() motors.largeD.clearCounts()
motors.largeD.setSpeed(-35); motors.largeD.run(-35);
pauseUntil(() => motors.largeD.angle() < -25); pauseUntil(() => motors.largeD.angle() < -25);
motors.largeD.stop(); motors.largeD.stop();
motors.largeD.setRegulated(false) motors.largeD.setRegulated(false)
motors.largeD.setSpeed(-15) motors.largeD.run(-15)
pauseUntil(() => motors.largeD.angle() < -65); pauseUntil(() => motors.largeD.angle() < -65);
motors.largeD.stop(); motors.largeD.stop();
}) })
motors.largeA.clearCounts() motors.largeA.clearCounts()
motors.largeA.setSpeed(-35); motors.largeA.run(-35);
pauseUntil(() => motors.largeA.angle() < -25); pauseUntil(() => motors.largeA.angle() < -25);
motors.largeA.stop(); motors.largeA.stop();
motors.largeA.setRegulated(false) motors.largeA.setRegulated(false)
motors.largeA.setSpeed(-15) motors.largeA.run(-15)
pauseUntil(() => motors.largeA.angle() < -65); pauseUntil(() => motors.largeA.angle() < -65);
motors.largeA.stop(); motors.largeA.stop();
@ -231,9 +231,9 @@ function IDL() {
function MHT(Pos: number) { function MHT(Pos: number) {
let _R = Pos - motors.mediumC.angle(); let _R = Pos - motors.mediumC.angle();
if (_R >= 0) { if (_R >= 0) {
motors.mediumC.setSpeed(100, _R, MoveUnit.Degrees); motors.mediumC.run(100, _R, MoveUnit.Degrees);
} else { } else {
motors.mediumC.setSpeed(-100, Math.abs(_R), MoveUnit.Degrees); motors.mediumC.run(-100, Math.abs(_R), MoveUnit.Degrees);
} }
} }
@ -304,15 +304,15 @@ function PPP() {
IS(2); IS(2);
UP(); UP();
pause(100) pause(100)
motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees); motors.largeA.run(-30, 70, MoveUnit.Degrees);
pause(800); pause(800);
music.playSoundEffect(sounds.mechanicalHorn1); music.playSoundEffect(sounds.mechanicalHorn1);
pause(1000); pause(1000);
for(let i = 0; i < 3; ++i) { for(let i = 0; i < 3; ++i) {
motors.largeA.setSpeed(-30, 20, MoveUnit.Degrees); motors.largeA.run(-30, 20, MoveUnit.Degrees);
motors.largeA.setSpeed(30, 20, MoveUnit.Degrees); motors.largeA.run(30, 20, MoveUnit.Degrees);
} }
motors.largeA.setSpeed(30, 70, MoveUnit.Degrees); motors.largeA.run(30, 70, MoveUnit.Degrees);
F_C = 1; F_C = 1;
CS(0); CS(0);
} }
@ -320,12 +320,12 @@ function PPP() {
function HPY() { function HPY() {
IS(8) IS(8)
MHT(0); MHT(0);
motors.largeAD.setSpeed(10, 0.8, MoveUnit.Seconds); motors.largeAD.run(10, 0.8, MoveUnit.Seconds);
for(let i = 0; i < 3; ++i) { for(let i = 0; i < 3; ++i) {
music.playSoundEffect(sounds.animalsDogBark1); music.playSoundEffect(sounds.animalsDogBark1);
motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds); motors.largeAD.run(-100, 0.2, MoveUnit.Seconds);
pause(300) pause(300)
motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds) motors.largeAD.run(10, 0.3, MoveUnit.Seconds)
} }
pause(500); pause(500);
music.stopAllSounds(); music.stopAllSounds();
@ -335,9 +335,9 @@ function HPY() {
function STL() { function STL() {
UP(); UP();
motors.largeAD.setSpeed(-20, 60, MoveUnit.Degrees); motors.largeAD.run(-20, 60, MoveUnit.Degrees);
music.playSoundEffect(sounds.animalsDogWhine); music.playSoundEffect(sounds.animalsDogWhine);
motors.largeAD.setSpeed(20, 60, MoveUnit.Degrees); motors.largeAD.run(20, 60, MoveUnit.Degrees);
} }
function WKU() { function WKU() {

View File

@ -5,14 +5,14 @@ function INI() {
motors.largeB.setBrake(true) motors.largeB.setBrake(true)
motors.largeC.setBrake(true) motors.largeC.setBrake(true)
motors.mediumA.setBrake(true) motors.mediumA.setBrake(true)
motors.largeB.setSpeed(-50) motors.largeB.run(-50)
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25); pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
motors.largeB.stop(); motors.largeB.stop();
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds); motors.mediumA.run(30, 1, MoveUnit.Seconds);
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees); motors.mediumA.run(-50, 90, MoveUnit.Degrees);
motors.largeC.setSpeed(50) motors.largeC.run(50)
sensors.touch1.pauseUntil(ButtonEvent.Pressed); sensors.touch1.pauseUntil(ButtonEvent.Pressed);
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations); motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
} }
INI() INI()
@ -27,24 +27,24 @@ forever(function () {
brick.showImage(images.informationAccept) brick.showImage(images.informationAccept)
if (down) { if (down) {
brick.showImage(images.informationForward) brick.showImage(images.informationForward)
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations); motors.largeC.run(65, 0.85, MoveUnit.Rotations);
} else { } else {
brick.showImage(images.informationBackward) brick.showImage(images.informationBackward)
motors.largeC.setSpeed(-65, 0.85, MoveUnit.Rotations); motors.largeC.run(-65, 0.85, MoveUnit.Rotations);
} }
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees) motors.largeB.run(20, 275, MoveUnit.Degrees)
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds) motors.mediumA.run(30, 1, MoveUnit.Seconds)
motors.largeB.setSpeed(-55) motors.largeB.run(-55)
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25); pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
motors.largeB.stop(); motors.largeB.stop();
if (down) { if (down) {
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations); motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
} else { } else {
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations); motors.largeC.run(65, 0.85, MoveUnit.Rotations);
} }
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees); motors.largeB.run(20, 275, MoveUnit.Degrees);
motors.mediumA.setSpeed(-30, 90, MoveUnit.Degrees); motors.mediumA.run(-30, 90, MoveUnit.Degrees);
motors.largeB.setSpeed(-55) motors.largeB.run(-55)
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25); pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
motors.largeB.stop() motors.largeB.stop()
}) })

View File

@ -5,14 +5,14 @@ function INI() {
motors.largeB.setBrake(true) motors.largeB.setBrake(true)
motors.largeC.setBrake(true) motors.largeC.setBrake(true)
motors.mediumA.setBrake(true) motors.mediumA.setBrake(true)
motors.largeB.setSpeed(-50) motors.largeB.run(-50)
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25); pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
motors.largeB.stop(); motors.largeB.stop();
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds); motors.mediumA.run(30, 1, MoveUnit.Seconds);
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees); motors.mediumA.run(-50, 90, MoveUnit.Degrees);
motors.largeC.setSpeed(50) motors.largeC.run(50)
sensors.touch1.pauseUntil(ButtonEvent.Pressed); sensors.touch1.pauseUntil(ButtonEvent.Pressed);
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations); motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
} }
INI() INI()
@ -27,24 +27,24 @@ forever(function () {
brick.showImage(images.informationAccept) brick.showImage(images.informationAccept)
if (down) { if (down) {
brick.showImage(images.informationForward) brick.showImage(images.informationForward)
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations); motors.largeC.run(65, 0.85, MoveUnit.Rotations);
} else { } else {
brick.showImage(images.informationBackward) brick.showImage(images.informationBackward)
motors.largeC.setSpeed(-65, 0.85, MoveUnit.Rotations); motors.largeC.run(-65, 0.85, MoveUnit.Rotations);
} }
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees) motors.largeB.run(20, 275, MoveUnit.Degrees)
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds) motors.mediumA.run(30, 1, MoveUnit.Seconds)
motors.largeB.setSpeed(-55) motors.largeB.run(-55)
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25); pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
motors.largeB.stop(); motors.largeB.stop();
if (down) { if (down) {
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations); motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
} else { } else {
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations); motors.largeC.run(65, 0.85, MoveUnit.Rotations);
} }
motors.largeB.setSpeed(20, 275, MoveUnit.Degrees); motors.largeB.run(20, 275, MoveUnit.Degrees);
motors.mediumA.setSpeed(-30, 90, MoveUnit.Degrees); motors.mediumA.run(-30, 90, MoveUnit.Degrees);
motors.largeB.setSpeed(-55) motors.largeB.run(-55)
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25); pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
motors.largeB.stop() motors.largeB.stop()
}) })

View File

@ -137,8 +137,8 @@ forever(function () {
GM(); GM();
EQ(); EQ();
cntrl(); cntrl();
motors.largeA.setSpeed(lpwr) motors.largeA.run(lpwr)
motors.largeD.setSpeed(rpwr) motors.largeD.run(rpwr)
CHK() CHK()
let t2 = control.timer1.millis(); let t2 = control.timer1.millis();
let p = 5 - (t2 - t1); let p = 5 - (t2 - t1);
@ -196,9 +196,9 @@ forever(function () {
Cstr = 0; Cstr = 0;
oldDr = Cdrv; oldDr = Cdrv;
Cdrv = -10; Cdrv = -10;
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees); motors.mediumC.run(30, 30, MoveUnit.Degrees);
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees); motors.mediumC.run(-30, 60, MoveUnit.Degrees);
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees); motors.mediumC.run(30, 30, MoveUnit.Degrees);
if (Math.randomRange(-1, 1) >= 1) if (Math.randomRange(-1, 1) >= 1)
Cstr = 70; Cstr = 70;
else else

View File

@ -43,7 +43,7 @@ forever(function () {
motors.largeBC.steer(P + (I + D), 100) motors.largeBC.steer(P + (I + D), 100)
lasterror = error lasterror = error
if (brick.buttonEnter.wasPressed()) { if (brick.buttonEnter.wasPressed()) {
motors.largeBC.setSpeed(0) motors.largeBC.run(0)
brick.buttonDown.pauseUntil(ButtonEvent.Bumped) brick.buttonDown.pauseUntil(ButtonEvent.Bumped)
} }
}) })

View File

@ -14,7 +14,7 @@ Take a look a the LabView program below: it **starts**, turns on motor A, waits
The blocks in MakeCode have similar functions and go together in the same way: they snap into the ``||loops:on start||`` block and then connect to each other vertically. The blocks in MakeCode have similar functions and go together in the same way: they snap into the ``||loops:on start||`` block and then connect to each other vertically.
```blocks ```blocks
motors.largeA.setSpeed(50) motors.largeA.run(50)
pause(1000) pause(1000)
motors.largeA.stop() motors.largeA.stop()
``` ```
@ -22,7 +22,7 @@ motors.largeA.stop()
Any block program can be converted to JavaScript and you can edit it as lines of code too. Any block program can be converted to JavaScript and you can edit it as lines of code too.
```typescript ```typescript
motors.largeA.setSpeed(50) motors.largeA.run(50)
pause(1000) pause(1000)
motors.largeA.stop() motors.largeA.stop()
``` ```
@ -40,10 +40,10 @@ This program controls a large motor on port A in several different ways. It sets
![Single motor blocks](/static/labview/motors.png) ![Single motor blocks](/static/labview/motors.png)
```blocks ```blocks
motors.largeA.setSpeed(50); motors.largeA.run(50);
motors.largeA.setSpeed(50, 1000, MoveUnit.MilliSeconds); motors.largeA.run(50, 1000, MoveUnit.MilliSeconds);
motors.largeA.setSpeed(50, 360, MoveUnit.Degrees); motors.largeA.run(50, 360, MoveUnit.Degrees);
motors.largeA.setSpeed(50, 1, MoveUnit.Rotations); motors.largeA.run(50, 1, MoveUnit.Rotations);
motors.largeA.stop(); motors.largeA.stop();
``` ```
@ -83,7 +83,7 @@ By default, all motors coast when any command used to move finishes. You can kee
```blocks ```blocks
motors.largeD.setBrake(true); motors.largeD.setBrake(true);
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations) motors.largeD.run(50, 1, MoveUnit.Rotations)
``` ```
## Inverting and regulating motors ## Inverting and regulating motors
@ -132,7 +132,7 @@ It is quite common to have to wait for a task to finish or for a sensor state to
![pause for time](/static/labview/pausefortime.png) ![pause for time](/static/labview/pausefortime.png)
```blocks ```blocks
motors.largeD.setSpeed(50) motors.largeD.run(50)
pause(1000) pause(1000)
motors.largeD.stop(); motors.largeD.stop();
``` ```
@ -140,7 +140,7 @@ motors.largeD.stop();
![pause for touch](/static/labview/pausefortouch.png) ![pause for touch](/static/labview/pausefortouch.png)
```blocks ```blocks
motors.largeD.setSpeed(50) motors.largeD.run(50)
sensors.touch1.pauseUntil(ButtonEvent.Pressed) sensors.touch1.pauseUntil(ButtonEvent.Pressed)
motors.largeD.stop(); motors.largeD.stop();
``` ```
@ -148,7 +148,7 @@ motors.largeD.stop();
![pause for distance](/static/labview/pausefordistance.png) ![pause for distance](/static/labview/pausefordistance.png)
```blocks ```blocks
motors.largeD.setSpeed(50) motors.largeD.run(50)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear) sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
motors.largeD.stop(); motors.largeD.stop();
``` ```
@ -156,7 +156,7 @@ motors.largeD.stop();
You can also use the ``||loops:pause until||`` block to wait on any [boolean](/types/boolean) expression. As your program runs, it waits until the condition (expression) inside becomes true. You can also use the ``||loops:pause until||`` block to wait on any [boolean](/types/boolean) expression. As your program runs, it waits until the condition (expression) inside becomes true.
```blocks ```blocks
motors.largeD.setSpeed(50) motors.largeD.run(50)
pauseUntil(() => sensors.touch1.isPressed()) pauseUntil(() => sensors.touch1.isPressed())
motors.largeD.stop() motors.largeD.stop()
``` ```
@ -167,8 +167,8 @@ motors.largeD.stop()
```blocks ```blocks
forever(() => { forever(() => {
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations); motors.largeD.run(50, 1, MoveUnit.Rotations);
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations); motors.largeD.run(-50, 1, MoveUnit.Rotations);
}) })
``` ```
@ -176,13 +176,13 @@ forever(() => {
```blocks ```blocks
for(let i = 0; i < 10; i++) { for(let i = 0; i < 10; i++) {
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations); motors.largeD.run(50, 1, MoveUnit.Rotations);
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations); motors.largeD.run(-50, 1, MoveUnit.Rotations);
} }
let k = 0; let k = 0;
while(k < 10) { while(k < 10) {
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations); motors.largeD.run(50, 1, MoveUnit.Rotations);
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations); motors.largeD.run(-50, 1, MoveUnit.Rotations);
k++; k++;
} }
``` ```
@ -195,7 +195,7 @@ while(k < 10) {
let light = 0; let light = 0;
forever(function () { forever(function () {
light = sensors.color3.light(LightIntensityMode.Reflected); light = sensors.color3.light(LightIntensityMode.Reflected);
motors.largeD.setSpeed(light) motors.largeD.run(light)
}) })
``` ```
@ -207,8 +207,8 @@ You can start up multiple ``||loops:forever||`` loops that will run at the same
```blocks ```blocks
forever(() => { forever(() => {
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations); motors.largeD.run(50, 1, MoveUnit.Rotations);
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations); motors.largeD.run(-50, 1, MoveUnit.Rotations);
}) })
forever(() => { forever(() => {
brick.showImage(images.eyesMiddleRight) brick.showImage(images.eyesMiddleRight)
@ -227,7 +227,7 @@ The ``||logic:if||`` block allows you to run different code depending on whether
```blocks ```blocks
forever(function() { forever(function() {
if(sensors.touch1.isPressed()) { if(sensors.touch1.isPressed()) {
motors.largeD.setSpeed(50) motors.largeD.run(50)
} else { } else {
motors.largeD.stop() motors.largeD.stop()
} }

View File

@ -213,13 +213,13 @@ music.playSoundEffect(sounds.systemGeneralAlert)
} }
while (true) { while (true) {
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright) while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeB.setSpeed(10) motors.largeB.run(10)
motors.largeC.setSpeed(-10) motors.largeC.run(-10)
} }
while (true) { while (true) {
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright) sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeA.setSpeed(-10) motors.largeA.run(-10)
motors.largeA.setSpeed(10) motors.largeA.run(10)
} }
} }
``` ```
@ -235,13 +235,13 @@ You will need to constantly debug your program in order to make your robot trave
```blocks ```blocks
while (true) { while (true) {
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright) while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeB.setSpeed(10) motors.largeB.run(10)
motors.largeC.setSpeed(-10) motors.largeC.run(-10)
} }
while (true) { while (true) {
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright) sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeB.setSpeed(-10) motors.largeB.run(-10)
motors.largeC.setSpeed(10) motors.largeC.run(10)
} }
} }
``` ```

View File

@ -4,11 +4,11 @@ Use this program with the Programmable Brick and Large Motor.
```blocks ```blocks
forever(function () { forever(function () {
motors.largeA.setSpeed(30) motors.largeA.run(30)
pause(100) pause(100)
motors.largeA.stop() motors.largeA.stop()
music.playSoundEffectUntilDone(sounds.animalsCatPurr) music.playSoundEffectUntilDone(sounds.animalsCatPurr)
motors.largeA.setSpeed(-30) motors.largeA.run(-30)
pause(100) pause(100)
motors.largeA.stop() motors.largeA.stop()
}) })

View File

@ -4,9 +4,9 @@ This example program combined with the small model will make a beat and rhythm o
```blocks ```blocks
forever(function () { forever(function () {
motors.largeA.setSpeed(50) motors.largeA.run(50)
pause(200) pause(200)
motors.largeA.setSpeed(100) motors.largeA.run(100)
pause(200) pause(200)
}) })
``` ```

View File

@ -3,7 +3,7 @@
## Motion ## Motion
```cards ```cards
motors.largeA.setSpeed(50) motors.largeA.run(50)
motors.largeAB.tank(50, 50) motors.largeAB.tank(50, 50)
motors.largeAB.steer(0, 50) motors.largeAB.steer(0, 50)
motors.largeA.pauseUntilReady() motors.largeA.pauseUntilReady()

View File

@ -19,7 +19,7 @@ Reset the motor connected to port **A** and run it for for 2 seconds at a speed
```blocks ```blocks
let motorAngle = 0; let motorAngle = 0;
motors.largeA.reset() motors.largeA.reset()
motors.largeA.setSpeed(45) motors.largeA.run(45)
pause(2000) pause(2000)
motors.largeA.stop() motors.largeA.stop()
motorAngle = motors.largeA.angle() motorAngle = motors.largeA.angle()

View File

@ -15,11 +15,11 @@ See if the motor turns the same number of times for each of two count periods. R
```blocks ```blocks
let tachoCount = 0; let tachoCount = 0;
motors.largeA.reset() motors.largeA.reset()
motors.largeA.setSpeed(50) motors.largeA.run(50)
pause(10000) pause(10000)
tachoCount = motors.largeA.tacho() tachoCount = motors.largeA.tacho()
motors.largeA.clearCounts() motors.largeA.clearCounts()
motors.largeA.setSpeed(50) motors.largeA.run(50)
pause(10000) pause(10000)
if (tachoCount == motors.largeA.tacho()) { if (tachoCount == motors.largeA.tacho()) {
brick.showString("Motor turns equal.", 1) brick.showString("Motor turns equal.", 1)

View File

@ -13,12 +13,12 @@ The motor's speed is set back to `0` and the **tacho**, **angle**, and **speed**
See what the angle count is when a motor is stopped. Then, try it again after a reset. See what the angle count is when a motor is stopped. Then, try it again after a reset.
```blocks ```blocks
motors.largeA.setSpeed(30) motors.largeA.run(30)
pause(2000) pause(2000)
motors.largeA.stop() motors.largeA.stop()
brick.showString("Angle count:", 1) brick.showString("Angle count:", 1)
brick.showNumber(motors.largeA.angle(), 2) brick.showNumber(motors.largeA.angle(), 2)
motors.largeA.setSpeed(30) motors.largeA.run(30)
pause(2000) pause(2000)
motors.largeA.reset() motors.largeA.reset()
brick.showString("Angle count:", 4) brick.showString("Angle count:", 4)

View File

@ -1,9 +1,9 @@
# set Speed # run
Set the rotation speed of the motor as a percentage of maximum speed. Set the rotation speed of the motor as a percentage of maximum speed.
```sig ```sig
motors.largeA.setSpeed(50) motors.largeA.run(50)
``` ```
The speed setting is a pecentage of the motor's full speed. Full speed is the speed that the motor runs when the brick supplies maximum output voltage to the port. The speed setting is a pecentage of the motor's full speed. Full speed is the speed that the motor runs when the brick supplies maximum output voltage to the port.
@ -19,7 +19,7 @@ If you use a number of milliseconds as movement units, then you don't need to in
To run the motor for 500 milliseconds: To run the motor for 500 milliseconds:
```block ```block
motors.largeA.setSpeed(50, 500) motors.largeA.run(50, 500)
``` ```
## ~ ## ~
@ -28,19 +28,19 @@ Here is how you use each different movement unit to run the motor for a fixed ro
```typescript ```typescript
// Run motor for 700 Milliseconds. // Run motor for 700 Milliseconds.
motors.largeA.setSpeed(25, 700, MoveUnit.MilliSeconds); motors.largeA.run(25, 700, MoveUnit.MilliSeconds);
// Run motor for 700 Milliseconds again but no units specified. // Run motor for 700 Milliseconds again but no units specified.
motors.largeA.setSpeed(25, 700); motors.largeA.run(25, 700);
// Run the motor for 45 seconds // Run the motor for 45 seconds
motors.largeA.setSpeed(50, 45, MoveUnit.Seconds); motors.largeA.run(50, 45, MoveUnit.Seconds);
// Turn the motor for 270 degrees // Turn the motor for 270 degrees
motors.largeA.setSpeed(50, 270, MoveUnit.Degrees) motors.largeA.run(50, 270, MoveUnit.Degrees)
// Turn the motor at full speed for 9 full rotations // Turn the motor at full speed for 9 full rotations
motors.largeA.setSpeed(100, 9, MoveUnit.Rotations); motors.largeA.run(100, 9, MoveUnit.Rotations);
``` ```
## Parameters ## Parameters
@ -56,7 +56,7 @@ motors.largeA.setSpeed(100, 9, MoveUnit.Rotations);
Turning the motor in the opposite direction (reverse) is simple. Reverse is just a negative speed setting. To drive the motor in reverse at 25% speed: Turning the motor in the opposite direction (reverse) is simple. Reverse is just a negative speed setting. To drive the motor in reverse at 25% speed:
```block ```block
motors.largeB.setSpeed(-25) motors.largeB.run(-25)
``` ```
## ~ ## ~
@ -68,7 +68,7 @@ motors.largeB.setSpeed(-25)
Run the motor connected to port **A** continuously. Pause 20 seconds and then stop the motor. Run the motor connected to port **A** continuously. Pause 20 seconds and then stop the motor.
```blocks ```blocks
motors.largeA.setSpeed(75) motors.largeA.run(75)
pause(20000) pause(20000)
motors.largeA.stop() motors.largeA.stop()
``` ```
@ -78,7 +78,7 @@ motors.largeA.stop()
Run the motor connected to port **A** in reverse. Pause 5 seconds and then stop the motor. Run the motor connected to port **A** in reverse. Pause 5 seconds and then stop the motor.
```blocks ```blocks
motors.largeA.setSpeed(-60) motors.largeA.run(-60)
pause(5000) pause(5000)
motors.largeA.stop() motors.largeA.stop()
``` ```
@ -88,7 +88,7 @@ motors.largeA.stop()
Run the motor connected to port **B** for 35 full rotations and then stop. Run the motor connected to port **B** for 35 full rotations and then stop.
```blocks ```blocks
motors.largeB.setSpeed(50, 35, MoveUnit.Rotations) motors.largeB.run(50, 35, MoveUnit.Rotations)
``` ```
## See also ## See also

View File

@ -19,7 +19,7 @@ Also, you can use the brake to do simple skid steering for your brick.
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and set the brake. Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and set the brake.
```blocks ```blocks
motors.largeA.setSpeed(30) motors.largeA.run(30)
pause(2000) pause(2000)
motors.largeA.stop() motors.largeA.stop()
motors.largeA.setBrake(true) motors.largeA.setBrake(true)

View File

@ -17,12 +17,12 @@ You use a positive value (some number greater than `0`) to drive you motor in th
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and switch the direciton of rotation. Run the motor at a speed of `-30`. Watch and see if the motor turns in the same direction as before. Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and switch the direciton of rotation. Run the motor at a speed of `-30`. Watch and see if the motor turns in the same direction as before.
```blocks ```blocks
motors.largeA.setSpeed(30) motors.largeA.run(30)
pause(2000) pause(2000)
motors.largeA.stop() motors.largeA.stop()
pause(2000) pause(2000)
motors.largeA.setInverted(true) motors.largeA.setInverted(true)
motors.largeA.setSpeed(-30) motors.largeA.run(-30)
pause(2000) pause(2000)
motors.largeA.stop() motors.largeA.stop()
``` ```

View File

@ -22,11 +22,11 @@ Turn off the speed regulation for the motor connected to port **A**.
```blocks ```blocks
motors.largeA.setRegulated(false) motors.largeA.setRegulated(false)
motors.largeA.setSpeed(75) motors.largeA.run(75)
pause(20000) pause(20000)
motors.largeA.stop() motors.largeA.stop()
``` ```
## See also ## See also
[set speed](/reference/motors/motor/set-speed), [stop](/reference/motors/motor/stop) [run](/reference/motors/motor/run), [stop](/reference/motors/motor/stop)

View File

@ -6,7 +6,7 @@ Get the current speed of motor rotation as a percentage of maximum speed.
motors.largeA.speed() motors.largeA.speed()
``` ```
The actual speed of the motor is the same or very close to it's current speed setting when the motor is regulated. If not regulated, the actual speed can change from the set speed when a force, or load, is applied to it. The actual speed of the motor is the same or very close to it's current speed setting when the motor is regulated. If not regulated, the actual speed can change from the set point speed when a force, or load, is applied to it.
## Returns ## Returns
@ -18,7 +18,7 @@ Turn speed regulation off and report the actual speed of the large motor in the
```blocks ```blocks
motors.largeA.setRegulated(false) motors.largeA.setRegulated(false)
motors.largeA.setSpeed(55) motors.largeA.run(55)
brick.showString("Actual speed:", 1) brick.showString("Actual speed:", 1)
for (let i = 0; i < 30; i++) { for (let i = 0; i < 30; i++) {
pause(500) pause(500)

View File

@ -13,11 +13,11 @@ The motor stops but any motion caused from previously running the motor continue
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and wait for 2 seconds, then continue at a speed of `50`. Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and wait for 2 seconds, then continue at a speed of `50`.
```blocks ```blocks
motors.largeA.setSpeed(30) motors.largeA.run(30)
pause(2000) pause(2000)
motors.largeA.stop() motors.largeA.stop()
pause(2000) pause(2000)
motors.largeA.setSpeed(50) motors.largeA.run(50)
``` ```
## See also ## See also

View File

@ -33,12 +33,12 @@ A standard way to know how fast a motor is turning is by measuring its _revoluti
Run the motor connected to port **A** at half speed for 5 seconds. Display the number of full rotations on the screen. Run the motor connected to port **A** at half speed for 5 seconds. Display the number of full rotations on the screen.
```blocks ```blocks
motors.largeA.setSpeed(50) motors.largeA.run(50)
pause(5000) pause(5000)
motors.largeA.stop() motors.largeA.stop()
brick.showString("Motor rotations:", 1) brick.showString("Motor rotations:", 1)
brick.showNumber(motors.largeA.tacho() / 360, 3) brick.showNumber(motors.largeA.tacho() / 360, 3)
motors.largeA.setSpeed(50) motors.largeA.run(50)
``` ```
## See also ## See also

View File

@ -18,7 +18,7 @@ The speed setting is a pecentage of the motor's full speed. Full speed is the sp
If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations. If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations.
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [set speed](/reference/motors/motor/set-speed) shows how to use different movement units. If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [run](/reference/motors/motor/run) shows how to use different movement units.
## Parameters ## Parameters
@ -81,4 +81,4 @@ motors.stopAll()
## See also ## See also
[tank](/reference/motors/synced/tank), [set speed](/reference/motors/motor/set-speed) [tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)

View File

@ -14,7 +14,7 @@ The speed setting is a pecentage of the motor's full speed. Full speed is the sp
If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations. If you use just the **speed** number, the motors run continously and won't stop unless you tell them to. You can also give a value for a certain amount of distance you want the motors to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations.
If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [set speed](/reference/motors/motor/set-speed) shows how to use different movement units. If you decide to use a **value** of rotation distance, you need to choose a type of movement **unit**. Also, if you use a number of milliseconds as movement units, then you don't need to include the unit type. The description in [run](/reference/motors/motor/run) shows how to use different movement units.
## Parameters ## Parameters
@ -78,4 +78,4 @@ motors.stopAll()
## See also ## See also
[steer](/reference/motors/synced/steer), [set speed](/reference/motors/motor/set-speed) [steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)

View File

@ -134,17 +134,17 @@ namespace motors {
protected _brake: boolean; protected _brake: boolean;
private _initialized: boolean; private _initialized: boolean;
private _init: () => void; private _init: () => void;
private _setSpeed: (speed: number) => void; private _run: (speed: number) => void;
private _move: (steps: boolean, stepsOrTime: number, speed: number) => void; private _move: (steps: boolean, stepsOrTime: number, speed: number) => void;
constructor(port: Output, init: () => void, setSpeed: (speed: number) => void, move: (steps: boolean, stepsOrTime: number, speed: number) => void) { constructor(port: Output, init: () => void, run: (speed: number) => void, move: (steps: boolean, stepsOrTime: number, speed: number) => void) {
super(); super();
this._port = port; this._port = port;
this._portName = outputToName(this._port); this._portName = outputToName(this._port);
this._brake = false; this._brake = false;
this._initialized = false; this._initialized = false;
this._init = init; this._init = init;
this._setSpeed = setSpeed; this._run = run;
this._move = move; this._move = move;
} }
@ -218,17 +218,17 @@ namespace motors {
} }
/** /**
* Sets the motor speed for limited time or distance. * Runs the motor at a given speed for limited time or distance.
* @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 value (optional) measured distance or rotation * @param value (optional) measured distance or rotation
* @param unit (optional) unit of the value * @param unit (optional) unit of the value
*/ */
//% blockId=motorSetSpeed block="set %motor speed to %speed=motorSpeedPicker|\\%||for %value %unit" //% blockId=motorRun block="run %motor at %speed=motorSpeedPicker|\\%||for %value %unit"
//% weight=100 blockGap=8 //% weight=100 blockGap=8
//% group="Move" //% group="Move"
//% expandableArgumentMode=toggle //% expandableArgumentMode=toggle
//% help=motors/motor/set-speed //% help=motors/motor/run
setSpeed(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) { run(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
this.init(); this.init();
speed = Math.clamp(-100, 100, speed >> 0); speed = Math.clamp(-100, 100, speed >> 0);
// stop if speed is 0 // stop if speed is 0
@ -238,7 +238,7 @@ namespace motors {
} }
// special: 0 is infinity // special: 0 is infinity
if (value == 0) { if (value == 0) {
this._setSpeed(speed); this._run(speed);
return; return;
} }
// timed motor moves // timed motor moves

View File

@ -7,8 +7,8 @@ A unit test framework
Tests are registered as event handlers. They will automatically run once ``on start`` is finished. Tests are registered as event handlers. They will automatically run once ``on start`` is finished.
```blocks ```blocks
tests.test("lgB set speed 10", () => { tests.test("lgB run 10", () => {
motors.largeB.setSpeed(10); motors.largeB.run(10);
pause(100) pause(100)
tests.assertClose("speedB", 10, motors.largeB.speed(), 2) tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
}); });

View File

@ -46,7 +46,7 @@
}, },
"dependencies": { "dependencies": {
"pxt-common-packages": "0.19.5", "pxt-common-packages": "0.19.5",
"pxt-core": "3.4.3" "pxt-core": "3.4.5"
}, },
"scripts": { "scripts": {
"test": "node node_modules/pxt-core/built/pxt.js travis" "test": "node node_modules/pxt-core/built/pxt.js travis"

View File

@ -1,17 +1,17 @@
// add tests package // add tests package
tests.test("lgB set speed 10", () => { tests.test("lgB run 10", () => {
motors.largeB.setSpeed(10); motors.largeB.run(10);
pause(500) pause(500)
tests.assertClose("speedB", 10, motors.largeB.speed(), 2) tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
}); });
tests.test("lgB set speed 25 (reversed)", () => { tests.test("lgB run 25 (reversed)", () => {
motors.largeB.setInverted(true) motors.largeB.setInverted(true)
motors.largeB.setSpeed(25) motors.largeB.run(25)
pause(500) pause(500)
tests.assertClose("speedB", -25, motors.largeB.speed(), 2) tests.assertClose("speedB", -25, motors.largeB.speed(), 2)
}); });
tests.test("lgBC set speed 5", () => { tests.test("lgBC run 5", () => {
motors.largeBC.setSpeed(5) motors.largeBC.run(5)
pause(500) pause(500)
tests.assertClose("speedB", 5, motors.largeB.speed(), 1); tests.assertClose("speedB", 5, motors.largeB.speed(), 1);
tests.assertClose("speedC", 5, motors.largeC.speed(), 1); tests.assertClose("speedC", 5, motors.largeC.speed(), 1);