Compare commits

..

12 Commits

Author SHA1 Message Date
7baf7cfede 0.0.70 2018-01-18 12:13:17 -08:00
efd6718ea3 converted lesson to tutorial 2018-01-18 12:09:43 -08:00
057a1d66dc PID support (#242)
* updated block definitions

* updated dependency on common packages
2018-01-18 10:34:06 -08:00
5ddfcd5508 Prototype lesson 'Make it Move" (#241)
* Prototype lesson 'Make it Move"

* Wrong blockq type
2018-01-17 19:45:07 -08:00
00f0922189 Merge pull request #240 from Microsoft/line-detect-lesson
Prototype lesson for 'Line Detection'
2018-01-17 19:07:29 -08:00
41f4b64087 Add to gallerys 2018-01-17 18:52:49 -08:00
ea5ee1c007 Prototype lesson for 'Line Detection' 2018-01-17 17:02:11 -08:00
603e4c0fc1 0.0.69 2018-01-16 17:06:52 -08:00
e50c88008a updated gyrobox 2018-01-16 17:05:57 -08:00
f057964a50 pausing until sound is done in mood 2018-01-16 16:44:32 -08:00
2eda2061cf updated modified gyro boy 2018-01-16 16:26:49 -08:00
a4ebf4c746 moving moods in separate namespace 2018-01-16 16:21:02 -08:00
29 changed files with 726 additions and 129 deletions

View File

@ -1,5 +1,11 @@
# @extends
## Lessons #Lessons
* [Lessons](/lessons)
* [Make it move](/lessons/make-it-move)
* [Line detection](/lessons/line-detection)
## Reference #reference
* [Reference](/reference)

View File

@ -0,0 +1,178 @@
# Gyroboy
Work in progress
```blocks
let motorSpeed1 = 0
let motorSpeed2 = 0
let motorSpeed3 = 0
let motorSpeed = 0
let fallen = false
let motorSpeed0 = 0
let oldControlDrive = 0
let controlDrive = 0
let power = 0
let motorAngle = 0
let gyroAngle = 0
let controlSteering = 0
let state = 0
let motorPosition = 0
let temp = 0
let gyroRate = 0
let timestep = 0
sensors.color1.onColorDetected(ColorSensorColor.Red, function () {
music.playTone(2000, 100)
controlDrive = 0
controlSteering = 0
})
// reads the motor angle and computes the motor speed,
// position
function computeMotors() {
temp = motorAngle
// read angle on both motors
motorAngle = motors.largeD.angle() + motors.largeA.angle()
// and estimate speed as angle difference
motorSpeed0 = motorAngle - temp
// average last 4 speed readings
motorSpeed = (motorSpeed0 + motorSpeed1 + motorSpeed2 + motorSpeed3) / 4 / timestep
// shift all previous recorded speeds by one
motorSpeed3 = motorSpeed2
motorSpeed2 = motorSpeed1
motorSpeed1 = motorSpeed0
// compute position from speed
motorPosition = motorPosition + timestep * motorSpeed
}
// read the gyro rate and computes the angle
function computeGyro() {
gyroRate = sensors.gyro2.rate()
gyroAngle = gyroAngle + timestep * gyroRate
}
function reset() {
state = 0
// sleeping
moods.sleeping.show();
// reset counters
motors.largeA.reset()
motors.largeD.reset()
// motors are unregulated
motors.largeA.setRegulated(false)
motors.largeD.setRegulated(false)
// clear the gyro sensor to remove drift
sensors.gyro2.reset()
// fall detection timer
control.timer2.reset()
// timestep computation timer
control.timer3.reset()
motorAngle = 0
motorPosition = 0
motorSpeed = 0
motorSpeed0 = 0
motorSpeed1 = 0
motorSpeed2 = 0
motorSpeed3 = 0
gyroRate = 0
gyroAngle = 0
fallen = false
power = 0
controlSteering = 0
controlDrive = 0
// awake
moods.awake.show();
gyroAngle = -0.25
state = 1;
}
// compute set point for motor position and required
// motor power
function computePower() {
// apply control and compute desired motor position
motorPosition -= timestep * controlDrive;
// estimate power based on sensor readings and control
// values
power = 0.8 * gyroRate + 15 * gyroAngle + (0.08 * motorSpeed + 0.12 * motorPosition) - 0.01 * controlDrive
// ensure that power stays within -100, 100
if (power > 100) {
power = 100
} else if (power < -100) {
power = -100
}
}
// test if the robot has fallen off
function checkFallen() {
if (Math.abs(power) < 100) {
control.timer2.reset()
}
if (control.timer2.seconds() > 2) {
fallen = true
}
}
// stop all motors and wait for touch button to be
// pressed
function stop() {
motors.stopAllMotors()
state = 0
moods.knockedOut.show();
sensors.touch3.pauseUntil(TouchSensorEvent.Pressed)
moods.neutral.show();
}
sensors.ultrasonic4.onEvent(UltrasonicSensorEvent.ObjectNear, function () {
moods.dizzy.show()
controlSteering = 0
oldControlDrive = controlDrive
controlDrive = -10
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
motors.mediumC.setSpeed(-30, 60, MoveUnit.Degrees);
motors.mediumC.setSpeed(30, 30, MoveUnit.Degrees);
if (Math.randomRange(-1, 1) >= 1) {
controlSteering = 70
} else {
controlSteering = -70
}
loops.pause(4000)
music.playTone(2000, 100)
controlSteering = 0
controlDrive = oldControlDrive
moods.neutral.show()
})
// compute the elapsed time since the last iteration
function computeTimestep() {
timestep = control.timer3.seconds()
control.timer3.reset()
}
sensors.color1.onColorDetected(ColorSensorColor.Green, function () {
moods.winking.show()
controlDrive = 150
controlSteering = 0
})
sensors.color1.onColorDetected(ColorSensorColor.Blue, function () {
moods.middleRight.show()
controlSteering = 70
})
// apply power to motors
function controlMotors() {
motors.largeA.setSpeed(power + controlSteering * 0.1)
motors.largeD.setSpeed(power - controlSteering * 0.1)
}
sensors.color1.onColorDetected(ColorSensorColor.Yellow, function () {
moods.middleLeft.show()
controlSteering = -70
})
sensors.color1.onColorDetected(ColorSensorColor.White, function () {
moods.sad.show();
controlDrive = -75
})
timestep = 0.014
// main loop
loops.forever(function () {
reset()
while (!fallen) {
control.timer3.pauseUntil(5)
computeTimestep()
computeGyro()
computeMotors()
computePower()
controlMotors()
checkFallen()
}
stop()
})
```

27
docs/lessons.md Normal file
View File

@ -0,0 +1,27 @@
# Lessons
Learning activities for LEGO Mindstorms with MakeCode.
## Motors and motion
```codecard
[{
"name": "Make it Move",
"imageUrl":"/static/lessons/make-it-move.jpg",
"url": "/lessons/make-it-move",
"cardType": "project",
"description": "Make a robot that moves itself without wheels."
}, {
"name": "Make it Move TUTORIAL",
"imageUrl":"/static/lessons/make-it-move.jpg",
"url": "/lessons/make-it-move-tutorial",
"cardType": "tutorial",
"description": "Make a robot that moves itself without wheels."
}, {
"name": "Line Detection",
"imageUrl":"/static/lessons/line-detection.jpg",
"url": "/lessons/line-detection",
"cardType": "project",
"description": "Make your robot drive itself by following lines."
}]
```

View File

@ -0,0 +1,266 @@
# Line Detection
## Objective
Design ways to improve driving safety by helping to prevent drivers from falling asleep and causing an accident.
![Car driving on highway](/static/lessons/line-detection/car-driving.jpg)
## Connect
Make sure that you can answer the following questions:
* Can autonomous cars react to different traffic light signals?
* What can happen if a driver falls asleep while driving?
* How can we detect when a driver is falling asleep?
Think about what you have learned, then document it. Describe the problem in your own words. Creatively record your ideas and findings.
## Construct
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.
![Color sensor on the driving base](/static/lessons/line-detection/color-sensor-driving.jpg)
## Program
Autonomous cars need to recognize and respond to traffic lights automatically.
First, create a program that will make your robot stop at red lights.
Make sure your robot is only responding to the color red.
Once you have succeeded, program your robot to drive forward again when the light changes from red to green.
There are two coding tasks for this lesson:
1. Create a program that will make your robot stop at red lights.
2. Create a program that drives the robot forward until the Color Sensor sees red. The robot then stops.
## Coding task 1 - Stop at red lights
**Goal:** Create a program that will make your robot stop at red lights.
### Step 1
Create a program that drives the robot forward until the Color Sensor sees red. The robot then stops.
Place a ``||motors:steer large B+C||`` block from ``||motors:Motors||`` under ``||loops:on start||``. Change the speed to 20%.
```blocks
motors.largeBC.steer(0, 20)
```
### Step 2
Place a ``||loops:while||`` loop block under ``||motors:steer large B+C||``.
```blocks
motors.largeBC.steer(0, 20)
while (true) {
}
```
### Step 3
Place a ``||sensors:pause for color||`` from ``||sensors:Sensors||`` inside the ``||loops:while||`` loop block. Change the color to red.
```blocks
motors.largeBC.steer(0, 20)
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Red)
}
```
### Step 4
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause for color||`` block.
Study the program...what do you think the program will do?
**Hint:** The motors will run until the Color Sensor senses the color red, then all motors will stop. The motors will run until the sensor reading in the while block is true.
```blocks
motors.largeBC.steer(0, 20)
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Red)
motors.stopAllMotors()
}
```
### Step 5
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.
## Coding task 2 - Detect light changes
**Goal:** Program your robot to drive forward again when the light changes from red to green.
### Step 1
Place a ``||loops:while||`` loop block under ``||loops:on start||``.
```blocks
while (true) {
}
```
### Step 2
Place a ``||motors:steer large B+C||`` block from ``||motors:Motors||`` inside the ``||loops:while||`` loop block. Change the speed to 20%.
```blocks
while (true) {
motors.largeBC.steer(0, 20)
}
```
### Step 4
Place a ``||loops:while||`` loop block under the ``||motors:steer large B+C||`` block.
```blocks
while (true) {
motors.largeBC.steer(0, 20)
while (true) {
}
}
```
### Step 5
Place a ``||sensors:pause for color||`` block from ``||sensors:Sensors||`` inside the ``||loops:while||`` loop block. Change the color to red.
```blocks
while (true) {
motors.largeBC.steer(0, 20)
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Red)
}
}
```
### Step 6
Place a ``||motors:stop all motors||`` block under the ``||sensors:pause for color||`` block.
```blocks
while (true) {
motors.largeBC.steer(0, 20)
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Red)
motors.stopAllMotors()
}
}
```
### Step 7
Place a ``||loops:while||`` loop block under the second ``||loops:while||`` loop block.
```blocks
while (true) {
motors.largeBC.steer(0, 20)
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Red)
motors.stopAllMotors()
}
while (true) {
}
}
```
### Step 8
Place a ``||sensors:pause for color||`` block inside the new ``||loops:while||`` loop block. Change the color to red.
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)
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Red)
motors.stopAllMotors()
}
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Red)
}
}
```
### Step 9
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
To simulate what could happen if a driver falls asleep while driving, your robot could sound an alarm signal when it crosses the line. This feature is often available in new cars.
Program your robot to perform this function.
Think about what you have learned, then document it. Describe your pseudocode for this task. Creatively record your ideas, and findings.
### Programming hint
```blocks
motors.largeBC.steer(0, 20)
while (true) {
sensors.color3.pauseForColor(ColorSensorColor.Yellow)
music.playSoundEffect(sounds.systemGeneralAlert)
}
while (true) {
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeB.setSpeed(10)
motors.largeC.setSpeed(-10)
}
while (true) {
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeA.setSpeed(-10)
motors.largeA.setSpeed(10)
}
}
```
## Continue
Program your robot to drive on “autopilot” along a given route. You will need to create a program that recognizes and responds to a dark line (or white line). You will create a line-following program and your robot will need to travel along the line without losing contact with it.
You will need to constantly debug your program in order to make your robot travel as smoothly as possible along the line.
### Programming hint
```blocks
while (true) {
while (true) { sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeB.setSpeed(10)
motors.largeC.setSpeed(-10)
}
while (true) {
sensors.color3.pauseForLight(LightIntensityMode.Reflected, LightCondition.Bright)
motors.largeB.setSpeed(-10)
motors.largeC.setSpeed(10)
}
}
```
## Share
Consider the following questions:
1. What challenged you?
2. Where there any surprises?
3. How could you improve your program?
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?
Think about what you have learned, then document it. Creatively record and present your ideas, creations, and findings.

View File

@ -0,0 +1,72 @@
# Make It Move Without Wheels
## Objective @fullscreen
Design, build and program a robot that can move itself:
Your robot will:
* Go a distance of at least 30cm
* Use at least one motor
* Use NO wheels for locomotion
![LECG Mindstorms brick with parts](/static/lessons/make-it-move/locomotion-no-wheels.jpg)
## Construct @fullscreen
Build a Walker Bot!
The Walker Bot is one example of many possible solutions for making a robot move without wheels.
The Walker Bot combines an EV3 Frame and two legs that are mirror-images to create left and right legs.
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.
![LEGO Mindstorms Walker Bot](/static/lessons/make-it-move/walker-bot.jpg)
## Program 1 @fullscreen
In nature, creatures use many methods to get around. None of them, however, use wheels to move. Can we copy the method of animal locomotion with our robot? Using motors and legs, make the robot move without using any wheels.
Place a ``||motors:tank large B+C||`` block from ``||motors:Motors||`` under ``||loops:on start||``.
Change the speed to `-60%` (for motor B) and `+60%` (for motor C).
Change the rotations to `9`.
The ``||motors:tank large B+C||`` block will run for `9` rotations when the **center** button is pressed on the EV3 brick. The motors are set for the reverse direction because they are mounted upside down in this model.
```blocks
motors.largeBC.tank(-60, 60, 9, MoveUnit.Rotations)
```
## Program 2 @fullscreen
Place a ``||motors:stop all motors||`` block under ``||motors:tank large B+C||``.
The ``||motors:tank large B+C||`` block will run for `9` rotations when the **center** button is pressed on the EV3 brick then stop.
```blocks
motors.largeBC.tank(-60, 60, 9, MoveUnit.Rotations)
motors.stopAllMotors()
```
## Program 3 @fullscreen
Place a ``||brick:show string||`` block under ``||motors:stop all motors||``.
Change the `"Hello World"` text to `"30 cm"`.
The ``||motors:tank large B+C||`` will run for `9` rotations when the **center** button is pressed on the EV3 brick then stop and display "30 cm" on the EV3 Bricks screen.
```blocks
motors.largeBC.tank(-60, 60, 9, MoveUnit.Rotations)
motors.stopAllMotors()
brick.showString("30 cm", 1)
```
## Program 4 @fullscreen
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.

View File

@ -0,0 +1,73 @@
# Make It Move Without Wheels
## Objective
Design, build and program a robot that can move itself:
Your robot will:
* Go a distance of at least 30cm
* Use at least one motor
* Use NO wheels for locomotion
![LECG Mindstorms brick with parts](/static/lessons/make-it-move/locomotion-no-wheels.jpg)
## Construct
Build a Walker Bot!
The Walker Bot is one example of many possible solutions for making a robot move without wheels.
The Walker Bot combines an EV3 Frame and two legs that are mirror-images to create left and right legs.
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.
![LEGO Mindstorms Walker Bot](/static/lessons/make-it-move/walker-bot.jpg)
## Program
In nature, creatures use many methods to get around. None of them, however, use wheels to move. Can we copy the method of animal locomotion with our robot? Using motors and legs, make the robot move without using any wheels.
### Step 1
Place a ``||motors:tank large B+C||`` block from ``||motors:Motors||`` under ``||loops:on start||``.
Change the speed to `-60%` (for motor B) and `+60%` (for motor C).
Change the rotations to `9`.
The ``||motors:tank large B+C||`` block will run for `9` rotations when the **center** button is pressed on the EV3 brick. The motors are set for the reverse direction because they are mounted upside down in this model.
```typescript-ignore
motors.largeBC.tankFor(-60, 60, 9, MoveUnit.Rotations)
```
### Step 2
Place a ``||motors:stop all motors||`` block under ``||motors:tank large B+C||``.
The ``||motors:tank large B+C||`` block will run for `9` rotations when the **center** button is pressed on the EV3 brick then stop.
```typescript-ignore
motors.largeBC.tankFor(-60, 60, 9, MoveUnit.Rotations)
motors.stopAllMotors()
```
### Step 3
Place a ``||brick:show string||`` block under ``||motors:stop all motors||``.
Change the `"Hello World"` text to `"30 cm"`.
The ``||motors:tank large B+C||`` will run for `9` rotations when the **center** button is pressed on the EV3 brick then stop and display "30 cm" on the EV3 Bricks screen.
```typescript-ignore
motors.largeBC.tankFor(-60, 60, 9, MoveUnit.Rotations)
motors.stopAllMotors()
brick.showString("30 cm", 1)
```
### Step 4
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.

BIN
docs/static/lessons/line-detection.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
docs/static/lessons/make-it-move.jpg vendored Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -0,0 +1,25 @@
{
"automation": "Automation, process control and robotic controllers\n\nProcess control, automation, robotics AI",
"automation.Behavior": "A behavior",
"automation.Behavior.update": "Called on each behavior iteration even for suppresed behaviors",
"automation.Behavior.update|param|elapsed": "milli seconds since last call",
"automation.BehaviorManager": "A manager for behaviors",
"automation.BehaviorManager.add": "Adds a new behavior to the behavior manager",
"automation.BehaviorManager.add|param|behavior": "the behavior to add",
"automation.BehaviorManager.start": "Starts the behavior control loop",
"automation.BehaviorManager.stop": "Stops the execution loop",
"automation.PIDController.compute": "Computes the output based on the system state",
"automation.PIDController.setControlSaturation": "Sets the control saturation values",
"automation.PIDController.setControlSaturation|param|high": "highest control value, eg: 100",
"automation.PIDController.setControlSaturation|param|low": "lowest control value, eg: -100",
"automation.PIDController.setDerivativeFilter": "Sets the derivative filter gain",
"automation.PIDController.setDerivativeFilter|param|N": "the filter gain, eg:10",
"automation.PIDController.setGains": "Sets the PID gains",
"automation.PIDController.setGains|param|b": "setpoint weight, eg: 0.9",
"automation.PIDController.setGains|param|kd": "derivative gain",
"automation.PIDController.setGains|param|ki": "integral gain",
"automation.PIDController.setGains|param|kp": "proportional gain",
"automation.PIDController.setPoint": "Updates the desired setpoint",
"automation.addBehavior": "Adds the behavior and starts it",
"automation.addBehavior|param|behavior": "a behavior"
}

View File

@ -0,0 +1,12 @@
{
"automation.PIDController.compute|block": "%pid|compute for timestep %timestep|(s) at state %y",
"automation.PIDController.setControlSaturation|block": "set %pid|control saturation from %low|to %high",
"automation.PIDController.setDerivativeFilter|block": "set %pid|derivative filter %N",
"automation.PIDController.setGains|block": "set %pid|gains kp %kp|ki %ki|kd %kd",
"automation.PIDController.setPoint|block": "set %pid|point to %ysp",
"automation.addBehavior|block": "add behavior %behavior",
"automation|block": "automation",
"{id:category}Automation": "Automation",
"{id:group}Behaviors": "Behaviors",
"{id:group}PID": "PID"
}

View File

@ -1,6 +1,6 @@
{
"additionalFilePath": "../../node_modules/pxt-common-packages/libs/behaviors",
"additionalFilePath": "../../node_modules/pxt-common-packages/libs/automation",
"dependencies": {
"core": "file:../ev3"
"ev3": "file:../ev3"
}
}

View File

@ -1,14 +0,0 @@
{
"behaviors": "Behavior drive blocks",
"behaviors.Behavior": "A behavior",
"behaviors.BehaviorManager": "A manager for behaviors",
"behaviors.BehaviorManager.add": "Adds a new behavior to the behavior manager",
"behaviors.BehaviorManager.add|param|behavior": "the behavior to add",
"behaviors.BehaviorManager.start": "Starts the behavior control loop",
"behaviors.BehaviorManager.stop": "Stops the execution loop",
"behaviors.addBehavior": "Adds the behavior and starts it",
"behaviors.addBehavior|param|behavior": "a behavior",
"behaviors.avoidCrash": "A behavior that stops all motors if the sensor distance get too short",
"behaviors.driveForward": "A behavior that turns on the motors to the specified speed",
"behaviors.driveForward|param|motors": "@param speed the desired speed, eg: 50"
}

View File

@ -1,7 +0,0 @@
{
"behaviors.addBehavior|block": "add behavior %behavior",
"behaviors.avoidCrash|block": "avoid crash using %ultrasonic",
"behaviors.driveForward|block": "drive %motors|forward at %speed=motorSpeedPicker|%",
"behaviors|block": "behaviors",
"{id:category}Behaviors": "Behaviors"
}

View File

@ -1,56 +0,0 @@
namespace behaviors {
class AvoidCrashBehavior extends behaviors.Behavior {
private ultrasonic: sensors.UltraSonicSensor;
constructor(ultrasonic: sensors.UltraSonicSensor) {
super();
this.ultrasonic = ultrasonic;
}
shouldRun(): boolean {
return this.ultrasonic.distance() < 5;
}
run(): void {
motors.stopAllMotors();
this.active = false;
}
}
/**
* A behavior that stops all motors if the sensor distance get too short
*/
//% blockId=behaviorsAvoidCrash block="avoid crash using %ultrasonic"
export function avoidCrash(ultrasonic: sensors.UltraSonicSensor) : behaviors.Behavior {
return new AvoidCrashBehavior(ultrasonic);
}
class DriveForwardBehavior extends behaviors.Behavior {
private motors: motors.MotorBase;
private speed: number;
constructor(motors: motors.MotorBase, speed: number) {
super();
this.motors = motors;
this.speed = speed;
}
shouldRun(): boolean {
return true;
}
run(): void {
this.motors.setSpeed(this.speed);
pauseUntil(() => !this.active);
this.motors.setSpeed(0);
}
}
/**
* A behavior that turns on the motors to the specified speed
* @param motors
* @param speed the desired speed, eg: 50
*/
//% blockId=behaviorsDriveForward block="drive %motors|forward at %speed=motorSpeedPicker|%"
export function driveForward(motors: motors.MotorBase, speed: number): behaviors.Behavior {
return new DriveForwardBehavior(motors, speed);
}
}

View File

@ -10,11 +10,11 @@
"base": "file:../base",
"core": "file:../core",
"music": "file:../music",
"mood": "file:../mood",
"color-sensor": "file:../color-sensor",
"touch-sensor": "file:../touch-sensor",
"ultrasonic-sensor": "file:../ultrasonic-sensor",
"gyro-sensor": "file:../gyro-sensor"
"gyro-sensor": "file:../gyro-sensor",
"mood": "file:../mood"
},
"public": true
}

View File

@ -1,16 +1,17 @@
{
"brick.Mood": "A mood",
"brick.Mood.show": "Shows the mood on the EV3",
"brick.angry": "An angry mood",
"brick.awake": "A awake mood",
"brick.dizzy": "A dizzy mood",
"brick.knockedOut": "A knocked out mood",
"brick.love": "In love mood",
"brick.middleLeft": "Looking around left",
"brick.middleRight": "Looking around right",
"brick.neutral": "In a neutral mood",
"brick.sad": "A sad mood",
"brick.sleeping": "A sleeping mood",
"brick.tired": "A tired mood",
"brick.winking": "In laughing mood"
"brick.showMood": "Shows a mood",
"moods.angry": "An angry mood",
"moods.awake": "A awake mood",
"moods.dizzy": "A dizzy mood",
"moods.knockedOut": "A knocked out mood",
"moods.love": "In love mood",
"moods.middleLeft": "Looking around left",
"moods.middleRight": "Looking around right",
"moods.neutral": "In a neutral mood",
"moods.sad": "A sad mood",
"moods.sleeping": "A sleeping mood",
"moods.tired": "A tired mood",
"moods.winking": "In laughing mood"
}

View File

@ -1,6 +1,8 @@
{
"brick.Mood.show|block": "show mood %mood=mood_image_picker",
"brick.showMood|block": "show mood %mood=mood_image_picker",
"brick|block": "brick",
"moods|block": "moods",
"{id:category}Brick": "Brick",
"{id:category}Moods": "Moods",
"{id:group}Screen": "Screen"
}

View File

@ -1,12 +1,23 @@
namespace brick {
/**
* Shows a mood
*/
//% weight=90
//% blockId=moodShow block="show mood %mood=mood_image_picker"
//% weight=101 group="Screen" blockGap=8
export function showMood(mood: Mood) {
if(mood)
mood.show();
}
/**
* A mood
*/
//% fixedInstances
export class Mood {
image: Image;
sound: Sound;
light: BrickLight;
private image: Image;
private sound: Sound;
private light: BrickLight;
constructor(image: Image, sound: Sound, light: BrickLight) {
this.image = image;
@ -17,14 +28,11 @@ namespace brick {
/**
* Shows the mood on the EV3
*/
//% weight=90
//% blockId=moodShow block="show mood %mood=mood_image_picker"
//% weight=101 group="Screen" blockGap=8
show() {
brick.setLight(this.light);
brick.showImage(this.image);
if (this.sound)
music.playSoundEffect(this.sound);
music.playSoundEffectUntilDone(this.sound);
loops.pause(20);
}
}
@ -39,77 +47,79 @@ namespace brick {
//% group="Screen" weight=0 blockHidden=1
export function __moodImagePicker(mood: Mood): Mood {
return mood;
}
}
}
namespace moods {
/**
* A sleeping mood
*/
//% fixedInstance jres=images.eyesSleeping
export const sleeping = new Mood(images.eyesSleeping, sounds.expressionsSnoring, BrickLight.OrangePulse);
export const sleeping = new brick.Mood(images.eyesSleeping, sounds.expressionsSnoring, BrickLight.OrangePulse);
/**
* A awake mood
*/
//% fixedInstance jres=images.eyesAwake
export const awake = new Mood(images.eyesAwake, sounds.informationActivate, BrickLight.Orange);
export const awake = new brick.Mood(images.eyesAwake, sounds.informationActivate, BrickLight.Orange);
/**
* A tired mood
*/
//% fixedInstance jres=images.eyesTiredMiddle
export const tired = new Mood(images.eyesTiredMiddle, sounds.expressionsSneezing, BrickLight.OrangeFlash);
export const tired = new brick.Mood(images.eyesTiredMiddle, sounds.expressionsSneezing, BrickLight.OrangeFlash);
/**
* An angry mood
*/
//% fixedInstance jres=images.eyesAngry
export const angry = new Mood(images.eyesAngry, sounds.animalsDogGrowl, BrickLight.RedPulse);
export const angry = new brick.Mood(images.eyesAngry, sounds.animalsDogGrowl, BrickLight.RedPulse);
/**
* A sad mood
*/
//% fixedInstance jres=images.eyesTear
export const sad = new Mood(images.eyesTear, sounds.animalsDogWhine, BrickLight.Red);
export const sad = new brick.Mood(images.eyesTear, sounds.animalsDogWhine, BrickLight.Red);
/**
* A dizzy mood
*/
//% fixedInstance jres=images.eyesDizzy
export const dizzy = new Mood(images.eyesDizzy, sounds.expressionsUhOh, BrickLight.OrangeFlash);
export const dizzy = new brick.Mood(images.eyesDizzy, sounds.expressionsUhOh, BrickLight.OrangeFlash);
/**
* A knocked out mood
*/
//% fixedInstance jres=images.eyesKnockedOut
export const knockedOut = new Mood(images.eyesKnockedOut, sounds.informationError, BrickLight.RedFlash);
export const knockedOut = new brick.Mood(images.eyesKnockedOut, sounds.informationError, BrickLight.RedFlash);
/**
* Looking around left
*/
//% fixedInstance jres=images.eyesMiddleLeft
export const middleLeft = new Mood(images.eyesMiddleLeft, sounds.informationAnalyze, BrickLight.Off);
export const middleLeft = new brick.Mood(images.eyesMiddleLeft, sounds.informationAnalyze, BrickLight.Off);
/**
* Looking around right
*/
//% fixedInstance jres=images.eyesMiddleRight
export const middleRight = new Mood(images.eyesMiddleRight, sounds.informationAnalyze, BrickLight.Off);
export const middleRight = new brick.Mood(images.eyesMiddleRight, sounds.informationAnalyze, BrickLight.Off);
/**
* In love mood
*/
//% fixedInstance jres=images.eyesLove
export const love = new Mood(images.eyesLove, sounds.expressionsMagicWand, BrickLight.GreenPulse);
export const love = new brick.Mood(images.eyesLove, sounds.expressionsMagicWand, BrickLight.GreenPulse);
/**
* In laughing mood
*/
//% fixedInstance jres=images.eyesWinking
export const winking = new Mood(images.eyesWinking, sounds.expressionsLaughing1, BrickLight.GreenFlash);
export const winking = new brick.Mood(images.eyesWinking, sounds.expressionsLaughing1, BrickLight.GreenFlash);
/**
* In a neutral mood
*/
//% fixedInstance jres=images.eyesNeutral
export const neutral = new Mood(images.eyesNeutral, undefined, BrickLight.Green);
export const neutral = new brick.Mood(images.eyesNeutral, undefined, BrickLight.Green);
}

View File

@ -9,6 +9,7 @@
],
"public": true,
"dependencies": {
"core": "file:../core"
"core": "file:../core",
"music": "file:../music"
}
}

View File

@ -23,7 +23,7 @@
"music.setTempo": "Set the tempo a number of beats per minute (bpm).",
"music.setTempo|param|bpm": "The new tempo in beats per minute, eg: 120",
"music.setVolume": "Set the output volume of the sound synthesizer.",
"music.setVolume|param|volume": "the volume 0...256, eg: 128",
"music.setVolume|param|volume": "the volume 0...100, eg: 50",
"music.stopAllSounds": "Play a tone through the speaker for some amount of time.",
"music.tempo": "Return the tempo in beats per minute (bpm).\nTempo is the speed (bpm = beats per minute) at which notes play. The larger the tempo value, the faster the notes will play."
}

View File

@ -13,7 +13,7 @@
namespace music {
uint8_t currVolume = 2;
uint8_t currVolume = 50;
uint8_t *lmsSoundMMap;
int writeDev(void *data, int size) {
@ -25,16 +25,16 @@ int writeDev(void *data, int size) {
/**
* Set the output volume of the sound synthesizer.
* @param volume the volume 0...256, eg: 128
* @param volume the volume 0...100, eg: 50
*/
//% weight=96
//% blockId=synth_set_volume block="set volume %volume"
//% parts="speaker" blockGap=8
//% volume.min=0 volume.max=256
//% volume.min=0 volume.max=100
//% help=music/set-volume
//% weight=1
void setVolume(int volume) {
currVolume = max(0, min(100, volume * 100 / 256));
currVolume = max(0, min(100, volume));
}
#define SOUND_CMD_BREAK 0

View File

@ -3,12 +3,12 @@ declare namespace music {
/**
* Set the output volume of the sound synthesizer.
* @param volume the volume 0...256, eg: 128
* @param volume the volume 0...100, eg: 50
*/
//% weight=96
//% blockId=synth_set_volume block="set volume %volume"
//% parts="speaker" blockGap=8
//% volume.min=0 volume.max=256
//% volume.min=0 volume.max=100
//% help=music/set-volume
//% weight=1 shim=music::setVolume
function setVolume(volume: int32): void;

View File

@ -1,6 +1,6 @@
{
"name": "pxt-ev3",
"version": "0.0.68",
"version": "0.0.70",
"description": "LEGO Mindstorms EV3 for Microsoft MakeCode",
"private": true,
"keywords": [
@ -44,7 +44,7 @@
"webfonts-generator": "^0.4.0"
},
"dependencies": {
"pxt-common-packages": "0.15.6",
"pxt-common-packages": "0.15.7",
"pxt-core": "3.0.11"
},
"scripts": {

View File

@ -21,7 +21,7 @@
"libs/storage",
"libs/datalog",
"libs/tests",
"libs/behaviors"
"libs/automation"
],
"simulator": {
"autoRun": true,

View File

@ -9,6 +9,7 @@
},
"galleries": {
"Maker Activities": "maker",
"Coding Activites": "coding"
"Coding Activites": "coding",
"Lessons": "lessons"
}
}