renaming 'set speed' to 'run' (#327)
This commit is contained in:
parent
3b6cfed5b2
commit
fad4ca98db
@ -67,7 +67,7 @@
|
||||
* [set light](/reference/brick/set-status-light)
|
||||
* [battery level](/reference/brick/battery-level)
|
||||
* [Motors](/reference/motors)
|
||||
* [set speed](/reference/motors/motor/set-speed)
|
||||
* [run](/reference/motors/motor/run)
|
||||
* [stop](/reference/motors/motor/stop)
|
||||
* [reset](/reference/motors/motor/reset)
|
||||
* [set brake](/reference/motors/motor/set-brake)
|
||||
|
@ -8,12 +8,12 @@ You can program the @boardname@ using [Blocks](/blocks) or [JavaScript](/javascr
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
```typescript
|
||||
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
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, () => {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
})
|
||||
```
|
||||
|
@ -5,6 +5,6 @@ let speed = 0;
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
```
|
@ -5,11 +5,11 @@ let speed = 0;
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed < 100)
|
||||
speed = speed + 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
if (speed > -100)
|
||||
speed = speed - 10;
|
||||
motors.largeBC.setSpeed(speed);
|
||||
motors.largeBC.run(speed);
|
||||
})
|
||||
```
|
@ -15,7 +15,7 @@ function accelerate() {
|
||||
function update() {
|
||||
brick.clearScreen()
|
||||
brick.showString("speed: " + speed, 1)
|
||||
motors.largeBC.setSpeed(speed)
|
||||
motors.largeBC.run(speed)
|
||||
}
|
||||
sensors.touch2.onEvent(ButtonEvent.Pressed, function () {
|
||||
accelerate()
|
||||
|
@ -5,7 +5,7 @@ forever(function () {
|
||||
music.playTone(440, sensors.ultrasonic4.distance());
|
||||
pause(50)
|
||||
})
|
||||
motors.largeBC.setSpeed(-20);
|
||||
motors.largeBC.run(-20);
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
@ -7,7 +7,7 @@ forever(function () {
|
||||
pause(50)
|
||||
}
|
||||
})
|
||||
motors.largeBC.setSpeed(-20);
|
||||
motors.largeBC.run(-20);
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
|
||||
motors.largeBC.stop();
|
||||
```
|
||||
|
@ -4,7 +4,7 @@
|
||||
let beep = false
|
||||
beep = true
|
||||
control.runInParallel(function () {
|
||||
motors.largeBC.setSpeed(-20)
|
||||
motors.largeBC.run(-20)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||
motors.largeBC.stop()
|
||||
beep = false
|
||||
|
@ -2,13 +2,13 @@
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -3,13 +3,13 @@
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -5,15 +5,15 @@ brick.buttonEnter.onEvent(ButtonEvent.Bumped, function () {
|
||||
brick.showImage(images.eyesSleeping)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesNeutral)
|
||||
motors.largeBC.setSpeed(50)
|
||||
motors.largeBC.run(50)
|
||||
sensors.touch2.pauseUntil(ButtonEvent.Pressed)
|
||||
brick.showImage(images.eyesTiredMiddle)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
pause(1000)
|
||||
brick.setStatusLight(StatusLight.OrangeFlash)
|
||||
brick.showImage(images.eyesDizzy)
|
||||
motors.largeBC.setSpeed(-50)
|
||||
motors.largeBC.run(-50)
|
||||
pause(2000)
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
})
|
||||
```
|
@ -19,13 +19,13 @@ pause(1000)
|
||||
music.playSoundEffectUntilDone(sounds.communicationGo)
|
||||
for (let d of drive) {
|
||||
if (d == 1) {
|
||||
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeC.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 3) {
|
||||
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeB.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 4) {
|
||||
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(50, 360, MoveUnit.Degrees)
|
||||
} else {
|
||||
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(-50, 360, MoveUnit.Degrees)
|
||||
}
|
||||
}
|
||||
music.playSoundEffectUntilDone(sounds.communicationGameOver)
|
||||
|
@ -23,13 +23,13 @@ pause(1000)
|
||||
music.playSoundEffectUntilDone(sounds.communicationGo)
|
||||
for (let d of drive) {
|
||||
if (d == 1) {
|
||||
motors.largeC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeC.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 3) {
|
||||
motors.largeB.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeB.run(50, 360, MoveUnit.Degrees)
|
||||
} else if (d == 4) {
|
||||
motors.largeBC.setSpeed(50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(50, 360, MoveUnit.Degrees)
|
||||
} else {
|
||||
motors.largeBC.setSpeed(-50, 360, MoveUnit.Degrees)
|
||||
motors.largeBC.run(-50, 360, MoveUnit.Degrees)
|
||||
}
|
||||
}
|
||||
music.playSoundEffectUntilDone(sounds.communicationGameOver)
|
||||
|
@ -119,9 +119,9 @@ sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
|
||||
controlSteering = 0
|
||||
oldControlDrive = controlDrive
|
||||
controlDrive = -10
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1) {
|
||||
controlSteering = 70
|
||||
} else {
|
||||
@ -149,8 +149,8 @@ sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
|
||||
})
|
||||
// apply power to motors
|
||||
function controlMotors() {
|
||||
motors.largeA.setSpeed(power + controlSteering * 0.1)
|
||||
motors.largeD.setSpeed(power - controlSteering * 0.1)
|
||||
motors.largeA.run(power + controlSteering * 0.1)
|
||||
motors.largeD.run(power - controlSteering * 0.1)
|
||||
}
|
||||
sensors.color1.onColorDetected(ColorSensorColor.Yellow, function () {
|
||||
moods.middleLeft.show()
|
||||
|
@ -137,8 +137,8 @@ forever(function () {
|
||||
GM();
|
||||
EQ();
|
||||
cntrl();
|
||||
motors.largeA.setSpeed(lpwr)
|
||||
motors.largeD.setSpeed(rpwr)
|
||||
motors.largeA.run(lpwr)
|
||||
motors.largeD.run(rpwr)
|
||||
CHK()
|
||||
let t2 = control.timer1.millis();
|
||||
let p = 5 - (t2 - t1);
|
||||
@ -196,9 +196,9 @@ forever(function () {
|
||||
Cstr = 0;
|
||||
oldDr = Cdrv;
|
||||
Cdrv = -10;
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1)
|
||||
Cstr = 70;
|
||||
else
|
||||
|
@ -32,9 +32,9 @@ function MNRH() {
|
||||
brick.setStatusLight(StatusLight.OrangePulse)
|
||||
while (!brick.buttonEnter.wasPressed()) {
|
||||
if (brick.buttonUp.wasPressed()) {
|
||||
motors.mediumC.setSpeed(-100);
|
||||
motors.mediumC.run(-100);
|
||||
} else if (brick.buttonDown.wasPressed()) {
|
||||
motors.mediumC.setSpeed(100);
|
||||
motors.mediumC.run(100);
|
||||
} else {
|
||||
motors.mediumC.stop();
|
||||
}
|
||||
@ -83,20 +83,20 @@ function UP() {
|
||||
if (motors.largeA.angle() > -50) {
|
||||
control.runInParallel(function () {
|
||||
motors.largeD.clearCounts()
|
||||
motors.largeD.setSpeed(-35);
|
||||
motors.largeD.run(-35);
|
||||
pauseUntil(() => motors.largeD.angle() < -25);
|
||||
motors.largeD.stop();
|
||||
motors.largeD.setRegulated(false)
|
||||
motors.largeD.setSpeed(-15)
|
||||
motors.largeD.run(-15)
|
||||
pauseUntil(() => motors.largeD.angle() < -65);
|
||||
motors.largeD.stop();
|
||||
})
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeA.setSpeed(-35);
|
||||
motors.largeA.run(-35);
|
||||
pauseUntil(() => motors.largeA.angle() < -25);
|
||||
motors.largeA.stop();
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(-15)
|
||||
motors.largeA.run(-15)
|
||||
pauseUntil(() => motors.largeA.angle() < -65);
|
||||
motors.largeA.stop();
|
||||
|
||||
@ -231,9 +231,9 @@ function IDL() {
|
||||
function MHT(Pos: number) {
|
||||
let _R = Pos - motors.mediumC.angle();
|
||||
if (_R >= 0) {
|
||||
motors.mediumC.setSpeed(100, _R, MoveUnit.Degrees);
|
||||
motors.mediumC.run(100, _R, MoveUnit.Degrees);
|
||||
} 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);
|
||||
UP();
|
||||
pause(100)
|
||||
motors.largeA.setSpeed(-30, 70, MoveUnit.Degrees);
|
||||
motors.largeA.run(-30, 70, MoveUnit.Degrees);
|
||||
pause(800);
|
||||
music.playSoundEffect(sounds.mechanicalHorn1);
|
||||
pause(1000);
|
||||
for(let i = 0; i < 3; ++i) {
|
||||
motors.largeA.setSpeed(-30, 20, MoveUnit.Degrees);
|
||||
motors.largeA.setSpeed(30, 20, MoveUnit.Degrees);
|
||||
motors.largeA.run(-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;
|
||||
CS(0);
|
||||
}
|
||||
@ -320,12 +320,12 @@ function PPP() {
|
||||
function HPY() {
|
||||
IS(8)
|
||||
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) {
|
||||
music.playSoundEffect(sounds.animalsDogBark1);
|
||||
motors.largeAD.setSpeed(-100, 0.2, MoveUnit.Seconds);
|
||||
motors.largeAD.run(-100, 0.2, MoveUnit.Seconds);
|
||||
pause(300)
|
||||
motors.largeAD.setSpeed(10, 0.3, MoveUnit.Seconds)
|
||||
motors.largeAD.run(10, 0.3, MoveUnit.Seconds)
|
||||
}
|
||||
pause(500);
|
||||
music.stopAllSounds();
|
||||
@ -335,9 +335,9 @@ function HPY() {
|
||||
|
||||
function STL() {
|
||||
UP();
|
||||
motors.largeAD.setSpeed(-20, 60, MoveUnit.Degrees);
|
||||
motors.largeAD.run(-20, 60, MoveUnit.Degrees);
|
||||
music.playSoundEffect(sounds.animalsDogWhine);
|
||||
motors.largeAD.setSpeed(20, 60, MoveUnit.Degrees);
|
||||
motors.largeAD.run(20, 60, MoveUnit.Degrees);
|
||||
}
|
||||
|
||||
function WKU() {
|
||||
|
@ -5,14 +5,14 @@ function INI() {
|
||||
motors.largeB.setBrake(true)
|
||||
motors.largeC.setBrake(true)
|
||||
motors.mediumA.setBrake(true)
|
||||
motors.largeB.setSpeed(-50)
|
||||
motors.largeB.run(-50)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.run(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
INI()
|
||||
@ -27,24 +27,24 @@ forever(function () {
|
||||
brick.showImage(images.informationAccept)
|
||||
if (down) {
|
||||
brick.showImage(images.informationForward)
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
} else {
|
||||
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.mediumA.setSpeed(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
if (down) {
|
||||
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
|
||||
} 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.mediumA.setSpeed(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.run(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop()
|
||||
})
|
||||
|
@ -5,14 +5,14 @@ function INI() {
|
||||
motors.largeB.setBrake(true)
|
||||
motors.largeC.setBrake(true)
|
||||
motors.mediumA.setBrake(true)
|
||||
motors.largeB.setSpeed(-50)
|
||||
motors.largeB.run(-50)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
motors.mediumA.setSpeed(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.setSpeed(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.setSpeed(50)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds);
|
||||
motors.mediumA.run(-50, 90, MoveUnit.Degrees);
|
||||
motors.largeC.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed);
|
||||
motors.largeC.setSpeed(-50, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-50, 0.86, MoveUnit.Rotations);
|
||||
}
|
||||
|
||||
INI()
|
||||
@ -27,24 +27,24 @@ forever(function () {
|
||||
brick.showImage(images.informationAccept)
|
||||
if (down) {
|
||||
brick.showImage(images.informationForward)
|
||||
motors.largeC.setSpeed(65, 0.85, MoveUnit.Rotations);
|
||||
motors.largeC.run(65, 0.85, MoveUnit.Rotations);
|
||||
} else {
|
||||
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.mediumA.setSpeed(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees)
|
||||
motors.mediumA.run(30, 1, MoveUnit.Seconds)
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop();
|
||||
if (down) {
|
||||
motors.largeC.setSpeed(-65, 0.86, MoveUnit.Rotations);
|
||||
motors.largeC.run(-65, 0.86, MoveUnit.Rotations);
|
||||
} 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.mediumA.setSpeed(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.setSpeed(-55)
|
||||
motors.largeB.run(20, 275, MoveUnit.Degrees);
|
||||
motors.mediumA.run(-30, 90, MoveUnit.Degrees);
|
||||
motors.largeB.run(-55)
|
||||
pauseUntil(() => sensors.color3.light(LightIntensityMode.Reflected) > 25);
|
||||
motors.largeB.stop()
|
||||
})
|
||||
|
@ -137,8 +137,8 @@ forever(function () {
|
||||
GM();
|
||||
EQ();
|
||||
cntrl();
|
||||
motors.largeA.setSpeed(lpwr)
|
||||
motors.largeD.setSpeed(rpwr)
|
||||
motors.largeA.run(lpwr)
|
||||
motors.largeD.run(rpwr)
|
||||
CHK()
|
||||
let t2 = control.timer1.millis();
|
||||
let p = 5 - (t2 - t1);
|
||||
@ -196,9 +196,9 @@ forever(function () {
|
||||
Cstr = 0;
|
||||
oldDr = Cdrv;
|
||||
Cdrv = -10;
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
motors.mediumC.run(-30, 60, MoveUnit.Degrees);
|
||||
motors.mediumC.run(30, 30, MoveUnit.Degrees);
|
||||
if (Math.randomRange(-1, 1) >= 1)
|
||||
Cstr = 70;
|
||||
else
|
||||
|
@ -43,7 +43,7 @@ forever(function () {
|
||||
motors.largeBC.steer(P + (I + D), 100)
|
||||
lasterror = error
|
||||
if (brick.buttonEnter.wasPressed()) {
|
||||
motors.largeBC.setSpeed(0)
|
||||
motors.largeBC.run(0)
|
||||
brick.buttonDown.pauseUntil(ButtonEvent.Bumped)
|
||||
}
|
||||
})
|
||||
|
@ -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.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
pause(1000)
|
||||
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.
|
||||
|
||||
```typescript
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
pause(1000)
|
||||
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)
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50);
|
||||
motors.largeA.setSpeed(50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeA.setSpeed(50, 360, MoveUnit.Degrees);
|
||||
motors.largeA.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeA.run(50);
|
||||
motors.largeA.run(50, 1000, MoveUnit.MilliSeconds);
|
||||
motors.largeA.run(50, 360, MoveUnit.Degrees);
|
||||
motors.largeA.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeA.stop();
|
||||
```
|
||||
|
||||
@ -83,7 +83,7 @@ By default, all motors coast when any command used to move finishes. You can kee
|
||||
|
||||
```blocks
|
||||
motors.largeD.setBrake(true);
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations)
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## 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)
|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
pause(1000)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
@ -140,7 +140,7 @@ motors.largeD.stop();
|
||||
![pause for touch](/static/labview/pausefortouch.png)
|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeD.stop();
|
||||
```
|
||||
@ -148,7 +148,7 @@ motors.largeD.stop();
|
||||
![pause for distance](/static/labview/pausefordistance.png)
|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
|
||||
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.
|
||||
|
||||
```blocks
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
pauseUntil(() => sensors.touch1.isPressed())
|
||||
motors.largeD.stop()
|
||||
```
|
||||
@ -167,8 +167,8 @@ motors.largeD.stop()
|
||||
|
||||
```blocks
|
||||
forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
})
|
||||
```
|
||||
|
||||
@ -176,13 +176,13 @@ forever(() => {
|
||||
|
||||
```blocks
|
||||
for(let i = 0; i < 10; i++) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
}
|
||||
let k = 0;
|
||||
while(k < 10) {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
k++;
|
||||
}
|
||||
```
|
||||
@ -195,7 +195,7 @@ while(k < 10) {
|
||||
let light = 0;
|
||||
forever(function () {
|
||||
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
|
||||
forever(() => {
|
||||
motors.largeD.setSpeed(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.setSpeed(-50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(50, 1, MoveUnit.Rotations);
|
||||
motors.largeD.run(-50, 1, MoveUnit.Rotations);
|
||||
})
|
||||
forever(() => {
|
||||
brick.showImage(images.eyesMiddleRight)
|
||||
@ -227,7 +227,7 @@ The ``||logic:if||`` block allows you to run different code depending on whether
|
||||
```blocks
|
||||
forever(function() {
|
||||
if(sensors.touch1.isPressed()) {
|
||||
motors.largeD.setSpeed(50)
|
||||
motors.largeD.run(50)
|
||||
} else {
|
||||
motors.largeD.stop()
|
||||
}
|
||||
|
@ -213,13 +213,13 @@ music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
}
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(10)
|
||||
motors.largeC.setSpeed(-10)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeA.setSpeed(-10)
|
||||
motors.largeA.setSpeed(10)
|
||||
motors.largeA.run(-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
|
||||
while (true) {
|
||||
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(10)
|
||||
motors.largeC.setSpeed(-10)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
|
||||
motors.largeB.setSpeed(-10)
|
||||
motors.largeC.setSpeed(10)
|
||||
motors.largeB.run(-10)
|
||||
motors.largeC.run(10)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -4,11 +4,11 @@ Use this program with the Programmable Brick and Large Motor.
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
motors.largeA.setSpeed(30)
|
||||
motors.largeA.run(30)
|
||||
pause(100)
|
||||
motors.largeA.stop()
|
||||
music.playSoundEffectUntilDone(sounds.animalsCatPurr)
|
||||
motors.largeA.setSpeed(-30)
|
||||
motors.largeA.run(-30)
|
||||
pause(100)
|
||||
motors.largeA.stop()
|
||||
})
|
||||
|
@ -4,9 +4,9 @@ This example program combined with the small model will make a beat and rhythm o
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
pause(200)
|
||||
motors.largeA.setSpeed(100)
|
||||
motors.largeA.run(100)
|
||||
pause(200)
|
||||
})
|
||||
```
|
@ -3,7 +3,7 @@
|
||||
## Motion
|
||||
|
||||
```cards
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
motors.largeAB.tank(50, 50)
|
||||
motors.largeAB.steer(0, 50)
|
||||
motors.largeA.pauseUntilReady()
|
||||
|
@ -19,7 +19,7 @@ Reset the motor connected to port **A** and run it for for 2 seconds at a speed
|
||||
```blocks
|
||||
let motorAngle = 0;
|
||||
motors.largeA.reset()
|
||||
motors.largeA.setSpeed(45)
|
||||
motors.largeA.run(45)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
motorAngle = motors.largeA.angle()
|
||||
|
@ -15,11 +15,11 @@ See if the motor turns the same number of times for each of two count periods. R
|
||||
```blocks
|
||||
let tachoCount = 0;
|
||||
motors.largeA.reset()
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
tachoCount = motors.largeA.tacho()
|
||||
motors.largeA.clearCounts()
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
pause(10000)
|
||||
if (tachoCount == motors.largeA.tacho()) {
|
||||
brick.showString("Motor turns equal.", 1)
|
||||
|
@ -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.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
brick.showString("Angle count:", 1)
|
||||
brick.showNumber(motors.largeA.angle(), 2)
|
||||
motors.largeA.setSpeed(30)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.reset()
|
||||
brick.showString("Angle count:", 4)
|
||||
|
@ -1,9 +1,9 @@
|
||||
# set Speed
|
||||
# run
|
||||
|
||||
Set the rotation speed of the motor as a percentage of maximum speed.
|
||||
|
||||
```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.
|
||||
@ -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:
|
||||
|
||||
```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
|
||||
// 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.
|
||||
motors.largeA.setSpeed(25, 700);
|
||||
motors.largeA.run(25, 700);
|
||||
|
||||
// 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
|
||||
motors.largeA.setSpeed(50, 270, MoveUnit.Degrees)
|
||||
motors.largeA.run(50, 270, MoveUnit.Degrees)
|
||||
|
||||
// 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
|
||||
@ -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:
|
||||
|
||||
```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.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(75)
|
||||
motors.largeA.run(75)
|
||||
pause(20000)
|
||||
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.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(-60)
|
||||
motors.largeA.run(-60)
|
||||
pause(5000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
@ -88,7 +88,7 @@ motors.largeA.stop()
|
||||
Run the motor connected to port **B** for 35 full rotations and then stop.
|
||||
|
||||
```blocks
|
||||
motors.largeB.setSpeed(50, 35, MoveUnit.Rotations)
|
||||
motors.largeB.run(50, 35, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## See also
|
@ -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.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
motors.largeA.setBrake(true)
|
||||
|
@ -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.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
pause(2000)
|
||||
motors.largeA.setInverted(true)
|
||||
motors.largeA.setSpeed(-30)
|
||||
motors.largeA.run(-30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
@ -22,11 +22,11 @@ Turn off the speed regulation for the motor connected to port **A**.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(75)
|
||||
motors.largeA.run(75)
|
||||
pause(20000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[set speed](/reference/motors/motor/set-speed), [stop](/reference/motors/motor/stop)
|
||||
[run](/reference/motors/motor/run), [stop](/reference/motors/motor/stop)
|
||||
|
@ -6,7 +6,7 @@ Get the current speed of motor rotation as a percentage of maximum 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
|
||||
|
||||
@ -18,7 +18,7 @@ Turn speed regulation off and report the actual speed of the large motor in the
|
||||
|
||||
```blocks
|
||||
motors.largeA.setRegulated(false)
|
||||
motors.largeA.setSpeed(55)
|
||||
motors.largeA.run(55)
|
||||
brick.showString("Actual speed:", 1)
|
||||
for (let i = 0; i < 30; i++) {
|
||||
pause(500)
|
||||
|
@ -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`.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(30)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
pause(2000)
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
@ -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.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
pause(5000)
|
||||
motors.largeA.stop()
|
||||
brick.showString("Motor rotations:", 1)
|
||||
brick.showNumber(motors.largeA.tacho() / 360, 3)
|
||||
motors.largeA.setSpeed(50)
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
@ -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 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
|
||||
|
||||
@ -81,4 +81,4 @@ motors.stopAll()
|
||||
|
||||
## See also
|
||||
|
||||
[tank](/reference/motors/synced/tank), [set speed](/reference/motors/motor/set-speed)
|
||||
[tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)
|
@ -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 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
|
||||
|
||||
@ -78,4 +78,4 @@ motors.stopAll()
|
||||
|
||||
## See also
|
||||
|
||||
[steer](/reference/motors/synced/steer), [set speed](/reference/motors/motor/set-speed)
|
||||
[steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)
|
@ -134,17 +134,17 @@ namespace motors {
|
||||
protected _brake: boolean;
|
||||
private _initialized: boolean;
|
||||
private _init: () => void;
|
||||
private _setSpeed: (speed: number) => void;
|
||||
private _run: (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();
|
||||
this._port = port;
|
||||
this._portName = outputToName(this._port);
|
||||
this._brake = false;
|
||||
this._initialized = false;
|
||||
this._init = init;
|
||||
this._setSpeed = setSpeed;
|
||||
this._run = run;
|
||||
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 value (optional) measured distance or rotation
|
||||
* @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
|
||||
//% group="Move"
|
||||
//% expandableArgumentMode=toggle
|
||||
//% help=motors/motor/set-speed
|
||||
setSpeed(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
//% help=motors/motor/run
|
||||
run(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
this.init();
|
||||
speed = Math.clamp(-100, 100, speed >> 0);
|
||||
// stop if speed is 0
|
||||
@ -238,7 +238,7 @@ namespace motors {
|
||||
}
|
||||
// special: 0 is infinity
|
||||
if (value == 0) {
|
||||
this._setSpeed(speed);
|
||||
this._run(speed);
|
||||
return;
|
||||
}
|
||||
// timed motor moves
|
||||
|
@ -7,8 +7,8 @@ A unit test framework
|
||||
Tests are registered as event handlers. They will automatically run once ``on start`` is finished.
|
||||
|
||||
```blocks
|
||||
tests.test("lgB set speed 10", () => {
|
||||
motors.largeB.setSpeed(10);
|
||||
tests.test("lgB run 10", () => {
|
||||
motors.largeB.run(10);
|
||||
pause(100)
|
||||
tests.assertClose("speedB", 10, motors.largeB.speed(), 2)
|
||||
});
|
||||
|
@ -46,7 +46,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"pxt-common-packages": "0.19.5",
|
||||
"pxt-core": "3.4.3"
|
||||
"pxt-core": "3.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node node_modules/pxt-core/built/pxt.js travis"
|
||||
|
@ -1,17 +1,17 @@
|
||||
// add tests package
|
||||
tests.test("lgB set speed 10", () => {
|
||||
motors.largeB.setSpeed(10);
|
||||
tests.test("lgB run 10", () => {
|
||||
motors.largeB.run(10);
|
||||
pause(500)
|
||||
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.setSpeed(25)
|
||||
motors.largeB.run(25)
|
||||
pause(500)
|
||||
tests.assertClose("speedB", -25, motors.largeB.speed(), 2)
|
||||
});
|
||||
tests.test("lgBC set speed 5", () => {
|
||||
motors.largeBC.setSpeed(5)
|
||||
tests.test("lgBC run 5", () => {
|
||||
motors.largeBC.run(5)
|
||||
pause(500)
|
||||
tests.assertClose("speedB", 5, motors.largeB.speed(), 1);
|
||||
tests.assertClose("speedC", 5, motors.largeC.speed(), 1);
|
||||
|
Loading…
Reference in New Issue
Block a user