Compare commits
141 Commits
Author | SHA1 | Date | |
---|---|---|---|
c4f5e425c2 | |||
361ae7a2d2 | |||
3769402ade | |||
5c3c83eb52 | |||
0f07a89981 | |||
11d887a213 | |||
8150b2dbb0 | |||
89f41f23da | |||
6b78e08053 | |||
186c86d2b1 | |||
181c71d2dd | |||
be05da3232 | |||
5958157a76 | |||
f72b825377 | |||
d76af5e5af | |||
23f48db20b | |||
2975bf2b55 | |||
5314515619 | |||
75b2db9f67 | |||
cf2e39f1b2 | |||
6d15d69aa1 | |||
72a0940235 | |||
b08dd8a7d2 | |||
def648a98b | |||
32a92789b3 | |||
9956bb06fb | |||
83b9aecd7a | |||
17ab24eaa9 | |||
9c5d5f9a86 | |||
43a13e0877 | |||
fe0915484d | |||
87a65aa38f | |||
1317da8904 | |||
62b2881e2a | |||
bf482a2ac9 | |||
243600ad8f | |||
349caa4aed | |||
56bbcde299 | |||
7e9cc791ec | |||
d5194b8d28 | |||
12b1eb349b | |||
68dc195ea4 | |||
0251b914f2 | |||
1fc818767c | |||
9aeaec477f | |||
7fc796d2cb | |||
cb1cd2a4b4 | |||
39bd7aa0eb | |||
140ba64462 | |||
42fe96aa5a | |||
1a5b42026d | |||
9fe649aa3c | |||
a97dfb17b2 | |||
277c9903bb | |||
0de8a84de2 | |||
a302bbfc2b | |||
bcb682b602 | |||
e4a7531541 | |||
348964c888 | |||
8b3461bebd | |||
e511630c2e | |||
db156d5df0 | |||
93c6975400 | |||
abc93dd7da | |||
85cfc86bf8 | |||
b66d4f2d64 | |||
5843deab11 | |||
8d5edc38bb | |||
0309e50058 | |||
aa40e7b169 | |||
75cf8da396 | |||
db9b6a995b | |||
fb255edafe | |||
f4c39f74e8 | |||
3e56e2c3e2 | |||
79b5f8cc88 | |||
312729142f | |||
5bd4aed0e1 | |||
cfaa4ae3ef | |||
faa839d59f | |||
630687bfce | |||
2b300a4094 | |||
5fb8c0de6e | |||
1f65cd59a8 | |||
fd75bb61d6 | |||
4d2f72575b | |||
1fe3d3e01a | |||
0c6e65d828 | |||
ae9c0603f2 | |||
06aeca228a | |||
31fd4799a5 | |||
7d8e6891ee | |||
462234b1c0 | |||
dad1bd0cd4 | |||
b71bfef418 | |||
2e0a34c99b | |||
4133828a10 | |||
f0c19bc976 | |||
a09b4a083f | |||
15dff9af08 | |||
6fa5c1b688 | |||
d76cea1477 | |||
ca09a0a833 | |||
fcc864823e | |||
166dc27b93 | |||
66e50473c4 | |||
58452e1ca3 | |||
2b7498ea2d | |||
5ab2b97663 | |||
ffe0f0fb32 | |||
f27d13f88e | |||
31067dcef8 | |||
123f6c84b2 | |||
c5f07ca67c | |||
22fc7dee18 | |||
1f58b649c5 | |||
fc75fe8e16 | |||
b399c37527 | |||
a054fdd3d3 | |||
a239589913 | |||
98a046237c | |||
eb385ec532 | |||
2fdce16685 | |||
74eb77a9ae | |||
4fba96588f | |||
03c07bdcf5 | |||
6da1bc3cb1 | |||
dfc9ca1db4 | |||
83b64c1e54 | |||
a0cf8655f2 | |||
e4cf2c99c0 | |||
076fb8487e | |||
c725561389 | |||
3dc781f4fd | |||
4456767f2d | |||
6dba240899 | |||
d7172a1f3a | |||
245ff9d5b2 | |||
bfb258ce61 | |||
63beb2cac7 | |||
73d3dce139 |
9
.travis.yml
Normal file
@ -0,0 +1,9 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "8.9.0"
|
||||
script:
|
||||
- "node node_modules/pxt-core/built/pxt.js travis"
|
||||
sudo: false
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
31
README.md
@ -1,13 +1,8 @@
|
||||
# LEGO® MINDSTORMS® Education EV3 for Microsoft MakeCode
|
||||
|
||||
[](https://ci2.dot.net/job/Private/job/pxt_project_rainbow/job/master/job/pxt-ev3_Push/)
|
||||
# LEGO® MINDSTORMS® Education EV3 for Microsoft MakeCode [](https://travis-ci.org/microsoft/pxt-ev3)
|
||||
|
||||
This repo contains the editor target hosted at https://makecode.mindstorms.com
|
||||
|
||||
LEGO Auth: https://src.education.lego.com/groups/ev3-makecode (use Google Authenticator)
|
||||
LEGO Chat: https://chat.internal.education.lego.com/make-code/channels/town-square
|
||||
|
||||
## Local Dev setup
|
||||
## Local setup
|
||||
|
||||
These instructions assume familiarity with dev tools and languages.
|
||||
|
||||
@ -15,10 +10,6 @@ These instructions assume familiarity with dev tools and languages.
|
||||
* install Docker; make sure `docker` command is in your `PATH`
|
||||
* (optional) install [Visual Studio Code](https://code.visualstudio.com/)
|
||||
|
||||
In a common folder,
|
||||
|
||||
* clone https://github.com/Microsoft/pxt to ``pxt`` folder
|
||||
* clone https://github.com/Microsoft/pxt-common-packages to ``pxt-common-packages`` folder
|
||||
* clone https://github.com/Microsoft/pxt-ev3 to ``pxt-ev3`` folder
|
||||
* go to ``pxt`` and run
|
||||
|
||||
@ -26,6 +17,18 @@ In a common folder,
|
||||
npm install
|
||||
```
|
||||
|
||||
* to run the local server,
|
||||
```
|
||||
pxt serve --cloud
|
||||
```
|
||||
|
||||
## Local Dev setup
|
||||
|
||||
In the common folder,
|
||||
|
||||
* clone https://github.com/Microsoft/pxt to ``pxt`` folder
|
||||
* clone https://github.com/Microsoft/pxt-common-packages to ``pxt-common-packages`` folder
|
||||
|
||||
* go to ``pxt-common-packages`` and run
|
||||
|
||||
```
|
||||
@ -57,12 +60,12 @@ cd libs/core
|
||||
pxt deploy
|
||||
```
|
||||
|
||||
### Jenkins build
|
||||
https://ci2.dot.net/job/Private/job/pxt_project_rainbow/job/master/
|
||||
|
||||
## License
|
||||
MIT
|
||||
|
||||
## Trademarks
|
||||
MICROSOFT, the Microsoft Logo, and MAKECODE are registered trademarks of Microsoft Corporation. They can only be used for the purposes described in and in accordance with Microsoft’s Trademark and Brand guidelines published at https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general.aspx. If the use is not covered in Microsoft’s published guidelines or you are not sure, please consult your legal counsel or the MakeCode team (makecode@microsoft.com).
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
* [Troubleshoot](/troubleshoot)
|
||||
* [EV3 Manager](https://ev3manager.education.lego.com/)
|
||||
* [Forum](https://forum.makecode.com)
|
||||
* [LEGO Support](https://www.lego.com/service/)
|
||||
* [FIRST LEGO League](/fll)
|
||||
|
||||
## Projects #projects
|
||||
|
||||
@ -18,11 +20,14 @@
|
||||
* [What Animal Am I?](/tutorials/what-animal-am-i)
|
||||
* [Music Brick](/tutorials/music-brick)
|
||||
* [Run Motors](/tutorials/run-motors)
|
||||
* [Tank ZigZag](/tutorials/tank-zigzag)
|
||||
* [Touch to Run](/tutorials/touch-to-run)
|
||||
* [Touch Sensor Values](/tutorials/touch-sensor-values)
|
||||
* [What Color?](/tutorials/what-color)
|
||||
* [Line Following](/tutorials/line-following)
|
||||
* [Red Light, Green Light](/tutorials/redlight-greenlight)
|
||||
* [Reflected Light Measure](/tutorials/reflected-light-measure)
|
||||
* [Reflected Light Calibration](/tutorials/reflected-light-calibration)
|
||||
* [Object Near?](/tutorials/object-near)
|
||||
* [Security Alert](/tutorials/security-alert)
|
||||
|
||||
@ -82,12 +87,12 @@
|
||||
* [reset](/reference/sensors/gyro/reset)
|
||||
* [Ultrasonic](/reference/sensors/ultrasonic)
|
||||
* [on event](/reference/sensors/ultrasonic/on-event)
|
||||
* [distance](reference/sensors/ultrasonic/distance)
|
||||
* [pause until](reference/sensors/ultrasonic/pause-until)
|
||||
* [distance](/reference/sensors/ultrasonic/distance)
|
||||
* [pause until](/reference/sensors/ultrasonic/pause-until)
|
||||
* [Infrared](/reference/sensors/infrared)
|
||||
* [on event](/reference/sensors/infrared/on-event)
|
||||
* [distance](reference/sensors/infrared/proximity)
|
||||
* [pause until](reference/sensors/infrared/pause-until)
|
||||
* [distance](/reference/sensors/infrared/proximity)
|
||||
* [pause until](/reference/sensors/infrared/pause-until)
|
||||
* [Infrared beacon](/reference/sensors/beacon)
|
||||
* [on event](/reference/sensors/beacon/on-event)
|
||||
* [pause until](/reference/sensors/beacon/pause-until)
|
||||
|
@ -70,3 +70,12 @@
|
||||
|  |
|
||||
| Download Button |
|
||||
|
||||
#### #explorer-images
|
||||
|
||||
| |
|
||||
|-|
|
||||
|  |
|
||||
| Explorer Button |
|
||||
| |
|
||||
|  |
|
||||
| Explorer File View |
|
||||
|
@ -12,7 +12,7 @@ Design cars that can park themselves safely without driver intervention.
|
||||
* What would it take to ensure that autonomous cars are safe?
|
||||
* What types of movements do autonomous cars need to perform?
|
||||
|
||||
## Construct
|
||||
## Construct
|
||||
|
||||
### Build
|
||||
|
||||
@ -20,6 +20,12 @@ Build a @boardname@ vehicle that can park itself safely without driver intervent
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||
### Check
|
||||
|
||||
Before you program, check:
|
||||
@ -28,7 +34,7 @@ Before you program, check:
|
||||
* Are the wheels correctly installed?
|
||||
* Are the wheels rotating freely?
|
||||
|
||||
### Program
|
||||
### Program
|
||||
|
||||
Write a program that will make the robot turn three times in various ways.
|
||||
|
||||
@ -109,7 +115,7 @@ Click Download and follow the instructions to get your code onto your EV3 Brick.
|
||||
|
||||
### Differentiation
|
||||
|
||||
Create a program that simulates displaying appropriate warning lights while parking.
|
||||
Create a program that simulates displaying appropriate warning lights while parking.
|
||||
|
||||
### ~hint
|
||||
|
||||
@ -164,8 +170,8 @@ Click Download and follow the instructions to get your code onto your EV3 Brick.
|
||||
|
||||
* Click on the JavaScript tab and experiment with changing the values in the code.
|
||||
* Add a custom image or sounds from the Brick or Music menus.
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
|
||||
Congratulations! What will you design next?
|
||||
|
@ -24,6 +24,12 @@ Build red and green “lights” for your robot to detect. You can use LEGO bric
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/color%20squares-0a88dfd98bb2e64b5b8151fc422bae36.pdf)
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above images doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||
### Check
|
||||
|
||||
Before you program, check:
|
||||
@ -51,7 +57,7 @@ Consider using these blocks in your solution:
|
||||
|
||||
```block
|
||||
loops.forever(function () {
|
||||
|
||||
|
||||
})
|
||||
motors.largeBC.steer(0, 50)
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Red)
|
||||
@ -77,9 +83,9 @@ loops.forever(function () {
|
||||
|
||||
### Download and test
|
||||
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
|
||||
Congratulations! Your robot can stop at a red light.
|
||||
Congratulations! Your robot can stop at a red light.
|
||||
|
||||
Now add to your program and have your robot to drive forward again when the light changes from red to green.
|
||||
|
||||
@ -102,7 +108,7 @@ loops.forever(function () {
|
||||
|
||||
### Download and test
|
||||
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
|
||||
## Contemplate
|
||||
|
||||
@ -116,7 +122,7 @@ Draw a dark line with tape or marker for your robot to cross.
|
||||
|
||||
Consider using these blocks in your solution:
|
||||
|
||||
```block
|
||||
```block
|
||||
motors.largeBC.steer(0, 50)
|
||||
music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
```
|
||||
@ -143,7 +149,7 @@ loops.forever(function () {
|
||||
|
||||
#### Download and test
|
||||
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
|
||||
#### Differentiation
|
||||
|
||||
@ -157,7 +163,7 @@ Consider using these blocks in your solution:
|
||||
|
||||
```block
|
||||
while (true) {
|
||||
|
||||
|
||||
}
|
||||
motors.largeBC.steer(0, 50)
|
||||
```
|
||||
@ -166,7 +172,7 @@ motors.largeBC.steer(0, 50)
|
||||
|
||||
```block
|
||||
if (true) {
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
@ -184,12 +190,10 @@ if (true) {
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
while (true) {
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Black)
|
||||
while (sensors.color3.color() == ColorSensorColor.Black) {
|
||||
motors.largeBC.steer(-30, 50)
|
||||
}
|
||||
while (true) {
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.White)
|
||||
while (sensors.color3.color() == ColorSensorColor.White) {
|
||||
motors.largeBC.steer(30, 50)
|
||||
}
|
||||
})
|
||||
@ -203,11 +207,9 @@ Else the Color Sensor detects the color white, start motors ``B`` and ``C`` (dri
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
if (true) {
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.Black)
|
||||
if (sensors.color3.color() == ColorSensorColor.Black) {
|
||||
motors.largeBC.steer(-30, 50)
|
||||
} else {
|
||||
sensors.color3.pauseUntilColorDetected(ColorSensorColor.White)
|
||||
motors.largeBC.steer(30, 50)
|
||||
}
|
||||
})
|
||||
@ -215,7 +217,7 @@ forever(function () {
|
||||
|
||||
### Download and test
|
||||
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick.
|
||||
|
||||
### Share
|
||||
|
||||
@ -232,8 +234,8 @@ Personalize:
|
||||
|
||||
* Click on the **JavaScript** tab and experiment with changing the values in the code.
|
||||
* Add a custom image or sounds from the ``||brick:Brick||`` or ``||music:Music||`` menus.
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
|
||||
Congratulations! What will you design next?
|
||||
|
@ -4,7 +4,7 @@ Design ways to avoid accidents between vehicles and objects in the road.
|
||||
|
||||

|
||||
|
||||
## Connect
|
||||
## Connect
|
||||
|
||||
Think about:
|
||||
|
||||
@ -12,7 +12,7 @@ Think about:
|
||||
* What do you need to be aware of to avoid collisions with obstacles?
|
||||
* What causes traffic jams in high density areas?
|
||||
|
||||
## Construct
|
||||
## Construct
|
||||
|
||||
### Build
|
||||
|
||||
@ -20,10 +20,16 @@ Build a @boardname@ vehicle that can avoid accidents between vehicles and object
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-ultrasonic-sensor-driving-base-61ffdfa461aee2470b8ddbeab16e2070.pdf)
|
||||
|
||||
Build an obstacle for your robot to detect. You can build the **cuboid model** out of LEGO bricks or an obstacle of your choice.
|
||||
Build an obstacle for your robot to detect. You can build the **cuboid model** out of LEGO bricks or an obstacle of your choice.
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-cuboid-dc93b2e60bed2981e76b3bac9ea04558.pdf)
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above images doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||
### Check
|
||||
|
||||
Before you program, check:
|
||||
@ -38,7 +44,7 @@ Before you program, check:
|
||||
* Program your robot to detect any obstacles that might appear while the robot is moving forward (or backward).
|
||||
* Make the robot stop when it detects an object that is less than 20 cm away.
|
||||
|
||||
Before you program, think about:
|
||||
Before you program, think about:
|
||||
* How will you program the robot to detect obstacles?
|
||||
* How will you program the robot to stop at obstacles?
|
||||
* Which programming blocks will you use?
|
||||
@ -59,7 +65,7 @@ motors.stopAll()
|
||||
|
||||
### ~
|
||||
|
||||
### Sample Solution
|
||||
### Sample Solution
|
||||
|
||||
1. Start the program when EV3 ``enter`` button is pressed.
|
||||
2. Turn motors ``B`` and ``C`` on at speed ``50``.
|
||||
@ -80,7 +86,7 @@ Click **Download** and follow the instructions to get your code onto your EV3 Br
|
||||
|
||||
## Contemplate
|
||||
|
||||
On the road, when a driver sees and object, they slow their car down before coming to a full stop.
|
||||
On the road, when a driver sees and object, they slow their car down before coming to a full stop.
|
||||
|
||||
Program your EV3 Driving Base to do the same.
|
||||
|
||||
@ -93,7 +99,7 @@ If the Ultrasonic Sensor:
|
||||
### ~hint
|
||||
|
||||
Consider using this block in your solution:
|
||||
|
||||
|
||||
```block
|
||||
if (true) {
|
||||
}
|
||||
@ -101,7 +107,7 @@ if (true) {
|
||||
|
||||
### ~
|
||||
|
||||
### Sample Solution
|
||||
### Sample Solution
|
||||
|
||||
```blocks
|
||||
loops.forever(function () {
|
||||
@ -118,7 +124,7 @@ loops.forever(function () {
|
||||
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick. Press the ``center`` button on the EV3 Brick to run the program.
|
||||
|
||||
## Continue
|
||||
## Continue
|
||||
|
||||
* Get together with other building teams and make a traffic jam by placing all of your robots in a line with varying amounts of space between them.
|
||||
* Have everyone start their robots at the same time and see what happens.
|
||||
@ -130,8 +136,8 @@ Click **Download** and follow the instructions to get your code onto your EV3 Br
|
||||
|
||||
* Share what you think “efficiency in programming” means.
|
||||
* Explore the different solutions other programmers came up with.
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
|
||||
Congratulations! What will you design next?
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Make A System That Communicates
|
||||
|
||||
## Connect
|
||||
## Connect
|
||||
|
||||
### Design Brief
|
||||
|
||||
@ -20,10 +20,10 @@ Think about:
|
||||
* What kind of motorized mechanism can be used to control the movements of a robot?
|
||||
* How can the robot sense where it is along the path?
|
||||
* How can the robot communicate its position?
|
||||
|
||||
|
||||

|
||||
|
||||
## Construct
|
||||
## Construct
|
||||
|
||||
### Build
|
||||
|
||||
@ -37,13 +37,19 @@ More building ideas:
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/color%20sensor_v2-e7fd54b6fa3cdfe36f414c1d2510f9cb.pdf)
|
||||
|
||||
### ~hint
|
||||
|
||||
Build a path for your robot to follow. You can use electrical tape on a floor, or marker on paper. You can use objects as milestones to indicate a path that can be detected by either the Touch Sensor, Color Sensor, or Ultrasonic Sensor.
|
||||
If clicking the above images doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### Program
|
||||
### ~
|
||||
|
||||
|
||||
Build a path for your robot to follow. You can use electrical tape on a floor, or marker on paper. You can use objects as milestones to indicate a path that can be detected by either the Touch Sensor, Color Sensor, or Ultrasonic Sensor.
|
||||
|
||||
### Program
|
||||
|
||||
Before you program, think about:
|
||||
|
||||
Before you program, think about:
|
||||
|
||||
* How will you program the robot to follow a path?
|
||||
* How will you program the robot to communicate its position?
|
||||
* Which programming blocks will you use?
|
||||
@ -54,7 +60,7 @@ Explore the different Motor and Sensor blocks in the programming menu.
|
||||
|
||||
### ~
|
||||
|
||||
### Sample Solution
|
||||
### Sample Solution
|
||||
|
||||
[](https://legoeducation.23video.com/v.ihtml/player.html?token=79c99735f906403a4dd7f2909935983d&source=embed&photo%5fid=19857954)
|
||||
|
||||
@ -70,15 +76,21 @@ Two copies of the tracks are built: one for the right side and a mirror image fo
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/ev3-dep/building%20instructions/track-rover-bi-6aadb1b053df0c58a0dea108b5ce0eea.pdf)
|
||||
|
||||
### Sample Program Solution
|
||||
### ~hint
|
||||
|
||||
This program works with the Track Rover. If you create a different robot, adjust the program to fit your solution.
|
||||
If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
Program summary:
|
||||
### ~
|
||||
|
||||
### Sample Program Solution
|
||||
|
||||
This program works with the Track Rover. If you create a different robot, adjust the program to fit your solution.
|
||||
|
||||
Program summary:
|
||||
|
||||
* If the Color Sensor sees black, Motor B runs at -50 power and Motor C turns off.
|
||||
* If the Color Sensor sees white, Motor B turns off and Motor C runs at -50 power.
|
||||
* If the Color Sensor sees green, all motors stop and the green sound plays.
|
||||
* If the Color Sensor sees green, all motors stop and the green sound plays.
|
||||
* The robot waits one second, then motors move forward.
|
||||
* If the Color Sensor sees red, all motors stop, and the red sound plays.
|
||||
* The robot waits one second, then motors move forward.
|
||||
@ -108,44 +120,44 @@ forever(function () {
|
||||
|
||||
Click Download and follow the instructions to get your code onto your EV3 Brick. Press the center button on the EV3 Brick to run the program.
|
||||
|
||||
## Contemplate
|
||||
## Contemplate
|
||||
|
||||
### Test and Analyze
|
||||
### Test and Analyze
|
||||
|
||||
As you work on your solution:
|
||||
|
||||
1. Describe one part of your design that worked especially well.
|
||||
2. Describe one design change that you had to make.
|
||||
3. What will you try next?
|
||||
1. Describe one part of your design that worked especially well.
|
||||
2. Describe one design change that you had to make.
|
||||
3. What will you try next?
|
||||
|
||||
|
||||
### Review and Revise
|
||||
### Review and Revise
|
||||
|
||||
Take a moment to reflect on your robot solution.
|
||||
Take a moment to reflect on your robot solution.
|
||||
|
||||
Think about:
|
||||
|
||||
* Can the robot’s movement be more accurate?
|
||||
* Can the robot’s movement be more accurate?
|
||||
* What are some ways that others have solved the problem?
|
||||
|
||||
Describe two ways you could improve your robot.
|
||||
|
||||
## Continue
|
||||
## Continue
|
||||
|
||||
### Personalize your project
|
||||
|
||||
* Add/remove LEGO elements to improve the way your robot moves.
|
||||
* Add/remove LEGO elements to improve the way your robot moves.
|
||||
* Click on the JavaScript tab and experiment with changing the values in the code.
|
||||
* Add a custom image or sounds by adding blocks from the Brick or Music menus.
|
||||
|
||||
## Communicate
|
||||
## Communicate
|
||||
|
||||
Here are some ideas:
|
||||
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance.
|
||||
* Explain some important features of your software program.
|
||||
* Produce a building guide for your model by taking a series of photographs as you deconstruct it.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance.
|
||||
* Explain some important features of your software program.
|
||||
* Produce a building guide for your model by taking a series of photographs as you deconstruct it.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
|
||||
Congratulations! What will you design next?
|
||||
|
@ -32,18 +32,24 @@ If you want some building help you can follow these instructions.
|
||||
|
||||
Click [here](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/toddle%20bot-3dcad146d7f5deac4753f93e9dcc0739.pdf)
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above image or link doesn't open the instructions, right-click on the link and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||
### Program
|
||||
|
||||
Before you program, think about:
|
||||
|
||||
* How will you program the robot to move?
|
||||
* How will you program the robot to move?
|
||||
* How will you program the robot to stop?
|
||||
* How will you program the robot to display the distance moved?
|
||||
|
||||
Which programming blocks will you use:
|
||||
|
||||
* To turn on and turn off the motor or motors?
|
||||
* To display the distance moved?
|
||||
* To turn on and turn off the motor or motors?
|
||||
* To display the distance moved?
|
||||
|
||||
### Sample Code
|
||||
|
||||
@ -51,7 +57,7 @@ Example code of a robot that moves without wheels using one motor:
|
||||
|
||||
* The robot moves with ``large motor D`` rotating at ``-100`` speed
|
||||
* The robot moves for ``30000`` milliseconds (30 seconds)
|
||||
* The robot stops
|
||||
* The robot stops
|
||||
* The robot displays the text ``"30cm"``
|
||||
|
||||
```blocks
|
||||
@ -67,7 +73,7 @@ brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick. Press the center button on the EV3 Brick to run the program.
|
||||
|
||||
## Contemplate
|
||||
## Contemplate
|
||||
|
||||
### Test and Analyze
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Make It Smarter and Faster
|
||||
# Make It Smarter and Faster
|
||||
|
||||
## Connect
|
||||
## Connect
|
||||
|
||||
### Design Brief
|
||||
|
||||
@ -10,52 +10,52 @@ https://www.youtube.com/watch?v=y9-A_C_08KY
|
||||
|
||||
* What do the robots in the video need to be able to sense, plan, and act?
|
||||
* What senses do humans have and why are they important to us?
|
||||
* How many human-like senses do you see the robots demonstrating?
|
||||
* How many human-like senses do you see the robots demonstrating?
|
||||
|
||||
### Brainstorm
|
||||
### Brainstorm
|
||||
|
||||
Discuss different solutions to the design brief.
|
||||
|
||||
Think about:
|
||||
Think about:
|
||||
|
||||
* What kind of creature can it be?
|
||||
* How can it move?
|
||||
* What does it need to be aware so that it stays safe, well fed and warm (or cool)?
|
||||
* Is it looking for food, a safe place to hide or a warm place to soak up the sun?
|
||||
* Will the creature need to move fast or slow?
|
||||
* Will it need to turn?
|
||||
* What kind of creature can it be?
|
||||
* How can it move?
|
||||
* What does it need to be aware so that it stays safe, well fed and warm (or cool)?
|
||||
* Is it looking for food, a safe place to hide or a warm place to soak up the sun?
|
||||
* Will the creature need to move fast or slow?
|
||||
* Will it need to turn?
|
||||
* Will it need to go backward?
|
||||
|
||||

|
||||
|
||||
## Construct
|
||||
|
||||
|
||||
### Build
|
||||
|
||||
Think about a creature’s movement for inspiration. Your mechanism can be attached or unattached to the EV3 Brick. You can start by tinkering with the LEGO elements in the picture add then build on.
|
||||
|
||||
More building ideas:
|
||||
More building ideas:
|
||||
|
||||
| | | | | |
|
||||
|-|-|-|-|-|
|
||||
|[][EV3 Frames] | |[][Color Sensor 1] | |[][Gyro Sensor] |
|
||||
| [EV3 Frames] | | [Color Sensor 1] | | [Gyro Sensor] |
|
||||
<br/>
|
||||
|
||||
| | | | | |
|
||||
|-|-|-|-|-|
|
||||
|[][Ultrasonic Sensor] | | [][Touch Sensor] | | [][Jaw] |
|
||||
| [Ultrasonic Sensor] | | [Touch Sensor] | | [Jaw] |
|
||||
<br/>
|
||||
* [EV3 Frames]
|
||||
* [Color Sensor 1]
|
||||
* [Gyro Sensor]
|
||||
* [Ultrasonic Sensor]
|
||||
* [Touch Sensor]
|
||||
* [Jaw]
|
||||
* [Leg 1]
|
||||
* [Leg 2]
|
||||
* [Leg 3]
|
||||
|
||||
| | | | | |
|
||||
|-|-|-|-|-|
|
||||
| [][Leg 1] | | [][Leg 2] | | [][Leg 3] |
|
||||
| [Leg 1] | | [Leg 2] | | [Leg 3] |
|
||||
### ~hint
|
||||
|
||||
### Program
|
||||
If clicking the above links doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
Before you program, think about:
|
||||
### ~
|
||||
|
||||
### Program
|
||||
|
||||
Before you program, think about:
|
||||
|
||||
* How will you program the robot to sense?
|
||||
* How will you program the robot to respond?
|
||||
@ -67,7 +67,7 @@ Before you program, think about:
|
||||
|
||||
### ~
|
||||
|
||||
### Sample Solution
|
||||
### Sample Solution
|
||||
|
||||
The Insect uses its Ultrasonic Sensor to sense danger and move away from a threat.
|
||||
|
||||
@ -86,18 +86,24 @@ Building Instructions:
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/files/support/mindstorms%20ev3/building-instructions/design%20engineering%20projects/insect-94b8a46f0dc5082c9d78ddb734626dc9.pdf)
|
||||
|
||||
### Sample Solution
|
||||
### ~hint
|
||||
|
||||
This program checks if the Ultrasonic Sensor senses something near.
|
||||
If clicking the above images or links doesn't open the instructions, right-click on the link and choose "Save link as..." to download the PDF.
|
||||
|
||||
The blocks inside the ``||loops:forever||`` loop have these actions:
|
||||
### ~
|
||||
|
||||
### Sample Solution
|
||||
|
||||
This program checks if the Ultrasonic Sensor senses something near.
|
||||
|
||||
The blocks inside the ``||loops:forever||`` loop have these actions:
|
||||
|
||||
1. Turn on the ``green`` EV3 Brick Status Light.
|
||||
2. Wait for Ultrasonic Sensor to detect an object.
|
||||
3. Turn on Motors ``A`` and ``D`` in opposite directions.
|
||||
4. Wait for one quarter of a second (``1500`` milli seconds).
|
||||
4. Wait for one and a half seconds (``1500`` milli seconds).
|
||||
5. Reverse the direction of Motors ``A`` and ``D``.
|
||||
6. Wait for one quarter of a second.
|
||||
6. Wait for one and a half seconds.
|
||||
7. Stop all motors.
|
||||
8. Make an insect chirping sound.
|
||||
9. Loop continuously so that the insect wanders around when the Ultrasonic Sensor is detects something.
|
||||
@ -119,44 +125,44 @@ forever(function () {
|
||||
|
||||
Click **Download** and follow the instructions to get your code onto your EV3 Brick. Press the center button on the EV3 Brick to run the program.
|
||||
|
||||
## Contemplate
|
||||
## Contemplate
|
||||
|
||||
### Test and Analyze
|
||||
### Test and Analyze
|
||||
|
||||
As you work on your solution:
|
||||
1. Describe one part of your design that worked especially well.
|
||||
2. Describe one design change that you had to make.
|
||||
3. What will you try next?
|
||||
As you work on your solution:
|
||||
1. Describe one part of your design that worked especially well.
|
||||
2. Describe one design change that you had to make.
|
||||
3. What will you try next?
|
||||
|
||||
### Review and Revise
|
||||
### Review and Revise
|
||||
|
||||
Take a moment to reflect on your robot solution.
|
||||
Take a moment to reflect on your robot solution.
|
||||
|
||||
Think about:
|
||||
Think about:
|
||||
|
||||
* Does your robot move when the sensor is activated?
|
||||
* If not, what will you change to make the robot’s ability to sense and respond more obvious?
|
||||
* What other behaviors can you add to the robot to make it more realistic?
|
||||
* Does your robot move when the sensor is activated?
|
||||
* If not, what will you change to make the robot’s ability to sense and respond more obvious?
|
||||
* What other behaviors can you add to the robot to make it more realistic?
|
||||
|
||||
Describe two ways you could improve your robot.
|
||||
|
||||
## Continue
|
||||
## Continue
|
||||
|
||||
Personalize your project:
|
||||
|
||||
* Add/remove LEGO elements to improve the way your robot moves.
|
||||
* Add/remove LEGO elements to improve the way your robot moves.
|
||||
* Click on the JavaScript tab and experiment with changing the values in the code.
|
||||
* Add a custom image or sounds by adding blocks from the Brick or Music menus.
|
||||
* Does your robot resemble a creature? Maybe add more craft materials to your project.
|
||||
|
||||
## Communicate
|
||||
## Communicate
|
||||
|
||||
Here are some ideas:
|
||||
Here are some ideas:
|
||||
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Produce a building guide for your model by taking a series of photographs as you deconstruct it.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
* Create a video of your project, especially your final presentation and your robot’s performance. Explain some important features of your software program.
|
||||
* Produce a building guide for your model by taking a series of photographs as you deconstruct it.
|
||||
* Include an image of your program with comments.
|
||||
* Add a team photograph!
|
||||
|
||||
Congratulations! What will you design next?
|
||||
|
||||
|
@ -212,6 +212,12 @@ Here are some fun programs for your @boardname@!
|
||||
"description": "Keep your brick entertained and happy",
|
||||
"url":"/examples/happy-unhappy",
|
||||
"cardType": "example"
|
||||
}, {
|
||||
{
|
||||
"name": "Turtle",
|
||||
"description": "Encode moves and run them on a driving base",
|
||||
"url":"/examples/turtle",
|
||||
"cardType": "example"
|
||||
}, {
|
||||
"name": "Distance Measurer",
|
||||
"description": "Use a motor to measure angle and distance",
|
||||
|
18
docs/extensions.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Extensions
|
||||
|
||||
## #gallery
|
||||
|
||||
## Using Extensions
|
||||
|
||||
In the web editor, click on ``Settings`` then ``Extensions`` to search and add extensions to the project.
|
||||
The Blocks and JavaScript definitions will be automatically loaded in the editor.
|
||||
|
||||
## Custom extensions
|
||||
|
||||
The [Build Your Own Extension](https://makecode.com/extensions/getting-started) manual is for advanced users who want to publish their own extension.
|
||||
|
||||
## ~ hint
|
||||
|
||||
**Extensions** were previously called **Packages** in MakeCode.
|
||||
|
||||
## ~
|
BIN
docs/file-manager.pdf
Normal file
110
docs/fll.md
Normal file
@ -0,0 +1,110 @@
|
||||
# MakeCode for _FIRST_ LEGO League
|
||||
|
||||

|
||||
|
||||
**For teams participating in City Shaper challenge**, you can use MakeCode for your challenge (see [City Shaper Challenge, page 7 bottom](https://firstinspiresst01.blob.core.windows.net/fll/2020/city-shaper-game-guide-pdf.pdf)!
|
||||
|
||||
We’ve compiled a list of resources and information that we hope will be helpful for you.
|
||||
|
||||
* **Got a question? Post it on the forums** at https://forum.makecode.com/
|
||||
|
||||
## FAQ
|
||||
|
||||
### I found a bug what do I do?
|
||||
|
||||
If you found a bug, please try if it hasn't been fixed yet! Go to https://makecode.mindstorms.com/beta and try if the bug is corrected. Otherwise, please tell us at https://forum.makecode.com/.
|
||||
|
||||
### How do I use MakeCode with my EV3?
|
||||
|
||||
* You will need to install the latest EV3 firmware on your brick. Instructions on how to do that are located here: https://makecode.mindstorms.com/troubleshoot.
|
||||
* You will need a computer with a USB port to connect to the EV3 in order to download your programs.
|
||||
* You will need internet access and a browser on your computer to get to https://makecode.mindstorms.com.
|
||||
* You can [install the app](/offline-app) to use the editor offline.
|
||||
|
||||
### I know LabView, how is MakeCode different?
|
||||
|
||||
We have compiled a guide for EV3 LabView users at https://makecode.mindstorms.com/labview.
|
||||
|
||||
### What’s the best way to get started with MakeCode?
|
||||
|
||||
Go to https://makecode.mindstorms.com. The home screen is filled with videos, tutorials and examples that might be relevant for your missions.
|
||||
|
||||
On the home page, scroll down to the **FLL / City Shaper / Crane Mission** section for specific lessons related to Mission 2.
|
||||
|
||||
### Can I load both LEGO MINDSTORMS EV3 Software and MakeCode programs onto my EV3?
|
||||
|
||||
Yes.
|
||||
|
||||
### Does it work without internet?
|
||||
|
||||
To make sure the editor works without internet, install the [offline app](/offline-app)!
|
||||
|
||||
### How do I figure out what a block does?
|
||||
|
||||
You can right-click on any block and select “Help” in the context menu to open the documentation page describing what that block does.
|
||||
|
||||

|
||||
|
||||
### How do I program in JavaScript?
|
||||
|
||||
Click the **JavaScript** button at the top of the page to get to the JavaScript editor. Students can drag and drop code snippets from the Toolbox on the left, or type directly in the editor. You can switch back and forth between **Blocks** and **JavaScript** as you program.
|
||||
|
||||

|
||||
|
||||
Also, watch the [Text-based Coding](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=3513a83b87fe536b2dc512237465fd1b&source=embed&photo%5fid=35719471) video for more about coding using the JavaScript editor.
|
||||
|
||||
### How do I use the Simulator?
|
||||
|
||||
The Simulator will show the physical representation of your code blocks. For example, based on this code snippet, the Simulator will show the touch sensor on Port 1, and a large motor on Port D.
|
||||
|
||||
```blocks
|
||||
sensors.touch1.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeD.run(50)
|
||||
})
|
||||
```
|
||||
|
||||

|
||||
|
||||
Note that the Simulator is also interactive, so you can simulate inputs with any of the sensors.
|
||||
|
||||
See the video [Block-based Coding and Simulation](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=629730c938e452f0fd7653fbc4708166&source=embed&photo%5fid=35719470) for more about using the simulator.
|
||||
|
||||
### How do I save my programs?
|
||||
|
||||
MakeCode will automatically save your recent projects in the browser. However, you can also save a copy of your project as a file on your computer:
|
||||
|
||||
* From the **Settings** menu, select **Save Project**
|
||||
* This will download your program from the browser as a _lego-myproject.uf2_ file
|
||||
|
||||

|
||||
|
||||
* You can import your saved projects by clicking the Import button on the Home Page
|
||||
|
||||

|
||||
|
||||
### How do I share my programs?
|
||||
|
||||
You can share your projects by clicking on the **share** button in the top left of the screen. This will create a URL which you can send others to open and view your project.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
Sharing programs is also shown in the [Tips and Tricks](https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=5c594c2373367f7870196f519f3bfc7a&source=embed&photo%5fid=35719472) video.
|
||||
|
||||
### Why can't I delete my program (*.uf2) files from the Brick?
|
||||
|
||||
There's a bug in the firmware which prevents you from deleting the programs (``*.uf2`` files) from your EV3 Brick. There isn't a firmware update to fix this yet.
|
||||
|
||||
We have prepared a special program that lets you delete UF2 files from the brick.
|
||||
Download [these PDF instructions](/file-manager.pdf) and drop the PDF on the brick drive.
|
||||
This will present you with an menu for deleting files.
|
||||
|
||||
For other common questions, try the FAQ page https://makecode.mindstorms.com/faq.
|
||||
|
||||
## Workarounds
|
||||
|
||||
1. Deleting Programs from the EV3 brick
|
||||
|
||||
>* Description: Unable to delete program files from the EV3 brick after downloading them
|
||||
>* Status: LEGO Education team is working on a fix, no estimated date yet
|
@ -7,7 +7,7 @@
|
||||
{
|
||||
"name": "Prepare",
|
||||
"imageUrl": "/static/lessons/firmware.png",
|
||||
"description": "To use Microsoft MakeCode with your EV3 Brick, you will need to install the latest LEGO® MINDSTORMS® Education EV3 firmware. Follow these steps to make sure you're up to date and install the latest firmware if you need to.",
|
||||
"description": "To use Microsoft MakeCode with your EV3 Brick, you will need to install the latest LEGO® MINDSTORMS® Education EV3 firmware.",
|
||||
"label": "New? Start Here!",
|
||||
"labelClass": "red ribbon large",
|
||||
"url": "https://makecode.mindstorms.com/troubleshoot"
|
||||
@ -25,6 +25,12 @@
|
||||
"description": "Build a robot and drive into the world of robotics!",
|
||||
"url": "/getting-started/use",
|
||||
"cardType": "side"
|
||||
},
|
||||
{
|
||||
"name": "First LEGO League",
|
||||
"imageUrl": "/static/fll/fll-big.png",
|
||||
"description": "Information about using MakeCode in FLL competitions",
|
||||
"url": "/fll"
|
||||
}
|
||||
]
|
||||
```
|
@ -20,6 +20,12 @@ Build the robot driving base:
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||
## Make It Move
|
||||
|
||||
**Code it:** Create a program that makes the Driving Base move forward and stop at the finish line, which is ``1`` meter away.
|
||||
@ -68,6 +74,12 @@ Build and attach an Ultrasonic Sensor to your driving base:
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-ultrasonic-sensor-driving-base-61ffdfa461aee2470b8ddbeab16e2070.pdf)
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||
## Detect an Object
|
||||
|
||||
**Code it:** Create a program that moves the Driving Base and makes it stop ``6`` cm from the Cuboid.
|
||||
|
@ -1,3 +1,3 @@
|
||||
{
|
||||
"appref": "v0.4.2"
|
||||
"appref": "v1.1.20"
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
## Objective
|
||||
|
||||
Design ways to improve driving safety by helping to prevent drivers from falling asleep and causing an accident.
|
||||
|
||||
|
||||

|
||||
|
||||
## Connect
|
||||
@ -20,6 +20,12 @@ Think about what you have learned, then document it. Describe the problem in you
|
||||
|
||||
Start by constructing this model. Read the building instructions [here](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-color-sensor-down-driving-base-d30ed30610c3d6647d56e17bc64cf6e2.pdf) first.
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
## Program
|
||||
@ -44,13 +50,13 @@ Create a program that drives the robot forward until the Color Sensor sees red.
|
||||
|
||||
Place a ``||motors:steer large B+C||`` block from ``||motors:Motors||`` under ``||loops:on start||``. Change the speed to 20%.
|
||||
|
||||
```blocks
|
||||
```blocks
|
||||
motors.largeBC.steer(0, 20)
|
||||
```
|
||||
|
||||
### Step 2
|
||||
|
||||
Place a ``||loops:while||`` loop block under ``||motors:steer large B+C||``.
|
||||
Place a ``||loops:while||`` loop block under ``||motors:steer large B+C||``.
|
||||
|
||||
```blocks
|
||||
motors.largeBC.steer(0, 20)
|
||||
@ -61,7 +67,7 @@ while (true) {
|
||||
### Step 3
|
||||
|
||||
Place a ``||sensors:pause until color detected||`` from ``||sensors:Sensors||`` inside the ``||loops:while||`` loop block. Change the color to red.
|
||||
|
||||
|
||||
```blocks
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
@ -99,7 +105,7 @@ Place a ``||loops:while||`` loop block under ``||loops:on start||``.
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
@ -121,7 +127,7 @@ Place a ``||loops:while||`` loop block under the ``||motors:steer large B+C||``
|
||||
while (true) {
|
||||
motors.largeBC.steer(0, 20)
|
||||
while (true) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -141,7 +147,7 @@ while (true) {
|
||||
|
||||
### Step 6
|
||||
|
||||
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause until color detected||`` block.
|
||||
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause until color detected||`` block.
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
@ -165,7 +171,7 @@ while (true) {
|
||||
motors.stopAll()
|
||||
}
|
||||
while (true) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
```
|
||||
@ -177,7 +183,7 @@ Place a ``||sensors:pause unril color detected||`` block inside the new ``||loop
|
||||
What do you think the program will do?
|
||||
|
||||
**Hint:** The motors will run until the Color Sensor detects the color red, then it will stop all motors. The motors will also run and not stop when the color sensor detects the color green.
|
||||
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
motors.largeBC.steer(0, 20)
|
||||
@ -212,7 +218,7 @@ sensors.color3.pauseUntilColorDetected(ColorSensorColor.Yellow)
|
||||
music.playSoundEffect(sounds.systemGeneralAlert)
|
||||
}
|
||||
while (true) {
|
||||
while (true) {
|
||||
while (true) {
|
||||
sensors.color3.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Bright)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
@ -235,7 +241,7 @@ You will need to constantly debug your program in order to make your robot trave
|
||||
|
||||
```blocks
|
||||
while (true) {
|
||||
while (true) {
|
||||
while (true) {
|
||||
sensors.color3.pauseUntilLightDetected(LightIntensityMode.Reflected, Light.Bright)
|
||||
motors.largeB.run(10)
|
||||
motors.largeC.run(-10)
|
||||
@ -252,10 +258,10 @@ while (true) {
|
||||
|
||||
Consider the following questions:
|
||||
|
||||
1. What challenged you?
|
||||
2. Where there any surprises?
|
||||
1. What challenged you?
|
||||
2. Where there any surprises?
|
||||
3. How could you improve your program?
|
||||
4. Could your program have been more streamlined?
|
||||
4. Could your program have been more streamlined?
|
||||
5. Have you used too many blocks?
|
||||
6. Is there a more efficient way of building your program?
|
||||
7. How could your program be used in real-world scenarios?
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Make It Move Without Wheels
|
||||
# Make It Move Without Wheels
|
||||
|
||||
## Objective @unplugged
|
||||
|
||||
@ -24,7 +24,13 @@ The Walker Bot combines an EV3 Frame and two legs that are mirror-images to crea
|
||||
The legs in the Walker Bot are designed to show how to change the rotary motion of a motor to reciprocating motion.
|
||||
|
||||
Start by reading [these](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/ev3-dep/building%20instructions/walker-bot-bi-180fc24f9298e1dd6201099627d43903.pdf) instructions first.
|
||||
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
# Make It Move Without Wheels
|
||||
# Make It Move Without Wheels
|
||||
|
||||
## Objective
|
||||
|
||||
@ -23,7 +23,13 @@ The Walker Bot combines an EV3 Frame and two legs that are mirror-images to crea
|
||||
The legs in the Walker Bot are designed to show how to change the rotary motion of a motor to reciprocating motion.
|
||||
|
||||
Start by reading [these](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/ev3-dep/building%20instructions/walker-bot-bi-180fc24f9298e1dd6201099627d43903.pdf) instructions first.
|
||||
|
||||
|
||||
### ~hint
|
||||
|
||||
If clicking the above image doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
### ~
|
||||
|
||||

|
||||
|
||||
|
||||
|
@ -42,14 +42,12 @@ This activity uses sensor inputs. You may want to try the [Use](/getting-started
|
||||
|
||||
Follow the steps of the _Maker Design Process_ for this lesson:
|
||||
|
||||
| | |
|
||||
|-|-|
|
||||
|  | **Define the Problem** |
|
||||
|  | **Brainstorming** |
|
||||
|  | **Define the Design Criteria** |
|
||||
|  | **Go Make** |
|
||||
|  | **Review and Revise Your Solution** |
|
||||
|  | **Communicate Your Solution** |
|
||||
* Define the Problem
|
||||
* Brainstorming
|
||||
* Define the Design Criteria
|
||||
* Go Make
|
||||
* Review and Revise Your Solution
|
||||
* Communicate Your Solution
|
||||
|
||||
### Defining the Problem
|
||||
|
||||
|
@ -41,14 +41,12 @@ This activity uses motor rotations and sensor inputs. You may want to try the [U
|
||||
|
||||
Follow the steps of the _Maker Design Process_ for this lesson:
|
||||
|
||||
| | |
|
||||
|-|-|
|
||||
|  | **Define the Problem** |
|
||||
|  | **Brainstorming** |
|
||||
|  | **Define the Design Criteria** |
|
||||
|  | **Go Make** |
|
||||
|  | **Review and Revise Your Solution** |
|
||||
|  | **Communicate Your Solution** |
|
||||
* Define the Problem
|
||||
* Brainstorming
|
||||
* Define the Design Criteria
|
||||
* Go Make
|
||||
* Review and Revise Your Solution
|
||||
* Communicate Your Solution
|
||||
|
||||
### Defining the Problem
|
||||
|
||||
|
@ -388,12 +388,12 @@
|
||||
}
|
||||
function downloadWin64() {
|
||||
// TODO: Keep this link up-to-date with the desired release version
|
||||
window.open("https://makecode.com/api/release/ev3/v0.4.2/win64");
|
||||
window.open("https://makecode.com/api/release/ev3/v1.1.20/win64");
|
||||
tickEvent("offlineapp.download", { "target": "ev3", "platform": "win64" });
|
||||
}
|
||||
function downloadMac64() {
|
||||
// TODO: Keep this link up-to-date with the desired release version
|
||||
window.open("https://makecode.com/api/release/ev3/v0.4.2/mac64");
|
||||
window.open("https://makecode.com/api/release/ev3/v1.1.20/mac64");
|
||||
tickEvent("offlineapp.download", { "target": "ev3", "platform": "mac64" });
|
||||
}
|
||||
</script>
|
||||
@ -461,25 +461,19 @@
|
||||
<p class="c2">
|
||||
<span class="c5 c1">3.</span>
|
||||
<span class="c1"> </span>
|
||||
<span class="c5 c1">Associated Online Services.</span>
|
||||
<span class="c1"> Some features of the software may provide access
|
||||
to, or rely on, Azure online services, including an associated Azure online service to the software
|
||||
currently in development (the “corresponding service”). The use of those services
|
||||
(but not the software) is governed by the separate terms and privacy policies in the agreement
|
||||
under which you obtained the Azure services at</span>
|
||||
<span class="c1">
|
||||
<a class="c9" href="https://www.google.com/url?q=https://go.microsoft.com/fwLink/p/?LinkID%3D233178&sa=D&ust=1529596153826000"> </a>
|
||||
<span class="c5 c1">ASSOCIATED ONLINE SERVICES.</span>
|
||||
<span class="c1"> Some features of the software provide access
|
||||
to, or rely on, online services to provide you information about updates to the software or extensions,
|
||||
or to enable you to retrieve content, collaborate with others, or otherwise supplement your development
|
||||
experience. As used throughout these license terms, the term <q>software</q> includes these online
|
||||
services and features. By using these online services and features you consent to the to the
|
||||
transmission of information as described in Section 5, DATA.
|
||||
</span>
|
||||
<span class="c1 c18">
|
||||
<a class="c9" href="https://www.google.com/url?q=https://go.microsoft.com/fwLink/p/?LinkID%3D233178&sa=D&ust=1529596153826000">https://go.microsoft.com/fwLink/p/?LinkID=233178</a>
|
||||
</span>
|
||||
<span class="c3 c1"> (and, with respect to the corresponding service, the additional terms below). Please read them.
|
||||
The services may not be available in all regions.</span>
|
||||
</p>
|
||||
<p class="c2">
|
||||
<span class="c5 c1">4.</span>
|
||||
<span class="c1"> </span>
|
||||
<span class="c5 c1">Licenses for other components.</span>
|
||||
<span class="c5 c1">LICENSES FOR OTHER COMPONENTS.</span>
|
||||
<span class="c3 c1"> The software may include third party components with separate legal notices or governed by
|
||||
other agreements, as described in the ThirdPartyNotices file accompanying the software. Even
|
||||
if such components are governed by other agreements, the disclaimers and the limitations on and
|
||||
@ -500,7 +494,7 @@
|
||||
In using the software, you must comply with applicable law. You can learn more about data collection
|
||||
and use in the help documentation and the privacy statement at </span>
|
||||
<span class="c14 c1">
|
||||
<a class="c9" href="https://www.google.com/url?q=http://go.microsoft.com/fwlink/?LinkId%3D398505&sa=D&ust=1529596153827000">http://go.microsoft.com/fwlink/?LinkId=398505</a>
|
||||
<a class="c9" href="http://go.microsoft.com/fwlink/?LinkId=398505">http://go.microsoft.com/fwlink/?LinkId=398505</a>
|
||||
</span>
|
||||
<span class="c1">.</span>
|
||||
<span class="c3 c1"> Your use of the software operates as your consent to these practices.</span>
|
||||
@ -513,7 +507,7 @@
|
||||
Microsoft makes the commitments in the European Union General Data Protection Regulation Terms
|
||||
of the Online Services Terms to all customers effective May 25, 2018, at </span>
|
||||
<span class="c1 c14">
|
||||
<a class="c9" href="https://www.google.com/url?q=http://go.microsoft.com/?linkid%3D9840733&sa=D&ust=1529596153828000">http://go.microsoft.com/?linkid=9840733</a>
|
||||
<a class="c9" href="http://go.microsoft.com/?linkid=9840733">http://go.microsoft.com/?linkid=9840733</a>
|
||||
</span>
|
||||
<span class="c3 c1">.</span>
|
||||
</p>
|
||||
@ -794,4 +788,4 @@
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
5
docs/offline.md
Normal file
@ -0,0 +1,5 @@
|
||||
# @extends
|
||||
|
||||
## Offline app #target-app
|
||||
|
||||
The MakeCode editor is available as app which you can install on a computer with Windows or Mac OS. Once installed, the **[MakeCode Offline App](/offline-app)** lets you create, run, and download your projects to the @boardname@. It works the same as the Web application does in your browser but it's a stand-alone application that will work when a connection to the internet is restricted or not available.
|
3
docs/packages-ref.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"redirect": "/extensions"
|
||||
}
|
3
docs/packages/approval-ref.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"redirect": "https://makecode.com/extensions/approval"
|
||||
}
|
3
docs/packages/build-your-own-ref.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"redirect": "https://makecode.com/extensions/getting-started"
|
||||
}
|
3
docs/packages/versioning-ref.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"redirect": "https://makecode.com/extensions/versioning"
|
||||
}
|
47
docs/reference/brick/battery-property.md
Normal file
@ -0,0 +1,47 @@
|
||||
# battery Property
|
||||
|
||||
Return the information about the battery
|
||||
|
||||
```sig
|
||||
brick.batteryInfo(BatteryProperty.Level)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
* property: the kind of information
|
||||
|
||||
## Returns
|
||||
|
||||
* a [number](/types/number) which represents the value of the property requested.
|
||||
|
||||
## Example
|
||||
|
||||
Show the battery level percentage on the screen. Also, show a green light if the battery level is above 15%. If the battery level is below 15% but above 5%, show a orange light. But, if the battery level is below 5%, show a pulsing red light.
|
||||
|
||||
```blocks
|
||||
let battery = 0;
|
||||
forever(function() {
|
||||
brick.showString("Battery level:", 1)
|
||||
brick.showNumber(battery, 2)
|
||||
battery = brick.batteryInfo(BatteryProperty.Level);
|
||||
if (battery > 15)
|
||||
{
|
||||
brick.setStatusLight(StatusLight.Green);
|
||||
} else if (battery > 5) {
|
||||
brick.setStatusLight(StatusLight.Orange);
|
||||
} else {
|
||||
brick.setStatusLight(StatusLight.RedPulse)
|
||||
}
|
||||
pause(30000)
|
||||
})
|
||||
```
|
||||
|
||||
Or see all the values
|
||||
|
||||
```blocks
|
||||
forever(function () {
|
||||
brick.showValue("bat V", brick.batteryInfo(BatteryProperty.Voltage), 1)
|
||||
brick.showValue("bat %", brick.batteryInfo(BatteryProperty.Level), 2)
|
||||
brick.showValue("bat I", brick.batteryInfo(BatteryProperty.Current), 3)
|
||||
})
|
||||
```
|
59
docs/reference/motors/motor/ramp.md
Normal file
@ -0,0 +1,59 @@
|
||||
# Ramp
|
||||
|
||||
Schedules an acceleration, constant and deceleration phase at a given speed.
|
||||
|
||||
```sig
|
||||
motors.largeA.ramp(50, 100, 500, 100)
|
||||
```
|
||||
|
||||
The speed setting is a percentage 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.
|
||||
|
||||
|
||||
## Parameters
|
||||
|
||||
* **speed**: a [number](/types/number) that is the percentage of full speed. A negative value runs the motor in the reverse direction.
|
||||
* **acceleration**: the [number](/types/number) of movement units to rotate for while accelerating.
|
||||
* **value**: the [number](/types/number) of movement units to rotate for.
|
||||
* **deceleration**: the [number](/types/number) of movement units to rotate for while decelerating.
|
||||
* **unit**: the movement unit of rotation. This can be `milliseconds`, `seconds`, `degrees`, or `rotations`. If the number for **value** is `0`, this parameter isn't used.
|
||||
|
||||
## Example
|
||||
|
||||
This is an interactive program that lets you change the values of
|
||||
the acceleration and deceleration and see the effects.
|
||||
|
||||
```blocks
|
||||
let steady = 0
|
||||
let dec = 0
|
||||
let acc = 0
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
acc += -100
|
||||
})
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeB.ramp(50, steady, MoveUnit.MilliSeconds, acc, dec)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
acc += 100
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
dec += 100
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
dec += -100
|
||||
})
|
||||
acc = 500
|
||||
steady = 1000
|
||||
acc = 500
|
||||
forever(function () {
|
||||
brick.showValue("acc", acc, 1)
|
||||
brick.showValue("steady", steady, 2)
|
||||
brick.showValue("dec", dec, 3)
|
||||
brick.showString("acc: left/right", 5)
|
||||
brick.showString("dec: up/down", 6)
|
||||
brick.showString("run large B: enter", 7)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[tank](/reference/motors/synced/tank), [steer](/reference/motors/synced/steer), [stop](/reference/motors/motor/stop)
|
@ -6,9 +6,9 @@ Set the rotation speed of the motor as a percentage of maximum speed.
|
||||
motors.largeA.run(50)
|
||||
```
|
||||
|
||||
The speed setting is a pecentage of the motor's full speed. Full speed is the speed that the motor runs when the brick supplies maximum output voltage to the port.
|
||||
The speed setting is a percentage 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.
|
||||
|
||||
If you use just the **speed** number, the motor runs continously and won't stop unless you tell it to. You can also give a value for a certain amount of distance you want the motor to rotate for. The **value** can be an amount of time, a turn angle in degrees, or a number of full rotations.
|
||||
If you use just the **speed** number, the motor runs continuously and won't stop unless you tell it to. You can also give a value for a certain amount of distance you want the motor 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**.
|
||||
|
||||
@ -30,8 +30,8 @@ Here is how you use each different movement unit to run the motor for a fixed ro
|
||||
// Run motor for 700 Milliseconds.
|
||||
motors.largeA.run(25, 700, MoveUnit.MilliSeconds);
|
||||
|
||||
// Run motor for 700 Milliseconds again but no units specified.
|
||||
motors.largeA.run(25, 700);
|
||||
// Run motors B and C for 700 Milliseconds again but no units specified.
|
||||
motors.largeBC.run(25, 700);
|
||||
|
||||
// Run the motor for 45 seconds
|
||||
motors.largeA.run(50, 45, MoveUnit.Seconds);
|
||||
@ -61,6 +61,14 @@ motors.largeB.run(-25)
|
||||
|
||||
## ~
|
||||
|
||||
## Multiple motors
|
||||
|
||||
When using **run** with multiple motors, there is no guarantee that their speed will stay in sync. Use [tank](/reference/motors/tank) or [steer](/reference/motors/steer) for synchronized motor operations.
|
||||
|
||||
```blocks
|
||||
motors.largeBC.run(50)
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Drive the motor for 20 seconds
|
||||
|
30
docs/reference/motors/motor/set-brake-settle-time.md
Normal file
@ -0,0 +1,30 @@
|
||||
# set Brake Settle Time
|
||||
|
||||
Set the time to wait after a motor stopped to allow it settle
|
||||
when brake is enabled. Default is 10ms.
|
||||
|
||||
```sig
|
||||
motors.largeA.setBrakeSettleTime(200)
|
||||
```
|
||||
|
||||
When a the motor is stopped and brake is applied, it can still wiggle for a little while. You can use the settle time to automatically way after stopping and let the robot settle.
|
||||
|
||||
## Parameters
|
||||
|
||||
* **time**: a [number](/types/number) value which represents the number of milliseconds to wait after braking.
|
||||
|
||||
## Example
|
||||
|
||||
Set the brake mode and the settle time to 500ms. Run the motor connected to port **A** for 2 seconds at a speed of `30` and stop after 2s.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setBrake(true)
|
||||
motors.largeA.setBrakeSettleTime(500)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[stop](/reference/motors/motor/stop)
|
@ -1,28 +1,28 @@
|
||||
# set Brake
|
||||
|
||||
Set the brake on the motor so it won't turn when it has no power.
|
||||
Set the brake on the motor so it will brake when it finishes a brake command.
|
||||
|
||||
```sig
|
||||
motors.largeA.setBrake(false)
|
||||
```
|
||||
|
||||
When a the motor is stopped, it can still rotate if an external force is applied to it. This can happen, for example, if your're tanking your brick on a inclined surface and stop the motors. Gravity will push down on the brick and might cause it to start rolling again. You can prevent this movement by setting the brake.
|
||||
When a the motor is stopped, it can still rotate if an external force is applied to it. This can happen, for example, if you're tanking your brick on a inclined surface and stop the motors. Gravity will push down on the brick and might cause it to start rolling again. You can prevent this movement by setting the brake.
|
||||
|
||||
Also, you can use the brake to do simple skid steering for your brick.
|
||||
|
||||
## Paramters
|
||||
## Parameters
|
||||
|
||||
* **brake**: a [boolean](/types/boolean) value which is either `true` to set the brake on or `false` to set the brake off.
|
||||
|
||||
## Example
|
||||
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30`. Stop and set the brake.
|
||||
Run the motor connected to port **A** for 2 seconds at a speed of `30` and stop after 2s.
|
||||
|
||||
```blocks
|
||||
motors.largeA.setBrake(true)
|
||||
motors.largeA.run(30)
|
||||
pause(2000)
|
||||
motors.largeA.stop()
|
||||
motors.largeA.setBrake(true)
|
||||
```
|
||||
|
||||
## See also
|
||||
|
26
docs/reference/motors/motor/set-run-phase.md
Normal file
@ -0,0 +1,26 @@
|
||||
# Set Run Phase
|
||||
|
||||
Allows to specify an acceleration or deceleration phases for run commands.
|
||||
|
||||
```sig
|
||||
motors.largeD.setRunPhase(MovePhase.Acceleration, 1, MoveUnit.Seconds)
|
||||
```
|
||||
|
||||
Once the run phase is specified on a motor (or pair of motors),
|
||||
it will be automatically applied to [run](/reference/motors/run) commands.
|
||||
|
||||
## Time vs Rotation
|
||||
|
||||
The phases specified for time units (seconds, milliseconds) only apply to run with time
|
||||
moves. Similarly, the phases specified for rotation units (# rotation, degrees) only
|
||||
apply to run with rotation units.
|
||||
|
||||
## Examples
|
||||
|
||||
```blocks
|
||||
motors.largeB.setRunPhase(MovePhase.Acceleration, 0.5, MoveUnit.Seconds)
|
||||
motors.largeB.setRunPhase(MovePhase.Deceleration, 0.2, MoveUnit.Seconds)
|
||||
forever(function () {
|
||||
motors.largeB.run(50, 1, MoveUnit.Seconds)
|
||||
})
|
||||
```
|
@ -39,6 +39,13 @@ motors.largeBC.steer(-15, -75)
|
||||
|
||||
## ~
|
||||
|
||||
## ~ hint
|
||||
|
||||
Only one set of synchronized motors will run at the same time. Once you launch tank/steer, it will cancel any existing synchronized speed command.
|
||||
|
||||
## ~
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
### Make a slight right
|
||||
@ -79,6 +86,51 @@ for (let i = 0; i < 4; i++) {
|
||||
motors.stopAll()
|
||||
```
|
||||
|
||||
### Steer tester
|
||||
|
||||
This program lets you change the values of speed and turn ratio with the buttons.
|
||||
|
||||
```typescript
|
||||
let speed = 0;
|
||||
let turnRatio = 0;
|
||||
|
||||
brick.showString(`steer tester`, 1)
|
||||
brick.showString(`connect motors BC`, 7)
|
||||
brick.showString(`up/down for speed`, 8)
|
||||
brick.showString(`left/right for turn ratio`, 9)
|
||||
|
||||
forever(function () {
|
||||
brick.showString(`motor B speed ${motors.largeB.speed()}%`, 4)
|
||||
brick.showString(`motor C speed ${motors.largeC.speed()}%`, 5)
|
||||
pause(100)
|
||||
})
|
||||
|
||||
function updateSteer() {
|
||||
motors.largeBC.steer(turnRatio, speed);
|
||||
brick.showString(`speed ${speed}%`, 2)
|
||||
brick.showString(`turnRatio ${turnRatio}`, 3)
|
||||
}
|
||||
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
speed += 10
|
||||
updateSteer()
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
speed -= 10
|
||||
updateSteer()
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
turnRatio -= 10
|
||||
updateSteer()
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
turnRatio += 10
|
||||
updateSteer()
|
||||
})
|
||||
|
||||
updateSteer()
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[tank](/reference/motors/synced/tank), [run](/reference/motors/motor/run)
|
@ -35,6 +35,12 @@ motors.largeBC.tank(-75, -75)
|
||||
|
||||
## ~
|
||||
|
||||
## ~ hint
|
||||
|
||||
Only one set of synchronized motors will run at the same time. Once you launch tank/steer, it will cancel any existing synchronized speed command.
|
||||
|
||||
## ~
|
||||
|
||||
## Examples
|
||||
|
||||
### Tank forward and backward
|
||||
@ -76,6 +82,51 @@ pause(5000)
|
||||
motors.stopAll()
|
||||
```
|
||||
|
||||
### Tank tester
|
||||
|
||||
This program lets you change the tank values using the brick buttons.
|
||||
|
||||
```typescript
|
||||
let tankB = 0;
|
||||
let tankC = 0;
|
||||
|
||||
brick.showString(`tank tester`, 1)
|
||||
brick.showString(`connect motors BC`, 7)
|
||||
brick.showString(`up/down for tank B`, 8)
|
||||
brick.showString(`left/right for tank C`, 9)
|
||||
|
||||
forever(function () {
|
||||
brick.showString(`motor B speed ${motors.largeB.speed()}%`, 4)
|
||||
brick.showString(`motor C speed ${motors.largeC.speed()}%`, 5)
|
||||
pause(100)
|
||||
})
|
||||
|
||||
function updateTank() {
|
||||
brick.showString(`tank A: ${tankB}%`, 2)
|
||||
brick.showString(`tank B: ${tankC}%`, 3)
|
||||
motors.largeBC.tank(tankB, tankC);
|
||||
}
|
||||
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
tankB += 10
|
||||
updateTank();
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
tankB -= 10
|
||||
updateTank();
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
tankC += 10
|
||||
updateTank();
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
tankC -= 10
|
||||
updateTank();
|
||||
})
|
||||
|
||||
updateTank();
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[steer](/reference/motors/synced/steer), [run](/reference/motors/motor/run)
|
BIN
docs/static/about/explorer-button.png
vendored
Normal file
After Width: | Height: | Size: 2.2 KiB |
BIN
docs/static/about/explorer-view.png
vendored
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
docs/static/fll/code-js.gif
vendored
Normal file
After Width: | Height: | Size: 349 KiB |
BIN
docs/static/fll/context-help.jpg
vendored
Normal file
After Width: | Height: | Size: 42 KiB |
BIN
docs/static/fll/fll-big.png
vendored
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
docs/static/fll/fll-logo.png
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
docs/static/fll/import-button.jpg
vendored
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
docs/static/fll/save-project.jpg
vendored
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
docs/static/fll/share-button.jpg
vendored
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/static/fll/share-program.gif
vendored
Normal file
After Width: | Height: | Size: 134 KiB |
BIN
docs/static/fll/share-program.jpg
vendored
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
docs/static/fll/simulator.gif
vendored
Normal file
After Width: | Height: | Size: 294 KiB |
1
docs/static/githubfilelogo.svg
vendored
Normal file
@ -0,0 +1 @@
|
||||
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414"><path d="M16.097 2.686c-7.64 0-13.834 6.194-13.834 13.835 0 6.113 3.964 11.298 9.462 13.128.692.127.944-.301.944-.667 0-.328-.012-1.199-.019-2.353-3.848.836-4.66-1.855-4.66-1.855-.629-1.598-1.536-2.023-1.536-2.023-1.256-.859.095-.842.095-.842 1.388.099 2.119 1.426 2.119 1.426 1.234 2.114 3.238 1.504 4.027 1.15.125-.894.482-1.504.878-1.85-3.072-.349-6.302-1.536-6.302-6.838 0-1.51.539-2.745 1.424-3.712-.143-.35-.617-1.756.135-3.661 0 0 1.162-.372 3.805 1.418a13.228 13.228 0 0 1 3.464-.465c1.174.005 2.358.158 3.463.465 2.642-1.79 3.801-1.418 3.801-1.418.755 1.905.28 3.311.137 3.661.887.967 1.423 2.202 1.423 3.712 0 5.316-3.235 6.485-6.317 6.827.497.428.939 1.272.939 2.563 0 1.849-.017 3.341-.017 3.795 0 .37.249.8.951.665 5.494-1.833 9.454-7.015 9.454-13.126 0-7.641-6.195-13.835-13.836-13.835" fill="#696969"/></svg>
|
After Width: | Height: | Size: 973 B |
BIN
docs/static/tutorials/coast-or-brake.png
vendored
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
docs/static/tutorials/pause-until-pressed.png
vendored
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
docs/static/tutorials/pivot-turn.png
vendored
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/static/tutorials/reflected-light-calibration.png
vendored
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
docs/static/tutorials/reflected-light-measure.png
vendored
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
docs/static/tutorials/smooth-turn.png
vendored
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/static/tutorials/spin-turn.png
vendored
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
docs/static/tutorials/tank-zigzag.png
vendored
Normal file
After Width: | Height: | Size: 19 KiB |
BIN
docs/static/tutorials/wall-follower.png
vendored
Normal file
After Width: | Height: | Size: 17 KiB |
@ -2,113 +2,46 @@
|
||||
|
||||
Step by step guides to coding your @boardname@.
|
||||
|
||||
## Brick
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Wake Up!",
|
||||
"description": "Show different moods on the screen. Is it tired, sleepy, or awake?",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/wake-up",
|
||||
"name": "Brick",
|
||||
"description": "Learn how to use the screen and the buttons",
|
||||
"url":"/tutorials/brick",
|
||||
"imageUrl":"/static/tutorials/wake-up.png"
|
||||
}, {
|
||||
"name": "Make an Animation",
|
||||
"description": "Create a custom animation on your EV3 Brick Display.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/make-an-animation",
|
||||
"imageUrl":"/static/tutorials/make-an-animation.png"
|
||||
}, {
|
||||
"name": "What Animal Am I?",
|
||||
"description": "Create different animal effects and have someone guess what the animal is.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/what-animal-am-i",
|
||||
"imageUrl":"/static/tutorials/what-animal-am-i.png"
|
||||
}, {
|
||||
"name": "Music Brick",
|
||||
"description": "Transform the brick into a musical instrument!",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/music-brick",
|
||||
"imageUrl":"/static/tutorials/music-brick.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## Motors
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Run Motors",
|
||||
"description": "Use the EV3 Brick buttons to start and stop the Large Motor and Medium Motor.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/run-motors",
|
||||
"name": "Motors",
|
||||
"description": "User motors to move the brick.",
|
||||
"url":"/tutorials/motors",
|
||||
"imageUrl":"/static/tutorials/run-motors.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## Touch Sensor
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Touch to Run",
|
||||
"description": "Press the Touch Sensor and run a motor.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/touch-to-run",
|
||||
}, {
|
||||
"name": "Touch Sensor",
|
||||
"description": "Use touch sensors in your robot.",
|
||||
"url":"/tutorials/touch-sensor",
|
||||
"imageUrl":"/static/tutorials/touch-to-run.png"
|
||||
}, {
|
||||
"name": "Touch Sensor Values",
|
||||
"description": "Check the value of a Touch Sensor and stop a motor if pressed.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/touch-sensor-values",
|
||||
"imageUrl":"/static/tutorials/touch-sensor-values.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## Color Sensor
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "What Color?",
|
||||
"description": "Use the Color Sensor to detect different colors.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/what-color",
|
||||
"name": "Color Sensor",
|
||||
"description": "Use the color sensor to follow line or detect colors",
|
||||
"url":"/tutorials/color-sensor",
|
||||
"imageUrl":"/static/tutorials/what-color.png"
|
||||
}, {
|
||||
"name": "Line Following",
|
||||
"description": "Use the Color Sensor to make a robot follow a line.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/line-following",
|
||||
"imageUrl":"/static/tutorials/line-following.png"
|
||||
"name": "Ultrasonic Sensor",
|
||||
"description": "Use the ultrasonic sensor to detect obstacles",
|
||||
"url":"/tutorials/ultrasonic-sensor",
|
||||
"imageUrl":"/static/tutorials/object-near.png"
|
||||
}, {
|
||||
"name": "Red Light, Green Light",
|
||||
"description": "Play Red Light, Green Light using the Color Sensor and the robot.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/redlight-greenlight",
|
||||
"imageUrl":"/static/tutorials/redlight-greenlight.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## Infrared Sensor
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Security Alert",
|
||||
"description": "Build an security alert using the Infrared Sensor.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/security-alert",
|
||||
"name": "Infrared Sensor",
|
||||
"description": "Use the infrared sensor to detect objects",
|
||||
"url":"/tutorials/infrared-sensor",
|
||||
"imageUrl":"/static/tutorials/security-alert.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[Wake Up!](/tutorials/wake-up),
|
||||
[Make An Animation](/tutorials/make-an-animation),
|
||||
[What Animal Am I?](/tutorials/what-animal-am-i),
|
||||
[Music Brick](/tutorials/music-brick),
|
||||
[Run Motors](/tutorials/run-motors),
|
||||
[Touch to Run](/tutorials/touch-to-run),
|
||||
[Touch Sensor Values](/tutorials/touch-sensor-values),
|
||||
[What Color?](/tutorials/what-color),
|
||||
[Line Following](/tutorials/line-following),
|
||||
[Red Light, Green Light](/tutorials/redlight-greenlight),
|
||||
[Object Near?](/tutorials/object-near),
|
||||
[Security Alert](/tutorials/security-alert)
|
||||
[Brick tutorials](/tutorials/brick),
|
||||
[Motors tutorials](/tutorials/motors),
|
||||
[Touch sensor tutorials](/tutorials/touch-sensor),
|
||||
[Color sensor tutorials](/tutorials/color-sensor),
|
||||
[Infrared sensor tutorials](/tutorials/infrared-sensor)
|
||||
|
38
docs/tutorials/brick.md
Normal file
@ -0,0 +1,38 @@
|
||||
# Brick Tutorials
|
||||
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Wake Up!",
|
||||
"description": "Show different moods on the screen. Is it tired, sleepy, or awake?",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/wake-up",
|
||||
"imageUrl":"/static/tutorials/wake-up.png"
|
||||
}, {
|
||||
"name": "Make an Animation",
|
||||
"description": "Create a custom animation on your EV3 Brick Display.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/make-an-animation",
|
||||
"imageUrl":"/static/tutorials/make-an-animation.png"
|
||||
}, {
|
||||
"name": "What Animal Am I?",
|
||||
"description": "Create different animal effects and have someone guess what the animal is.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/what-animal-am-i",
|
||||
"imageUrl":"/static/tutorials/what-animal-am-i.png"
|
||||
}, {
|
||||
"name": "Music Brick",
|
||||
"description": "Transform the brick into a musical instrument!",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/music-brick",
|
||||
"imageUrl":"/static/tutorials/music-brick.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[Wake Up!](/tutorials/wake-up),
|
||||
[Make An Animation](/tutorials/make-an-animation),
|
||||
[What Animal Am I?](/tutorials/what-animal-am-i),
|
||||
[Music Brick](/tutorials/music-brick),
|
27
docs/tutorials/city-shaper/crane-mission.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Crane Mission Lessons
|
||||
|
||||
The [Crane Mission Lessons](https://firstinspiresst01.blob.core.windows.net/fll/2020/fll-ev3-overview.pdf) adapted for MakeCode.
|
||||
|
||||
## Lessons
|
||||
|
||||
```codecard
|
||||
[
|
||||
{
|
||||
"name": "Crane Mission / Robot 1",
|
||||
"description": "Learn the basics and build your first robot driving base.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/city-shaper/robot-1"
|
||||
}, {
|
||||
"name": "Crane Mission / Robot 2",
|
||||
"description": "Program your robot to move in different ways.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/city-shaper/robot-2"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[Robot 1](/tutorials/city-shaper/robot-1),
|
||||
[Robot 2](/tutorials/city-shaper/robot-2)
|
||||
|
20
docs/tutorials/city-shaper/mission-2.md
Normal file
@ -0,0 +1,20 @@
|
||||
# Mission 2 Lesson
|
||||
|
||||
Use the program below to tell your robot how to solve the Crane Mission (Mission 2).
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeBC.steer(0, 25, 2.25, MoveUnit.Rotations)
|
||||
control.timer1.reset()
|
||||
while (control.timer1.seconds() < 1.5) {
|
||||
motors.largeBC.steer(sensors.color1.light(LightIntensityMode.Reflected) - 40, 50)
|
||||
}
|
||||
motors.largeBC.stop()
|
||||
motors.largeBC.steer(0, 15, 0.25, MoveUnit.Rotations)
|
||||
motors.mediumA.run(25, 60, MoveUnit.Degrees)
|
||||
pause(2000)
|
||||
motors.mediumA.run(-25, 1, MoveUnit.Seconds)
|
||||
motors.largeBC.steer(0, -100, 4, MoveUnit.Rotations)
|
||||
})
|
||||
motors.largeBC.setBrake(true)
|
||||
```
|
40
docs/tutorials/city-shaper/robot-1.md
Normal file
@ -0,0 +1,40 @@
|
||||
# Robot 1 Lesson
|
||||
|
||||
## Step 1 - Build Your Driving Base Robot @unplugged
|
||||
|
||||
Build the robot driving base:
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||
|
||||
If clicking on the image above doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
## Step 2 - Show an image @fullscreen
|
||||
|
||||
At first, it's nice to know that your program is running. Plug in a ``||brick:show mood||`` from the **BRICK** toolbox drawer
|
||||
into the ``||loops:on start||`` block. Change the image to something else if you want!
|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.neutral)
|
||||
```
|
||||
|
||||
## Step 3 - Try your code @fullscreen
|
||||
|
||||
Look at the simulator and check that your image is showing on the screen. When you are ready, press the **DOWNLOAD** button
|
||||
and follow the instructions to transfer your code on the brick.
|
||||
|
||||
## Step 4 - Steer motors @fullscreen
|
||||
|
||||
Drag a ``||motors:steer motors||`` block from the **MOTORS** toolbox drawer and snap it in under ``||brick:show mood||``.
|
||||
Click on the **(+)** symbol and make sure to tell your motors to turn **1** rotation.
|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.neutral)
|
||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## Step 5 - Try your code @fullscreen
|
||||
|
||||
Whenever you make a code change, the simulator will restart so you can see what your latest change will do.
|
||||
When you are ready, click **DOWNLOAD** and follow the instructions to transfer the code into your brick.
|
||||
|
||||
**Remember**: Take the driving base apart at the end of the session so that another group can build their robot too.
|
94
docs/tutorials/city-shaper/robot-2.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Robot 2 Lesson
|
||||
|
||||
## Step 1 - Build Your Driving Base Robot @unplugged
|
||||
|
||||
Build the robot driving base:
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||
|
||||
If clicking on the image above doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
## Step 2 - Show an image and move @fullscreen
|
||||
|
||||
Add blocks to the ``||loops:on start||`` block to show an image and move the motors **B+C** for ``1`` rotation.
|
||||
|
||||
```blocks
|
||||
brick.showMood(moods.neutral)
|
||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||
```
|
||||
|
||||
## Step 3 - Brick button @fullscreen
|
||||
|
||||
Let's change the code so that your robot moves when the **UP** button is pressed.
|
||||
Add an ``||brick:on button up||`` block and move ``||motors:steer motors||`` inside of it.
|
||||
After downloading your code, press **UP** to move the robot.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||
})
|
||||
brick.showMood(moods.neutral)
|
||||
```
|
||||
|
||||
## Step 4 - Braking @fullscreen
|
||||
|
||||
When the motors are done turning, the robot keeps on moving for a short distance.
|
||||
Turn on the **brakes** so that your robot stops immediately.
|
||||
Drag a ``||motors:set brake||`` block into the ``||loops:on start||`` and set it to **ON** for the the **BC** motors.
|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||
})
|
||||
brick.showMood(moods.neutral)
|
||||
motors.largeBC.setBrake(true)
|
||||
```
|
||||
|
||||
## Step 5 - Left and Right turn @fullscreen
|
||||
|
||||
Let's make the robot turn to the left when the **LEFT** button is pressed on the brick.
|
||||
Find an ``||brick:on button||`` block and put a ``||motors:steer motors||`` in it. Make the turn ratio drive the motor to left.
|
||||
Get another ``||brick:on button||`` and set it to run when the **RIGHT** is pressed.
|
||||
Put a ``||motors:steer motors||`` in for that button and set the turn ratio to drive to the right.
|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeBC.steer(-50, 50, 1, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeBC.steer(50, 50, 1, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 6 - Backwards @fullscreen
|
||||
|
||||
Let's make the robot go backwards when the **DOWN** button is pressed on the brick.
|
||||
Add a ``||motors:steer motors||`` to an ``||brick:on button||`` block and change the speed to be negative. This will make the motor go backwards.
|
||||
|
||||
```blocks
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeBC.steer(0, -50, 1, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 7 - Add an Ultrasonic sensor @fullscreen
|
||||
|
||||
Add an Ultrasonic sensor to your driving base.
|
||||
|
||||
[](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-ultrasonic-sensor-driving-base-61ffdfa461aee2470b8ddbeab16e2070.pdf)
|
||||
|
||||
If clicking on the image above doesn't open the instructions, right-click on the image and choose "Save link as..." to download the PDF.
|
||||
|
||||
## Step 8 - Stopping distance @fullscreen
|
||||
|
||||
Create a program that moves the Driving Base and makes it stop 6 cm from the Cuboid.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
motors.largeBC.steer(0, 50)
|
||||
pauseUntil(() => sensors.ultrasonic4.distance() < 6)
|
||||
motors.largeBC.stop()
|
||||
})
|
||||
```
|
||||
|
||||
Try sending your robot towards a wall!
|
16
docs/tutorials/coast-or-brake.md
Normal file
@ -0,0 +1,16 @@
|
||||
# Coast or Brake
|
||||
|
||||
This code example will set the brake when button **A** is pressed or let the motor coast (turn freely when not running) when button **B** is pressed. The motor is turned by one rotation to cause motion.
|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
// tell motor to brake once the run command is done
|
||||
motors.largeB.setBrake(true)
|
||||
motors.largeB.run(100, 1, MoveUnit.Rotations)
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
// tell motor to coast once the run command is done
|
||||
motors.largeB.setBrake(false)
|
||||
motors.largeB.run(100, 1, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
43
docs/tutorials/color-sensor.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Color Sensor
|
||||
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "What Color?",
|
||||
"description": "Use the Color Sensor to detect different colors.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/what-color",
|
||||
"imageUrl":"/static/tutorials/what-color.png"
|
||||
}, {
|
||||
"name": "Line Following",
|
||||
"description": "Use the Color Sensor to make a robot follow a line.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/line-following",
|
||||
"imageUrl":"/static/tutorials/line-following.png"
|
||||
}, {
|
||||
"name": "Red Light, Green Light",
|
||||
"description": "Play Red Light, Green Light using the Color Sensor and the robot.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/redlight-greenlight",
|
||||
"imageUrl":"/static/tutorials/redlight-greenlight.png"
|
||||
}, {
|
||||
"name": "Reflected Light Measure",
|
||||
"description": "Teach the sensor what light or dark is.",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/reflected-light-measure",
|
||||
"imageUrl":"/static/tutorials/reflected-light-measure.png"
|
||||
}, {
|
||||
"name": "Reflected Light Calibration",
|
||||
"description": "Use the auto-calibration feature to setup the dark and bright values.",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/reflected-light-calibration",
|
||||
"imageUrl":"/static/tutorials/reflected-light-calibration.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[What Color?](/tutorials/what-color),
|
||||
[Line Following](/tutorials/line-following),
|
||||
[Red Light, Green Light](/tutorials/redlight-greenlight),
|
17
docs/tutorials/infrared-sensor.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Infrared sensor
|
||||
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Security Alert",
|
||||
"description": "Build an security alert using the Infrared Sensor.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/security-alert",
|
||||
"imageUrl":"/static/tutorials/security-alert.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[Security Alert](/tutorials/security-alert)
|
58
docs/tutorials/motors.md
Normal file
@ -0,0 +1,58 @@
|
||||
# Motors
|
||||
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Run Motors",
|
||||
"description": "Use the EV3 Brick buttons to start and stop the Large Motor and Medium Motor.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/run-motors",
|
||||
"imageUrl":"/static/tutorials/run-motors.png"
|
||||
}, {
|
||||
"name": "Spin Turn",
|
||||
"description": "Turn the driving base around its center.",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/spin-turn",
|
||||
"imageUrl":"/static/tutorials/spin-turn.png"
|
||||
}, {
|
||||
"name": "Pivot Turn",
|
||||
"description": "Turn the driving base around a wheel.",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/pivot-turn",
|
||||
"imageUrl":"/static/tutorials/pivot-turn.png"
|
||||
}, {
|
||||
"name": "Smooth Turn",
|
||||
"description": "Turn the driving base in a smooth, steering motion.",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/smooth-turn",
|
||||
"imageUrl":"/static/tutorials/smooth-turn.png"
|
||||
}, {
|
||||
"name": "Tank ZigZag",
|
||||
"description": "Use the tank block to keep motors in sync.",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/tank-zigzag",
|
||||
"imageUrl":"/static/tutorials/tank-zigzag.png"
|
||||
}, {
|
||||
"name": "Coast Or Brake",
|
||||
"description": "Tell motors to coast or brake once the run command is done.",
|
||||
"cardType": "example",
|
||||
"url":"/tutorials/coast-or-brake",
|
||||
"imageUrl":"/static/tutorials/coast-or-brake.png"
|
||||
}, {
|
||||
"name": "Turtle",
|
||||
"description": "Encode moves and run them on a driving base",
|
||||
"url":"/tutorials/turtle",
|
||||
"cardType": "example"
|
||||
}]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[Run Motors](/tutorials/run-motors),
|
||||
[Spin Turn](/tutorials/spin-turn),
|
||||
[Pivot Turn](/tutorials/pivot-turn),
|
||||
[Smooth Turn](/tutorials/smooth-turn),
|
||||
[Tank ZigZag](/tutorials/tank-zigzag),
|
||||
[Coast Or Brake](/tutorials/coast-or-brake),
|
||||
[Turtle](/tutorials/turtle)
|
@ -31,7 +31,7 @@ Open the ``||brick:Brick||`` Toolbox drawer. From the **Buttons** section, drag
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
})
|
||||
brick.showString("Press my buttons!" 1)
|
||||
brick.showString("Press my buttons!", 1)
|
||||
```
|
||||
|
||||
## Step 4
|
||||
|
9
docs/tutorials/pause-until-pressed.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Pause Until Pressed
|
||||
|
||||
This is a code example to detect contact or collision with another object. It uses a touch sensor to detect hitting a wall or other obstacle. The motors are run and then stopped when the sensor is pressed.
|
||||
|
||||
```blocks
|
||||
motors.largeBC.tank(50, 50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.stop()
|
||||
```
|
12
docs/tutorials/pivot-turn.md
Normal file
@ -0,0 +1,12 @@
|
||||
# Pivot Turn
|
||||
|
||||
A **pivot turn** happens when a [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf) turns around the wheel on the inside of the turn by spinning just the single wheel at the outside of the turn.
|
||||
|
||||
You can make a turn happen with either a ``||motors:tank||`` or a ``||motors:steer||`` block.
|
||||
|
||||
```blocks
|
||||
forever(function() {
|
||||
motors.largeBC.tank(50, 0, 2, MoveUnit.Rotations)
|
||||
motors.largeBC.tank(0, 50, 2, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
24
docs/tutorials/reflected-light-calibration.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Reflected light calibration
|
||||
|
||||
The ``||sensors:calibrateLight||`` blocks allows you to calibrate the reflected light of the color sensor in one block. At the time you run the block, move the sensor over a dark surface and a bright surface; then stop moving it.
|
||||
|
||||
```blocks
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {
|
||||
brick.showString("dark", 2)
|
||||
})
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Bright, function () {
|
||||
brick.showString("bright", 2)
|
||||
})
|
||||
console.sendToScreen()
|
||||
console.log("move color sensor")
|
||||
console.log("over DARK and BRIGHT color")
|
||||
console.log("and stop moving when done")
|
||||
console.log("press ENTER when ready")
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
|
||||
sensors.color3.calibrateLight(LightIntensityMode.Reflected)
|
||||
brick.showValue("dark", sensors.color3.threshold(Light.Dark), 4)
|
||||
brick.showValue("bright", sensors.color3.threshold(Light.Bright), 5)
|
||||
forever(function () {
|
||||
brick.showValue("reflected light", sensors.color3.light(LightIntensityMode.Reflected), 1)
|
||||
})
|
||||
```
|
29
docs/tutorials/reflected-light-measure.md
Normal file
@ -0,0 +1,29 @@
|
||||
# Reflected light measure
|
||||
|
||||
This example uses a color sensor to measure the reflected light from a dark and light surface
|
||||
and sets the light/dark thresholds.
|
||||
|
||||
```blocks
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Dark, function () {
|
||||
brick.showString("dark", 2)
|
||||
})
|
||||
sensors.color3.onLightDetected(LightIntensityMode.Reflected, Light.Bright, function () {
|
||||
brick.showString("bright", 2)
|
||||
})
|
||||
console.sendToScreen()
|
||||
console.log("move color sensor")
|
||||
console.log("over DARK color")
|
||||
console.log("press ENTER when ready")
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
|
||||
sensors.color3.setThreshold(Light.Dark, sensors.color3.light(LightIntensityMode.Reflected) + 5)
|
||||
console.logValue("dark", sensors.color3.threshold(Light.Dark))
|
||||
console.log("move color sensor")
|
||||
console.log("over BRIGHT color")
|
||||
console.log("press ENTER when ready")
|
||||
brick.buttonEnter.pauseUntil(ButtonEvent.Pressed)
|
||||
sensors.color3.setThreshold(Light.Bright, sensors.color3.light(LightIntensityMode.Reflected) - 5)
|
||||
console.logValue("bright", sensors.color3.threshold(Light.Bright))
|
||||
forever(function () {
|
||||
brick.showValue("reflected light", sensors.color3.light(LightIntensityMode.Reflected), 1)
|
||||
})
|
||||
```
|
@ -106,9 +106,9 @@ brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
||||
For the ``||motors:run||`` blocks that are in the ``||brick:on button left||`` and ``||brick:on button right||`` blocks, use the drop-down menu to select a ``medium motor`` on Port ``D``.
|
||||
|
||||
| | | |
|
||||
|-|-|-|
|
||||
|  | | |  |
|
||||

|
||||
<br/>
|
||||

|
||||
|
||||
```blocks
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
|
12
docs/tutorials/smooth-turn.md
Normal file
@ -0,0 +1,12 @@
|
||||
# Smooth Turn
|
||||
|
||||
A **smooth turn** happens when a [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf) makes a turn by spinning both both wheels but with each running at a different speed.
|
||||
|
||||
You can make a turn happen with either a ``||motors:tank||`` or a ``||motors:steer||`` block.
|
||||
|
||||
```blocks
|
||||
forever(function() {
|
||||
motors.largeBC.tank(50, 20, 2, MoveUnit.Rotations)
|
||||
motors.largeBC.tank(20, 50, 2, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
12
docs/tutorials/spin-turn.md
Normal file
@ -0,0 +1,12 @@
|
||||
# Spin Turn
|
||||
|
||||
A **spin turn** happens when a [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf) turns, or rotates, on a single spot by spinning both wheels, but with each turning in opposite directions.
|
||||
|
||||
You can make a turn happen with either a ``||motors:tank||`` or a ``||motors:steer||`` block.
|
||||
|
||||
```blocks
|
||||
forever(function() {
|
||||
motors.largeBC.tank(50, -50, 2, MoveUnit.Rotations)
|
||||
motors.largeBC.tank(-50, 50, 2, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
9
docs/tutorials/stop-at-object.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Stop At Object
|
||||
|
||||
This is a code example to detect contact or collision with another object. It uses a touch sensor to detect hitting a wall or other obstacle. The motors are run and then stopped when the sensor is pressed.
|
||||
|
||||
```blocks
|
||||
motors.largeBC.tank(50, 50)
|
||||
sensors.touch1.pauseUntil(ButtonEvent.Pressed)
|
||||
motors.largeBC.stop()
|
||||
```
|
17
docs/tutorials/tank-zigzag.md
Normal file
@ -0,0 +1,17 @@
|
||||
# Tank ZigZag
|
||||
|
||||
This example shows how to use the [tank](/reference/motors/tank) block to keep the speed of 2 large motors synchronized. The [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||
) will move in a zig zag pattern.
|
||||
|
||||
```blocks
|
||||
/**
|
||||
* Use the tank block to keep large motors synched.
|
||||
Use this code with a EV3 driving base.
|
||||
*/
|
||||
forever(function () {
|
||||
brick.showImage(images.eyesMiddleRight)
|
||||
motors.largeBC.tank(50, 10, 2, MoveUnit.Rotations)
|
||||
brick.showImage(images.eyesMiddleLeft)
|
||||
motors.largeBC.tank(10, 50, 2, MoveUnit.Rotations)
|
||||
})
|
||||
```
|
31
docs/tutorials/touch-sensor.md
Normal file
@ -0,0 +1,31 @@
|
||||
# Touch Sensor
|
||||
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Touch to Run",
|
||||
"description": "Press the Touch Sensor and run a motor.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/touch-to-run",
|
||||
"imageUrl":"/static/tutorials/touch-to-run.png"
|
||||
}, {
|
||||
"name": "Sensor Values",
|
||||
"description": "Check the value of a Touch Sensor and stop a motor if pressed.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/touch-sensor-values",
|
||||
"imageUrl":"/static/tutorials/touch-sensor-values.png"
|
||||
}, {
|
||||
"name": "Stop At Object",
|
||||
"description": "Waits for the sensor to be pressed before continuing the program",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/stop-at-object",
|
||||
"imageUrl":"/static/tutorials/pause-until-pressed.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[Touch to Run](/tutorials/touch-to-run),
|
||||
[Touch Sensor Values](/tutorials/touch-sensor-values),
|
||||
[Stop At Object](/tutorials/stop-at-object)
|
52
docs/tutorials/turtle.md
Normal file
@ -0,0 +1,52 @@
|
||||
# Turtle
|
||||
|
||||
A fun interactive program where the user enters a sequence of moves using the buttons and the robot executes it.
|
||||
|
||||
|
||||
```blocks
|
||||
/**
|
||||
* Run this program with a driving base.
|
||||
**/
|
||||
let indent = ""
|
||||
let command = ""
|
||||
let c = ""
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
command = command + "L"
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
command = command + "R"
|
||||
})
|
||||
brick.buttonUp.onEvent(ButtonEvent.Pressed, function () {
|
||||
command = command + "F"
|
||||
})
|
||||
brick.buttonDown.onEvent(ButtonEvent.Pressed, function () {
|
||||
command = command + "B"
|
||||
})
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
indent = ""
|
||||
for (let index = 0; index <= command.length; index++) {
|
||||
c = command[index]
|
||||
brick.showString("" + indent + c, 4)
|
||||
indent = "" + indent + " "
|
||||
if (c == "L") {
|
||||
motors.largeBC.steer(-100, 50, 378, MoveUnit.Degrees)
|
||||
} else if (c == "R") {
|
||||
motors.largeBC.steer(100, 50, 378, MoveUnit.Degrees)
|
||||
} else if (c == "F") {
|
||||
motors.largeBC.steer(0, 50, 1, MoveUnit.Rotations)
|
||||
} else if (c == "B") {
|
||||
motors.largeBC.steer(0, -50, 1, MoveUnit.Rotations)
|
||||
}
|
||||
}
|
||||
command = ""
|
||||
brick.showString("", 2)
|
||||
})
|
||||
motors.largeBC.setBrake(true)
|
||||
forever(function () {
|
||||
brick.showString("TURTLE", 1)
|
||||
brick.showString(command, 3)
|
||||
brick.showString("up/down: forward/backward", 8)
|
||||
brick.showString("left/right: turn", 9)
|
||||
brick.showString("enter: play commands", 10)
|
||||
})
|
||||
```
|
24
docs/tutorials/ultrasonic-sensor.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Infrared sensor
|
||||
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[{
|
||||
"name": "Object Near",
|
||||
"description": "Detect if objects are near.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/object-near",
|
||||
"imageUrl":"/static/tutorials/object-near.png"
|
||||
}, {
|
||||
"name": "Wall Follower",
|
||||
"description": "Follow a wall at a distance using the ultrasonic sensor and a proportional controller.",
|
||||
"cardType": "tutorial",
|
||||
"url":"/tutorials/wall-follower",
|
||||
"imageUrl":"/static/tutorials/wall-follower.png"
|
||||
}]
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
[Object Near?](/tutorials/object-near),
|
||||
[Wall Follower](/tutorials/wall-follower)
|
191
docs/tutorials/wall-follower.md
Normal file
@ -0,0 +1,191 @@
|
||||
# Wall Follower
|
||||
|
||||
## Introduction @unplugged
|
||||
|
||||
This tutorial shows you how to use the ultrasonic sensor to
|
||||
move a [EV3 Driving Base](https://le-www-live-s.legocdn.com/sc/media/lessons/mindstorms-ev3/building-instructions/ev3-rem-driving-base-79bebfc16bd491186ea9c9069842155e.pdf)
|
||||
along a wall.
|
||||
|
||||
Your ultrasonic sensor should be placed horizontally, near the driving wheel, facing the wall.
|
||||
|
||||
## Step 1 Measure distance
|
||||
|
||||
Declare a new variable ``distance`` and store the distance from
|
||||
the ultrasonic sensor on port 4.
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
forever(function () {
|
||||
distance = sensors.ultrasonic4.distance()
|
||||
})
|
||||
```
|
||||
|
||||
## Step 2 Show distance
|
||||
|
||||
Use a ``||brick:show value||`` block to display the distance value on the screen.
|
||||
This is **very** helpful when you are debugging your code on the robot.
|
||||
|
||||
Once your code is ready, download it to your robot and check that the measured distance looks ok.
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
forever(function () {
|
||||
distance = sensors.ultrasonic4.distance()
|
||||
brick.showValue("distance", distance, 1)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 3 Goal
|
||||
|
||||
Declare a new variable ``goal`` and assign it to ``10`` in ``on start``.
|
||||
The value should be the distance in centimeters between your robot and the wall.
|
||||
|
||||
```blocks
|
||||
let goal = 0
|
||||
goal = 10
|
||||
```
|
||||
|
||||
## Step 4 Compute Error
|
||||
|
||||
Declare a new variable ``error`` and assign a difference between ``distance`` and ``goal``.
|
||||
We will use this value to determine how much the robot needs to correct its trajectory.
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
let goal = 0
|
||||
let error = 0
|
||||
goal = 10
|
||||
forever(function () {
|
||||
distance = sensors.ultrasonic4.distance()
|
||||
brick.showValue("distance", distance, 1)
|
||||
error = distance - goal
|
||||
brick.showValue("error", error, 2)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 5 Show Error
|
||||
|
||||
Just like ``distance``, use ``||brick:show value||`` to display the value of the error (line 2).
|
||||
This will allow you to debug your code while it is running on the robot.
|
||||
|
||||
Download your program to the robot and check that the error goes to ``0`` when
|
||||
the robot is around 10cm from the wall.
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
let goal = 0
|
||||
let error = 0
|
||||
goal = 10
|
||||
forever(function () {
|
||||
distance = sensors.ultrasonic4.distance()
|
||||
brick.showValue("distance", distance, 1)
|
||||
error = distance - goal
|
||||
brick.showValue("error", error, 2)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 6 Kp
|
||||
|
||||
Declare a new variable ``kp`` and assign it to ``1``.
|
||||
This number determines how to convert the error into a ``turn ratio`` for the steer block.
|
||||
For starter, set it to 1 and we will go through the steps to tune its value later on.
|
||||
As usual, also use ``||brick:show value||`` to display the value of ``kp`` on the screen (line 3).
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
let goal = 0
|
||||
let error = 0
|
||||
let kp = 0
|
||||
goal = 10
|
||||
kp = 1
|
||||
forever(function () {
|
||||
distance = sensors.ultrasonic4.distance()
|
||||
brick.showValue("distance", distance, 1)
|
||||
error = distance - goal
|
||||
brick.showValue("error", error, 2)
|
||||
brick.showValue("kp", kp, 3)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 7 Turn ratio
|
||||
|
||||
Declare a new variable ``turnratio`` and store the product of ``error`` and ``kp`` in it.
|
||||
Also use ``||brick:show value||`` to display its value on screen.
|
||||
|
||||
Download the program on the robot and try moving the robot around the wall. You should see
|
||||
the value of ``turnratio`` change similarly to ``error``.
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
let goal = 0
|
||||
let error = 0
|
||||
let kp = 0
|
||||
let turnratio = 0
|
||||
goal = 10
|
||||
kp = 1
|
||||
forever(function () {
|
||||
distance = sensors.ultrasonic4.distance()
|
||||
brick.showValue("distance", distance, 1)
|
||||
error = distance - goal
|
||||
brick.showValue("error", error, 2)
|
||||
brick.showValue("kp", kp, 3)
|
||||
turnratio = error * kp
|
||||
brick.showValue("turn", turnratio, 4)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 8 Steering
|
||||
|
||||
Add a ``||motors:steer motors||`` block for ``large B+C`` at 35% and place the ``turnratio``
|
||||
variable for the turn value.
|
||||
|
||||
Download the code to your robot and try it out. Does it follow the wall?...
|
||||
Not really, this is because we need to tune the ``kp`` variable.
|
||||
|
||||
```blocks
|
||||
let distance = 0
|
||||
let goal = 0
|
||||
let error = 0
|
||||
let kp = 0
|
||||
let turnratio = 0
|
||||
goal = 10
|
||||
kp = 1
|
||||
forever(function () {
|
||||
distance = sensors.ultrasonic4.distance()
|
||||
brick.showValue("distance", distance, 1)
|
||||
error = distance - goal
|
||||
brick.showValue("error", error, 2)
|
||||
brick.showValue("kp", kp, 3)
|
||||
turnratio = error * kp
|
||||
brick.showValue("turn", turnratio, 4)
|
||||
motors.largeBC.steer(turnratio, 35)
|
||||
})
|
||||
```
|
||||
|
||||
## Step 9 Tuning kp
|
||||
|
||||
As mentioned in a previous step, we need to find the right value for kp so that the robot
|
||||
follows the wall properly. This tuning can be tedious so we are going to the brick buttons
|
||||
to speed up the process.
|
||||
|
||||
Add ``||brick:on button||`` blocks to handle the left and right button pressed. When left is pressed, change ``kp`` by ``-1``. When right is pressed, change ``kp`` by 1.
|
||||
|
||||
Download your code to the robot and change the values of ``kp`` until the robot follows the wall. (Tip try something around -5 / -10).
|
||||
|
||||
```blocks
|
||||
let kp = 0
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
kp += -1
|
||||
})
|
||||
brick.buttonRight.onEvent(ButtonEvent.Pressed, function () {
|
||||
kp += 1
|
||||
})
|
||||
```
|
||||
|
||||
## Step 10 @unplugged
|
||||
|
||||
Well done! Your robot is using the ultrasonic distance
|
||||
to correct is trajectory using a proportional controller!
|
||||
|
||||
The robot will be more precise if it goes slow... Try using a variable
|
||||
and the brick up and down events to control the speed as well.
|
33
docs/videos.md
Normal file
@ -0,0 +1,33 @@
|
||||
# Videos
|
||||
|
||||
## Tutorials
|
||||
|
||||
```codecard
|
||||
[
|
||||
{
|
||||
"name": "",
|
||||
"url": "https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=5d009e5f93fbf479c2e5ed2bf87a7990&source=embed&photo%5fid=35719444",
|
||||
"imageUrl": "https://legoeducation.videomarketingplatform.co/27288170/35719444/5d009e5f93fbf479c2e5ed2bf87a7990/thumbnail.png"
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"url": "https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=2008a566f1fb034d58d5ebe19ba8621f&source=embed&photo%5fid=35719467",
|
||||
"imageUrl": "https://legoeducation.videomarketingplatform.co/27288175/35719467/2008a566f1fb034d58d5ebe19ba8621f/thumbnail.png"
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"url": "https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=629730c938e452f0fd7653fbc4708166&source=embed&photo%5fid=35719470",
|
||||
"imageUrl": "https://legoeducation.videomarketingplatform.co/27288172/35719470/629730c938e452f0fd7653fbc4708166/thumbnail.png"
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"url": "https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=3513a83b87fe536b2dc512237465fd1b&source=embed&photo%5fid=35719471",
|
||||
"imageUrl": "https://legoeducation.videomarketingplatform.co/27288172/35719471/3513a83b87fe536b2dc512237465fd1b/thumbnail.png"
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"url": "https://legoeducation.videomarketingplatform.co/v.ihtml/player.html?token=5c594c2373367f7870196f519f3bfc7a&source=embed&photo%5fid=35719472",
|
||||
"imageUrl": "https://legoeducation.videomarketingplatform.co/27288175/35719472/5c594c2373367f7870196f519f3bfc7a/thumbnail.png"
|
||||
}
|
||||
]
|
||||
```
|
@ -30,7 +30,7 @@ pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): P
|
||||
<div class="ui header">${lf("First time here?")}</div>
|
||||
<strong style="font-size:small">${lf("You must have version 1.10E or above of the firmware")}</strong>
|
||||
<div style="justify-content: center;display: flex;padding: 1rem;">
|
||||
<img class="ui image" src="./static/download/firmware.png" style="height:100px;" />
|
||||
<img class="ui image" src="/static/download/firmware.png" style="height:100px;" />
|
||||
</div>
|
||||
<a href="/troubleshoot" target="_blank">${lf("Check your firmware version here and update if needed")}</a>
|
||||
</div>
|
||||
@ -42,7 +42,7 @@ pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): P
|
||||
<div class="column">
|
||||
<div class="ui">
|
||||
<div class="image">
|
||||
<img class="ui medium rounded image" src="./static/download/connect.svg" style="height:109px;width:261px;margin-bottom:1rem;" />
|
||||
<img class="ui medium rounded image" src="/static/download/connect.svg" style="height:109px;width:261px;margin-bottom:1rem;" />
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="description">
|
||||
@ -57,7 +57,7 @@ pxt.editor.initExtensionsAsync = function (opts: pxt.editor.ExtensionOptions): P
|
||||
<div class="column">
|
||||
<div class="ui">
|
||||
<div class="image">
|
||||
<img class="ui medium rounded image" src="./static/download/transfer.svg" style="height:109px;width:261px;margin-bottom:1rem;" />
|
||||
<img class="ui medium rounded image" src="/static/download/transfer.svg" style="height:109px;width:261px;margin-bottom:1rem;" />
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="description">
|
||||
|
13
ev3.code-workspace
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
},
|
||||
{
|
||||
"path": "../pxt-common-packages"
|
||||
},
|
||||
{
|
||||
"path": "../pxt"
|
||||
}
|
||||
]
|
||||
}
|
@ -133,14 +133,27 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
this.setText(text);
|
||||
}
|
||||
|
||||
getFirstValue(text: string) {
|
||||
// Get first set of words up until last space
|
||||
return this.normalizeText_(text.substring(0, text.lastIndexOf(' ')));
|
||||
getFirstValue(value: string) {
|
||||
const typeValue = value.indexOf('large') != -1 ? 'large' : 'medium';
|
||||
const portValue = this.getSecondValue(value);
|
||||
const isDual = portValue.length > 1;
|
||||
return `${typeValue} motor${isDual ? 's' : ''}`;
|
||||
}
|
||||
|
||||
getSecondValue(text: string) {
|
||||
// Get last word
|
||||
return this.normalizeText_(text.match(/\S*$/)[0]);
|
||||
getSecondValue(value: string) {
|
||||
return (value.indexOf('large') != -1) ?
|
||||
value.substring(value.indexOf('large') + 5) :
|
||||
value.substring(value.indexOf('medium') + 6);
|
||||
}
|
||||
|
||||
getFirstValueI11n(value: string) {
|
||||
const firstValue = this.getFirstValue(value);
|
||||
const motorOptions = {
|
||||
'medium motor': lf('medium motor'),
|
||||
'large motor': lf('large motor'),
|
||||
'large motors': lf('large motors')
|
||||
}
|
||||
return motorOptions[firstValue];
|
||||
}
|
||||
|
||||
private normalizeText_(text: string) {
|
||||
@ -198,8 +211,8 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
if (text === null) {
|
||||
return text;
|
||||
}
|
||||
if (text.indexOf(' ') == -1) {
|
||||
text = `large motors ${text}`;
|
||||
if (text.indexOf('|') == -1) {
|
||||
text = this.sourceBlock_.RTL ? `${text}|${lf("large motors")}` : `${lf("large motors")}|${text}`;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
@ -296,16 +309,14 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
goog.dom.removeChildren(/** @type {!Element} */(this.textElement_));
|
||||
goog.dom.removeChildren(/** @type {!Element} */(this.textElement2_));
|
||||
|
||||
var text = this.text_;
|
||||
text = this.patchDualMotorText(text);
|
||||
|
||||
// First dropdown
|
||||
const textNode1 = document.createTextNode(this.getFirstValue(text));
|
||||
// Use one of the following options, medium motor, large motor or large motors (translated)
|
||||
const textNode1 = document.createTextNode(this.getFirstValueI11n(this.value_));
|
||||
this.textElement_.appendChild(textNode1);
|
||||
|
||||
// Second dropdown
|
||||
// Second dropdown, no need to translate. Only port numbers
|
||||
if (this.textElement2_) {
|
||||
const textNode2 = document.createTextNode(this.getSecondValue(text));
|
||||
const textNode2 = document.createTextNode(this.getSecondValue(this.value_));
|
||||
this.textElement2_.appendChild(textNode2);
|
||||
}
|
||||
this.updateWidth();
|
||||
@ -402,29 +413,28 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
contentDiv.setAttribute('aria-haspopup', 'true');
|
||||
let options = this.getOptions();
|
||||
|
||||
// Hashmap of options
|
||||
let opts = {};
|
||||
let conts = {};
|
||||
let vals = {};
|
||||
// Go through all option values and split them into groups
|
||||
for (let opt = 0; opt < options.length; opt++) {
|
||||
let text = options[opt][0].alt ? options[opt][0].alt : options[opt][0];
|
||||
if (text.indexOf(' ') == -1) {
|
||||
// Patch dual motors as they don't have prefixes.
|
||||
text = this.patchDualMotorText(text);
|
||||
if (options[opt][0].alt) options[opt][0].alt = text;
|
||||
}
|
||||
const value = options[opt][1];
|
||||
const firstValue = this.getFirstValue(text);
|
||||
const secondValue = this.getSecondValue(text);
|
||||
if (!opts[firstValue]) opts[firstValue] = [secondValue];
|
||||
else opts[firstValue].push(secondValue);
|
||||
// Store a hash of the original key value pairs for later
|
||||
const motorValue = value.substring(value.indexOf('.') + 1);
|
||||
const typeValue = motorValue.indexOf('large') == 0 ? 'large' : 'medium';
|
||||
const portValue = motorValue.indexOf('large') == 0 ? motorValue.substring(5) : motorValue.substring(6);
|
||||
const isDual = portValue.length > 1;
|
||||
|
||||
const text = `${typeValue} motor${isDual ? 's' : ''}|${portValue}`;
|
||||
const key = `${typeValue} motor${isDual ? 's' : ''}`;
|
||||
if (!opts[key]) opts[key] = [];
|
||||
opts[key].push(portValue);
|
||||
|
||||
conts[text] = options[opt][0];
|
||||
vals[text] = value;
|
||||
}
|
||||
|
||||
const currentFirst = this.getFirstValue(this.text_);
|
||||
const currentSecond = this.getSecondValue(this.text_);
|
||||
const currentFirst = this.getFirstValue(this.value_);
|
||||
const currentSecond = this.getSecondValue(this.value_);
|
||||
|
||||
if (!this.isFirst_) {
|
||||
options = opts[currentFirst];
|
||||
@ -432,9 +442,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
options = Object.keys(opts);
|
||||
// Flip the first and second options to make it sorted the way we want it (medium, large, dual)
|
||||
if (options.length == 3) {
|
||||
const temp = options[1];
|
||||
options[1] = options[0];
|
||||
options[0] = temp;
|
||||
options = [lf("medium motor"), lf("large motor"), lf("large motors")];
|
||||
} else {
|
||||
options.reverse();
|
||||
}
|
||||
@ -448,7 +456,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
const columns = options.length;
|
||||
|
||||
for (let i = 0, option: any; option = options[i]; i++) {
|
||||
let text = this.isFirst_ ? option + ' ' + opts[option][0] : currentFirst + ' ' + option;
|
||||
let text = this.isFirst_ ? option + '|' + (option.indexOf('motors') != -1 ? 'BC' : 'A') : currentFirst + '|' + option;
|
||||
text = text.replace(/\xA0/g, ' ');
|
||||
const content: any = conts[text];
|
||||
const value = vals[text];
|
||||
@ -466,7 +474,7 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
button.setAttribute('id', ':' + i); // For aria-activedescendant
|
||||
button.setAttribute('role', 'menuitem');
|
||||
button.setAttribute('class', 'blocklyDropDownButton');
|
||||
button.title = this.isFirst_ ? this.getFirstValue(content.alt) : content.alt;
|
||||
button.title = this.isFirst_ ? this.getFirstValueI11n(value) : this.getSecondValue(value);
|
||||
button.style.width = ((this.itemWidth_) - 8) + 'px';
|
||||
button.style.height = ((this.itemWidth_) - 8) + 'px';
|
||||
let backgroundColor = this.backgroundColour_;
|
||||
@ -495,7 +503,15 @@ export class FieldMotors extends Blockly.FieldDropdown implements Blockly.FieldC
|
||||
contentDiv.removeAttribute('aria-activedescendant');
|
||||
});
|
||||
let buttonImg = document.createElement('img');
|
||||
buttonImg.src = this.isFirst_ ? isFirstUrl[option.replace(/\xA0/g, ' ')] : content.src;
|
||||
let imgSrc = content.src;
|
||||
if (this.isFirst_) {
|
||||
const motorValue = value.substring(value.indexOf('.') + 1);
|
||||
// Find out what kind of motor this is based on it's value, possible values: mediumX, largeX, and largeXY
|
||||
if (motorValue.indexOf('medium') == 0) imgSrc = isFirstUrl['medium motor'];
|
||||
else if (motorValue.length == 6) imgSrc = isFirstUrl['large motor'];
|
||||
else imgSrc = isFirstUrl['large motors'];
|
||||
}
|
||||
buttonImg.src = imgSrc;
|
||||
//buttonImg.alt = icon.alt;
|
||||
// Upon click/touch, we will be able to get the clicked element as e.target
|
||||
// Store a data attribute on all possible click targets so we can match it to the icon.
|
||||
|
@ -1,41 +0,0 @@
|
||||
import jobs.generation.Utilities;
|
||||
import jobs.generation.InternalUtilities;
|
||||
|
||||
def project = GithubProject
|
||||
def projectName = "pxt-ev3"
|
||||
|
||||
[true, false].each { isPR ->
|
||||
def newJobName = projectName
|
||||
|
||||
if (isPR) {
|
||||
newJobName += "_PR"
|
||||
} else {
|
||||
newJobName += "_Push"
|
||||
}
|
||||
|
||||
def newJob = job(newJobName) {
|
||||
steps {
|
||||
shell("chmod +x ./jenkins.sh")
|
||||
shell("./jenkins.sh ${isPR}")
|
||||
}
|
||||
|
||||
if (!isPR) {
|
||||
wrappers {
|
||||
credentialsBinding {
|
||||
string("PXT_ACCESS_TOKEN", "pxt_access_token")
|
||||
string("PXT_RELEASE_REPO", "pxt_release_repo_ev3")
|
||||
string("CROWDIN_KEY", "pxt_crowdin_key")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Utilities.setMachineAffinity(newJob, "Ubuntu", "20161020")
|
||||
InternalUtilities.standardJobSetup(newJob, project, isPR, "*/*")
|
||||
|
||||
if (isPR) {
|
||||
Utilities.addGithubPRTrigger(newJob, "Default Testing")
|
||||
} else {
|
||||
Utilities.addGithubPushTrigger(newJob)
|
||||
}
|
||||
}
|
56
jenkins.sh
@ -1,56 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Set up NVM
|
||||
export NVM_DIR="/home/dotnet-bot/.nvm"
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
|
||||
|
||||
nvm install 8
|
||||
|
||||
# Set up build environment variables
|
||||
echo ---------- Setting build environment variables
|
||||
echo Git branch: $GIT_BRANCH
|
||||
echo isPR: $1
|
||||
|
||||
originRegex="^origin/.*"
|
||||
branchRegex="^origin/\K.*(?=$)"
|
||||
releaseBranchRegex="^(master|v\d+)$"
|
||||
|
||||
if [[ "$GIT_BRANCH" =~ $originRegex ]]; then
|
||||
branchName=$(echo ${GIT_BRANCH} | grep -oP $branchRegex)
|
||||
echo Setting TRAVIS_BRANCH to ${branchName}
|
||||
export TRAVIS_BRANCH=${branchName}
|
||||
else
|
||||
echo Setting TRAVIS_BRANCH to $GIT_BRANCH
|
||||
export TRAVIS_BRANCH=$GIT_BRANCH
|
||||
fi
|
||||
|
||||
if [ "$1" == "false" ]; then
|
||||
echo Setting TRAVIS_PULL_REQUEST to false
|
||||
export TRAVIS_PULL_REQUEST=false
|
||||
|
||||
if [[ "$TRAVIS_BRANCH" =~ $releaseBranchRegex ]]; then
|
||||
if [[ -z $PXT_RELEASE_REPO ]]; then
|
||||
echo Cannot find release repo\; skipping tag checks
|
||||
else
|
||||
gitTag=$(git describe --tags --exact-match 2> /dev/null)
|
||||
builtTag=$(git ls-remote --tags $PXT_RELEASE_REPO | grep -o "refs/tags/$gitTag$")
|
||||
|
||||
echo Current tag: $gitTag
|
||||
echo Built tag: $builtTag
|
||||
|
||||
if [[ ! -z $gitTag && -z $builtTag ]]; then
|
||||
echo Built tag not found\; building tag
|
||||
echo Setting TRAVIS_BRANCH to $gitTag
|
||||
export TRAVIS_BRANCH=$gitTag
|
||||
echo Setting TRAVIS_TAG to $gitTag
|
||||
export TRAVIS_TAG=$gitTag
|
||||
else
|
||||
echo Not a tag build
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Perform build
|
||||
npm install
|
||||
npm test
|
@ -1,5 +1,5 @@
|
||||
const enum ColorSensorMode {
|
||||
None = -1,
|
||||
None = 0,
|
||||
//% block="reflected light intensity"
|
||||
ReflectedLightIntensity = 0,
|
||||
//% block="ambient light intensity"
|
||||
@ -15,7 +15,9 @@ enum LightIntensityMode {
|
||||
//% block="reflected light"
|
||||
Reflected = ColorSensorMode.ReflectedLightIntensity,
|
||||
//% block="ambient light"
|
||||
Ambient = ColorSensorMode.AmbientLightIntensity
|
||||
Ambient = ColorSensorMode.AmbientLightIntensity,
|
||||
//% block="reflected light (raw)"
|
||||
ReflectedRaw = ColorSensorMode.RefRaw
|
||||
}
|
||||
|
||||
const enum ColorSensorColor {
|
||||
@ -93,6 +95,8 @@ namespace sensors {
|
||||
|| this.mode == ColorSensorMode.AmbientLightIntensity
|
||||
|| this.mode == ColorSensorMode.ReflectedLightIntensity)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
if (this.mode == ColorSensorMode.RefRaw || this.mode == ColorSensorMode.RgbRaw)
|
||||
return this.getNumber(NumberFormat.UInt16LE, 0)
|
||||
return 0
|
||||
}
|
||||
|
||||
@ -114,7 +118,7 @@ namespace sensors {
|
||||
|
||||
_update(prev: number, curr: number) {
|
||||
if (this.calibrating) return; // simply ignore data updates while calibrating
|
||||
if (this.mode == ColorSensorMode.Color)
|
||||
if (this.mode == ColorSensorMode.Color || this.mode == ColorSensorMode.RgbRaw || this.mode == ColorSensorMode.RefRaw)
|
||||
control.raiseEvent(this._id, this._colorEventValue(curr));
|
||||
else
|
||||
this.thresholdDetector.setLevel(curr);
|
||||
@ -179,6 +183,23 @@ namespace sensors {
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current raw rgb values as an array from the color sensor.
|
||||
* @param sensor the color sensor to query the request
|
||||
*/
|
||||
//% help=sensors/color-sensor/rgbraw
|
||||
//% blockId=colorRgbRaw block="**color sensor** %this| RGB raw"
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% this.fieldEditor="ports"
|
||||
//% weight=1
|
||||
//% group="Color Sensor"
|
||||
//% blockGap=8
|
||||
rgbRaw(): number[] {
|
||||
this.setMode(ColorSensorMode.RgbRaw);
|
||||
return [this.getNumber(NumberFormat.UInt16LE, 0), this.getNumber(NumberFormat.UInt16LE, 2), this.getNumber(NumberFormat.UInt16LE, 4)];
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers code to run when the ambient light changes.
|
||||
* @param condition the light condition
|
||||
@ -225,11 +246,16 @@ namespace sensors {
|
||||
//% parts="colorsensor"
|
||||
//% blockNamespace=sensors
|
||||
//% this.fieldEditor="ports"
|
||||
//% weight=87
|
||||
//% weight=87 blockGap=8
|
||||
//% group="Color Sensor"
|
||||
light(mode: LightIntensityMode) {
|
||||
this.setMode(<ColorSensorMode><number>mode)
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
switch(mode) {
|
||||
case LightIntensityMode.ReflectedRaw:
|
||||
return this.reflectedLightRaw();
|
||||
default:
|
||||
return this.getNumber(NumberFormat.UInt8LE, 0)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -248,6 +274,15 @@ namespace sensors {
|
||||
return this.light(LightIntensityMode.Reflected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the raw reflection light value
|
||||
*/
|
||||
//%
|
||||
reflectedLightRaw(): number {
|
||||
this.setMode(ColorSensorMode.RefRaw);
|
||||
return this.getNumber(NumberFormat.UInt16LE, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a threshold value
|
||||
* @param condition the dark or bright light condition
|
||||
@ -297,9 +332,22 @@ namespace sensors {
|
||||
calibrateLight(mode: LightIntensityMode, deviation: number = 8) {
|
||||
this.calibrating = true; // prevent events
|
||||
|
||||
this.light(mode); // trigger a read
|
||||
pauseUntil(() => this.isActive()); // ensure sensor is live
|
||||
const statusLight = brick.statusLight(); // save current status light
|
||||
brick.setStatusLight(StatusLight.Orange);
|
||||
|
||||
this.light(mode); // trigger a read
|
||||
pauseUntil(() => this.isActive(), 5000); // ensure sensor is live
|
||||
|
||||
// check sensor is ready
|
||||
if (!this.isActive()) {
|
||||
brick.setStatusLight(StatusLight.RedFlash); // didn't work
|
||||
pause(2000);
|
||||
brick.setStatusLight(statusLight); // restore previous light
|
||||
return;
|
||||
}
|
||||
|
||||
// calibrating
|
||||
brick.setStatusLight(StatusLight.OrangePulse);
|
||||
|
||||
let vold = 0;
|
||||
let vcount = 0;
|
||||
@ -331,6 +379,10 @@ namespace sensors {
|
||||
this.thresholdDetector.setLowThreshold(min);
|
||||
this.thresholdDetector.setHighThreshold(max);
|
||||
|
||||
brick.setStatusLight(StatusLight.Green); // success
|
||||
pause(1000);
|
||||
brick.setStatusLight(statusLight); // resture previous light
|
||||
|
||||
this.calibrating = false;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,15 @@ Sometimes when external lighting conditions change, the light sensor measures li
|
||||
* **mode**: the type of light threshold to calibrate. This is either ``ambient`` or ``reflected`` light.
|
||||
* **deviation**: a [number](/types/number) that is the amount of light level change to adjust in a measurement.
|
||||
|
||||
## Calibration states
|
||||
|
||||
Calibration happens in the following phases and each phase is tracked by the brick status light.
|
||||
|
||||
* **orange**: sensor initialization. This phase ensures that the sensor is in the desired mode and ready to collect data.
|
||||
* **orange pulse**: data collection. Light information is being collected, move the sensor over the various light sources to detect.
|
||||
* **green**: calibration success. The calibration data has been saved.
|
||||
* **red flash**: sensor failure. We were unable to connect to the sensor.
|
||||
|
||||
## Example
|
||||
|
||||
Calibrate the ``dark`` and ``light`` thresholds for the ``color 2`` sensor using reflected light.
|
||||
@ -23,4 +32,4 @@ sensors.color2.calibrateLight(LightIntensityMode.Reflected)
|
||||
|
||||
## See also
|
||||
|
||||
[set threshold](/reference/sensors/color-sensor/set-threshold)
|
||||
[set threshold](/reference/sensors/color-sensor/set-threshold)
|
||||
|
@ -1,13 +1,40 @@
|
||||
|
||||
const enum BatteryProperty {
|
||||
//% block="level (%)"
|
||||
Level,
|
||||
//% block="current (I)"
|
||||
Current,
|
||||
//% block="voltage (V)"
|
||||
Voltage
|
||||
}
|
||||
|
||||
namespace brick {
|
||||
/**
|
||||
* Returns the current battery level
|
||||
*/
|
||||
//% blockId=brickBatteryLevel block="battery level"
|
||||
//% group="More"
|
||||
//% group="Battery"
|
||||
//% help=brick/battery-level
|
||||
//% deprecated blockHidden=1
|
||||
export function batteryLevel(): number {
|
||||
const info = sensors.internal.getBatteryInfo();
|
||||
return info.current;
|
||||
return info.level;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns information about the battery
|
||||
*/
|
||||
//% blockId=brickBatteryProperty block="battery %property"
|
||||
//% group="Battery"
|
||||
//% help=brick/battery-property
|
||||
export function batteryInfo(property: BatteryProperty): number {
|
||||
const info = sensors.internal.getBatteryInfo();
|
||||
switch(property) {
|
||||
case BatteryProperty.Level: return info.level;
|
||||
case BatteryProperty.Current: return info.Ibatt;
|
||||
case BatteryProperty.Voltage: return info.Vbatt;
|
||||
default: return 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -159,12 +159,6 @@ 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.stopAll(); // ensuring that all motors are off
|
||||
control.reset()
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
@ -247,6 +241,15 @@ namespace brick {
|
||||
// the brick starts with the red color
|
||||
let currPattern: StatusLight = StatusLight.Off;
|
||||
|
||||
/**
|
||||
* Gets the current light pattern.
|
||||
*/
|
||||
//% weight=99 group="Buttons"
|
||||
//% help=brick/status-light
|
||||
export function statusLight() {
|
||||
return currPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set lights.
|
||||
* @param pattern the lights pattern to use. eg: StatusLight.Orange
|
||||
|
@ -25,10 +25,28 @@ namespace sensors.internal {
|
||||
})
|
||||
}
|
||||
|
||||
export function bufferToString(buf: Buffer): string {
|
||||
let s = ''
|
||||
for (let i = 0; i < buf.length; i++)
|
||||
s += String.fromCharCode(buf[i])
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
let analogMM: MMap
|
||||
let uartMM: MMap
|
||||
let IICMM: MMap
|
||||
let powerMM: MMap
|
||||
let devcon: Buffer
|
||||
let sensorInfos: SensorInfo[]
|
||||
let sensorInfos: SensorInfo[];
|
||||
|
||||
let batteryInfo: {
|
||||
CinCnt: number;
|
||||
CoutCnt: number;
|
||||
VinCnt: number;
|
||||
};
|
||||
let batteryVMin: number;
|
||||
let batteryVMax: number;
|
||||
|
||||
class SensorInfo {
|
||||
port: number
|
||||
@ -36,11 +54,13 @@ namespace sensors.internal {
|
||||
sensors: Sensor[]
|
||||
connType: number
|
||||
devType: number
|
||||
iicid: string
|
||||
|
||||
constructor(p: number) {
|
||||
this.port = p
|
||||
this.connType = DAL.CONN_NONE
|
||||
this.devType = DAL.DEVICE_TYPE_NONE
|
||||
this.iicid = ''
|
||||
this.sensors = []
|
||||
}
|
||||
}
|
||||
@ -57,22 +77,25 @@ namespace sensors.internal {
|
||||
uartMM = control.mmap("/dev/lms_uart", UartOff.Size, 0)
|
||||
if (!uartMM) control.fail("no uart sensor")
|
||||
|
||||
forever(() => {
|
||||
detectDevices()
|
||||
pause(500)
|
||||
})
|
||||
IICMM = control.mmap("/dev/lms_iic", IICOff.Size, 0)
|
||||
if (!IICMM) control.fail("no iic sensor")
|
||||
|
||||
for (let info_ of sensorInfos) {
|
||||
let info = info_
|
||||
powerMM = control.mmap("/dev/lms_power", 2, 0)
|
||||
|
||||
unsafePollForChanges(500,
|
||||
() => { return hashDevices(); },
|
||||
(prev, curr) => {
|
||||
detectDevices();
|
||||
});
|
||||
sensorInfos.forEach(info => {
|
||||
unsafePollForChanges(50, () => {
|
||||
if (info.sensor) return info.sensor._query()
|
||||
return 0
|
||||
}, (prev, curr) => {
|
||||
if (info.sensor) info.sensor._update(prev, curr)
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function getActiveSensors(): Sensor[] {
|
||||
init();
|
||||
@ -89,60 +112,216 @@ 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: Math.round(analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.BatteryCurrent) / 10)
|
||||
export function readIICID(port: number) {
|
||||
const buf = output.createBuffer(IICStr.Size)
|
||||
buf[IICStr.Port] = port
|
||||
IICMM.ioctl(IO.IIC_READ_TYPE_INFO, buf)
|
||||
const manufacturer = bufferToString(buf.slice(IICStr.Manufacturer, 8))
|
||||
const sensorType = bufferToString(buf.slice(IICStr.SensorType, 8))
|
||||
return manufacturer + sensorType;
|
||||
}
|
||||
|
||||
const ADC_REF = 5000 //!< [mV] maximal value on ADC
|
||||
const ADC_RES = 4095 //!< [CNT] maximal count on ADC
|
||||
// see c_ui.c
|
||||
const SHUNT_IN = 0.11 // [Ohm]
|
||||
const AMP_CIN = 22.0 // [Times]
|
||||
|
||||
const EP2_SHUNT_IN = 0.05 // [Ohm]
|
||||
const EP2_AMP_CIN = 15.0 // [Times]
|
||||
|
||||
const SHUNT_OUT = 0.055 // [Ohm]
|
||||
const AMP_COUT = 19.0 // [Times]
|
||||
|
||||
const VCE = 0.05 // [V]
|
||||
const AMP_VIN = 0.5 // [Times]
|
||||
|
||||
const AVR_CIN = 300
|
||||
const AVR_COUT = 30
|
||||
const AVR_VIN = 30
|
||||
// lms2012
|
||||
const BATT_INDICATOR_HIGH = 7500 //!< Battery indicator high [mV]
|
||||
const BATT_INDICATOR_LOW = 6200 //!< Battery indicator low [mV]
|
||||
const ACCU_INDICATOR_HIGH = 7500 //!< Rechargeable battery indicator high [mV]
|
||||
const ACCU_INDICATOR_LOW = 7100 //!< Rechargeable battery indicator low [mV]
|
||||
|
||||
function CNT_V(C: number) {
|
||||
return ((C * ADC_REF) / (ADC_RES * 1000.0))
|
||||
}
|
||||
|
||||
function updateBatteryInfo() {
|
||||
let CinCnt = analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.BatteryCurrent);
|
||||
let CoutCnt = analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.MotorCurrent);
|
||||
let VinCnt = analogMM.getNumber(NumberFormat.Int16LE, AnalogOff.Cell123456);
|
||||
if (!batteryInfo) {
|
||||
batteryVMin = BATT_INDICATOR_LOW;
|
||||
batteryVMax = BATT_INDICATOR_HIGH;
|
||||
if (powerMM) {
|
||||
const accu = powerMM.getNumber(NumberFormat.UInt8LE, 0);
|
||||
if (accu > 0) {
|
||||
control.dmesg("rechargeable battery")
|
||||
batteryVMin = ACCU_INDICATOR_LOW;
|
||||
batteryVMax = ACCU_INDICATOR_HIGH;
|
||||
}
|
||||
}
|
||||
batteryInfo = {
|
||||
CinCnt: CinCnt,
|
||||
CoutCnt: CoutCnt,
|
||||
VinCnt: VinCnt
|
||||
};
|
||||
// update in background
|
||||
control.runInParallel(() => forever(updateBatteryInfo));
|
||||
} else {
|
||||
CinCnt = batteryInfo.CinCnt = ((batteryInfo.CinCnt * (AVR_CIN - 1)) + CinCnt) / AVR_CIN;
|
||||
CoutCnt = batteryInfo.CoutCnt = ((batteryInfo.CoutCnt * (AVR_COUT - 1)) + CoutCnt) / AVR_COUT;
|
||||
VinCnt = batteryInfo.VinCnt = ((batteryInfo.VinCnt * (AVR_VIN - 1)) + VinCnt) / AVR_VIN;
|
||||
}
|
||||
}
|
||||
|
||||
function detectDevices() {
|
||||
let conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
||||
let numChanged = 0
|
||||
export function getBatteryInfo(): {
|
||||
level: number;
|
||||
Ibatt: number,
|
||||
Vbatt: number,
|
||||
Imotor: number
|
||||
} {
|
||||
init();
|
||||
if (!batteryInfo) updateBatteryInfo();
|
||||
const CinCnt = batteryInfo.CinCnt;
|
||||
const CoutCnt = batteryInfo.CoutCnt;
|
||||
const VinCnt = batteryInfo.VinCnt;
|
||||
/*
|
||||
void cUiUpdatePower(void)
|
||||
{
|
||||
#ifndef Linux_X86
|
||||
DATAF CinV;
|
||||
DATAF CoutV;
|
||||
|
||||
for (let info of sensorInfos) {
|
||||
let newConn = conns[info.port]
|
||||
if (newConn == info.connType)
|
||||
continue
|
||||
if ((UiInstance.Hw == FINAL) || (UiInstance.Hw == FINALB))
|
||||
{
|
||||
CinV = CNT_V(UiInstance.CinCnt) / AMP_CIN;
|
||||
UiInstance.Vbatt = (CNT_V(UiInstance.VinCnt) / AMP_VIN) + CinV + VCE;
|
||||
|
||||
UiInstance.Ibatt = CinV / SHUNT_IN;
|
||||
CoutV = CNT_V(UiInstance.CoutCnt) / AMP_COUT;
|
||||
UiInstance.Imotor = CoutV / SHUNT_OUT;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
CinV = CNT_V(UiInstance.CinCnt) / EP2_AMP_CIN;
|
||||
UiInstance.Vbatt = (CNT_V(UiInstance.VinCnt) / AMP_VIN) + CinV + VCE;
|
||||
|
||||
UiInstance.Ibatt = CinV / EP2_SHUNT_IN;
|
||||
UiInstance.Imotor = 0;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifdef DEBUG_TEMP_SHUTDOWN
|
||||
|
||||
UiInstance.Vbatt = 7.0;
|
||||
UiInstance.Ibatt = 5.0;
|
||||
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
const CinV = CNT_V(CinCnt) / AMP_CIN;
|
||||
const Vbatt = CNT_V(VinCnt) / AMP_VIN + CinV + VCE;
|
||||
const Ibatt = CinV / SHUNT_IN;
|
||||
const CoutV = CNT_V(CoutCnt) / AMP_COUT;
|
||||
const Imotor = CoutV / SHUNT_OUT;
|
||||
const level = Math.max(0, Math.min(100, Math.floor((Vbatt * 1000.0 - batteryVMin)
|
||||
/ (batteryVMax - batteryVMin) * 100)));
|
||||
|
||||
return {
|
||||
level: level,
|
||||
Vbatt: Vbatt,
|
||||
Ibatt: Ibatt,
|
||||
Imotor: Imotor
|
||||
};
|
||||
}
|
||||
|
||||
function hashDevices(): number {
|
||||
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
||||
let r = 0;
|
||||
for (let i = 0; i < conns.length; ++i) {
|
||||
r = (r << 8 | conns[i]);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
let nonActivated = 0;
|
||||
function detectDevices() {
|
||||
//control.dmesg(`detect devices (${nonActivated} na)`)
|
||||
const conns = analogMM.slice(AnalogOff.InConn, DAL.NUM_INPUTS)
|
||||
let numChanged = 0;
|
||||
const uartSensors: SensorInfo[] = [];
|
||||
|
||||
for (const sensorInfo of sensorInfos) {
|
||||
const newConn = conns[sensorInfo.port]
|
||||
if (newConn == sensorInfo.connType) {
|
||||
// control.dmesg(`connection unchanged ${newConn} at ${sensorInfo.port}`)
|
||||
continue;
|
||||
}
|
||||
numChanged++
|
||||
info.connType = newConn
|
||||
info.devType = DAL.DEVICE_TYPE_NONE
|
||||
sensorInfo.connType = newConn
|
||||
sensorInfo.devType = DAL.DEVICE_TYPE_NONE
|
||||
if (newConn == DAL.CONN_INPUT_UART) {
|
||||
control.dmesg(`new UART connection at ${info.port}`)
|
||||
setUartMode(info.port, 0)
|
||||
let uinfo = readUartInfo(info.port, 0)
|
||||
info.devType = uinfo[TypesOff.Type]
|
||||
control.dmesg(`UART type ${info.devType}`)
|
||||
control.dmesg(`new UART connection at ${sensorInfo.port}`)
|
||||
updateUartMode(sensorInfo.port, 0);
|
||||
uartSensors.push(sensorInfo);
|
||||
} else if (newConn == DAL.CONN_NXT_IIC) {
|
||||
control.dmesg(`new IIC connection at ${sensorInfo.port}`)
|
||||
sensorInfo.devType = DAL.DEVICE_TYPE_IIC_UNKNOWN
|
||||
sensorInfo.iicid = readIICID(sensorInfo.port)
|
||||
control.dmesg(`IIC ID ${sensorInfo.iicid.length}`)
|
||||
} else if (newConn == DAL.CONN_INPUT_DUMB) {
|
||||
control.dmesg(`new DUMB connection at ${info.port}`)
|
||||
control.dmesg(`new DUMB connection at ${sensorInfo.port}`)
|
||||
// TODO? for now assume touch
|
||||
info.devType = DAL.DEVICE_TYPE_TOUCH
|
||||
sensorInfo.devType = DAL.DEVICE_TYPE_TOUCH
|
||||
} else if (newConn == DAL.CONN_NONE || newConn == 0) {
|
||||
control.dmesg(`disconnect at ${info.port}`)
|
||||
control.dmesg(`disconnect at port ${sensorInfo.port}`)
|
||||
} else {
|
||||
control.dmesg(`unknown connection type: ${newConn} at ${info.port}`)
|
||||
control.dmesg(`unknown connection type: ${newConn} at ${sensorInfo.port}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (numChanged == 0)
|
||||
if (uartSensors.length > 0) {
|
||||
setUartModes();
|
||||
for (const sensorInfo of uartSensors) {
|
||||
let uinfo = readUartInfo(sensorInfo.port, 0)
|
||||
sensorInfo.devType = uinfo[TypesOff.Type]
|
||||
control.dmesg(`UART type ${sensorInfo.devType}`)
|
||||
}
|
||||
}
|
||||
|
||||
if (numChanged == 0 && nonActivated == 0)
|
||||
return
|
||||
|
||||
for (let si of sensorInfos) {
|
||||
if (si.sensor && si.sensor._deviceType() != si.devType) {
|
||||
si.sensor = null
|
||||
}
|
||||
if (si.devType != DAL.DEVICE_TYPE_NONE) {
|
||||
// TODO figure out compiler problem when '|| null' is added here!
|
||||
si.sensor = si.sensors.filter(s => s._deviceType() == si.devType)[0]
|
||||
if (si.sensor == null) {
|
||||
control.dmesg(`sensor not found for type=${si.devType} at ${si.port}`)
|
||||
control.dmesg(`updating sensor status`)
|
||||
nonActivated = 0;
|
||||
for (const sensorInfo of sensorInfos) {
|
||||
if (sensorInfo.devType == DAL.DEVICE_TYPE_IIC_UNKNOWN) {
|
||||
sensorInfo.sensor = sensorInfo.sensors.filter(s => s._IICId() == sensorInfo.iicid)[0]
|
||||
if (!sensorInfo.sensor) {
|
||||
control.dmesg(`sensor not found for iicid=${sensorInfo.iicid} at ${sensorInfo.port}`)
|
||||
nonActivated++;
|
||||
} else {
|
||||
control.dmesg(`sensor connected type=${si.devType} at ${si.port}`)
|
||||
si.sensor._activated()
|
||||
control.dmesg(`sensor connected iicid=${sensorInfo.iicid} at ${sensorInfo.port}`)
|
||||
sensorInfo.sensor._activated()
|
||||
}
|
||||
} else if (sensorInfo.devType != DAL.DEVICE_TYPE_NONE) {
|
||||
sensorInfo.sensor = sensorInfo.sensors.filter(s => s._deviceType() == sensorInfo.devType)[0]
|
||||
if (!sensorInfo.sensor) {
|
||||
control.dmesg(`sensor not found for type=${sensorInfo.devType} at ${sensorInfo.port}`)
|
||||
nonActivated++;
|
||||
} else {
|
||||
control.dmesg(`sensor connected type=${sensorInfo.devType} at ${sensorInfo.port}`)
|
||||
sensorInfo.sensor._activated()
|
||||
}
|
||||
}
|
||||
}
|
||||
//control.dmesg(`detect devices done`)
|
||||
}
|
||||
|
||||
export class Sensor extends control.Component {
|
||||
@ -187,6 +366,10 @@ namespace sensors.internal {
|
||||
_deviceType() {
|
||||
return 0
|
||||
}
|
||||
|
||||
_IICId() {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export class AnalogSensor extends Sensor {
|
||||
@ -207,12 +390,11 @@ namespace sensors.internal {
|
||||
constructor(port: number) {
|
||||
super(port)
|
||||
this.mode = 0
|
||||
this.realmode = -1
|
||||
this.realmode = 0
|
||||
}
|
||||
|
||||
_activated() {
|
||||
this.realmode = 0
|
||||
// uartReset(this.port) // TODO is it ever needed?
|
||||
this._setMode(this.mode)
|
||||
}
|
||||
|
||||
@ -243,6 +425,55 @@ namespace sensors.internal {
|
||||
}
|
||||
}
|
||||
|
||||
export class IICSensor extends Sensor {
|
||||
protected mode: number // the mode user asked for
|
||||
protected realmode: number // the mode the hardware is in
|
||||
private readLength: number
|
||||
|
||||
constructor(port: number) {
|
||||
super(port)
|
||||
this.mode = 0
|
||||
this.realmode = 0
|
||||
this.readLength = 1;
|
||||
}
|
||||
|
||||
_activated() {
|
||||
this.realmode = 0
|
||||
this._setMode(this.mode)
|
||||
}
|
||||
|
||||
protected _setMode(m: number) {
|
||||
let v = m | 0
|
||||
this.mode = v
|
||||
if (!this.isActive()) return
|
||||
if (this.realmode != this.mode) {
|
||||
this.realmode = v
|
||||
setIICMode(this._port, this._deviceType(), v)
|
||||
}
|
||||
}
|
||||
|
||||
getBytes(): Buffer {
|
||||
return getIICBytes(this.isActive() ? this._port : -1, this.readLength)
|
||||
}
|
||||
|
||||
getNumber(fmt: NumberFormat, off: number) {
|
||||
if (!this.isActive())
|
||||
return 0
|
||||
return getIICNumber(this.readLength, fmt, off, this._port)
|
||||
}
|
||||
|
||||
transaction(deviceAddress: number, write: number[], read: number) {
|
||||
this.readLength = read;
|
||||
transactionIIC(this._port, deviceAddress, write, read)
|
||||
}
|
||||
|
||||
_deviceType() {
|
||||
return DAL.DEVICE_TYPE_IIC_UNKNOWN
|
||||
}
|
||||
}
|
||||
|
||||
export const iicsensor = new IICSensor(3)
|
||||
|
||||
function uartReset(port: number) {
|
||||
if (port < 0) return
|
||||
control.dmesg(`UART reset at ${port}`)
|
||||
@ -267,6 +498,7 @@ namespace sensors.internal {
|
||||
}
|
||||
|
||||
function uartClearChange(port: number) {
|
||||
control.dmesg(`UART clear change`);
|
||||
const UART_DATA_READY = 8
|
||||
const UART_PORT_CHANGED = 1
|
||||
while (true) {
|
||||
@ -288,20 +520,43 @@ namespace sensors.internal {
|
||||
}
|
||||
}
|
||||
|
||||
function setUartModes() {
|
||||
control.dmesg(`UART set modes`)
|
||||
uartMM.ioctl(IO.UART_SET_CONN, devcon)
|
||||
const ports: number[] = [];
|
||||
for (let port = 0; port < DAL.NUM_INPUTS; ++port) {
|
||||
if (devcon.getNumber(NumberFormat.Int8LE, DevConOff.Connection + port) == DAL.CONN_INPUT_UART) {
|
||||
ports.push(port);
|
||||
}
|
||||
}
|
||||
|
||||
while (ports.length) {
|
||||
const port = ports.pop();
|
||||
const status = waitNonZeroUartStatus(port)
|
||||
control.dmesg(`UART set mode ${status} at ${port}`);
|
||||
}
|
||||
}
|
||||
|
||||
function updateUartMode(port: number, mode: number) {
|
||||
control.dmesg(`UART set mode to ${mode} at ${port}`)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_INPUT_UART)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 33)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
||||
}
|
||||
|
||||
function setUartMode(port: number, mode: number) {
|
||||
const UART_PORT_CHANGED = 1
|
||||
while (true) {
|
||||
if (port < 0) return
|
||||
control.dmesg(`UART set mode to ${mode} at ${port}`)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_INPUT_UART)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, 33)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
||||
updateUartMode(port, mode);
|
||||
uartMM.ioctl(IO.UART_SET_CONN, devcon)
|
||||
let status = waitNonZeroUartStatus(port)
|
||||
if (status & UART_PORT_CHANGED) {
|
||||
control.dmesg(`UART clear changed at ${port}`)
|
||||
uartClearChange(port)
|
||||
} else {
|
||||
break
|
||||
control.dmesg(`UART status ${status}`);
|
||||
break;
|
||||
}
|
||||
pause(10)
|
||||
}
|
||||
@ -322,6 +577,48 @@ namespace sensors.internal {
|
||||
UartOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index + off)
|
||||
}
|
||||
|
||||
export function setIICMode(port: number, type: number, mode: number) {
|
||||
if (port < 0) return;
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Connection + port, DAL.CONN_NXT_IIC)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Type + port, type)
|
||||
devcon.setNumber(NumberFormat.Int8LE, DevConOff.Mode + port, mode)
|
||||
IICMM.ioctl(IO.IIC_SET_CONN, devcon)
|
||||
}
|
||||
|
||||
export function transactionIIC(port: number, deviceAddress: number, writeBuf: number[], readLen: number) {
|
||||
if (port < 0) return;
|
||||
let iicdata = output.createBuffer(IICDat.Size)
|
||||
iicdata.setNumber(NumberFormat.Int8LE, IICDat.Port, port)
|
||||
iicdata.setNumber(NumberFormat.Int8LE, IICDat.Repeat, 0)
|
||||
iicdata.setNumber(NumberFormat.Int16LE, IICDat.Time, 0)
|
||||
iicdata.setNumber(NumberFormat.Int8LE, IICDat.WrLng, writeBuf.length + 1)
|
||||
for (let i = 0; i < writeBuf.length; i++)
|
||||
iicdata.setNumber(NumberFormat.Int8LE, IICDat.WrData + i + 1, writeBuf[i])
|
||||
iicdata.setNumber(NumberFormat.Int8LE, IICDat.WrData, deviceAddress)
|
||||
iicdata.setNumber(NumberFormat.Int8LE, IICDat.RdLng, readLen)
|
||||
IICMM.ioctl(IO.IIC_SETUP, iicdata)
|
||||
}
|
||||
|
||||
export function getIICBytes(port: number, length: number) {
|
||||
if (port < 0) return output.createBuffer(length);
|
||||
let index = IICMM.getNumber(NumberFormat.UInt16LE, IICOff.Actual + port * 2);
|
||||
let buf = IICMM.slice(
|
||||
IICOff.Raw + DAL.MAX_DEVICE_DATALENGTH * 300 * port + DAL.MAX_DEVICE_DATALENGTH * index,
|
||||
length
|
||||
);
|
||||
|
||||
// Reverse
|
||||
for (let i = 0; i < length / 2; i++) {
|
||||
let c = buf[i]
|
||||
buf[i] = buf[length - i - 1]
|
||||
buf[length - i - 1] = c
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
export function getIICNumber(length: number, format: NumberFormat, off: number, port: number) {
|
||||
return getIICBytes(port, length).getNumber(format, off)
|
||||
}
|
||||
|
||||
const enum NxtColOff {
|
||||
Calibration = 0, // uint32[4][3]
|
||||
@ -405,6 +702,52 @@ namespace sensors.internal {
|
||||
Size = 58
|
||||
}
|
||||
|
||||
const enum IICOff {
|
||||
TypeData = 0, // Types[8][4]
|
||||
Repeat = 1792, // uint16[300][4]
|
||||
Raw = 4192, // int8[32][300][4]
|
||||
Actual = 42592, // uint16[4]
|
||||
LogIn = 42600, // uint16[4]
|
||||
Status = 42608, // int8[4]
|
||||
Output = 42612, // int8[32][4]
|
||||
OutputLength = 42740, // int8[4]
|
||||
Size = 42744
|
||||
}
|
||||
|
||||
const enum IICCtlOff {
|
||||
TypeData = 0, // Types
|
||||
Port = 56, // int8
|
||||
Mode = 57, // int8
|
||||
Size = 58
|
||||
}
|
||||
|
||||
const enum IICDat {
|
||||
Result = 0, // result
|
||||
Port = 4, // int8
|
||||
Repeat = 5, // int8
|
||||
Time = 6, // int16
|
||||
WrLng = 8, // int8
|
||||
WrData = 9, // int8[32]
|
||||
RdLng = 41, // int8
|
||||
RdData = 42, //int8[32]
|
||||
Size = 74,
|
||||
}
|
||||
|
||||
const enum IICStr {
|
||||
Port = 0, // int8
|
||||
Time = 2, // int16
|
||||
Type = 4, // int8
|
||||
Mode = 5, // int8
|
||||
Manufacturer = 6, // int8[9]
|
||||
SensorType = 15, // int[9]
|
||||
SetupLng = 24, // int8
|
||||
SetupString = 28, // ulong
|
||||
PollLng = 32, // int8
|
||||
PollString = 36, // ulong
|
||||
ReadLng = 40, // int8
|
||||
Size = 44
|
||||
}
|
||||
|
||||
const enum IO {
|
||||
UART_SET_CONN = 0xc00c7500,
|
||||
UART_READ_MODE_INFO = 0xc03c7501,
|
||||
@ -472,7 +815,7 @@ namespace sensors {
|
||||
}
|
||||
|
||||
public threshold(t: ThresholdState): number {
|
||||
switch(t) {
|
||||
switch (t) {
|
||||
case ThresholdState.High: return this.highThreshold;
|
||||
case ThresholdState.Low: return this.lowThreshold;
|
||||
default: return (this.max - this.min) / 2;
|
||||
@ -512,5 +855,5 @@ namespace sensors {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,9 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <malloc.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "ev3const.h"
|
||||
|
||||
#define THREAD_DBG(...)
|
||||
|
||||
@ -144,6 +147,29 @@ static void startUsb() {
|
||||
pthread_detach(pid);
|
||||
}
|
||||
|
||||
static void *exitThread(void *) {
|
||||
int fd = open("/dev/lms_ui", O_RDWR, 0666);
|
||||
if (fd < 0)
|
||||
return 0;
|
||||
uint8_t *data =
|
||||
(uint8_t *)mmap(NULL, NUM_BUTTONS, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
if (data == MAP_FAILED) {
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
for (;;) {
|
||||
if (data[5])
|
||||
target_reset();
|
||||
sleep_core_us(50000);
|
||||
}
|
||||
}
|
||||
|
||||
static void startExitThread() {
|
||||
pthread_t pid;
|
||||
pthread_create(&pid, NULL, exitThread, NULL);
|
||||
pthread_detach(pid);
|
||||
}
|
||||
|
||||
void sendUsb(uint16_t code, const char *data, int len) {
|
||||
while (len > 0) {
|
||||
int sz = len;
|
||||
@ -489,14 +515,22 @@ void runLMS() {
|
||||
}
|
||||
|
||||
void stopMotors() {
|
||||
uint8_t cmd[2] = { 0xA3, 0x0F };
|
||||
uint8_t cmd[3] = {opOutputStop, 0x0F, 0};
|
||||
int fd = open("/dev/lms_pwm", O_RDWR);
|
||||
write(fd, cmd, 2);
|
||||
write(fd, cmd, 3);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
void stopProgram() {
|
||||
uint8_t cmd[1] = {opOutputProgramStop};
|
||||
int fd = open("/dev/lms_pwm", O_RDWR);
|
||||
write(fd, cmd, 1);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
extern "C" void target_reset() {
|
||||
stopMotors();
|
||||
stopProgram();
|
||||
if (lmsPid)
|
||||
runLMS();
|
||||
else
|
||||
@ -510,6 +544,7 @@ void initRuntime() {
|
||||
DMESG("runtime starting...");
|
||||
stopLMS();
|
||||
startUsb();
|
||||
startExitThread();
|
||||
pthread_t disp;
|
||||
pthread_create(&disp, NULL, evtDispatcher, NULL);
|
||||
pthread_detach(disp);
|
||||
|
@ -36,6 +36,13 @@ enum MoveUnit {
|
||||
MilliSeconds
|
||||
}
|
||||
|
||||
enum MovePhase {
|
||||
//% block="acceleration"
|
||||
Acceleration,
|
||||
//% block="deceleration"
|
||||
Deceleration
|
||||
}
|
||||
|
||||
namespace motors {
|
||||
let pwmMM: MMap
|
||||
let motorMM: MMap
|
||||
@ -116,7 +123,8 @@ namespace motors {
|
||||
//% help=motors/stop-all
|
||||
export function stopAll() {
|
||||
const b = mkCmd(Output.ALL, DAL.opOutputStop, 0)
|
||||
writePWM(b)
|
||||
writePWM(b);
|
||||
pause(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -125,6 +133,13 @@ namespace motors {
|
||||
//% group="Move"
|
||||
export function resetAllMotors() {
|
||||
reset(Output.ALL)
|
||||
pause(1);
|
||||
}
|
||||
|
||||
interface MoveSchedule {
|
||||
speed: number;
|
||||
useSteps: boolean;
|
||||
steps: number[];
|
||||
}
|
||||
|
||||
//% fixedInstances
|
||||
@ -132,22 +147,32 @@ namespace motors {
|
||||
protected _port: Output;
|
||||
protected _portName: string;
|
||||
protected _brake: boolean;
|
||||
protected _regulated: boolean;
|
||||
private _pauseOnRun: boolean;
|
||||
private _initialized: boolean;
|
||||
private _brakeSettleTime: number;
|
||||
private _init: () => void;
|
||||
private _run: (speed: number) => void;
|
||||
private _move: (steps: boolean, stepsOrTime: number, speed: number) => void;
|
||||
private _accelerationSteps: number;
|
||||
private _accelerationTime: number;
|
||||
private _decelerationSteps: number;
|
||||
private _decelerationTime: number;
|
||||
|
||||
constructor(port: Output, init: () => void, run: (speed: number) => void, move: (steps: boolean, stepsOrTime: number, speed: number) => void) {
|
||||
protected static output_types: number[] = [0x7, 0x7, 0x7, 0x7];
|
||||
|
||||
constructor(port: Output, init: () => void) {
|
||||
super();
|
||||
this._port = port;
|
||||
this._portName = outputToName(this._port);
|
||||
this._brake = false;
|
||||
this._regulated = true;
|
||||
this._pauseOnRun = true;
|
||||
this._initialized = false;
|
||||
this._brakeSettleTime = 10;
|
||||
this._init = init;
|
||||
this._run = run;
|
||||
this._move = move;
|
||||
this._accelerationSteps = 0;
|
||||
this._accelerationTime = 0;
|
||||
this._decelerationSteps = 0;
|
||||
this._decelerationTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -202,6 +227,21 @@ namespace motors {
|
||||
writePWM(b)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the settle time after braking in milliseconds (default is 10ms).
|
||||
*/
|
||||
//% blockId=motorSetBrakeSettleTime block="set %motor|brake settle time %millis|ms"
|
||||
//% motor.fieldEditor="motors"
|
||||
//% weight=1 blockGap=8
|
||||
//% group="Properties"
|
||||
//% millis.defl=200 millis.min=0 millis.max=500
|
||||
//% help=motors/motor/set-brake-settle-time
|
||||
setBrakeSettleTime(millis: number) {
|
||||
this.init();
|
||||
// ensure in [0,500]
|
||||
this._brakeSettleTime = Math.max(0, Math.min(500, millis | 0))
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the motor(s).
|
||||
*/
|
||||
@ -219,8 +259,10 @@ namespace motors {
|
||||
protected settle() {
|
||||
// if we've recently completed a motor command with brake
|
||||
// allow 500ms for robot to settle
|
||||
if (this._brake)
|
||||
pause(500);
|
||||
if (this._brake && this._brakeSettleTime > 0)
|
||||
pause(this._brakeSettleTime);
|
||||
else
|
||||
pause(1); // give a tiny breather
|
||||
}
|
||||
|
||||
protected pauseOnRun(stepsOrTime: number) {
|
||||
@ -229,6 +271,9 @@ namespace motors {
|
||||
this.pauseUntilReady();
|
||||
// allow robot to settle
|
||||
this.settle();
|
||||
} else {
|
||||
// give a breather to the event system in tight loops
|
||||
pause(1);
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,6 +290,34 @@ namespace motors {
|
||||
reset(this._port);
|
||||
}
|
||||
|
||||
private normalizeSchedule(speed: number, step1: number, step2: number, step3: number, unit: MoveUnit): MoveSchedule {
|
||||
const r: MoveSchedule = {
|
||||
speed: Math.clamp(-100, 100, speed >> 0),
|
||||
useSteps: true,
|
||||
steps: [step1 || 0, step2 || 0, step3 || 0]
|
||||
}
|
||||
let scale = 1;
|
||||
switch (unit) {
|
||||
case MoveUnit.Rotations:
|
||||
scale = 360;
|
||||
r.useSteps = true;
|
||||
break;
|
||||
case MoveUnit.Degrees:
|
||||
r.useSteps = true;
|
||||
break;
|
||||
case MoveUnit.Seconds:
|
||||
scale = 1000;
|
||||
r.useSteps = false;
|
||||
break;
|
||||
default:
|
||||
r.useSteps = false;
|
||||
break;
|
||||
}
|
||||
for (let i = 0; i < r.steps.length; ++i)
|
||||
r.steps[i] = Math.max(0, (r.steps[i] * scale) | 0);
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
@ -259,41 +332,156 @@ namespace motors {
|
||||
//% help=motors/motor/run
|
||||
run(speed: number, value: number = 0, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
this.init();
|
||||
speed = Math.clamp(-100, 100, speed >> 0);
|
||||
const schedule = this.normalizeSchedule(speed, 0, value, 0, unit);
|
||||
// stop if speed is 0
|
||||
if (!speed) {
|
||||
if (!schedule.speed) {
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
// special: 0 is infinity
|
||||
if (value == 0) {
|
||||
this._run(speed);
|
||||
if (schedule.steps[0] + schedule.steps[1] + schedule.steps[2] == 0) {
|
||||
this._run(schedule.speed);
|
||||
pause(1);
|
||||
return;
|
||||
}
|
||||
|
||||
// timed motor moves
|
||||
const steps = schedule.steps;
|
||||
const useSteps = schedule.useSteps;
|
||||
|
||||
// compute ramp up and down
|
||||
steps[0] = (useSteps ? this._accelerationSteps : this._accelerationTime) || 0;
|
||||
steps[2] = (useSteps ? this._decelerationSteps : this._decelerationTime) || 0;
|
||||
if (steps[0] + steps[2] > steps[1]) {
|
||||
// rescale
|
||||
const r = steps[1] / (steps[0] + steps[2]);
|
||||
steps[0] = Math.floor(steps[0] * r);
|
||||
steps[2] *= Math.floor(steps[2] * r);
|
||||
}
|
||||
steps[1] -= (steps[0] + steps[2]);
|
||||
|
||||
// send ramped command
|
||||
this._schedule(schedule);
|
||||
this.pauseOnRun(steps[0] + steps[1] + steps[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a run of the motor with an acceleration, constant and deceleration phase.
|
||||
* @param speed the speed from ``100`` full forward to ``-100`` full backward, eg: 50
|
||||
* @param value measured distance or rotation, eg: 500
|
||||
* @param unit (optional) unit of the value, eg: MoveUnit.MilliSeconds
|
||||
* @param acceleration acceleration phase measured distance or rotation, eg: 500
|
||||
* @param deceleration deceleration phase measured distance or rotation, eg: 500
|
||||
*/
|
||||
//% blockId=motorSchedule block="ramp %motor at %speed=motorSpeedPicker|\\%|for %value|%unit||accelerate %acceleration|decelerate %deceleration"
|
||||
//% weight=99 blockGap=8
|
||||
//% group="Move"
|
||||
//% motor.fieldEditor="motors"
|
||||
//% help=motors/motor/ramp
|
||||
//% inlineInputMode=inline
|
||||
//% expandableArgumentMode=toggle
|
||||
//% value.defl=500
|
||||
ramp(speed: number, value: number = 500, unit: MoveUnit = MoveUnit.MilliSeconds, acceleration?: number, deceleration?: number) {
|
||||
this.init();
|
||||
const schedule = this.normalizeSchedule(speed, acceleration, value, deceleration, unit);
|
||||
// stop if speed is 0
|
||||
if (!schedule.speed) {
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
// special case: do nothing
|
||||
if (schedule.steps[0] + schedule.steps[1] + schedule.steps[2] == 0) {
|
||||
return;
|
||||
}
|
||||
// timed motor moves
|
||||
let useSteps: boolean;
|
||||
let stepsOrTime: number;
|
||||
const steps = schedule.steps;
|
||||
// send ramped command
|
||||
this._schedule(schedule);
|
||||
this.pauseOnRun(steps[0] + steps[1] + steps[2]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the amount of rotation or time for the acceleration
|
||||
* of run commands.
|
||||
*/
|
||||
//% blockId=outputMotorsetRunRamp block="set %motor|run %ramp to $value||$unit"
|
||||
//% motor.fieldEditor="motors"
|
||||
//% weight=21 blockGap=8
|
||||
//% group="Properties"
|
||||
//% help=motors/motor/set-run-phase
|
||||
setRunPhase(phase: MovePhase, value: number, unit: MoveUnit = MoveUnit.MilliSeconds) {
|
||||
let temp: number;
|
||||
switch (unit) {
|
||||
case MoveUnit.Rotations:
|
||||
stepsOrTime = (value * 360) >> 0;
|
||||
useSteps = true;
|
||||
temp = Math.max(0, (value * 360) | 0);
|
||||
if (phase == MovePhase.Acceleration)
|
||||
this._accelerationSteps = temp;
|
||||
else
|
||||
this._decelerationSteps = temp;
|
||||
break;
|
||||
case MoveUnit.Degrees:
|
||||
stepsOrTime = value >> 0;
|
||||
useSteps = true;
|
||||
temp = Math.max(0, value | 0);
|
||||
if (phase == MovePhase.Acceleration)
|
||||
this._accelerationSteps = temp;
|
||||
else
|
||||
this._decelerationSteps = temp;
|
||||
break;
|
||||
case MoveUnit.Seconds:
|
||||
stepsOrTime = (value * 1000) >> 0;
|
||||
useSteps = false;
|
||||
temp = Math.max(0, (value * 1000) | 0);
|
||||
if (phase == MovePhase.Acceleration)
|
||||
this._accelerationTime = temp;
|
||||
else
|
||||
this._decelerationTime = temp;
|
||||
break;
|
||||
default:
|
||||
stepsOrTime = value;
|
||||
useSteps = false;
|
||||
case MoveUnit.MilliSeconds:
|
||||
temp = Math.max(0, value | 0);
|
||||
if (phase == MovePhase.Acceleration)
|
||||
this._accelerationTime = temp;
|
||||
else
|
||||
this._decelerationTime = temp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this._move(useSteps, stepsOrTime, speed);
|
||||
this.pauseOnRun(stepsOrTime);
|
||||
private _run(speed: number) {
|
||||
// ramp up acceleration
|
||||
if (this._accelerationTime) {
|
||||
this._schedule({ speed: speed, useSteps: false, steps: [this._accelerationTime, 100, 0] });
|
||||
pause(this._accelerationTime);
|
||||
}
|
||||
// keep going
|
||||
const b = mkCmd(this._port, this._regulated ? DAL.opOutputSpeed : DAL.opOutputPower, 1)
|
||||
b.setNumber(NumberFormat.Int8LE, 2, speed)
|
||||
writePWM(b)
|
||||
if (speed) {
|
||||
writePWM(mkCmd(this._port, DAL.opOutputStart, 0))
|
||||
}
|
||||
}
|
||||
|
||||
private _schedule(schedule: MoveSchedule) {
|
||||
const p = {
|
||||
useSteps: schedule.useSteps,
|
||||
step1: schedule.steps[0],
|
||||
step2: schedule.steps[1],
|
||||
step3: schedule.steps[2],
|
||||
speed: this._regulated ? schedule.speed : undefined,
|
||||
power: this._regulated ? undefined : schedule.speed,
|
||||
useBrake: this._brake
|
||||
};
|
||||
step(this._port, p)
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the motor(s) speed should be regulated. Default is true.
|
||||
* @param value true for regulated motor
|
||||
*/
|
||||
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
|
||||
//% motor.fieldEditor="motors"
|
||||
//% weight=58 blockGap=8
|
||||
//% group="Properties"
|
||||
//% help=motors/motor/set-regulated
|
||||
setRegulated(value: boolean) {
|
||||
this._regulated = value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -320,33 +508,40 @@ namespace motors {
|
||||
pauseUntil(() => this.isReady(), timeOut);
|
||||
}
|
||||
|
||||
setRunSmoothness(accelerationPercent: number, decelerationPercent: number) {
|
||||
|
||||
}
|
||||
|
||||
protected setOutputType(large: boolean) {
|
||||
/*
|
||||
Instruction opOutput_Set_Type (LAYER, NO, TYPE)
|
||||
Opcode 0xA1 Arguments (Data8) LAYER – Specify chain layer number [0 - 3]
|
||||
(Data8) NO – Port number [0 - 3]
|
||||
(Data8) TYPE – Output device type, (0x07: Large motor, Medium motor = 0x08) Dispatch status Unchanged
|
||||
Description This function enables specifying the output device type
|
||||
*/
|
||||
for (let i = 0; i < DAL.NUM_OUTPUTS; ++i) {
|
||||
if (this._port & (1 << i)) {
|
||||
const b = mkCmd(i, DAL.opOutputSetType, 1)
|
||||
b.setNumber(NumberFormat.Int8LE, 2, large ? 0x07 : 0x08)
|
||||
writePWM(b)
|
||||
// (0x07: Large motor, Medium motor = 0x08)
|
||||
MotorBase.output_types[i] = large ? 0x07 : 0x08;
|
||||
}
|
||||
}
|
||||
MotorBase.setTypes();
|
||||
}
|
||||
|
||||
// Note, we are having to create our own buffer here as mkCmd creates a buffer with a command
|
||||
// In the case of opOutputSetType, it expects the arguments to be opOutputSetType [type0, type1, type2, type3]
|
||||
static setTypes() {
|
||||
const b = output.createBuffer(5)
|
||||
b.setNumber(NumberFormat.UInt8LE, 0, DAL.opOutputSetType)
|
||||
b.setNumber(NumberFormat.Int8LE, 1, MotorBase.output_types[0]);
|
||||
b.setNumber(NumberFormat.Int8LE, 2, MotorBase.output_types[1]);
|
||||
b.setNumber(NumberFormat.Int8LE, 3, MotorBase.output_types[2]);
|
||||
b.setNumber(NumberFormat.Int8LE, 4, MotorBase.output_types[3]);
|
||||
writePWM(b)
|
||||
}
|
||||
}
|
||||
|
||||
//% fixedInstances
|
||||
export class Motor extends MotorBase {
|
||||
private _large: boolean;
|
||||
private _regulated: boolean;
|
||||
|
||||
constructor(port: Output, large: boolean) {
|
||||
super(port, () => this.__init(), (speed) => this.__setSpeed(speed), (steps, stepsOrTime, speed) => this.__move(steps, stepsOrTime, speed));
|
||||
super(port, () => this.__init());
|
||||
this._large = large;
|
||||
this._regulated = true;
|
||||
this.markUsed();
|
||||
}
|
||||
|
||||
@ -358,40 +553,6 @@ namespace motors {
|
||||
this.setOutputType(this._large);
|
||||
}
|
||||
|
||||
private __setSpeed(speed: number) {
|
||||
const b = mkCmd(this._port, this._regulated ? DAL.opOutputSpeed : DAL.opOutputPower, 1)
|
||||
b.setNumber(NumberFormat.Int8LE, 2, speed)
|
||||
writePWM(b)
|
||||
if (speed) {
|
||||
writePWM(mkCmd(this._port, DAL.opOutputStart, 0))
|
||||
}
|
||||
}
|
||||
|
||||
private __move(steps: boolean, stepsOrTime: number, speed: number) {
|
||||
step(this._port, {
|
||||
useSteps: steps,
|
||||
step1: 0,
|
||||
step2: stepsOrTime,
|
||||
step3: 0,
|
||||
speed: this._regulated ? speed : undefined,
|
||||
power: this._regulated ? undefined : speed,
|
||||
useBrake: this._brake
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the motor speed should be regulated. Default is true.
|
||||
* @param value true for regulated motor
|
||||
*/
|
||||
//% blockId=outputMotorSetRegulated block="set %motor|regulated %value=toggleOnOff"
|
||||
//% motor.fieldEditor="motors"
|
||||
//% weight=58
|
||||
//% group="Properties"
|
||||
//% help=motors/motor/set-regulated
|
||||
setRegulated(value: boolean) {
|
||||
this._regulated = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets motor actual speed.
|
||||
* @param motor the port which connects to the motor
|
||||
@ -479,7 +640,7 @@ namespace motors {
|
||||
export class SynchedMotorPair extends MotorBase {
|
||||
|
||||
constructor(ports: Output) {
|
||||
super(ports, () => this.__init(), (speed) => this.__setSpeed(speed), (steps, stepsOrTime, speed) => this.__move(steps, stepsOrTime, speed));
|
||||
super(ports, () => this.__init());
|
||||
this.markUsed();
|
||||
}
|
||||
|
||||
@ -491,24 +652,6 @@ namespace motors {
|
||||
this.setOutputType(true);
|
||||
}
|
||||
|
||||
private __setSpeed(speed: number) {
|
||||
syncMotors(this._port, {
|
||||
speed: speed,
|
||||
turnRatio: 0, // same speed
|
||||
useBrake: !!this._brake
|
||||
})
|
||||
}
|
||||
|
||||
private __move(steps: boolean, stepsOrTime: number, speed: number) {
|
||||
syncMotors(this._port, {
|
||||
useSteps: steps,
|
||||
speed: 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,
|
||||
@ -534,10 +677,12 @@ namespace motors {
|
||||
speedRight = Math.clamp(-100, 100, speedRight >> 0);
|
||||
|
||||
const speed = Math.abs(speedLeft) > Math.abs(speedRight) ? speedLeft : speedRight;
|
||||
const turnRatio = speedLeft == speed
|
||||
? (100 - speedRight / speedLeft * 100)
|
||||
: (speedLeft / speedRight * 100 - 100);
|
||||
let turnRatio = speedLeft == speed
|
||||
? speedLeft == 0 ? 0 : (100 - speedRight / speedLeft * 100)
|
||||
: speedRight == 0 ? 0 : (speedLeft / speedRight * 100 - 100);
|
||||
turnRatio = Math.floor(turnRatio);
|
||||
|
||||
//control.dmesg(`tank ${speedLeft} ${speedRight} => ${turnRatio} ${speed}`)
|
||||
this.steer(turnRatio, speed, value, unit);
|
||||
}
|
||||
|
||||
@ -560,7 +705,7 @@ namespace motors {
|
||||
this.init();
|
||||
speed = Math.clamp(-100, 100, speed >> 0);
|
||||
if (!speed) {
|
||||
stop(this._port, this._brake);
|
||||
this.stop();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -706,35 +851,24 @@ namespace motors {
|
||||
}
|
||||
|
||||
function step(out: Output, opts: StepOptions) {
|
||||
control.dmesg('step')
|
||||
let op = opts.useSteps ? DAL.opOutputStepSpeed : DAL.opOutputTimeSpeed
|
||||
let speed = opts.speed
|
||||
if (speed == null) {
|
||||
if (undefined == speed) {
|
||||
speed = opts.power
|
||||
op = opts.useSteps ? DAL.opOutputStepPower : DAL.opOutputTimePower
|
||||
if (speed == null)
|
||||
if (undefined == speed)
|
||||
return
|
||||
}
|
||||
speed = Math.clamp(-100, 100, speed)
|
||||
|
||||
let b = mkCmd(out, op, 15)
|
||||
b.setNumber(NumberFormat.Int8LE, 2, speed)
|
||||
// note that b[3] is padding
|
||||
b.setNumber(NumberFormat.Int32LE, 4 + 4 * 0, opts.step1)
|
||||
b.setNumber(NumberFormat.Int32LE, 4 + 4 * 1, opts.step2)
|
||||
b.setNumber(NumberFormat.Int32LE, 4 + 4 * 2, opts.step3)
|
||||
b.setNumber(NumberFormat.Int8LE, 4 + 4 * 3, opts.useBrake ? 1 : 0)
|
||||
writePWM(b)
|
||||
}
|
||||
|
||||
const types = [0, 0, 0, 0]
|
||||
export function setType(out: Output, type: OutputType) {
|
||||
let b = mkCmd(out, DAL.opOutputSetType, 3)
|
||||
for (let i = 0; i < 4; ++i) {
|
||||
if (out & (1 << i)) {
|
||||
types[i] = type
|
||||
}
|
||||
b.setNumber(NumberFormat.UInt8LE, i + 1, types[i])
|
||||
}
|
||||
const br = !!opts.useBrake ? 1 : 0;
|
||||
b.setNumber(NumberFormat.Int8LE, 4 + 4 * 3, br)
|
||||
writePWM(b)
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
|
||||
//% color="#68C3E2" weight=100 icon="\uf106"
|
||||
//% groups='["Buttons", "Screen"]'
|
||||
//% groups='["Buttons", "Screen", "Battery"]'
|
||||
//% labelLineWidth=60
|
||||
namespace brick {
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
// This is the last thing executed before user code
|
||||
|
||||
console.addListener(function(msg: string) {
|
||||
control.dmesg(msg.substr(0, msg.length - 1))
|
||||
})
|
||||
// pulse green, play startup sound, turn off light
|
||||
brick.setStatusLight(StatusLight.GreenPulse);
|
||||
// We pause for 100ms to give time to read sensor values, so they work in on_start block
|
||||
|
@ -3,6 +3,7 @@
|
||||
```cards
|
||||
sensors.gyro1.angle();
|
||||
sensors.gyro1.rate();
|
||||
sensors.gyro1.calibrate();
|
||||
sensors.gyro1.reset();
|
||||
```
|
||||
|
||||
@ -10,4 +11,6 @@ sensors.gyro1.reset();
|
||||
|
||||
[angle](/reference/sensors/gyro/angle),
|
||||
[rate](/reference/sensors/gyro/rate),
|
||||
[reset](/reference/sensors/gyro/calibrate),
|
||||
[reset](/reference/sensors/gyro/reset)
|
||||
|
||||
|
@ -12,7 +12,7 @@ When the brick changes its position, it's moved in the direction of one of the a
|
||||
|
||||
## Accuracy and calibration
|
||||
|
||||
Gyro sensors aren't perfectly accurate. Sometimes, because of temperature and changes in the way elecricity behaves in the sensor, the gyro returns a small error in it's measurement. This causes the gyro sensor to return an incorrect value for the amount of angle it detected. This might make your robot drive off course and not go to where you want it to.
|
||||
Gyro sensors aren't perfectly accurate. Sometimes, because of temperature and changes in the way electricity behaves in the sensor, the gyro returns a small error in it's measurement. This causes the gyro sensor to return an incorrect value for the amount of angle it detected. This might make your robot drive off course and not go to where you want it to.
|
||||
|
||||
### Drift
|
||||
|
||||
@ -20,7 +20,7 @@ If you want to turn the tank or robot you built to the left by 45 degrees, you m
|
||||
|
||||
The problem is that when you need to read the angle measurement frequently, the amount of error in the angle measurement may continue to increase. If the sensor thought it moved by 45 degrees the first time instead of really 49 degrees, your second turn will put you at 98 degrees when the sensor said 90 degrees. If you want a robot to turn right 90 degrees and drive for 5 meters, it might actually turn 98 degrees and drive 0.7 meters off course before it stops. This error in the sensor's measurement is called _drift_.
|
||||
|
||||
### Time to reset
|
||||
### Calibration
|
||||
|
||||
If errors in the angle values returned by the gyro sensor are making your project not work right, then it's time to **[reset](/reference/sensors/gyro/reset)**. A reset will return the gyro sensor's current angle value back to `0` and _calibrate_ for drift. Calibration is the process of finding out how much error there is in a sensor's measurement and then removing the error from the value returned to your program.
|
||||
|
||||
@ -42,7 +42,14 @@ Turn the brick and press ENTER to see the current rotation angle of `gyro 2`.
|
||||
|
||||
```blocks
|
||||
brick.buttonEnter.onEvent(ButtonEvent.Pressed, function () {
|
||||
brick.showNumber(sensors.gyro2.angle(), 1)
|
||||
sensors.gyro2.reset()
|
||||
})
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
sensors.gyro2.calibrate()
|
||||
})
|
||||
forever(function () {
|
||||
brick.showNumber(control.millis(), 1)
|
||||
brick.showNumber(sensors.gyro2.angle(), 2)
|
||||
})
|
||||
```
|
||||
|
||||
|
51
libs/gyro-sensor/docs/reference/sensors/gyro/calibrate.md
Normal file
@ -0,0 +1,51 @@
|
||||
# calibrate
|
||||
|
||||
Reset the zero reference for the gyro to current position of the brick.
|
||||
|
||||
```sig
|
||||
sensors.gyro2.calibrate()
|
||||
```
|
||||
|
||||
To make the gyro measure rotation angle from the current position of the brick, it is recalibrated. That is, the brick's current position is set to `0` degrees and rotation angle measurements start from there.
|
||||
|
||||
This function adds a few pauses to ensure that the robot is still. If you only want to reset the sensor, use [reset](/reference/gyro-sensor/reset).
|
||||
|
||||
|
||||
## ~hint
|
||||
|
||||
The current position is considered to be the [_horizon_](https://en.wikipedia.org/wiki/Attitude_indicator) or a place that is the _plane of reference_ (this is possibly someplace that's flat for a horizontal reference).
|
||||
|
||||
## ~
|
||||
|
||||
## ~hint
|
||||
|
||||
**Important**
|
||||
|
||||
To properly reset the gyro, the brick must remain still (undisturbed) while the reset operation takes place.
|
||||
|
||||
## ~
|
||||
|
||||
## Calibration states
|
||||
|
||||
Calibration happens in the following phases and each phase is tracked by the brick status light.
|
||||
|
||||
* **orange**: sensor initialization. This phase ensures that the sensor is in the desired mode and ready to collect data.
|
||||
* **orange pulse**: data collection. Light information is being collected, move the sensor over the various light sources to detect.
|
||||
* **green**: calibration success. The calibration data has been saved.
|
||||
* **red flash**: sensor failure. We were unable to connect to the sensor.
|
||||
|
||||
## Example
|
||||
Set the brick on a flat surface. Reset `gyro 2` and tilt the brick slightly. Reset it again while it's still tilted. Lay the brick down flat again and display the angle measurement.
|
||||
|
||||
```blocks
|
||||
brick.buttonLeft.onEvent(ButtonEvent.Pressed, function () {
|
||||
sensors.gyro2.calibrate()
|
||||
})
|
||||
forever(function() {
|
||||
brick.showNumber(sensors.gyro2.angle(), 1)
|
||||
})
|
||||
```
|
||||
|
||||
## See also
|
||||
|
||||
[angle](/reference/sensors/gyro/angle), [rate](/reference/sensors/gyro/rate)
|