From 471234d842b400aafde5999a4ddb7241caf72e82 Mon Sep 17 00:00:00 2001 From: Katlin Walsh Date: Tue, 22 Oct 2024 16:07:14 -0400 Subject: [PATCH 1/2] =?UTF-8?q?UMC=20tutorial=20refresh=20for=20Delivery?= =?UTF-8?q?=20Robot=20lesson=20=F0=9F=A4=96=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hs-autodelivery-modify.md | 421 ++++++++++++++++++++++++++++++++++++++ hs-autodelivery-use.md | 284 +++++++++++++++++++++++++ pxt.json | 2 + 3 files changed, 707 insertions(+) create mode 100644 hs-autodelivery-modify.md create mode 100644 hs-autodelivery-use.md diff --git a/hs-autodelivery-modify.md b/hs-autodelivery-modify.md new file mode 100644 index 00000000..53092ecf --- /dev/null +++ b/hs-autodelivery-modify.md @@ -0,0 +1,421 @@ +# Forward Education Smart Warehouse Vehicle - Modify Tutorial + +```package +fwd-edu-breakout=github:climate-action-kits/pxt-fwd-edu/fwd-breakout +sonar=github:climate-action-kits/pxt-fwd-edu +``` + +```template +input.onButtonPressed(Button.A, function () { + IsDrivingEnabled = false +}) +input.onButtonPressed(Button.B, function () { + IsDrivingEnabled = true +}) +let IsDrivingEnabled = false +fwdSensors.ledRing.fwdSetAllPixelsColour(0xffffff) +fwdMotors.setupDriving( +fwdMotors.leftServo, +fwdMotors.rightServo +) +basic.forever(function () { + if (IsDrivingEnabled == false) { + fwdMotors.stop() + basic.showIcon(IconNames.No) + } + if (IsDrivingEnabled == true) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + } + } else if (fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . # . . . + # . . . . + . # . . . + . . # . . + `) + fwdMotors.turn(-2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.West) + fwdMotors.turn(-1) + } + } else { + fwdMotors.stop() + basic.showIcon(IconNames.Square) + } + } +}) +``` + +## Activity 1: Build Your Project @showdialog +Let's build a smart warehouse vehicle! We are going to do this in four parts: +1. **Build** our smart warehouse vehicle +2. **Add code** to make our project move +3. **Modify** our project to learn about other sensors +4. Apply what we learned with a small **challenge** + +Full smart warehouse vehicle render + +## Build Step 1 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs01.webp) + +## Build Step 2 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs02.webp) + +## Build Step 3 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs03.webp) + +## Build Step 4 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs04.webp) + +## Build Step 5 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs05.webp) + +## Build Step 6 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs06.webp) + +## Build Step 7 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs07.webp) + +## Build Step 8 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs08.webp) + +## Build Step 9 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs09.webp) + +## Build Step 10 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs10.webp) + +## Build Step 11 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs11.webp) + +## Build Step 12 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs12.webp) + +## Build Step 13 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs13.webp) + +## Build Step 14 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs14.webp) + +## Build Step 15 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs15.webp) + +## Build Step 16 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs16.webp) + +## Build Step 17 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs17.webp) + +## Build Step 18 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs18.webp) + +## Activity 2: Code Your Project @showdialog +We need to connect our project to the computer to make it come to life with code! + +The code will be the instructions that tell our micro:bit what to do. + +## Code Step 1 @showdialog +IMPORTANT! Make sure your Climate Action Kit Breakout Board is turned on and your micro:bit is plugged into your computer. + +Plug micro:bit into USB port on computer + +## Code Step 2 @showdialog +Click the three dots beside the ``|Download|`` button, then click on _Connect Device_. +Next, follow the steps to pair your micro:bit. + +Pairing gif + +## Code Step 3 +Click the ``|Download|`` button to download the starter code to your project. + +## Activity 3: Modify Your Project @showdialog +We have a smart warehouse vehicle that **follows a straight line** and **signals its direction** let's explore how to optimize our sensors by **modifying** our code! + +As you go through the next steps: +* Use the instructions at the top of the screen to **Modify** your code. +* When you are ready for more information, click **'Tell Me More!'** +* If you need help with the code, click the **lightbulb**! + +## Modify Step 1 +Think back to the lesson about automation in industrial warehouses. Our smart warehouse vehicle is an example of an [automated guided vehicle (AGV)](https://youtu.be/qahujJ-8vdk?si=2v8G7Mf5MFFAhvWM). + +What should it be able to do? + +~hint Tell Me More! +To move products around a warehouse, the smart warehouse vehicle should be able to: +1. **Follow** a pre-defined path (or black line) +2. **Communicate** the direction it will be travelling in + +We’ll also **modify** our code to enhance our project even further by: +3. **Sense** when an obstacle is in its path and stop driving +hint~ + +## Modify Step 2 +Let’s test it out! + +Unplug your project from your computer, place it on a straight black line, and press **B**. What happens? + +~hint Tell Me More! +* The micro:bit collects data from the line follower. The criteria for turning the motors is: +* **If** the left OR right side of the line senses the white paper, turn the motor in the opposite direction. +* This is known as a **conditional expression.** It is a **boolean**, meaning it must be evaluated as **true** or **false**. +hint~ + +```blocks +input.onButtonPressed(Button.B, function () { +//@highlight + IsDrivingEnabled = true +}) +``` + +## Modify Step 2 + +What will happen when we increase the driving speed in the driving block from **20** to **40**? + +Press the ``|Download|`` button to update the code on your micro:bit, set your vehicle down on the line again, and press **B** to test it. + +~hint Tell Me More! +The vehicle is moving forward twice as fast! +hint~ + +```block +fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 40) +``` +## Modify Step 3 +Did you notice if the speed change impacted the reliability of the following line? + +How many times did the vehicle have to re-adjust before reaching the end of the straight line? + +~hint Tell Me More! +It takes time for the micro:bit to process the data collected from the line sensor. The faster the vehicle moves, the less time the micro:bit has to sense where it is in relation to the line. +hint~ + +## Modify Step 4 +Updating our program doesn’t _always_ make it more efficient. How could you improve or adjust the code so the vehicle still senses the line properly? + +Adjust your code and document how many times the vehicle had to re-adjust before reaching the end of the straight line. + +~hint Tell Me More +Remember to download your code to your micro:bit after editing your code! + +We could increase the accuracy of our line follower in a few ways: +* Set the speed back to 20 (or lower!) +* Add a wait block after each conditional statement +hint~ + +```blocks +basic.forever(function () { + else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + //@highlight + basic.pause(1000) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + //@highlight + basic.pause(1000) + } + } + } +``` + +## Modify Step 5 +Let’s test another component that our Smart Warehouse Vehicle is using! + +How do you think that the **LED Light** is helping our warehouse vehicle drive on the black line? + +~hint Tell Me More! +Our line follower senses the contrast between black and white. + +The LED ring helps light up the **black** line on the **white** paper in different lighting conditions. +hint~ + +```block +fwdSensors.ledRing.fwdSetAllPixelsColour(0xffffff) +``` +## Modify Step 6 @showdialog +Based on your understanding of how the vehicle acted the first time you tested it, how do you think it will navigate a black line when the LED is set to different lighting conditions? + +1. Set the LED light to white +2. Set the LED light to red +3. Turn the LED light off +4. Turn off the lights in the room with the LED light off + +Write your prediction down! + +## Modify Step 7 +Now it’s time to test your prediction! + +Test each of the four lighting conditions 5 times on the straight line and document your findings in a table. + +Remember to download the code each time you change the lighting conditions. + +~hint Tell Me More! +You may wish to collect data about: + +1. How long does it take to complete the course? +2. How many times does the vehicle need to adjust its position? +3. How many times did the vehicle successfully complete the course? +hint~ + +## Challenge Time! @showdialog +Our project build includes a **sonar sensor** we’re not currently using. + +Now that our smart warehouse vehicle drives on a line in different lighting conditions, add the ability to sense its surroundings and **wait until the path is clear**! + +## Challenge Step 1 +Think about where in your conditional statement you should add the **sonar sensor** so that your vehicle detects an obstacle and safely waits until the path is clear. + +Remember to download your code once you add the sonar block to your conditional statement. + +~hint Tell Me More! +The sonar sensor should only drive forward if: +* Obstacles are **Over** a certain distance in front of your vehicle. +* **After** IsDrivingEnabled is set to true +* **Before** driving forward or turning on a line. +hint~ + +```block +fwdSensors.sonar1.fwdDistancePastThreshold(0, fwdSensors.ThresholdDirection.Over) +``` + +## Challenge Step 2 +Test your vehicle again on the straight line. Does it act the way you expected it to? + +Did you include a way for your vehicle to signal that an obstacle is in the way? + +~hint Tell Me More! +Click on the lightbulb for one example of how to add a sonar sensor and signal to our code! +hint~ + +```blocks +basic.forever(function () { + if (IsDrivingEnabled == true) { + //@highlight + if (fwdSensors.sonar1.fwdDistancePastThreshold(1, fwdSensors.ThresholdDirection.Over)) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + } + } else if (fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . # . . . + # . . . . + . # . . . + . . # . . + `) + fwdMotors.turn(-2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.West) + fwdMotors.turn(-1) + } + } else { + fwdMotors.stop() + basic.showIcon(IconNames.Square) + } + } + //@highlight + else { + //@highlight + basic.showIcon(IconNames.Sad) + //@highlight + fwdMotors.stop() + } + } +}) +``` + +## Challenge Step 3 +Now that your vehicle detects an obstacle, we need to decide **how far away** it should stop from an obstacle! + +Using your ruler, measure the distance the vehicle should detect. Our vehicle uses metres as a unit of measurement. You may need to convert your measurement. + +~hint Tell Me More! +For example: If we want the vehicle to sense obstacles under 30 cm, our code block should be 0.3 m. + +If your vehicle is plugged into your computer, you can use the **live visualizer** to see how far away your sonar sensor detects objects! + +Remember to download the code each time you change the code. +hint~ + +```blocks +basic.forever(function () { + if (IsDrivingEnabled == true) { + //@highlight + if (fwdSensors.sonar1.fwdDistancePastThreshold(.3, fwdSensors.ThresholdDirection.Over)) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } + } + else { + basic.showIcon(IconNames.Sad) + fwdMotors.stop() + } + } +}) +``` + +fwdSensors.sonar1.fwdDistancePastThreshold(.3, fwdSensors.ThresholdDirection.Over) +``` +## Challenge Complete! +You did it! + +Think about how you would test the effectiveness of the sonar sensor. What tests should you complete to verify that your vehicle still follows a line? + +~hint Tell Me More! +You may wish to think about: +* How far away should the sonar sensor detect? +* How should it signal that it senses an obstacle? +* How should you test that the existing line follower is still accurate? +hint~ + +## Congratulations! @showdialog +You've completed the activity! + +Did anything surprise you about the project? + +## Reflection @showdialog +How did using predictions and data collection help you better understand your code? + +What differences did you find in the accuracy of the line follower? + +What else do you want to modify to enhance your vehicle build even more? + +## Finished! @showdialog +In the next step, you can click the ``|Done|`` button to finish the tutorial. \ No newline at end of file diff --git a/hs-autodelivery-use.md b/hs-autodelivery-use.md new file mode 100644 index 00000000..c486f63d --- /dev/null +++ b/hs-autodelivery-use.md @@ -0,0 +1,284 @@ +# Forward Education Smart Warehouse Vehicle - Use Tutorial + +```package +fwd-edu-breakout=github:climate-action-kits/pxt-fwd-edu/fwd-breakout +sonar=github:climate-action-kits/pxt-fwd-edu +``` +```template +input.onButtonPressed(Button.A, function () { + IsDrivingEnabled = false +}) +input.onButtonPressed(Button.B, function () { + IsDrivingEnabled = true +}) +let IsDrivingEnabled = false +fwdSensors.ledRing.fwdSetAllPixelsColour(0xffffff) +fwdMotors.setupDriving( +fwdMotors.leftServo, +fwdMotors.rightServo +) +basic.forever(function () { + if (IsDrivingEnabled == false) { + fwdMotors.stop() + basic.showIcon(IconNames.No) + } + if (IsDrivingEnabled == true) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + } + } else if (fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . # . . . + # . . . . + . # . . . + . . # . . + `) + fwdMotors.turn(-2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.West) + fwdMotors.turn(-1) + } + } else { + fwdMotors.stop() + basic.showIcon(IconNames.Square) + } + } +}) +``` + +## Activity 1: Build Your Project @showdialog +Let's build a smart warehouse vehicle! We are going to do this in four parts: +1. **Build** our smart warehouse vehicle +2. **Add code** to make our project move +3. **Use** or test out our line follower to learn how it works +4. Apply what we learned with a small **challenge** + +Full smart warehouse vehicle render + +## Build Step 1 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs01.webp) + +## Build Step 2 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs02.webp) + +## Build Step 3 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs03.webp) + +## Build Step 4 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs04.webp) + +## Build Step 5 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs05.webp) + +## Build Step 6 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs06.webp) + +## Build Step 7 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs07.webp) + +## Build Step 8 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs08.webp) + +## Build Step 9 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs09.webp) + +## Build Step 10 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs10.webp) + +## Build Step 11 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs11.webp) + +## Build Step 12 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs12.webp) + +## Build Step 13 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs13.webp) + +## Build Step 14 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs14.webp) + +## Build Step 15 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs15.webp) + +## Build Step 16 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs16.webp) + +## Build Step 17 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs17.webp) + +## Build Step 18 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs18.webp) + +## Activity 2: Code Your Project @showdialog +We need to connect our project to the computer to make it come to life with code! + +The code will be the instructions that tell our micro:bit what to do. + +## Code Step 1 @showdialog +IMPORTANT! Make sure your Climate Action Kit Breakout Board is turned on and your micro:bit is plugged into your computer. + +Plug micro:bit into USB port on computer + +## Code Step 2 @showdialog +Click the three dots beside the ``|Download|`` button, then click on _Connect Device_. +Next, follow the steps to pair your micro:bit. + +Pairing gif + +## Code Step 3 +Click the ``|Download|`` button to download the starter code to your project. + +## Activity 3: Use Your Project @showdialog +Now that we've built our smart warehouse vehicle, we'll start by **using** sample code to see how it works. + +As you go through the next steps: +* **Use** the instructions at the top of the screen. +* When you are ready for more information, click **'Tell Me More!'** +* If you need help with the code, click the **lightbulb**! + +## Use Step 1 +Think back to the lesson about automation in industrial warehouses. Our smart warehouse vehicle is an example of an [automated guided vehicle (AGV)](https://youtu.be/qahujJ-8vdk?si=2v8G7Mf5MFFAhvWM). + +What should it be able to do? + +~hint Tell Me More! +To move products around a warehouse, the smart warehouse vehicle should be able to: +1. **Follow** a pre-defined path (or black line) +2. **Communicate** the direction it will be travelling in + +Different warehouse automation products may have more features, but these are the minimum requirements. +hint~ + +## Use Step 2 +Take a look at the physical project you just built. + +What robotic components do you notice? How do you think they’ll work together to make the smart warehouse vehicle function as expected? + +~hint Tell Me More! +The smart warehouse vehicle has: + +* Two **continuous servo motors** that rotate a full 360 degrees. They will spin the wheels to allow the vehicle to drive forward. +* One **line follower** with three sensors to identify black and white. They will identify if the robot is on the line, drifting one way or the other, and if it is at the end of a path. +* One **LED ring** to light up the path to help the line follower see black and white. +* One **sonar sensor** that you may use to see if there is an object in the vehicle’s way. +* These parts are all connected to the **breakout board** through **cables**. +* Finally, the breakout board is connected to the **micro:bit** which holds all the code that will tell our motors what to do and when to do it! +hint~ + +## Use Step 3 +Let’s test it out! + +Unplug your project from your computer, place it on a straight black line, and press **B**. What happens? + +~hint Tell Me More! +* The micro:bit collects data from the line follower. The criteria for turning the motors is: +* **If** the left OR right side of the line senses the white paper, turn the motor in the opposite direction. +* This is known as a **conditional expression.** It is a **boolean**, meaning it must be evaluated as **true** or **false**. +hint~ + +```blocks +input.onButtonPressed(Button.B, function () { +//@highlight + IsDrivingEnabled = true +}) +``` + +## Use Step 4 +Can you explain how the vehicle can drive along the line? + +~hint Tell Me More! +* We are controlling the vehicle with a **nested conditional statement**. +* Nested conditional statements are "**if-then**" rules used in coding for programs with **many paths**. +* They add checkpoints to our programs and tell the computer what to do in different situations, like showing a different message if it is sunny, raining, or cloudy outside. +hint~ + +## Use Step 5 +Can you identify one of the **nested conditionals** that helps the vehicle navigate a straight line? + +What _criteria_ help the micro:bit decide what to do? + +~hint Tell Me More! +There are several conditionals nested in this code! + +1. If the **B button is pressed** > set driving enabled to true +2. If the vehicle **senses a line** > signal using the LEDs on the micro:bit and drive forward. +3. If the vehicle senses that it’s drifted to the **right or left of the line** > signal using the LEDs on the micro:bit and turn 2 degrees toward the line +4. If the vehicle **still isn’t on the line** > signal with the LEDs on the micro:bit and turn 1 degree toward the line +5. If the vehicle senses the **end of the line** > signal using the LEDs on the micro:bit and stop driving +hint~ + +```blocks +basic.forever(function () { + if (IsDrivingEnabled == true) { + //@highlight + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) +``` + +## Challenge Time! @showdialog +Now that we have **used** code to create a smart warehouse vehicle that **follows a straight line** and **signals its direction**, we need to collect data to evaluate what other types of lines it can follow! + +## Challenge Step 1 +Based on how the vehicle acted the first time you tested it, how do you think the vehicle will perform on the following types of lines: + +1. A straight line +2. A straight line with a 45-degree turn +3. A wide curved line + +Write your prediction down! + +## Challenge Step 2 +Now it’s time to test your prediction! + +Test each of the three courses 5 times and document your findings in a table. + +~hint Tell Me More! +You may wish to collect data about: + +1. How long does it take to complete the course? +2. How many times does the vehicle need to adjust its position? +3. How many times did the vehicle successfully complete each course? +hint~ + +## Challenge Step 3 +Does the vehicle drift to one side more often than the other? Why do you think this is? + +Is there any part of your course that your robot gets “stuck” every time? + +Try making a new line for your robot to follow what you’ve learned from your data. + +~hint Tell Me More! +Line-following vehicles need lots of testing to make the path more reliable! + +You may have found that a long, straight line can be followed more reliably than a tightly curved line or a sharp, 90-degree turn. +hint~ + +## Congratulations! @showdialog +You've completed the activity! + +Did anything surprise you about the project? + +## Reflection @showdialog +How did using predictions and data collection help you better understand your code? + +What differences did you find in the accuracy of the line follower? + +What else do you want to modify to enhance your vehicle build even more? + +## Finished! @showdialog +In the next step, you can click the ``|Done|`` button to finish the tutorial. \ No newline at end of file diff --git a/pxt.json b/pxt.json index e9fb828b..50a6e03b 100644 --- a/pxt.json +++ b/pxt.json @@ -86,6 +86,8 @@ "gr9-treeSeeder-modify.md", "gr9-verticalfarm-use.md", "gr9-verticalfarm-modify.md", + "hs-autodelivery-use.md", + "hs-autodelivery-modify.md", "hs-mobileirrigation-use.md", "hs-mobileirrigation-modify.md", "icon.png", From b38d75bee16614c0fecb323ebb496f147710af38 Mon Sep 17 00:00:00 2001 From: Katlin Walsh Date: Tue, 22 Oct 2024 16:20:00 -0400 Subject: [PATCH 2/2] UMC Tutorial Refresh Delivery Vehicle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created new use and modify tutorial for high school warehouse delivery robot lesson. 🚚🚚 --- hs-autodelivery-modify.md | 421 ++++++++++++++++++++++++++++++++++++++ hs-autodelivery-use.md | 284 +++++++++++++++++++++++++ pxt.json | 2 + 3 files changed, 707 insertions(+) create mode 100644 hs-autodelivery-modify.md create mode 100644 hs-autodelivery-use.md diff --git a/hs-autodelivery-modify.md b/hs-autodelivery-modify.md new file mode 100644 index 00000000..53092ecf --- /dev/null +++ b/hs-autodelivery-modify.md @@ -0,0 +1,421 @@ +# Forward Education Smart Warehouse Vehicle - Modify Tutorial + +```package +fwd-edu-breakout=github:climate-action-kits/pxt-fwd-edu/fwd-breakout +sonar=github:climate-action-kits/pxt-fwd-edu +``` + +```template +input.onButtonPressed(Button.A, function () { + IsDrivingEnabled = false +}) +input.onButtonPressed(Button.B, function () { + IsDrivingEnabled = true +}) +let IsDrivingEnabled = false +fwdSensors.ledRing.fwdSetAllPixelsColour(0xffffff) +fwdMotors.setupDriving( +fwdMotors.leftServo, +fwdMotors.rightServo +) +basic.forever(function () { + if (IsDrivingEnabled == false) { + fwdMotors.stop() + basic.showIcon(IconNames.No) + } + if (IsDrivingEnabled == true) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + } + } else if (fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . # . . . + # . . . . + . # . . . + . . # . . + `) + fwdMotors.turn(-2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.West) + fwdMotors.turn(-1) + } + } else { + fwdMotors.stop() + basic.showIcon(IconNames.Square) + } + } +}) +``` + +## Activity 1: Build Your Project @showdialog +Let's build a smart warehouse vehicle! We are going to do this in four parts: +1. **Build** our smart warehouse vehicle +2. **Add code** to make our project move +3. **Modify** our project to learn about other sensors +4. Apply what we learned with a small **challenge** + +Full smart warehouse vehicle render + +## Build Step 1 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs01.webp) + +## Build Step 2 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs02.webp) + +## Build Step 3 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs03.webp) + +## Build Step 4 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs04.webp) + +## Build Step 5 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs05.webp) + +## Build Step 6 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs06.webp) + +## Build Step 7 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs07.webp) + +## Build Step 8 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs08.webp) + +## Build Step 9 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs09.webp) + +## Build Step 10 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs10.webp) + +## Build Step 11 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs11.webp) + +## Build Step 12 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs12.webp) + +## Build Step 13 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs13.webp) + +## Build Step 14 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs14.webp) + +## Build Step 15 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs15.webp) + +## Build Step 16 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs16.webp) + +## Build Step 17 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs17.webp) + +## Build Step 18 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs18.webp) + +## Activity 2: Code Your Project @showdialog +We need to connect our project to the computer to make it come to life with code! + +The code will be the instructions that tell our micro:bit what to do. + +## Code Step 1 @showdialog +IMPORTANT! Make sure your Climate Action Kit Breakout Board is turned on and your micro:bit is plugged into your computer. + +Plug micro:bit into USB port on computer + +## Code Step 2 @showdialog +Click the three dots beside the ``|Download|`` button, then click on _Connect Device_. +Next, follow the steps to pair your micro:bit. + +Pairing gif + +## Code Step 3 +Click the ``|Download|`` button to download the starter code to your project. + +## Activity 3: Modify Your Project @showdialog +We have a smart warehouse vehicle that **follows a straight line** and **signals its direction** let's explore how to optimize our sensors by **modifying** our code! + +As you go through the next steps: +* Use the instructions at the top of the screen to **Modify** your code. +* When you are ready for more information, click **'Tell Me More!'** +* If you need help with the code, click the **lightbulb**! + +## Modify Step 1 +Think back to the lesson about automation in industrial warehouses. Our smart warehouse vehicle is an example of an [automated guided vehicle (AGV)](https://youtu.be/qahujJ-8vdk?si=2v8G7Mf5MFFAhvWM). + +What should it be able to do? + +~hint Tell Me More! +To move products around a warehouse, the smart warehouse vehicle should be able to: +1. **Follow** a pre-defined path (or black line) +2. **Communicate** the direction it will be travelling in + +We’ll also **modify** our code to enhance our project even further by: +3. **Sense** when an obstacle is in its path and stop driving +hint~ + +## Modify Step 2 +Let’s test it out! + +Unplug your project from your computer, place it on a straight black line, and press **B**. What happens? + +~hint Tell Me More! +* The micro:bit collects data from the line follower. The criteria for turning the motors is: +* **If** the left OR right side of the line senses the white paper, turn the motor in the opposite direction. +* This is known as a **conditional expression.** It is a **boolean**, meaning it must be evaluated as **true** or **false**. +hint~ + +```blocks +input.onButtonPressed(Button.B, function () { +//@highlight + IsDrivingEnabled = true +}) +``` + +## Modify Step 2 + +What will happen when we increase the driving speed in the driving block from **20** to **40**? + +Press the ``|Download|`` button to update the code on your micro:bit, set your vehicle down on the line again, and press **B** to test it. + +~hint Tell Me More! +The vehicle is moving forward twice as fast! +hint~ + +```block +fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 40) +``` +## Modify Step 3 +Did you notice if the speed change impacted the reliability of the following line? + +How many times did the vehicle have to re-adjust before reaching the end of the straight line? + +~hint Tell Me More! +It takes time for the micro:bit to process the data collected from the line sensor. The faster the vehicle moves, the less time the micro:bit has to sense where it is in relation to the line. +hint~ + +## Modify Step 4 +Updating our program doesn’t _always_ make it more efficient. How could you improve or adjust the code so the vehicle still senses the line properly? + +Adjust your code and document how many times the vehicle had to re-adjust before reaching the end of the straight line. + +~hint Tell Me More +Remember to download your code to your micro:bit after editing your code! + +We could increase the accuracy of our line follower in a few ways: +* Set the speed back to 20 (or lower!) +* Add a wait block after each conditional statement +hint~ + +```blocks +basic.forever(function () { + else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + //@highlight + basic.pause(1000) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + //@highlight + basic.pause(1000) + } + } + } +``` + +## Modify Step 5 +Let’s test another component that our Smart Warehouse Vehicle is using! + +How do you think that the **LED Light** is helping our warehouse vehicle drive on the black line? + +~hint Tell Me More! +Our line follower senses the contrast between black and white. + +The LED ring helps light up the **black** line on the **white** paper in different lighting conditions. +hint~ + +```block +fwdSensors.ledRing.fwdSetAllPixelsColour(0xffffff) +``` +## Modify Step 6 @showdialog +Based on your understanding of how the vehicle acted the first time you tested it, how do you think it will navigate a black line when the LED is set to different lighting conditions? + +1. Set the LED light to white +2. Set the LED light to red +3. Turn the LED light off +4. Turn off the lights in the room with the LED light off + +Write your prediction down! + +## Modify Step 7 +Now it’s time to test your prediction! + +Test each of the four lighting conditions 5 times on the straight line and document your findings in a table. + +Remember to download the code each time you change the lighting conditions. + +~hint Tell Me More! +You may wish to collect data about: + +1. How long does it take to complete the course? +2. How many times does the vehicle need to adjust its position? +3. How many times did the vehicle successfully complete the course? +hint~ + +## Challenge Time! @showdialog +Our project build includes a **sonar sensor** we’re not currently using. + +Now that our smart warehouse vehicle drives on a line in different lighting conditions, add the ability to sense its surroundings and **wait until the path is clear**! + +## Challenge Step 1 +Think about where in your conditional statement you should add the **sonar sensor** so that your vehicle detects an obstacle and safely waits until the path is clear. + +Remember to download your code once you add the sonar block to your conditional statement. + +~hint Tell Me More! +The sonar sensor should only drive forward if: +* Obstacles are **Over** a certain distance in front of your vehicle. +* **After** IsDrivingEnabled is set to true +* **Before** driving forward or turning on a line. +hint~ + +```block +fwdSensors.sonar1.fwdDistancePastThreshold(0, fwdSensors.ThresholdDirection.Over) +``` + +## Challenge Step 2 +Test your vehicle again on the straight line. Does it act the way you expected it to? + +Did you include a way for your vehicle to signal that an obstacle is in the way? + +~hint Tell Me More! +Click on the lightbulb for one example of how to add a sonar sensor and signal to our code! +hint~ + +```blocks +basic.forever(function () { + if (IsDrivingEnabled == true) { + //@highlight + if (fwdSensors.sonar1.fwdDistancePastThreshold(1, fwdSensors.ThresholdDirection.Over)) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + } + } else if (fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . # . . . + # . . . . + . # . . . + . . # . . + `) + fwdMotors.turn(-2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.West) + fwdMotors.turn(-1) + } + } else { + fwdMotors.stop() + basic.showIcon(IconNames.Square) + } + } + //@highlight + else { + //@highlight + basic.showIcon(IconNames.Sad) + //@highlight + fwdMotors.stop() + } + } +}) +``` + +## Challenge Step 3 +Now that your vehicle detects an obstacle, we need to decide **how far away** it should stop from an obstacle! + +Using your ruler, measure the distance the vehicle should detect. Our vehicle uses metres as a unit of measurement. You may need to convert your measurement. + +~hint Tell Me More! +For example: If we want the vehicle to sense obstacles under 30 cm, our code block should be 0.3 m. + +If your vehicle is plugged into your computer, you can use the **live visualizer** to see how far away your sonar sensor detects objects! + +Remember to download the code each time you change the code. +hint~ + +```blocks +basic.forever(function () { + if (IsDrivingEnabled == true) { + //@highlight + if (fwdSensors.sonar1.fwdDistancePastThreshold(.3, fwdSensors.ThresholdDirection.Over)) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } + } + else { + basic.showIcon(IconNames.Sad) + fwdMotors.stop() + } + } +}) +``` + +fwdSensors.sonar1.fwdDistancePastThreshold(.3, fwdSensors.ThresholdDirection.Over) +``` +## Challenge Complete! +You did it! + +Think about how you would test the effectiveness of the sonar sensor. What tests should you complete to verify that your vehicle still follows a line? + +~hint Tell Me More! +You may wish to think about: +* How far away should the sonar sensor detect? +* How should it signal that it senses an obstacle? +* How should you test that the existing line follower is still accurate? +hint~ + +## Congratulations! @showdialog +You've completed the activity! + +Did anything surprise you about the project? + +## Reflection @showdialog +How did using predictions and data collection help you better understand your code? + +What differences did you find in the accuracy of the line follower? + +What else do you want to modify to enhance your vehicle build even more? + +## Finished! @showdialog +In the next step, you can click the ``|Done|`` button to finish the tutorial. \ No newline at end of file diff --git a/hs-autodelivery-use.md b/hs-autodelivery-use.md new file mode 100644 index 00000000..c486f63d --- /dev/null +++ b/hs-autodelivery-use.md @@ -0,0 +1,284 @@ +# Forward Education Smart Warehouse Vehicle - Use Tutorial + +```package +fwd-edu-breakout=github:climate-action-kits/pxt-fwd-edu/fwd-breakout +sonar=github:climate-action-kits/pxt-fwd-edu +``` +```template +input.onButtonPressed(Button.A, function () { + IsDrivingEnabled = false +}) +input.onButtonPressed(Button.B, function () { + IsDrivingEnabled = true +}) +let IsDrivingEnabled = false +fwdSensors.ledRing.fwdSetAllPixelsColour(0xffffff) +fwdMotors.setupDriving( +fwdMotors.leftServo, +fwdMotors.rightServo +) +basic.forever(function () { + if (IsDrivingEnabled == false) { + fwdMotors.stop() + basic.showIcon(IconNames.No) + } + if (IsDrivingEnabled == true) { + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) + } else if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . . . # . + . . . . # + . . . # . + . . # . . + `) + fwdMotors.turn(2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.East) + fwdMotors.turn(1) + } + } else if (fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) || fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit)) { + basic.showLeds(` + . . # . . + . # . . . + # . . . . + . # . . . + . . # . . + `) + fwdMotors.turn(-2) + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && (fwdSensors.line2.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Hit))) { + basic.showArrow(ArrowNames.West) + fwdMotors.turn(-1) + } + } else { + fwdMotors.stop() + basic.showIcon(IconNames.Square) + } + } +}) +``` + +## Activity 1: Build Your Project @showdialog +Let's build a smart warehouse vehicle! We are going to do this in four parts: +1. **Build** our smart warehouse vehicle +2. **Add code** to make our project move +3. **Use** or test out our line follower to learn how it works +4. Apply what we learned with a small **challenge** + +Full smart warehouse vehicle render + +## Build Step 1 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs01.webp) + +## Build Step 2 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs02.webp) + +## Build Step 3 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs03.webp) + +## Build Step 4 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs04.webp) + +## Build Step 5 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs05.webp) + +## Build Step 6 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs06.webp) + +## Build Step 7 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs07.webp) + +## Build Step 8 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs08.webp) + +## Build Step 9 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs09.webp) + +## Build Step 10 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs10.webp) + +## Build Step 11 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs11.webp) + +## Build Step 12 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs12.webp) + +## Build Step 13 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs13.webp) + +## Build Step 14 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs14.webp) + +## Build Step 15 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs15.webp) + +## Build Step 16 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs16.webp) + +## Build Step 17 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs17.webp) + +## Build Step 18 @showdialog +![sbs1](https://raw.githubusercontent.com/climate-action-kits/pxt-fwd-edu/refs/heads/main/tutorial-assets/hs-autodelivery-sbs18.webp) + +## Activity 2: Code Your Project @showdialog +We need to connect our project to the computer to make it come to life with code! + +The code will be the instructions that tell our micro:bit what to do. + +## Code Step 1 @showdialog +IMPORTANT! Make sure your Climate Action Kit Breakout Board is turned on and your micro:bit is plugged into your computer. + +Plug micro:bit into USB port on computer + +## Code Step 2 @showdialog +Click the three dots beside the ``|Download|`` button, then click on _Connect Device_. +Next, follow the steps to pair your micro:bit. + +Pairing gif + +## Code Step 3 +Click the ``|Download|`` button to download the starter code to your project. + +## Activity 3: Use Your Project @showdialog +Now that we've built our smart warehouse vehicle, we'll start by **using** sample code to see how it works. + +As you go through the next steps: +* **Use** the instructions at the top of the screen. +* When you are ready for more information, click **'Tell Me More!'** +* If you need help with the code, click the **lightbulb**! + +## Use Step 1 +Think back to the lesson about automation in industrial warehouses. Our smart warehouse vehicle is an example of an [automated guided vehicle (AGV)](https://youtu.be/qahujJ-8vdk?si=2v8G7Mf5MFFAhvWM). + +What should it be able to do? + +~hint Tell Me More! +To move products around a warehouse, the smart warehouse vehicle should be able to: +1. **Follow** a pre-defined path (or black line) +2. **Communicate** the direction it will be travelling in + +Different warehouse automation products may have more features, but these are the minimum requirements. +hint~ + +## Use Step 2 +Take a look at the physical project you just built. + +What robotic components do you notice? How do you think they’ll work together to make the smart warehouse vehicle function as expected? + +~hint Tell Me More! +The smart warehouse vehicle has: + +* Two **continuous servo motors** that rotate a full 360 degrees. They will spin the wheels to allow the vehicle to drive forward. +* One **line follower** with three sensors to identify black and white. They will identify if the robot is on the line, drifting one way or the other, and if it is at the end of a path. +* One **LED ring** to light up the path to help the line follower see black and white. +* One **sonar sensor** that you may use to see if there is an object in the vehicle’s way. +* These parts are all connected to the **breakout board** through **cables**. +* Finally, the breakout board is connected to the **micro:bit** which holds all the code that will tell our motors what to do and when to do it! +hint~ + +## Use Step 3 +Let’s test it out! + +Unplug your project from your computer, place it on a straight black line, and press **B**. What happens? + +~hint Tell Me More! +* The micro:bit collects data from the line follower. The criteria for turning the motors is: +* **If** the left OR right side of the line senses the white paper, turn the motor in the opposite direction. +* This is known as a **conditional expression.** It is a **boolean**, meaning it must be evaluated as **true** or **false**. +hint~ + +```blocks +input.onButtonPressed(Button.B, function () { +//@highlight + IsDrivingEnabled = true +}) +``` + +## Use Step 4 +Can you explain how the vehicle can drive along the line? + +~hint Tell Me More! +* We are controlling the vehicle with a **nested conditional statement**. +* Nested conditional statements are "**if-then**" rules used in coding for programs with **many paths**. +* They add checkpoints to our programs and tell the computer what to do in different situations, like showing a different message if it is sunny, raining, or cloudy outside. +hint~ + +## Use Step 5 +Can you identify one of the **nested conditionals** that helps the vehicle navigate a straight line? + +What _criteria_ help the micro:bit decide what to do? + +~hint Tell Me More! +There are several conditionals nested in this code! + +1. If the **B button is pressed** > set driving enabled to true +2. If the vehicle **senses a line** > signal using the LEDs on the micro:bit and drive forward. +3. If the vehicle senses that it’s drifted to the **right or left of the line** > signal using the LEDs on the micro:bit and turn 2 degrees toward the line +4. If the vehicle **still isn’t on the line** > signal with the LEDs on the micro:bit and turn 1 degree toward the line +5. If the vehicle senses the **end of the line** > signal using the LEDs on the micro:bit and stop driving +hint~ + +```blocks +basic.forever(function () { + if (IsDrivingEnabled == true) { + //@highlight + if (fwdSensors.line1.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss) && fwdSensors.line3.fwdIsLineSensorState(fwdSensors.LineSensorState.Miss)) { + basic.showArrow(ArrowNames.North) + fwdMotors.drive(fwdMotors.DrivingDirection.Forward, 20) +``` + +## Challenge Time! @showdialog +Now that we have **used** code to create a smart warehouse vehicle that **follows a straight line** and **signals its direction**, we need to collect data to evaluate what other types of lines it can follow! + +## Challenge Step 1 +Based on how the vehicle acted the first time you tested it, how do you think the vehicle will perform on the following types of lines: + +1. A straight line +2. A straight line with a 45-degree turn +3. A wide curved line + +Write your prediction down! + +## Challenge Step 2 +Now it’s time to test your prediction! + +Test each of the three courses 5 times and document your findings in a table. + +~hint Tell Me More! +You may wish to collect data about: + +1. How long does it take to complete the course? +2. How many times does the vehicle need to adjust its position? +3. How many times did the vehicle successfully complete each course? +hint~ + +## Challenge Step 3 +Does the vehicle drift to one side more often than the other? Why do you think this is? + +Is there any part of your course that your robot gets “stuck” every time? + +Try making a new line for your robot to follow what you’ve learned from your data. + +~hint Tell Me More! +Line-following vehicles need lots of testing to make the path more reliable! + +You may have found that a long, straight line can be followed more reliably than a tightly curved line or a sharp, 90-degree turn. +hint~ + +## Congratulations! @showdialog +You've completed the activity! + +Did anything surprise you about the project? + +## Reflection @showdialog +How did using predictions and data collection help you better understand your code? + +What differences did you find in the accuracy of the line follower? + +What else do you want to modify to enhance your vehicle build even more? + +## Finished! @showdialog +In the next step, you can click the ``|Done|`` button to finish the tutorial. \ No newline at end of file diff --git a/pxt.json b/pxt.json index e9fb828b..50a6e03b 100644 --- a/pxt.json +++ b/pxt.json @@ -86,6 +86,8 @@ "gr9-treeSeeder-modify.md", "gr9-verticalfarm-use.md", "gr9-verticalfarm-modify.md", + "hs-autodelivery-use.md", + "hs-autodelivery-modify.md", "hs-mobileirrigation-use.md", "hs-mobileirrigation-modify.md", "icon.png",