- Product pages (Code Editor, Robot Simulator): text-left/image-right hero layout - Related resources capped at 3 items on all product pages - Making Music activities renamed to I, II, III - New Maze I/II/III and Sumo I/II/III difficulty-graded activities - YouTube demo videos restored on 12 activity pages from old site - Activity pages: two-column hero with coding skills & rover concepts tags - Blog/news pages: same two-column hero layout with date - Resource type extended with codingSkills, roverConcepts, tags fields - Removed raw "Relevant Coding Skills/Rover Concepts" text from activity MDX Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
40 lines
2.1 KiB
Plaintext
40 lines
2.1 KiB
Plaintext
---
|
||
title: "Activity: Random Bug Bot"
|
||
date: "2021-06-03"
|
||
categories: ["Activities", "All"]
|
||
tags: ["Iteration", "Motors", "Maths", "Beginner", "Colour Sensors"]
|
||
codingSkills: ["Iteration", "Maths"]
|
||
roverConcepts: ["Motors", "Colour"]
|
||
excerpt: "Learn branching using the motors and maths."
|
||
featuredImage: "/images/resources/random-bug-bot.png"
|
||
---
|
||
|
||
|
||
Program the rover to act like a bug and move around randomly looking for food. Using the random number math block generate a speed for each of the motors. This will create a randomly moving bug rover.
|
||
|
||
### Activity Demonstration
|
||
|
||
<iframe width="560" height="315" src="https://www.youtube.com/embed/xiA_f1Zi-b8" title="Random Bug Bot Activity Demonstration" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowFullScreen></iframe>
|
||
|
||
### Setup
|
||
|
||
The random number generation of the rovers speed in our approach will have the rover move around randomly. Depending on the ranges students use, their random numbers may result in rovers driving a long way. Make sure to set the speeds and durations to suit the space you have and keep an eye on the rovers while they’re driving.
|
||
|
||
### Here’s Our Approach
|
||
|
||
#### **Stage 1**
|
||
|
||
Start with an advanced motor block for setting different speeds for our left and right motors. Inside each of these slots we can use the random integer block from our math category. We use the numbers -15 to 15, any number that is negative will cause the motor to go backwards. The block has a chance of setting either motors to go forward or backward.
|
||
|
||
#### **Stage 2**
|
||
|
||
We need to control how long our rovers run at this speed. We can use the delay block to tell our code to continue what it’s doing for now. To continue the trend of our rover being unpredictable we will use another random integer block to set a random number between 1 and 3 for the amount of seconds our rover will move.
|
||
|
||
#### **Stage 3**
|
||
|
||
After the delay has ended we want our rover to pick new random speeds so we place the code in a repeat while true loop.
|
||
|
||

|
||
|
||
Example Code
|