Activity: Random Bug Bot

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.

Relevant Coding Skills

Iteration
Maths

Relevant Rover Concepts

Motors

Activity Demonstration

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

Example Code

 

Related Posts

Previous
Previous

Activity: Driving Shapes 2

Next
Next

Activity: Puppy Bot