Compare commits

..

34 Commits

Author SHA1 Message Date
0345277bef 0.0.55 2018-01-06 00:00:40 -08:00
9ae6482f28 fixing isReady query on motors (#197) 2018-01-06 00:00:04 -08:00
77fb64043d stop all motors when pressing escape 2018-01-05 22:56:11 -08:00
f875681661 added roaming 2018-01-05 22:04:18 -08:00
fbb1fa688d fixing gallery 2018-01-05 21:50:50 -08:00
485f02ed27 cruise control activities 2018-01-05 21:49:04 -08:00
81f406c6cc ignition activities 2018-01-05 21:40:11 -08:00
ac0a7b326f 0.0.54 2018-01-05 21:30:05 -08:00
c814728354 pdated ultrasonic default 2018-01-05 21:29:52 -08:00
abeb378b17 reverse beeper 2018-01-05 21:20:00 -08:00
6928f9e50e traffic lights activity 2018-01-05 19:28:24 -08:00
931987468a light the way activities 2018-01-05 19:14:55 -08:00
94c4e508fe reversing the robot 2018-01-05 18:36:20 -08:00
ea46f1cbc7 3 activies from curriculum (#194)
* 3 activies from curriculum

* fixing style
2018-01-05 18:24:23 -08:00
9f9ce29476 Merge branch 'master' of https://github.com/Microsoft/pxt-ev3 2018-01-05 17:35:47 -08:00
50f6b04ed4 Re-implement Math.sign so it works on IE 11 (not supported). Square shaped corners for Flyout 2018-01-05 17:35:25 -08:00
64d6c2b090 Motors cleanup (#192)
* refactoring

* moving chassis into separate project

* added set motors
2018-01-05 16:02:52 -08:00
76ff39605a Remove synced motor label when motors are no longer in sync (#189) 2018-01-05 10:54:42 -08:00
2d3ea5631a Merge pull request #190 from Microsoft/consoleicon
Add console icon and set color.
2018-01-05 10:38:52 -08:00
e938f354fd Add console icon and set color. Fixes #152 2018-01-05 10:38:26 -08:00
886464b470 Merge branch 'master' of https://github.com/microsoft/pxt-ev3 2018-01-05 08:47:26 -08:00
b9ff9d21f1 bump common packages 2018-01-05 08:47:22 -08:00
aa06fd344a store synched motor info always (#187) 2018-01-05 08:40:49 -08:00
dc6ce0efc7 0.0.53 2018-01-05 08:39:30 -08:00
4039a85bc9 Make sure the ESC button always stops the program 2018-01-05 16:17:33 +00:00
7bd6280292 Disable HID deploy from command line (seems broken; was crashing until my previous checkin) 2018-01-05 16:17:20 +00:00
2ebe96e563 Fix command line deploy 2018-01-05 15:33:09 +00:00
a9be582f90 gyro calibration done right (#186) 2018-01-04 23:21:19 -08:00
de91dc6ab7 Handle the case where multiple motors or multiple sensors are connected to the same port. (#181) 2018-01-04 21:57:01 -08:00
1e460eef9e basic reading of battery level (#182) 2018-01-04 21:50:13 -08:00
0db6987ee5 Add loader and animation (#180) 2018-01-04 16:17:14 -08:00
148657908c Merge pull request #179 from Microsoft/syncedmotorui
Synced motors label (in simulator)
2018-01-04 14:38:29 -08:00
f3f87331c8 nit 2018-01-04 14:09:10 -08:00
5aef77ccc6 Generalizing motorView for both medium and large motor views. Initial work towards synced motor views. Adding sync label for controller motor. 2018-01-04 14:03:50 -08:00
77 changed files with 1254 additions and 241 deletions

View File

@ -2,14 +2,10 @@
import * as fs from 'fs';
require("./editor/deploy")
declare namespace pxt.editor {
function deployCoreAsync(resp: pxtc.CompileResult, disconnect?: boolean): Promise<void>;
}
const deploy = require("./editor/deploy")
export function deployCoreAsync(resp: pxtc.CompileResult) {
return pxt.editor.deployCoreAsync(resp, process.env["PXT_SERIAL"] ? false : true)
return deploy.deployCoreAsync(resp, process.env["PXT_SERIAL"] ? false : true)
.then(() => {
fs.writeFileSync("built/full-" + pxtc.BINARY_UF2, resp.outfiles[pxtc.BINARY_UF2], {
encoding: "base64"

170
docs/coding.md Normal file
View File

@ -0,0 +1,170 @@
# Coding Activites
12 computer science activities, with cross-curricular opportunities in design and technology, science, and math.
* [Download Curriculum Materials](https://education.lego.com/en-us/downloads/mindstorms-ev3)
## Three Point Turn
```codecard
[
{
"name": "Three Point Turn 1",
"description": "Activity 1",
"url":"/coding/three-point-turn-1",
"cardType": "example"
}, {
"name": "Three Point Turn 2",
"description": "Activity 2",
"url":"/coding/three-point-turn-2",
"cardType": "example"
}, {
"name": "Three Point Turn 3",
"description": "Activity 3",
"url":"/coding/three-point-turn-3",
"cardType": "example"
}]
```
## Reversing the robot
```codecard
[{
"name": "Reversing the robot 1",
"description": "Activity 1",
"url":"/coding/reversing-the-robot-1",
"cardType": "example"
}, {
"name": "Reversing the robot 2",
"description": "Activity 2",
"url":"/coding/reversing-the-robot-2",
"cardType": "example"
}, {
"name": "Reversing the robot 3",
"description": "Activity 3",
"url":"/coding/reversing-the-robot-3",
"cardType": "example"
}]
```
## Light the way
```codecard
[{
"name": "Light the way 1",
"description": "Activity 1",
"url":"/coding/light-the-way-1",
"cardType": "example"
}, {
"name": "Light the way 2",
"description": "Activity 2",
"url":"/coding/light-the-way-2",
"cardType": "example"
}, {
"name": "Light the way 3",
"description": "Activity 3",
"url":"/coding/light-the-way-3",
"cardType": "example"
}
]
```
## Traffic Lights
```codecard
[{
"name": "Traffic Lights 1",
"description": "Activity 1",
"url":"/coding/traffic-lights-1",
"cardType": "example"
}, {
"name": "Traffic Lights 2",
"description": "Activity 2",
"url":"/coding/traffic-lights-2",
"cardType": "example"
}, {
"name": "Traffic Lights 3",
"description": "Activity 3",
"url":"/coding/traffic-lights-3",
"cardType": "example"
}
]
```
## Reverse Bepper
```codecard
[{
"name": "Reverse Beeper 1",
"description": "Activity 1",
"url":"/coding/reverse-beeper-1",
"cardType": "example"
}, {
"name": "Reverse Beeper 2",
"description": "Activity 2",
"url":"/coding/reverse-beeper-2",
"cardType": "example"
}, {
"name": "Reverse Beeper 3",
"description": "Activity 3",
"url":"/coding/reverse-beeper-3",
"cardType": "example"
}]
```
## Ignition
```codecard
[{
"name": "Ignition 1",
"description": "Activity 1",
"url":"/coding/ingition-1",
"cardType": "example"
}, {
"name": "Ignition 2",
"description": "Activity 2",
"url":"/coding/ignition-2",
"cardType": "example"
}, {
"name": "Ignition 3",
"description": "Activity 3",
"url":"/coding/ignition-3",
"cardType": "example"
}]
```
## Cruise Control
```codecard
[{
"name": "Cruise Control 1",
"description": "Activity 1",
"url":"/coding/cruise-control-1",
"cardType": "example"
}, {
"name": "Cruise Control 2",
"description": "Activity 2",
"url":"/coding/cruise-control-2",
"cardType": "example"
}, {
"name": "Cruise Control 3",
"description": "Activity 3",
"url":"/coding/cruise-control-3",
"cardType": "example"
}]
```
## Roaming
```codecard
[{
"name": "Roaming 1",
"description": "Activity 1",
"url":"/coding/roaming-1",
"cardType": "example"
}, {
"name": "Roaming 2",
"description": "Activity 2",
"url":"/coding/roaming-2",
"cardType": "example"
}, {

View File

@ -0,0 +1,10 @@
# Cruise Control Activity 1
```blocks
let speed = 0;
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
if (speed < 100)
speed = speed + 10;
motors.largeBC.setSpeed(speed);
})
```

View File

@ -0,0 +1,15 @@
# Cruise Control Activity 2
```blocks
let speed = 0;
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
if (speed < 100)
speed = speed + 10;
motors.largeBC.setSpeed(speed);
})
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {
if (speed > -100)
speed = speed - 10;
motors.largeBC.setSpeed(speed);
})
```

View File

@ -0,0 +1,28 @@
# Cruise Control Activity 3
```blocks
let speed = 0
function decelerate() {
if (speed > -100) {
speed = speed - 10
}
}
function accelerate() {
if (speed < 100) {
speed = speed + 10
}
}
function update() {
brick.clearScreen()
brick.printLine("speed: " + speed, 1)
motors.largeBC.setSpeed(speed)
}
sensors.touch2.onEvent(TouchSensorEvent.Pressed, function () {
accelerate()
update()
})
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
decelerate()
update()
})
```

11
docs/coding/ignition-1.md Normal file
View File

@ -0,0 +1,11 @@
# Ignition Activity 1
```blocks
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
brick.showImage(images.eyesDizzy)
})
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectDetected, function () {
brick.showImage(images.eyesTiredMiddle)
})
brick.showImage(images.eyesSleeping)
```

12
docs/coding/ignition-2.md Normal file
View File

@ -0,0 +1,12 @@
# Ignition Activity 2
```blocks
while (true) {
if (sensors.touch1.wasPressed() &&
sensors.ultrasonic4.distance() < 10) {
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
}
loops.pause(1);
}
```

13
docs/coding/ignition-3.md Normal file
View File

@ -0,0 +1,13 @@
# Ignition Activity 3
```blocks
while (true) {
if (sensors.ultrasonic4.distance() < 10 &&
sensors.touch1.wasPressed() &&
brick.buttonEnter.wasPressed()) {
music.playSoundEffectUntilDone(sounds.mechanicalMotorStart)
music.playSoundEffectUntilDone(sounds.mechanicalMotorIdle);
}
loops.pause(1);
}
```

View File

@ -0,0 +1,9 @@
# Light the way Activity 1
```blocks
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
brick.showImage(images.objectsLightOn)
loops.pause(5000)
brick.clearScreen()
})
```

View File

@ -0,0 +1,10 @@
# Light the way Activity 2
```blocks
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Bright, function () {
brick.clearScreen()
})
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
brick.showImage(images.objectsLightOn)
})
```

View File

@ -0,0 +1,13 @@
# Light the way Activity 3
```blocks
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Bright, function () {
brick.clearScreen()
})
sensors.color3.onLightChanged(LightIntensityMode.Ambient, LightCondition.Dark, function () {
brick.showImage(images.objectsLightOn)
})
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
brick.showImage(images.objectsLightOn);
})
```

View File

@ -0,0 +1,11 @@
# Reverse Beeper Activity 1
```blocks
loops.forever(function () {
music.playTone(440, sensors.ultrasonic4.distance());
loops.pause(50)
})
motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors();
```

View File

@ -0,0 +1,13 @@
# Reverse Beeper Activity 2
```blocks
loops.forever(function () {
if (motors.largeB.speed() != 0 && sensors.ultrasonic4.distance() < 20) {
music.playTone(440, sensors.ultrasonic4.distance());
loops.pause(50)
}
})
motors.largeBC.setSpeed(-20);
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.stopAllMotors();
```

View File

@ -0,0 +1,21 @@
# Reverse Beeper Activity 2
```blocks
let beep = false
beep = true
control.runInBackground(function () {
motors.largeB.setSpeed(-20)
motors.largeC.setSpeed(-20)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear)
motors.stopAllMotors()
beep = false
})
control.runInBackground(function () {
while (beep) {
if (sensors.ultrasonic4.distance() < 20) {
music.playTone(440, sensors.ultrasonic4.distance())
loops.pause(50)
}
}
})
```

View File

@ -0,0 +1,14 @@
# Reversing the robot Activity 1
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
motors.largeBC.setSpeed(50)
sensors.touchSensor1.pauseUntil(TouchSensorEvent.Pressed)
motors.largeBC.setSpeed(0)
loops.pause(1000)
brick.setLight(LightsPattern.OrangeFlash)
motors.largeBC.setSpeed(-50)
loops.pause(2000)
motors.largeBC.setSpeed(0)
})
```

View File

@ -0,0 +1,15 @@
# Reversing the robot Activity 2
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
sensors.touchSensor1.pauseUntil(TouchSensorEvent.Pressed)
motors.largeBC.setSpeed(50)
sensors.touchSensor2.pauseUntil(TouchSensorEvent.Pressed)
motors.largeBC.setSpeed(0)
loops.pause(1000)
brick.setLight(LightsPattern.OrangeFlash)
motors.largeBC.setSpeed(-50)
loops.pause(2000)
motors.largeBC.setSpeed(0)
})
```

View File

@ -0,0 +1,19 @@
# Reversing the robot Activity 3
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
brick.showImage(images.eyesSleeping)
sensors.touchSensor1.pauseUntil(TouchSensorEvent.Pressed)
brick.showImage(images.eyesNeutral)
motors.largeBC.setSpeed(50)
sensors.touchSensor2.pauseUntil(TouchSensorEvent.Pressed)
brick.showImage(images.eyesTiredMiddle)
motors.largeBC.setSpeed(0)
loops.pause(1000)
brick.setLight(LightsPattern.OrangeFlash)
brick.showImage(images.eyesDizzy)
motors.largeBC.setSpeed(-50)
loops.pause(2000)
motors.largeBC.setSpeed(0)
})
```

36
docs/coding/roaming-1.md Normal file
View File

@ -0,0 +1,36 @@
# Roaming Activity 1
```blocks
let drive: number[] = []
brick.buttonLeft.onEvent(ButtonEvent.Click, function () {
drive.push(1)
})
brick.buttonRight.onEvent(ButtonEvent.Click, function () {
drive.push(3)
})
brick.buttonUp.onEvent(ButtonEvent.Click, function () {
drive.push(4)
})
brick.buttonDown.onEvent(ButtonEvent.Click, function () {
drive.push(5)
})
pauseUntil(() => drive.length >= 5)
loops.pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) {
if (d == 1) {
motors.largeC.setSpeedFor(50, 360, MoveUnit.Degrees)
motors.largeC.pauseUntilReady()
} else if (d == 3) {
motors.largeB.setSpeedFor(50, 360, MoveUnit.Degrees)
motors.largeB.pauseUntilReady()
} else if (d == 4) {
motors.largeBC.setSpeedFor(50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
} else {
motors.largeBC.setSpeedFor(-50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
}
}
music.playSoundEffectUntilDone(sounds.communicationGameOver)
```

40
docs/coding/roaming-2.md Normal file
View File

@ -0,0 +1,40 @@
# Roaming Activity 2
```blocks
let drive: number[] = []
brick.buttonLeft.onEvent(ButtonEvent.Click, function () {
drive.push(1)
music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonRight.onEvent(ButtonEvent.Click, function () {
drive.push(3)
music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonUp.onEvent(ButtonEvent.Click, function () {
drive.push(4)
music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonDown.onEvent(ButtonEvent.Click, function () {
drive.push(5)
music.playSoundEffectUntilDone(sounds.systemClick)
})
brick.buttonEnter.pauseUntil(ButtonEvent.Click);
loops.pause(1000)
music.playSoundEffectUntilDone(sounds.communicationGo)
for (let d of drive) {
if (d == 1) {
motors.largeC.setSpeedFor(50, 360, MoveUnit.Degrees)
motors.largeC.pauseUntilReady()
} else if (d == 3) {
motors.largeB.setSpeedFor(50, 360, MoveUnit.Degrees)
motors.largeB.pauseUntilReady()
} else if (d == 4) {
motors.largeBC.setSpeedFor(50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
} else {
motors.largeBC.setSpeedFor(-50, 360, MoveUnit.Degrees)
motors.largeBC.pauseUntilReady()
}
}
music.playSoundEffectUntilDone(sounds.communicationGameOver)
```

View File

@ -0,0 +1,12 @@
# Three Point Turn Activity 1
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
motors.largeBC.tank(75, 30)
loops.pause(1500)
motors.largeBC.tank(-30, -75)
loops.pause(1000)
motors.largeBC.tank(50, 50)
loops.pause(3000)
})
```

View File

@ -0,0 +1,14 @@
# Three Point Turn Activity 2
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
motors.largeBC.tank(75, 30)
loops.pause(1500)
motors.largeBC.tank(-30, -75)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.largeBC.tank(0, 0)
loops.pause(1000)
motors.largeBC.tank(50, 50)
loops.pause(3000)
})
```

View File

@ -0,0 +1,15 @@
# Three Point Turn Activity 3
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
motors.largeBC.tank(75, 30)
loops.pause(1500)
motors.largeBC.tank(-30, -75)
sensors.ultrasonic4.pauseUntil(UltrasonicSensorEvent.ObjectNear);
motors.largeBC.tank(0, 0)
music.playSoundEffect(sounds.animalsDogBark1)
loops.pause(1000)
motors.largeBC.tank(50, 50)
loops.pause(3000)
})
```

View File

@ -0,0 +1,9 @@
# Traffic Lights Activity 1
```blocks
brick.buttonEnter.onEvent(ButtonEvent.Click, function () {
motors.largeBC.tank(20, 20)
sensors.color3.pauseForColor(ColorSensorColor.Red)
motors.largeBC.tank(0, 0)
})
```

View File

@ -0,0 +1,10 @@
# Traffic Lights Activity 2
```blocks
sensors.color3.onColorDetected(ColorSensorColor.Red, function () {
motors.largeBC.tank(0, 0)
})
sensors.color3.onColorDetected(ColorSensorColor.Green, function () {
motors.largeBC.tank(20, 20)
})
```

View File

@ -0,0 +1,11 @@
# Traffic Lights Activity 3
```blocks
loops.forever(function () {
if (sensors.color3.light(LightIntensityMode.Reflected) < 15) {
motors.largeBC.tank(30, 12)
} else {
motors.largeBC.tank(12, 30)
}
})
```

View File

@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont";
src: url("iconfont.eot?73552ec404b3a3d3769a3f04fa58c2c4?#iefix") format("embedded-opentype"),
url("iconfont.woff2?73552ec404b3a3d3769a3f04fa58c2c4") format("woff2"),
url("iconfont.woff?73552ec404b3a3d3769a3f04fa58c2c4") format("woff");
src: url("iconfont.eot?8b7e57577c2d1f1ae9e810b9e010bc84?#iefix") format("embedded-opentype"),
url("iconfont.woff2?8b7e57577c2d1f1ae9e810b9e010bc84") format("woff2"),
url("iconfont.woff?8b7e57577c2d1f1ae9e810b9e010bc84") format("woff");
}
.icon {
@ -67,24 +67,27 @@ url("iconfont.woff?73552ec404b3a3d3769a3f04fa58c2c4") format("woff");
.icon-variables:before {
content: "\f111";
}
.icon-advancedcollapsed:before {
.icon-console:before {
content: "\f112";
}
.icon-advancedexpanded:before {
.icon-advancedcollapsed:before {
content: "\f113";
}
.icon-cancel:before {
.icon-advancedexpanded:before {
content: "\f114";
}
.icon-check:before {
.icon-cancel:before {
content: "\f115";
}
.icon-download:before {
.icon-check:before {
content: "\f116";
}
.icon-save:before {
.icon-download:before {
content: "\f117";
}
.icon-blocks:before {
.icon-save:before {
content: "\f118";
}
.icon-blocks:before {
content: "\f119";
}

Binary file not shown.

View File

@ -58,26 +58,29 @@
<glyph glyph-name="variables"
unicode="&#xF111;"
horiz-adv-x="40" d=" M36.8 12V7.8H3.4V12H36.8z M36.8 22.1V17.9H3.4V22.1H36.8z M36.7 32.2V28H3.3V32.2H36.7z" />
<glyph glyph-name="advancedcollapsed"
<glyph glyph-name="console"
unicode="&#xF112;"
horiz-adv-x="40" d=" M15.6 21.3L2.3 15L2.3 19.8L11.1 23.6L2.3 27.4L2.3 32.2L15.6 25.9L15.6 21.3z M36 9.1L16.6 9.1L16.6 12.2L36 12.2L36 9.1z" />
<glyph glyph-name="advancedcollapsed"
unicode="&#xF113;"
horiz-adv-x="40" d=" M39.7 28.2L36.2 31.5L20 15.3L3.8 31.5L0.3 28.2L18.3 10.3L18.3 10.3L20 8.5L20.5 9L20.5 9z" />
<glyph glyph-name="advancedexpanded"
unicode="&#xF113;"
unicode="&#xF114;"
horiz-adv-x="40" d=" M39.3 12L21.7 29.6L21.7 29.6L20 31.3L19.5 30.8L19.5 30.8L0.7 12L4 8.7L20 24.7L36 8.7z" />
<glyph glyph-name="cancel"
unicode="&#xF114;"
unicode="&#xF115;"
horiz-adv-x="40" d=" M33 29.6L29.4 33.2L20.2 24L11 33.2L7.3 29.6L16.5 20.3L7.3 11.1L11 7.3L20.2 16.5L29.4 7.3L33 11.1L23.8 20.3z" />
<glyph glyph-name="check"
unicode="&#xF115;"
unicode="&#xF116;"
horiz-adv-x="40" d=" M33.7 32.9L15.3 14.4L7.5 22.3L3.8 18.4L11.7 10.8L11.7 10.8L15.3 7.1L37.4 29.2z" />
<glyph glyph-name="download"
unicode="&#xF116;"
unicode="&#xF117;"
horiz-adv-x="40" d=" M5.2 15.7H36.5V1.7H5.2V15.7z M28.5 24.2L26.1 26.6L22.6 23.1L22.6 36.5L19.1 36.5L19.1 23.5L16 26.6L13.6 24.2L20.9 16.7L21 16.9L21.2 16.7z" />
<glyph glyph-name="save"
unicode="&#xF117;"
unicode="&#xF118;"
horiz-adv-x="40" d=" M25 34.5C25 33.6 25 32.8 25 31.9C25 31 24.7 30.9 24 30.9C23.5 30.9 22.8 30.9 22.4 30.9C22.1 30.9 21.4 31 21.4 31.7V31.9V36.9C21.4 37.3 21.6 37.8 22.3 38C22.3 38 22.3 38 22.4 38C23 38 23.7 38 24.2 38C24.7 38 25.2 37.6 25.2 37.1C25.2 37.1 25.2 37.1 25.2 36.9C25 36.3 25 35.2 25 34.5z M37.6 31.2C35.8 32.9 34.3 34.5 32.5 36.3C31 37.8 31 37.8 28.5 37.8C27.5 37.8 27.3 37.6 27.3 36.6V28.4C27.3 27.4 27.1 27.2 26.1 27.2H14.3C13.2 27.2 13 27.4 13 28.4V36.4C13 37.6 12.9 37.8 11.7 37.8H3.8C2.6 37.8 2.4 37.6 2.4 36.4V19.9C2.4 14.3 2.4 8.9 2.4 3.2C2.4 2 2.6 1.8 3.7 1.8H36.9C37.9 1.8 38.1 2.2 38.1 3.2V29.6C38.3 30.5 37.9 30.9 37.6 31.2zM33.7 6.7H7.1V23H33.7V6.7z" />
<glyph glyph-name="blocks"
unicode="&#xF118;"
unicode="&#xF119;"
horiz-adv-x="40" d=" M10.9 23H39V16.9H10.9V23z M39.2 27.1L39.2 33L0.9 33L0.9 31.1L0.9 27.1L0.9 12.9L0.9 7L39.2 7L39.2 12.9L6.9 12.9L6.9 27.1z" />
</font>
</defs>

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

1
docs/static/loader_back.svg vendored Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="301.499" height="179.742" viewBox="0 0 282.655 168.508"><g transform="translate(-41.005 -446.364)"><rect ry="30" rx="30" y="458.77" x="53.41" height="143.698" width="105.312" stroke="#000" stroke-width="17.724" stroke-linecap="round" stroke-linejoin="round"/><rect width="105.668" height="144.183" x="53.232" y="458.527" rx="30.101" ry="30.101" fill="#fff"/></g><g transform="translate(111.528 -446.364)"><rect width="105.312" height="143.698" x="53.41" y="458.77" rx="30" ry="30" stroke="#000" stroke-width="17.724" stroke-linecap="round" stroke-linejoin="round"/><rect ry="30.101" rx="30.101" y="458.527" x="53.232" height="144.183" width="105.668" fill="#fff"/></g></svg>

After

Width:  |  Height:  |  Size: 721 B

1
docs/static/loader_front.svg vendored Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="301.499" height="179.742" viewBox="0 0 282.655 168.508"><g stroke="#000" stroke-linecap="round" stroke-linejoin="round"><g transform="translate(124.66 -243.829)"><circle r="25.968" cy="356.872" cx="-38.891" fill="none"/><circle cx="-38.891" cy="356.872" r="21.013" stroke-width=".809"/><path d="M-30.581 341.741a13.835 13.835 0 0 1 5.76 4.504l-11.099 8.26z" fill="#fff" stroke-width=".533"/></g><g transform="translate(277.193 -243.829)"><circle cx="-38.891" cy="356.872" r="25.968" fill="none"/><circle r="21.013" cy="356.872" cx="-38.891" stroke-width=".809"/><path d="M-30.581 341.741a13.835 13.835 0 0 1 5.76 4.504l-11.099 8.26z" fill="#fff" stroke-width=".533"/></g></g></svg>

After

Width:  |  Height:  |  Size: 728 B

1
docs/static/loader_full.svg vendored Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="301.499" height="179.742" viewBox="0 0 282.655 168.508"><g transform="translate(-41.005 -446.364)"><rect ry="30" rx="30" y="458.77" x="53.41" height="143.698" width="105.312" stroke="#000" stroke-width="17.724" stroke-linecap="round" stroke-linejoin="round"/><rect width="105.668" height="144.183" x="53.232" y="458.527" rx="30.101" ry="30.101" fill="#fff"/></g><g transform="translate(124.66 -243.829)" stroke="#000" stroke-linecap="round" stroke-linejoin="round"><circle r="25.968" cy="356.872" cx="-38.891" fill="none"/><circle cx="-38.891" cy="356.872" r="21.013" stroke-width=".809"/><path d="M-30.581 341.741a13.835 13.835 0 0 1 5.76 4.504l-11.099 8.26z" fill="#fff" stroke-width=".533"/></g><g transform="translate(111.528 -446.364)"><rect width="105.312" height="143.698" x="53.41" y="458.77" rx="30" ry="30" stroke="#000" stroke-width="17.724" stroke-linecap="round" stroke-linejoin="round"/><rect ry="30.101" rx="30.101" y="458.527" x="53.232" height="144.183" width="105.668" fill="#fff"/></g><g transform="translate(277.193 -243.829)" stroke="#000" stroke-linecap="round" stroke-linejoin="round"><circle cx="-38.891" cy="356.872" r="25.968" fill="none"/><circle r="21.013" cy="356.872" cx="-38.891" stroke-width=".809"/><path d="M-30.581 341.741a13.835 13.835 0 0 1 5.76 4.504l-11.099 8.26z" fill="#fff" stroke-width=".533"/></g></svg>

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -29,7 +29,8 @@ export function initAsync() {
let canHID = false
if (pxt.U.isNodeJS) {
canHID = true
// doesn't seem to work ATM
canHID = false
} else {
const forceHexDownload = /forceHexDownload/i.test(window.location.href);
if (pxt.Cloud.isLocalHost() && pxt.Cloud.localToken && !forceHexDownload)

View File

@ -5,7 +5,7 @@ import { deployCoreAsync, initAsync } from "./deploy";
import { FieldPorts } from "./field_ports";
import { FieldImages } from "./field_images";
pxt.editor.initExtensionsAsync = function(opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): Promise<pxt.editor.ExtensionResult> {
pxt.debug('loading pxt-ev3 target extensions...')
updateBlocklyShape();
const res: pxt.editor.ExtensionResult = {
@ -111,6 +111,20 @@ function updateBlocklyShape() {
'l ' + 0 + ',' + (Blockly.BlockSvg as any).CORNER_RADIUS * 2 +
'l ' + (Blockly.BlockSvg as any).CORNER_RADIUS + ',' + 0;
/**
* Corner radius of the flyout background.
* @type {number}
* @const
*/
(Blockly as any).Flyout.prototype.CORNER_RADIUS = 0;
/**
* Margin around the edges of the blocks in the flyout.
* @type {number}
* @const
*/
(Blockly as any).Flyout.prototype.MARGIN = 8;
}
// When require()d from node, bind the global pxt namespace

3
libs/chassis/README.md Normal file
View File

@ -0,0 +1,3 @@
# Chassis
A library to control a chassis.

View File

@ -0,0 +1,14 @@
{
"chassis.Chassis": "A differential drive robot",
"chassis.Chassis.drive": "Makes a differential drive robot move with a given speed (cm/s) and rotation rate (deg/s)\nusing a unicycle model.",
"chassis.Chassis.driveFor": "Makes a differential drive robot move with a given speed (cm/s) and rotation rate (deg/s)\nusing a unicycle model.",
"chassis.Chassis.driveFor|param|rotationSpeed": "rotation of the robot around the center point, eg: 30",
"chassis.Chassis.driveFor|param|speed": "speed of the center point between motors, eg: 10",
"chassis.Chassis.driveFor|param|value": "the amount of movement, eg: 2",
"chassis.Chassis.drive|param|rotationSpeed": "rotation of the robot around the center point, eg: 30",
"chassis.Chassis.drive|param|speed": "speed of the center point between motors, eg: 10",
"chassis.Chassis.setMotors": "Sets the motors used by the chassis, default is B+C",
"chassis.Chassis.setProperty": "Sets a property of the robot",
"chassis.Chassis.setProperty|param|property": "the property to set",
"chassis.Chassis.setProperty|param|value": "the value to set"
}

View File

@ -0,0 +1,10 @@
{
"ChassisProperty.BaseLength|block": "base length (cm)",
"ChassisProperty.WheelRadius|block": "wheel radius (cm)",
"chassis.Chassis.driveFor|block": "drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s|for %value|%unit",
"chassis.Chassis.drive|block": "drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s",
"chassis.Chassis.setMotors|block": "set %chassis|motors to %motors",
"chassis.Chassis.setProperty|block": "set %chassis|%property|to %value",
"chassis|block": "chassis",
"{id:category}Chassis": "Chassis"
}

101
libs/chassis/chassis.ts Normal file
View File

@ -0,0 +1,101 @@
enum ChassisProperty {
//% block="wheel radius (cm)"
WheelRadius,
//% block="base length (cm)"
BaseLength
}
namespace chassis {
/**
* A differential drive robot
*/
//% fixedInstances
export class Chassis {
// the motor pair
public motors: motors.SynchedMotorPair;
// the radius of the wheel (cm)
public wheelRadius: number;
// the distance between the wheels (cm)
public baseLength: number;
constructor() {
this.motors = motors.largeBC;
this.wheelRadius = 3;
this.baseLength = 12;
}
/**
* Makes a differential drive robot move with a given speed (cm/s) and rotation rate (deg/s)
* using a unicycle model.
* @param speed speed of the center point between motors, eg: 10
* @param rotationSpeed rotation of the robot around the center point, eg: 30
*/
//% blockId=motorDrive block="drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s"
//% inlineInputMode=inline
//% weight=99 blockGap=8
drive(speed: number, rotationSpeed: number) {
this.driveFor(speed, rotationSpeed, 0, MoveUnit.Degrees);
}
/**
* Makes a differential drive robot move with a given speed (cm/s) and rotation rate (deg/s)
* using a unicycle model.
* @param speed speed of the center point between motors, eg: 10
* @param rotationSpeed rotation of the robot around the center point, eg: 30
* @param value the amount of movement, eg: 2
* @param unit
*/
//% blockId=motorDriveFor block="drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s|for %value|%unit"
//% inlineInputMode=inline
//% weight=95 blockGap=8
driveFor(speed: number, rotationSpeed: number, value: number, unit: MoveUnit) {
// speed is expressed in %
const R = this.wheelRadius; // cm
const L = this.baseLength; // cm
const PI = 3.14;
const maxw = 170 / 60 * 2 * PI; // rad / s
const maxv = maxw * R; // cm / s
// speed is cm / s
const v = speed; // cm / s
const w = rotationSpeed / 360 * 2 * PI; // rad / s
const vr = (2 * v + w * L) / (2 * R); // rad / s
const vl = (2 * v - w * L) / (2 * R); // rad / s
const sr = vr / maxw * 100; // %
const sl = vl / maxw * 100; // %
this.motors.tankFor(sr, sl, value, unit)
}
/**
* Sets a property of the robot
* @param property the property to set
* @param value the value to set
*/
//% blockId=chassisSetProperty block="set %chassis|%property|to %value"
//% blockGap=8
//% weight=10
setProperty(property: ChassisProperty, value: number) {
switch (property) {
case ChassisProperty.WheelRadius:
this.wheelRadius = Math.max(0.1, value); break;
case ChassisProperty.BaseLength:
this.baseLength = Math.max(0.1, value); break;
}
}
/**
* Sets the motors used by the chassis, default is B+C
* @param motors
*/
//% blockId=chassisSetMotors block="set %chassis|motors to %motors"
//% weight=10
setMotors(motors: motors.SynchedMotorPair) {
this.motors = motors;
}
}
//% fixedInstance whenUsed
export const chassis = new Chassis();
}

15
libs/chassis/pxt.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "chassis",
"description": "Chassis robot support",
"files": [
"README.md",
"chassis.ts"
],
"testFiles": [
"test.ts"
],
"public": true,
"dependencies": {
"core": "file:../core"
}
}

1
libs/chassis/test.ts Normal file
View File

@ -0,0 +1 @@

View File

@ -223,15 +223,15 @@ namespace sensors {
}
}
//% whenUsed block="color 3" weight=90 fixedInstance jres=icons.port3
export const color3: ColorSensor = new ColorSensor(3)
//% whenUsed block="color 1" weight=95 fixedInstance jres=icons.port1
export const color1: ColorSensor = new ColorSensor(1)
//% whenUsed block="color 2" weight=90 fixedInstance jres=icons.port2
export const color2: ColorSensor = new ColorSensor(2)
//% whenUsed block="color 3" weight=90 fixedInstance jres=icons.port3
export const color3: ColorSensor = new ColorSensor(3)
//% whenUsed block="color 4" weight=90 fixedInstance jres=icons.port4
export const color4: ColorSensor = new ColorSensor(4)
}

View File

@ -21,6 +21,7 @@
"brick.Button.pauseUntil": "Waits until the event is raised",
"brick.Button.pauseUntil|param|ev": "the event to wait for",
"brick.Button.wasPressed": "See if the button was pressed again since the last time you checked.",
"brick.batteryLevel": "Returns the current battery level",
"brick.buttonDown": "Down button on the EV3 Brick.",
"brick.buttonEnter": "Enter button on the EV3 Brick.",
"brick.buttonLeft": "Left button on the EV3 Brick.",
@ -58,10 +59,6 @@
"motors.Motor.tacho": "Gets motor tachometer count.",
"motors.Motor.toString": "Returns the status of the motor",
"motors.MotorBase.isReady": "Returns a value indicating if the motor is still running a previous command.",
"motors.MotorBase.move": "Moves the motor by a number of rotations, degress or seconds",
"motors.MotorBase.move|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.MotorBase.move|param|unit": "the meaning of the value",
"motors.MotorBase.move|param|value": "the move quantity, eg: 2",
"motors.MotorBase.pauseUntilReady": "Pauses the execution until the previous command finished.",
"motors.MotorBase.pauseUntilReady|param|timeOut": "optional maximum pausing time in milliseconds",
"motors.MotorBase.reset": "Resets the motor(s).",
@ -69,23 +66,28 @@
"motors.MotorBase.setBrake|param|brake": "a value indicating if the motor should break when off",
"motors.MotorBase.setReversed": "Reverses the motor polarity",
"motors.MotorBase.setSpeed": "Sets the speed of the motor.",
"motors.MotorBase.setSpeedFor": "Sets the motor speed for limited time or distance",
"motors.MotorBase.setSpeedFor|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.MotorBase.setSpeedFor|param|unit": "the meaning of the value",
"motors.MotorBase.setSpeedFor|param|value": "the move quantity, eg: 2",
"motors.MotorBase.setSpeed|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.MotorBase.stop": "Stops the motor(s).",
"motors.SynchedMotorPair.drive": "Makes a differential drive robot move with a given speed (%) and rotation rate (deg/s)\nusing a unicycle model.",
"motors.SynchedMotorPair.drive|param|rotationSpeed": "rotation of the robot around the center point, eg: 30",
"motors.SynchedMotorPair.drive|param|speed": "speed of the center point between motors, eg: 10",
"motors.SynchedMotorPair.drive|param|value": "the amount of movement, eg: 2",
"motors.SynchedMotorPair.setDimensions": "Sets the wheels radius and base length of a directional drive robot",
"motors.SynchedMotorPair.setDimensions|param|wheelRadius": "@param baseLength ",
"motors.SynchedMotorPair.steer": "Turns the motor and the follower motor by a number of rotations",
"motors.SynchedMotorPair.steerFor": "Turns the motor and the follower motor by a number of rotations",
"motors.SynchedMotorPair.steerFor|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.SynchedMotorPair.steerFor|param|turnRatio": "the ratio of power sent to the follower motor, from ``-200`` to ``200``, eg: 0",
"motors.SynchedMotorPair.steerFor|param|unit": "the meaning of the value",
"motors.SynchedMotorPair.steerFor|param|value": "the move quantity, eg: 2",
"motors.SynchedMotorPair.steer|param|speed": "the speed from ``100`` full forward to ``-100`` full backward, eg: 50",
"motors.SynchedMotorPair.steer|param|turnRatio": "the ratio of power sent to the follower motor, from ``-200`` to ``200``, eg: 0",
"motors.SynchedMotorPair.steer|param|unit": "the meaning of the value",
"motors.SynchedMotorPair.steer|param|value": "the move quantity, eg: 2",
"motors.SynchedMotorPair.tank": "The Move Tank block can make a robot drive forward, backward, turn, or stop. \nUse the Move Tank block for robot vehicles that have two Large Motors, \nwith one motor driving the left side of the vehicle and the other the right side. \nYou can make the two motors go at different speeds or in different directions \nto make your robot turn.",
"motors.SynchedMotorPair.tankFor": "The Move Tank block can make a robot drive forward, backward, turn, or stop. \nUse the Move Tank block for robot vehicles that have two Large Motors, \nwith one motor driving the left side of the vehicle and the other the right side. \nYou can make the two motors go at different speeds or in different directions \nto make your robot turn.",
"motors.SynchedMotorPair.tankFor|param|speedLeft": "the speed on the left motor, eg: 50",
"motors.SynchedMotorPair.tankFor|param|speedRight": "the speed on the right motor, eg: 50",
"motors.SynchedMotorPair.tankFor|param|unit": "the unit of the value",
"motors.SynchedMotorPair.tankFor|param|value": "the amount of movement, eg: 2",
"motors.SynchedMotorPair.tank|param|speedLeft": "the speed on the left motor, eg: 50",
"motors.SynchedMotorPair.tank|param|speedRight": "the speed on the right motor, eg: 50",
"motors.SynchedMotorPair.tank|param|unit": "@param speedLeft the speed on the left motor, eg: 50",
"motors.SynchedMotorPair.tank|param|value": "the amount of movement, eg: 2",
"motors.SynchedMotorPair.toString": "Returns the name(s) of the motor",
"motors.mkCmd": "Allocates a message buffer",
"motors.mkCmd|param|addSize": "required additional bytes",

View File

@ -15,6 +15,7 @@
"MoveUnit.Degrees|block": "degrees",
"MoveUnit.MilliSeconds|block": "milliseconds",
"MoveUnit.Rotations|block": "rotations",
"MoveUnit.Seconds|block": "seconds",
"Output.AB|block": "A+B",
"Output.AD|block": "A+D",
"Output.ALL|block": "All",
@ -28,6 +29,7 @@
"brick.Button.onEvent|block": "on %button|%event",
"brick.Button.pauseUntil|block": "pause until %button|%event",
"brick.Button.wasPressed|block": "%button|was pressed",
"brick.batteryLevel|block": "battery level",
"brick.buttonDown|block": "down",
"brick.buttonEnter|block": "enter",
"brick.buttonLeft|block": "left",
@ -50,14 +52,15 @@
"motors.Motor.clearCounts|block": "%motor|clear counts",
"motors.Motor.speed|block": "%motor|speed",
"motors.Motor.tacho|block": "%motor|tacho",
"motors.MotorBase.move|block": "move %motor|for %value|%unit|at %speed|%",
"motors.MotorBase.pauseUntilReady|block": "%motor|pause until ready",
"motors.MotorBase.setBrake|block": "set %motor|brake %brake",
"motors.MotorBase.setReversed|block": "set %motor|reversed %reversed",
"motors.MotorBase.setSpeed|block": "set speed of %motor|to %speed|%",
"motors.SynchedMotorPair.drive|block": "drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s|for %value|%unit",
"motors.SynchedMotorPair.steer|block": "steer %chassis turn by|%turnRatio|at speed %speed|%|for %value|%unit",
"motors.SynchedMotorPair.tank|block": "tank %chassis|left %speedLeft|%|right %speedRight|%|for %value|%unit",
"motors.MotorBase.setSpeedFor|block": "set %motor|speed to %speed|%|for %value|%unit",
"motors.MotorBase.setSpeed|block": "set %motor|speed to %speed|%",
"motors.SynchedMotorPair.steerFor|block": "steer %chassis|turn ratio %turnRatio|speed %speed|%|for %value|%unit",
"motors.SynchedMotorPair.steer|block": "steer %chassis|turn ratio %turnRatio|speed %speed|%",
"motors.SynchedMotorPair.tankFor|block": "tank %motors|%speedLeft|%|%speedRight|%|for %value|%unit",
"motors.SynchedMotorPair.tank|block": "tank %motors|%speedLeft|%|%speedRight|%",
"motors.largeAB|block": "large A+B",
"motors.largeAD|block": "large A+D",
"motors.largeA|block": "large A",
@ -87,9 +90,11 @@
"{id:category}Screen": "Screen",
"{id:category}Serial": "Serial",
"{id:group}Buttons": "Buttons",
"{id:group}Chassis": "Chassis",
"{id:group}Counters": "Counters",
"{id:group}Light": "Light",
"{id:group}More": "More",
"{id:group}Motion": "Motion",
"{id:group}Screen": "Screen",
"{id:group}Sensors": "Sensors"
"{id:group}Sensors": "Sensors",
"{id:group}Sync Motion": "Sync Motion"
}

12
libs/core/battery.ts Normal file
View File

@ -0,0 +1,12 @@
namespace brick {
/**
* Returns the current battery level
*/
//% blockId=brickBatteryLevel block="battery level"
//% group="More"
export function batteryLevel(): number {
const info = sensors.internal.getBatteryInfo();
return info.current;
}
}

View File

@ -163,6 +163,12 @@ namespace brick {
if (sl[i])
ret |= 1 << i
}
// this needs to be done in query(), which is run without the main JS execution mutex
// otherwise, while(true){} will lock the device
if (ret & DAL.BUTTON_ID_ESCAPE) {
motors.stopAllMotors();
control.reset()
}
return ret
}
@ -172,8 +178,6 @@ namespace brick {
if (!btnsMM) control.fail("no buttons?")
buttons = []
sensors.internal.unsafePollForChanges(50, readButtons, (prev, curr) => {
if (curr & DAL.BUTTON_ID_ESCAPE)
control.reset()
for (let b of buttons)
b._update(!!(curr & b.mask))
})
@ -188,7 +192,7 @@ namespace brick {
initBtns()
buttons.push(this)
}
}
}
initBtns() // always ON as it handles ESCAPE button
@ -229,6 +233,7 @@ namespace control {
/**
* Determine the version of system software currently running.
*/
//%
export function deviceFirmwareVersion(): string {
let buf = output.createBuffer(6)
brick.internal.getBtnsMM().read(buf)

View File

@ -3,7 +3,7 @@
/**
* Reading and writing data to the console output.
*/
//% weight=12 color=#002050 icon="\uf120"
//% weight=12 color=#00451A icon="\uf112"
//% advanced=true
namespace console {
type Listener = (text: string) => void;

View File

@ -89,6 +89,14 @@ namespace sensors.internal {
//serial.writeLine("UART " + port + " / " + mode + " - " + info)
}
export function getBatteryInfo(): { temp: number; current: number } {
init();
return {
temp: analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.BatteryTemp),
current: analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.BatteryCurrent)
}
}
function detectDevices() {
let conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
let numChanged = 0
@ -301,6 +309,10 @@ namespace sensors.internal {
return 0
return getUartNumber(fmt, off, this._port)
}
protected reset() {
if (this.isActive()) uartReset(this._port);
}
}
function uartReset(port: number) {

View File

@ -30,6 +30,8 @@ enum MoveUnit {
Rotations,
//% block="degrees"
Degrees,
//% block="seconds"
Seconds,
//% block="milliseconds"
MilliSeconds
}
@ -204,7 +206,7 @@ namespace motors {
* Sets the speed of the motor.
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
*/
//% blockId=motorSetSpeed block="set speed of %motor|to %speed|%"
//% blockId=motorSetSpeed block="set %motor|speed to %speed|%"
//% on.fieldEditor=toggleonoff
//% weight=99 blockGap=8
//% speed.min=-100 speed.max=100
@ -219,16 +221,16 @@ namespace motors {
}
/**
* Moves the motor by a number of rotations, degress or seconds
* Sets the motor speed for limited time or distance
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
* @param value the move quantity, eg: 2
* @param unit the meaning of the value
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
*/
//% blockId=motorMove block="move %motor|for %value|%unit|at %speed|%"
//% blockId=motorMove block="set %motor|speed to %speed|%|for %value|%unit"
//% weight=98 blockGap=8
//% speed.min=-100 speed.max=100
//% group="Motion"
move(value: number, unit: MoveUnit, speed: number) {
setSpeedFor(speed: number, value: number, unit: MoveUnit) {
this.init();
speed = Math.clamp(-100, 100, speed >> 0);
if (!speed) {
@ -246,6 +248,10 @@ namespace motors {
stepsOrTime = value >> 0;
useSteps = true;
break;
case MoveUnit.Seconds:
stepsOrTime = (value * 1000) >> 0;
useSteps = false;
break;
default:
stepsOrTime = value;
useSteps = false;
@ -264,13 +270,7 @@ namespace motors {
const buf = mkCmd(this._port, DAL.opOutputTest, 2);
readPWM(buf)
const flags = buf.getNumber(NumberFormat.UInt8LE, 2);
// TODO: FIX with ~ support
for(let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
const flag = 1 << i;
if ((this._port & flag) && (flags & flag))
return false;
}
return true;
return (~flags & this._port) == this._port;
}
/**
@ -333,7 +333,7 @@ namespace motors {
//% blockId=motorSpeed block="%motor|speed"
//% weight=72
//% blockGap=8
//% group="Sensors"
//% group="Counters"
speed(): number {
this.init();
return getMotorData(this._port).actualSpeed;
@ -345,7 +345,8 @@ namespace motors {
*/
//% blockId=motorAngle block="%motor|angle"
//% weight=70
//% group="Sensors"
//% blockGap=8
//% group="Counters"
angle(): number {
this.init();
return getMotorData(this._port).count;
@ -359,7 +360,7 @@ namespace motors {
//% blockId=motorTachoCount block="%motor|tacho"
//% weight=69
//% blockGap=8
//% group="Sensors"
//% group="Counters"
tacho(): number {
this.init();
return getMotorData(this._port).tachoCount;
@ -371,7 +372,7 @@ namespace motors {
//% blockId=motorClearCount block="%motor|clear counts"
//% weight=68
//% blockGap=8
//% group="Sensors"
//% group="Counters"
clearCounts() {
this.init();
const b = mkCmd(this._port, DAL.opOutputClearCount, 0)
@ -418,13 +419,9 @@ namespace motors {
//% fixedInstances
export class SynchedMotorPair extends MotorBase {
private wheelRadius: number;
private baseLength: number;
constructor(ports: Output) {
super(ports, () => this.__init(), (speed) => this.__setSpeed(speed), (steps, stepsOrTime, speed) => this.__move(steps, stepsOrTime, speed));
this.wheelRadius = 3;
this.baseLength = 12;
this.markUsed();
}
@ -445,7 +442,7 @@ namespace motors {
private __setSpeed(speed: number) {
syncMotors(this._port, {
speed: speed,
turnRatio: 100, // same speed
turnRatio: 0, // same speed
useBrake: !!this._brake
})
}
@ -454,30 +451,47 @@ namespace motors {
syncMotors(this._port, {
useSteps: steps,
speed: speed,
turnRatio: 100, // same speed
turnRatio: 0, // same speed
stepsOrTime: stepsOrTime,
useBrake: this._brake
});
}
/**
* The Move Tank block can make a robot drive forward, backward, turn, or stop.
* Use the Move Tank block for robot vehicles that have two Large Motors,
* with one motor driving the left side of the vehicle and the other the right side.
* You can make the two motors go at different speeds or in different directions
* to make your robot turn.
* @param speedLeft the speed on the left motor, eg: 50
* @param speedRight the speed on the right motor, eg: 50
*/
//% blockId=motorPairTank block="tank %motors|%speedLeft|%|%speedRight|%"
//% weight=20 blockGap=8
//% group="Sync Motion"
tank(speedLeft: number, speedRight: number) {
this.tankFor(speedLeft, speedRight, 0, MoveUnit.Degrees);
}
/**
* The Move Tank block can make a robot drive forward, backward, turn, or stop.
* Use the Move Tank block for robot vehicles that have two Large Motors,
* with one motor driving the left side of the vehicle and the other the right side.
* You can make the two motors go at different speeds or in different directions
* to make your robot turn.
* @param value the amount of movement, eg: 2
* @param unit
* @param speedLeft the speed on the left motor, eg: 50
* @param speedRight the speed on the right motor, eg: 50
* @param value the amount of movement, eg: 2
* @param unit the unit of the value
*/
//% blockId=motorPairTank block="tank %chassis|left %speedLeft|%|right %speedRight|%|for %value|%unit"
//% weight=9 blockGap=8
//% blockId=motorPairTankFor block="tank %motors|%speedLeft|%|%speedRight|%|for %value|%unit"
//% weight=19
//% speedLeft.min=-100 speedLeft=100
//% speedRight.min=-100 speedRight=100
//% inlineInputMode=inline
//% group="Chassis"
tank(speedLeft: number, speedRight: number, value: number, unit: MoveUnit) {
//% group="Sync Motion"
tankFor(speedLeft: number, speedRight: number, value: number, unit: MoveUnit) {
this.init();
speedLeft = Math.clamp(-100, 100, speedLeft >> 0);
@ -487,43 +501,11 @@ namespace motors {
const turnRatio = speedLeft == speed
? (100 - speedRight / speedLeft * 100)
: (speedLeft / speedRight * 100 - 100);
this.steer(turnRatio, speed, value, unit);
this.steerFor(turnRatio, speed, value, unit);
}
/**
* Makes a differential drive robot move with a given speed (%) and rotation rate (deg/s)
* using a unicycle model.
* @param speed speed of the center point between motors, eg: 10
* @param rotationSpeed rotation of the robot around the center point, eg: 30
* @param value the amount of movement, eg: 2
* @param unit
*/
//% blockId=motorDrive block="drive %chassis|at %speed|cm/s|turning %rotationSpeed|deg/s|for %value|%unit"
//% inlineInputMode=inline
//% group="Chassis"
//% weight=8 blockGap=8
drive(speed: number, rotationSpeed: number, value: number, unit: MoveUnit) {
this.init();
// speed is expressed in %
const R = this.wheelRadius; // cm
const L = this.baseLength; // cm
const PI = 3.14;
const maxw = 170 / 60 * 2 * PI; // rad / s
const maxv = maxw * R; // cm / s
// speed is cm / s
const v = speed; // cm / s
const w = rotationSpeed / 360 * 2 * PI; // rad / s
const vr = (2 * v + w * L) / (2 * R); // rad / s
const vl = (2 * v - w * L) / (2 * R); // rad / s
const sr = vr / maxw * 100; // %
const sl = vl / maxw * 100; // %
this.tank(sr, sl, value, unit)
}
/**
* Turns the motor and the follower motor by a number of rotations
* @param turnRatio the ratio of power sent to the follower motor, from ``-200`` to ``200``, eg: 0
@ -531,12 +513,28 @@ namespace motors {
* @param value the move quantity, eg: 2
* @param unit the meaning of the value
*/
//% blockId=motorPairTurn block="steer %chassis turn by|%turnRatio|at speed %speed|%|for %value|%unit"
//% blockId=motorPairSteer block="steer %chassis|turn ratio %turnRatio|speed %speed|%"
//% weight=7 blockGap=8
//% turnRatio.min=-200 turnRatio=200
//% inlineInputMode=inline
//% group="Sync Motion"
steer(turnRatio: number, speed: number) {
this.steer(turnRatio, speed);
}
/**
* Turns the motor and the follower motor by a number of rotations
* @param turnRatio the ratio of power sent to the follower motor, from ``-200`` to ``200``, eg: 0
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
* @param value the move quantity, eg: 2
* @param unit the meaning of the value
*/
//% blockId=motorPairSteerFor block="steer %chassis|turn ratio %turnRatio|speed %speed|%|for %value|%unit"
//% weight=6 blockGap=8
//% turnRatio.min=-200 turnRatio=200
//% inlineInputMode=inline
//% group="Chassis"
steer(turnRatio: number, speed: number, value: number, unit: MoveUnit) {
//% group="Sync Motion"
steerFor(turnRatio: number, speed: number, value: number, unit: MoveUnit) {
this.init();
speed = Math.clamp(-100, 100, speed >> 0);
if (!speed) {
@ -556,6 +554,10 @@ namespace motors {
stepsOrTime = value >> 0;
useSteps = true;
break;
case MoveUnit.Seconds:
stepsOrTime = (value * 1000) >> 0;
useSteps = false;
break;
default:
stepsOrTime = value >> 0;
useSteps = false;
@ -569,17 +571,6 @@ namespace motors {
stepsOrTime: stepsOrTime,
useBrake: this._brake
});
}
/**
* Sets the wheels radius and base length of a directional drive robot
* @param wheelRadius
* @param baseLength
*/
//% group="Chassis"
setDimensions(wheelRadius: number, baseLength: number): void {
this.wheelRadius = wheelRadius;
this.baseLength = baseLength;
}
/**

View File

@ -16,6 +16,7 @@
"png.cpp",
"screen.cpp",
"screen.ts",
"battery.ts",
"output.cpp",
"output.ts",
"core.ts",

View File

@ -14,11 +14,16 @@ namespace sensors {
}
//% color="#A5CA18" weight=90 icon="\uf10d"
//% groups='["Motion", "Sensors", "Chassis"]'
//% groups='["Motion", "Counters", "Sync Motion"]'
//% labelLineWidth=0
namespace motors {
}
//% labelLineWidth=0
namespace chassis {
}
//% labelLineWidth=0
namespace behaviors {
}

View File

@ -1,4 +1,5 @@
{
"sensors.GyroSensor.angle": "Get the current angle from the gyroscope.",
"sensors.GyroSensor.rate": "Get the current rotation rate from the gyroscope."
"sensors.GyroSensor.calibrate": "Forces a calibration of the gyro. Must be called when the sensor is completely still.",
"sensors.GyroSensor.rotationRate": "Get the current rotation rate from the gyroscope."
}

View File

@ -1,6 +1,7 @@
{
"sensors.GyroSensor.angle|block": "%sensor|angle",
"sensors.GyroSensor.rate|block": "%sensor|rotation rate",
"sensors.GyroSensor.calibrate|block": "%sensor|calibrate",
"sensors.GyroSensor.rotationRate|block": "%sensor|rotation rate",
"sensors.gyro1|block": "gyro 1",
"sensors.gyro2|block": "gyro 2",
"sensors.gyro3|block": "gyro 3",

View File

@ -7,8 +7,10 @@ const enum GyroSensorMode {
namespace sensors {
//% fixedInstances
export class GyroSensor extends internal.UartSensor {
private calibrating: boolean;
constructor(port: number) {
super(port)
this.calibrating = false;
}
_deviceType() {
@ -32,6 +34,9 @@ namespace sensors {
//% weight=65 blockGap=8
//% group="Gyro Sensor"
angle(): number {
if (this.calibrating)
pauseUntil(() => !this.calibrating, 2000);
this.setMode(GyroSensorMode.Angle)
return this.getNumber(NumberFormat.Int16LE, 0)
}
@ -40,7 +45,7 @@ namespace sensors {
* Get the current rotation rate from the gyroscope.
* @param sensor the gyroscope to query the request
*/
//% help=input/gyro/rate
//% help=input/gyro/rotation-rate
//% block="%sensor|rotation rate"
//% blockId=gyroGetRate
//% parts="gyroscope"
@ -48,18 +53,53 @@ namespace sensors {
//% sensor.fieldEditor="ports"
//% weight=65 blockGap=8
//% group="Gyro Sensor"
rate(): number {
rotationRate(): number {
if (this.calibrating)
pauseUntil(() => !this.calibrating, 2000);
this.setMode(GyroSensorMode.Rate)
return this.getNumber(NumberFormat.Int16LE, 0)
}
}
//% fixedInstance whenUsed block="gyro 1" jres=icons.port1
export const gyro1: GyroSensor = new GyroSensor(1)
/**
* Forces a calibration of the gyro. Must be called when the sensor is completely still.
*/
//% help=input/gyro/calibrate
//% block="%sensor|calibrate"
//% blockId=gyroCalibrate
//% parts="gyroscope"
//% blockNamespace=sensors
//% sensor.fieldEditor="ports"
//% weight=65 blockGap=8
//% group="Gyro Sensor"
calibrate(): void {
if (this.calibrating) return; // already in calibration mode
this.calibrating = true;
// may be triggered by a button click, give time to settle
loops.pause(500);
// send a reset command
this.reset();
// we need to switch mode twice to perform a calibration
if (this.mode == GyroSensorMode.Rate)
this.setMode(GyroSensorMode.Angle);
else
this.setMode(GyroSensorMode.Rate);
// switch back and wait
if (this.mode == GyroSensorMode.Rate)
this.setMode(GyroSensorMode.Angle);
else
this.setMode(GyroSensorMode.Rate);
this.calibrating = false;
}
}
//% fixedInstance whenUsed block="gyro 2" weight=95 jres=icons.port2
export const gyro2: GyroSensor = new GyroSensor(2)
//% fixedInstance whenUsed block="gyro 1" jres=icons.port1
export const gyro1: GyroSensor = new GyroSensor(1)
//% fixedInstance whenUsed block="gyro 3" jres=icons.port3
export const gyro3: GyroSensor = new GyroSensor(3)

View File

@ -6,10 +6,10 @@
"sensors.TouchSensor.onEvent|block": "on %sensor|%event",
"sensors.TouchSensor.pauseUntil|block": "pause until %sensor|%event",
"sensors.TouchSensor.wasPressed|block": "%sensor|was pressed",
"sensors.touchSensor1|block": "touch 1",
"sensors.touchSensor2|block": "touch 2",
"sensors.touchSensor3|block": "touch 3",
"sensors.touchSensor4|block": "touch 4",
"sensors.touch1|block": "touch 1",
"sensors.touch2|block": "touch 2",
"sensors.touch3|block": "touch 3",
"sensors.touch4|block": "touch 4",
"{id:category}Sensors": "Sensors",
"{id:group}Touch Sensor": "Touch Sensor"
}

View File

@ -1,8 +1,8 @@
sensors.touchSensor1.onEvent(TouchSensorEvent.Pressed, function () {
sensors.touch1.onEvent(TouchSensorEvent.Pressed, function () {
})
sensors.touchSensor2.onEvent(TouchSensorEvent.Bumped, function () {
sensors.touch2.onEvent(TouchSensorEvent.Bumped, function () {
})
sensors.touchSensor3.onEvent(TouchSensorEvent.Released, function () {
sensors.touch3.onEvent(TouchSensorEvent.Released, function () {
})
sensors.touchSensor4.isPressed();
sensors.touchSensor4.wasPressed();
sensors.touch4.isPressed();
sensors.touch4.wasPressed();

View File

@ -102,11 +102,11 @@ namespace sensors {
}
//% whenUsed block="touch 1" weight=95 fixedInstance jres=icons.port1
export const touchSensor1: TouchSensor = new TouchSensor(1)
export const touch1: TouchSensor = new TouchSensor(1)
//% whenUsed block="touch 2" weight=95 fixedInstance jres=icons.port2
export const touchSensor2: TouchSensor = new TouchSensor(2)
export const touch2: TouchSensor = new TouchSensor(2)
//% whenUsed block="touch 3" weight=95 fixedInstance jres=icons.port3
export const touchSensor3: TouchSensor = new TouchSensor(3)
export const touch3: TouchSensor = new TouchSensor(3)
//% whenUsed block="touch 4" weight=95 fixedInstance jres=icons.port4
export const touchSensor4: TouchSensor = new TouchSensor(4)
export const touch4: TouchSensor = new TouchSensor(4)
}

View File

@ -86,6 +86,9 @@ namespace sensors {
return this._query();
}
}
//% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4
export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
//% fixedInstance whenUsed block="ultrasonic 1" jres=icons.port1
export const ultrasonic1: UltraSonicSensor = new UltraSonicSensor(1)
@ -95,7 +98,4 @@ namespace sensors {
//% fixedInstance whenUsed block="ultrasonic 3" jres=icons.port3
export const ultrasonic3: UltraSonicSensor = new UltraSonicSensor(3)
//% fixedInstance whenUsed block="ultrasonic 4" jres=icons.port4
export const ultrasonic4: UltraSonicSensor = new UltraSonicSensor(4)
}

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.52",
"version": "0.0.55",
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
"private": true,
"keywords": [
@ -44,7 +44,7 @@
"webfonts-generator": "^0.4.0"
},
"dependencies": {
"pxt-common-packages": "0.15.3",
"pxt-common-packages": "0.15.4",
"pxt-core": "3.0.5"
},
"scripts": {

View File

@ -15,6 +15,7 @@
"libs/ultrasonic-sensor",
"libs/infrared-sensor",
"libs/gyro-sensor",
"libs/chassis",
"libs/ev3",
"libs/tests",
"libs/behaviors"

View File

@ -3,24 +3,6 @@
/// <reference path="../built/common-sim.d.ts"/>
namespace pxsim {
export enum CPlayPinName {
A0,
A1,
A2,
A3,
A4,
A5,
A6,
A7,
A8,
A9,
D4,
D5,
D6,
D7,
D8,
D13
}
export class EV3Board extends CoreBoard {
view: SVGSVGElement;
@ -36,7 +18,7 @@ namespace pxsim {
brickNode: BrickNode;
outputNodes: MotorNode[] = [];
private motorMap: pxt.Map<number> = {
public motorMap: pxt.Map<number> = {
0x01: 0,
0x02: 1,
0x04: 2,
@ -115,27 +97,40 @@ namespace pxsim {
return this.brickNode;
}
motorUsed(port:number, large: boolean) {
for(let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
motorUsed(port: number, large: boolean) {
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
const p = 1 << i;
if (port & p) {
const motorPort = this.motorMap[p];
if (!this.outputNodes[motorPort])
this.outputNodes[motorPort] = new MotorNode(motorPort, large);
}
}
}
}
}
hasMotor(port: number) {
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
const p = 1 << i;
if (port & p) {
const motorPort = this.motorMap[p];
const outputNode = this.outputNodes[motorPort];
if (outputNode)
return true;
}
}
return false;
}
getMotor(port: number, large?: boolean): MotorNode[] {
const r = [];
for(let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
const p = 1 << i;
if (port & p) {
const motorPort = this.motorMap[p];
const outputNode = this.outputNodes[motorPort];
if (outputNode)
r.push(outputNode);
}
}
}
return r;
}
@ -144,6 +139,10 @@ namespace pxsim {
return this.outputNodes;
}
hasSensor(port: number) {
return !!this.inputNodes[port];
}
getSensor(port: number, type: number): SensorNode {
if (!this.inputNodes[port]) {
switch (type) {
@ -168,6 +167,7 @@ namespace pxsim {
runtime.postError = (e) => {
// TODO
runtime.updateDisplay();
console.log('runtime error: ' + e);
}
}

View File

@ -24,13 +24,14 @@ namespace pxsim {
}
export class EV3AnalogState {
constructor() {
let data = new Uint8Array(5172)
MMapMethods.register("/dev/lms_analog", {
data,
beforeMemRead: () => {
//console.log("analog before read");
data[AnalogOff.BatteryTemp] = 21; // TODO simulate this
data[AnalogOff.BatteryCurrent] = 100; // TODO simulate this
const inputNodes = ev3board().getInputNodes();
for (let port = 0; port < DAL.NUM_INPUTS; port++) {
const node = inputNodes[port];

View File

@ -1,10 +1,17 @@
import lf = pxsim.localization.lf;
namespace pxsim.motors {
export function __motorUsed(port: number, large: boolean) {
//console.log("MOTOR INIT " + port);
ev3board().motorUsed(port, large);
runtime.queueDisplayUpdate();
if (!ev3board().hasMotor(port)) {
ev3board().motorUsed(port, large);
runtime.queueDisplayUpdate();
} else {
U.userError(`${lf("Multiple motors are connected to Port")} ${String.fromCharCode('A'.charCodeAt(0) + ev3board().motorMap[port])}`);
}
}
}
@ -12,7 +19,11 @@ namespace pxsim.sensors {
export function __sensorUsed(port: number, type: number) {
//console.log("SENSOR INIT " + port + ", type: " + type);
const sensor = ev3board().getSensor(port, type);
runtime.queueDisplayUpdate();
if (!ev3board().hasSensor(port)) {
const sensor = ev3board().getSensor(port, type);
runtime.queueDisplayUpdate();
} else {
U.userError(`${lf("Multiple sensors are connected to Port")} ${port + 1}`);
}
}
}

View File

@ -15,13 +15,17 @@ namespace pxsim {
private speedCmdValues: number[];
private speedCmdTacho: number;
private speedCmdTime: number;
private _synchedMotor: MotorNode; // non-null if master motor
private _synchedMotor: MotorNode; // non-null if synchronized
constructor(port: number, large: boolean) {
super(port);
this.setLarge(large);
}
isReady() {
return !this.speedCmd;
}
getSpeed() {
return this.speed * (this.polarity == 0 ? -1 : 1);
}
@ -50,6 +54,7 @@ namespace pxsim {
clearSpeedCmd() {
delete this.speedCmd;
delete this.speedCmdValues;
delete this._synchedMotor;
}
@ -88,7 +93,7 @@ namespace pxsim {
}
updateState(elapsed: number) {
console.log(`motor: ${elapsed}ms - ${this.speed}% - ${this.angle}> - ${this.tacho}|`)
//console.log(`motor: ${elapsed}ms - ${this.speed}% - ${this.angle}> - ${this.tacho}|`)
const interval = Math.min(20, elapsed);
let t = 0;
while (t < elapsed) {
@ -135,10 +140,10 @@ namespace pxsim {
}
case DAL.opOutputStepSync:
case DAL.opOutputTimeSync: {
if (!this._synchedMotor) // handled in other motor code
const otherMotor = this._synchedMotor;
if (otherMotor.port < this.port) // handled in other motor code
break;
const otherMotor = this._synchedMotor;
const speed = this.speedCmdValues[0];
const turnRatio = this.speedCmdValues[1];
const stepsOrTime = this.speedCmdValues[2];
@ -153,8 +158,21 @@ namespace pxsim {
if (brake) this.speed = 0;
this.clearSpeedCmd();
}
// send synched motor state
otherMotor.speed = Math.floor(this.speed * turnRatio / 100);
// turn ratio is a bit weird to interpret
// see https://communities.theiet.org/blogs/698/1706
if (turnRatio < 0) {
otherMotor.speed = speed;
this.speed *= (100 + turnRatio) / 100;
} else {
otherMotor.speed = this.speed * (100 - turnRatio) / 100;
}
// clamp
this.speed = Math.max(-100, Math.min(100, this.speed >> 0));
otherMotor.speed = Math.max(-100, Math.min(100, otherMotor.speed >> 0));;
// stop other motor if needed
if (!this._synchedMotor)
otherMotor.clearSpeedCmd();
break;
@ -175,8 +193,15 @@ namespace pxsim {
// let it coast to speed 0
if (this.speed && !(this.started || this.speedCmd)) {
// decay speed 5% per tick
this.speed = Math.round(Math.max(0, Math.abs(this.speed) - 10) * Math.sign(this.speed));
this.speed = Math.round(Math.max(0, Math.abs(this.speed) - 10) * sign(this.speed));
}
}
}
}
namespace pxsim {
// A re-implementation of Math.sign (since IE11 doesn't support it)
export function sign(num: number) {
return num ? num < 0 ? -1 : 1 : 0;
}
}

View File

@ -12,10 +12,24 @@ namespace pxsim {
data[i] = 0
},
read: buf => {
let v = "vSIM"
for (let i = 0; i < buf.data.length; ++i)
buf.data[i] = v.charCodeAt(i) || 0
console.log("pwm read");
// console.log("pwm read");
if (buf.data.length == 0) return 2;
const cmd = buf.data[0];
switch (cmd) {
case DAL.opOutputTest:
const port = buf.data[1];
let r = 0;
ev3board().getMotor(port)
.filter(motor => !motor.isReady())
.forEach(motor => r |= (1 << motor.port));
pxsim.BufferMethods.setNumber(buf, BufferMethods.NumberFormat.UInt8LE, 2, r);
break;
default:
let v = "vSIM"
for (let i = 0; i < buf.data.length; ++i)
buf.data[i] = v.charCodeAt(i) || 0
break;
}
return buf.data.length
},
write: buf => {
@ -70,7 +84,7 @@ namespace pxsim {
for (const motor of motors) {
const otherMotor = motors.filter(m => m.port != motor.port)[0];
motor.setSyncCmd(
motor.port < otherMotor.port ? otherMotor : undefined,
otherMotor,
cmd, [speed, turnRatio, stepsOrTime, brake]);
}
return 2;

View File

@ -1,26 +1,51 @@
/// <reference path="./moduleView.ts" />
/// <reference path="./motorView.ts" />
namespace pxsim.visuals {
export class LargeMotorView extends ModuleView implements LayoutElement {
private static ROTATING_ECLIPSE_ID = "hole";
export class LargeMotorView extends MotorView implements LayoutElement {
constructor(port: number) {
super(LARGE_MOTOR_SVG, "large-motor", NodeType.LargeMotor, port);
super(LARGE_MOTOR_SVG, "large-motor", NodeType.LargeMotor, port, "hole");
}
private syncedMotor: MotorNode;
private syncedLabelG: SVGGElement;
updateState() {
super.updateState();
const motorState = ev3board().getMotors()[this.port];
if (!motorState) return;
const speed = motorState.getSpeed();
if (!speed) return;
this.setMotorAngle(motorState.getAngle());
const syncedMotor = motorState.getSynchedMotor();
if ((syncedMotor || this.syncedMotor) && syncedMotor != this.syncedMotor) {
this.syncedMotor = syncedMotor;
if (this.syncedMotor) {
this.showSyncedLabel(motorState, syncedMotor);
} else if (this.syncedLabelG) {
this.syncedLabelG.parentNode.removeChild(this.syncedLabelG);
}
}
}
private setMotorAngle(angle: number) {
const holeEl = this.content.getElementById(this.normalizeId(LargeMotorView.ROTATING_ECLIPSE_ID))
private showSyncedLabel(motorNode: MotorNode, syncedMotor: MotorNode) {
const a = String.fromCharCode('A'.charCodeAt(0) + motorNode.port);
const b = String.fromCharCode('A'.charCodeAt(0) + syncedMotor.port);
this.syncedLabelG = pxsim.svg.child(this.element, 'g', {'transform': 'scale(0.5)'}) as SVGGElement;
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 15, 'ry': 15, 'x': 0, 'y': 0, 'width': 84, 'height': 34, 'fill': '#A8A9A8'});
pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 17, 'cy': 17, 'r': 15, 'fill': 'white'});
const leftLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(11, 22)', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'});
leftLabel.textContent = a;
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 12, 'width': 10, 'height': 3, 'fill': '#ffffff'});
pxsim.svg.child(this.syncedLabelG, 'rect', {'rx': 0, 'ry': 0, 'x': 37, 'y': 18, 'width': 10, 'height': 3, 'fill': '#ffffff'});
pxsim.svg.child(this.syncedLabelG, 'circle', {'cx': 67, 'cy': 17, 'r': 15, 'fill': 'white'});
const rightLabel = pxsim.svg.child(this.syncedLabelG, 'text', {'transform': 'translate(61, 22)', 'style': 'isolation: isolate;font-size: 16px;fill: #A8A9A8;font-family: ArialMT, Arial'});
rightLabel.textContent = b;
}
protected renderMotorAngle(holeEl: Element, angle: number) {
const width = 125.92;
const height = 37.9;
const transform = `rotate(${angle} ${width / 2} ${height / 2})`;

View File

@ -2,35 +2,17 @@
namespace pxsim.visuals {
export const MOTOR_ROTATION_FPS = 32;
export class MediumMotorView extends ModuleView implements LayoutElement {
private static ROTATING_ECLIPSE_ID = "medmotor_Hole";
private hasPreviousAngle: boolean;
private previousAngle: number;
export class MediumMotorView extends MotorView implements LayoutElement {
constructor(port: number) {
super(MEDIUM_MOTOR_SVG, "medium-motor", NodeType.MediumMotor, port);
super(MEDIUM_MOTOR_SVG, "medium-motor", NodeType.MediumMotor, port, "medmotor_Hole");
}
public getPaddingRatio() {
return 1 / 5;
}
updateState() {
super.updateState();
const motorState = ev3board().getMotors()[this.port];
if (!motorState) return;
const speed = motorState.getSpeed();
if (!speed) return;
this.setMotorAngle(motorState.getAngle());
}
private setMotorAngle(angle: number) {
const holeEl = this.content.getElementById(this.normalizeId(MediumMotorView.ROTATING_ECLIPSE_ID))
protected renderMotorAngle(holeEl: Element, angle: number) {
const width = 44.45;
const height = 44.45;
const transform = `translate(2 1.84) rotate(${angle} ${width / 2} ${height / 2})`;

View File

@ -0,0 +1,33 @@
/// <reference path="./moduleView.ts" />
namespace pxsim.visuals {
export abstract class MotorView extends ModuleView implements LayoutElement {
constructor(xml: string, prefix: string, id: NodeType, port: NodeType,
protected rotating_hole_id: string) {
super(xml, prefix, id, port);
}
updateState() {
super.updateState();
const motorState = ev3board().getMotors()[this.port];
if (!motorState) return;
const speed = motorState.getSpeed();
if (!speed) return;
this.setMotorAngle(motorState.getAngle());
}
private setMotorAngle(angle: number) {
const holeEl = this.content.getElementById(this.normalizeId(this.rotating_hole_id))
this.renderMotorAngle(holeEl, angle);
}
protected abstract renderMotorAngle(holeEl: Element, angle: number): void;
getWiringRatio() {
return 0.37;
}
}
}

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 22.0.1, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
id="svg41"
x="0px"
y="0px"
viewBox="0 0 23 23"
style="enable-background:new 0 0 23 23;"
xml:space="preserve"
inkscape:version="0.91 r13725"
sodipodi:docname="console.svg"><metadata
id="metadata12"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title>color</dc:title></cc:Work></rdf:RDF></metadata><defs
id="defs10" /><sodipodi:namedview
pagecolor="#ffff44"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1090"
inkscape:window-height="695"
id="namedview8"
showgrid="false"
inkscape:zoom="10.26087"
inkscape:cx="11.5"
inkscape:cy="11.5"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="0"
inkscape:current-layer="svg41" /><style
type="text/css"
id="style3">
.st0{fill:#FFFFFF;}
</style><title
id="title5">color</title><g
id="g3830"
transform="matrix(0.98283231,0,0,-1.0120366,8.9614614,10.754156)"><path
d="m 0,0 -7.762,-3.561 0,2.701 5.142,2.18 -5.142,2.16 0,2.721 L 0,2.62 0,0 Z"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
id="path3832"
inkscape:connector-curvature="0" /></g><path
d="m 20.692705,17.741823 -11.1512146,0 0,-1.743739 11.1512146,0 0,1.743739 z"
style="fill:#ffffff;fill-opacity:1;fill-rule:nonzero;stroke:none"
id="path3834"
inkscape:connector-curvature="0" /></svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@ -19,6 +19,7 @@ webfontsGenerator({
"./categories/sensors.svg",
"./categories/text.svg",
"./categories/variables.svg",
"./categories/console.svg",
"./categories/advancedcollapsed.svg",
"./categories/advancedexpanded.svg",
"./icons/cancel.svg",

View File

@ -8,6 +8,7 @@
]
},
"galleries": {
"Maker Activities": "maker"
"Maker Activities": "maker",
"Coding Activites": "coding"
}
}

View File

@ -3,5 +3,5 @@ tests.test("Touch sensor pressed", function () {
brick.print("and click enter", 0, 60)
brick.buttonEnter.pauseUntil(ButtonEvent.Click)
brick.clearScreen()
tests.assert("Pressed", sensors.touchSensor1.isPressed())
tests.assert("Pressed", sensors.touch1.isPressed())
})

View File

@ -53,7 +53,6 @@ div.blocklyTreeSeparator {
/* Blockly Text */
span.blocklyTreeLabel {
font-family: @pageFont !important;
text-transform: uppercase !important;
font-size:1rem !important;
font-weight: bold;
}
@ -118,34 +117,34 @@ span.blocklyTreeIcon.blocklyTreeIconaddpackage::before {
}
span.blocklyTreeIcon.blocklyTreeIconadvancedcollapsed::before {
content: "\f112";
content: "\f113";
}
span.blocklyTreeIcon.blocklyTreeIconadvancedexpanded::before {
content: "\f113";
content: "\f114";
}
.save-editortools-btn .icon.save:before {
font-family: 'legoIcons';
content: "\f117";
content: "\f118";
}
.download-button .icon.download.icon-and-text:before {
font-family: 'legoIcons';
content: "\f116";
content: "\f117";
}
.button.approve.positive i.icon.checkmark:before {
font-family: 'legoIcons';
content: "\f115";
content: "\f116";
}
.button.approve.cancel i.icon.cancel:before {
font-family: 'legoIcons';
content: "\f114";
content: "\f115";
}
.blocks-menuitem i.icon.blocks:before {
font-family: 'legoIcons' !important;
content: "\f118" !important;
content: "\f119" !important;
}

View File

@ -1,3 +1,79 @@
/*******************************
Site Overrides
*******************************/
.ui.loader:before {
border: none;
border-radius: 0px;
box-shadow: none;
background: transparent @loaderBackImage no-repeat center center;
background-size: 100%;
}
.ui.loader:after {
border: none;
box-shadow: none;
border-radius: 0px;
margin: 40px auto;
background: transparent @loaderImage no-repeat center center;
background-size: 100%;
-webkit-animation: @loaderAnimation @loaderSpeed infinite linear;
animation: @loaderAnimation @loaderSpeed infinite linear;
}
.ui.loader.avatar:after {
border: none;
box-shadow: none;
border-radius: 0px;
margin: 40px auto;
background: transparent @avatarImage no-repeat center center;
background-size: 100%;
-webkit-animation: @loaderAnimation @loaderSpeed infinite linear;
animation: @loaderAnimation @loaderSpeed infinite linear;
}
@-webkit-keyframes loader-pxt-ev3 {
0% {
-webkit-transform: translateX(@loaderStartPoint);
transform: translateX(@loaderStartPoint);
}
20% {
-webkit-transform: translateX(-@loaderMiddlePoint);
transform: translateX(-@loaderMiddlePoint);
}
50% {
-webkit-transform: translateX(-@loaderEndPoint);
transform: translateX(-@loaderEndPoint);
}
75% {
-webkit-transform: translateX(-@loaderMiddlePoint);
transform: translateX(-@loaderMiddlePoint);
}
100% {
-webkit-transform: translateX(@loaderStartPoint);
transform: translateX(@loaderStartPoint);
}
}
@keyframes loader-pxt-ev3 {
0% {
-webkit-transform: translateX(@loaderStartPoint);
transform: translateX(@loaderStartPoint);
}
20% {
-webkit-transform: translateX(-@loaderMiddlePoint);
transform: translateX(-@loaderMiddlePoint);
}
50% {
-webkit-transform: translateX(-@loaderEndPoint);
transform: translateX(-@loaderEndPoint);
}
75% {
-webkit-transform: translateX(-@loaderMiddlePoint);
transform: translateX(-@loaderMiddlePoint);
}
100% {
-webkit-transform: translateX(@loaderStartPoint);
transform: translateX(@loaderStartPoint);
}
}

View File

@ -1,3 +1,19 @@
/*******************************
User Variable Overrides
*******************************/
@loaderBackImageUrl: "../docs/static/loader_back.svg";
@loaderBackImage: data-uri(@loaderBackImageUrl);
@loaderImageUrl: "../docs/static/loader_front.svg";
@loaderImage: data-uri(@loaderImageUrl);
@loaderSpeed: 2s;
@loaderStartPoint: 0px;
@loaderMiddlePoint: 14px;
@loaderEndPoint: 28px;
@loaderAnimation: loader-pxt-ev3;
@large : 200px;

View File

@ -132,7 +132,7 @@
Full screen
--------------------*/
@fullscreenBackgroundGradientStart: @blue;
@fullscreenBackgroundGradientStart: #fff;
@fullscreenBackgroundGradientEnd: #fff;
/*-------------------
@ -170,6 +170,6 @@
--------------------*/
@flyoutLabelColor: white;
@blocklyFlyoutColor: #282828;
@blocklyFlyoutColorOpacity: 0.9;
@monacoFlyoutColor: rgba(40, 40, 40,0.9);
@blocklyFlyoutColor: #3B3C3D;
@blocklyFlyoutColorOpacity: 1.0;
@monacoFlyoutColor: rgba(59, 60, 61, 1.0);