Chapter 1 – Introduction to Blockly with Zumis

1.2 – How to Move

Welcome to your first lesson with Zumi! Before you start exploring artificial intelligence and having Zumi drive on her own, you need to learn some basic drive commands. In this lesson, you will program Zumi to go forward, drive in reverse, turn right, and turn left.

Step 1: What is a Function?

In Blockly, each block makes Zumi do a different action. These blocks run code called functions. Functions are packages of code that you can use to write your programs. They can have inputs and outputs, where inputs are called parameters. Here are some sample blocks that have parameters:

image

Step 2: Drive Forward

Let’s get Zumi to move forward! To do this, we will need to open the “Driving” menu from the Junior blocks tab, which contains all the Junior driving functions.

image

Once you have opened the “Driving” menu, you can click and drag the “forward” block into the workspace and press the green “Run” button. But make sure that Zumi has enough space to move forward!

image

If Zumi moves forward successfully, you can try changing the seconds parameter. A parameter is an input that can modify a function. So, you can try driving forward for 3 seconds instead of the default time.

image

You can also change the speed at which Zumi moves. To do this, you will need to change the speed parameter. The speed parameter ranges from 0 to 100 and is related to Zumi’s battery power, not miles per hour.

image

Step 3: Wait!

You can connect more than one forward block in a row to create a sequence of movements.

image

But sometimes, it’s hard to tell when one function ends and the next one begins. This is where the “Wait” block comes in. To add a wait time between functions, open the timing menu and find the “Wait” block.

image

Then, add a wait for 1 second in between each drive command. You can also change the seconds parameter in the “Wait” blocks to pause for longer between each drive command.

image

By following these steps, you can program Zumi to move forward, change the duration of the movement, adjust the speed of the movement, and add wait time in between movements.

Step 4: Reverse

To make Zumi move backward, you can use the reverse function, which works similarly to the forward function. You can adjust the seconds parameter to determine how long Zumi should move in reverse. For example, you can drive forward for 2 seconds, wait for 2 seconds, and then move in reverse for 2 seconds to return to the starting point.

image

## Step 5: Turning
Zumi needs to be able to navigate curves, bends, and turns on the road. There are two turn functions available: one for right turns and one for left turns. To execute a turn, you must specify the number of degrees to turn.

image

Practice driving and turning by experimenting with different degree values.

image

If you’re unsure how many degrees to turn, remember that a circle has 360 degrees. The following chart may help you:

image

Step 6: Challenge

Problem

It’s time for a challenge! Use what you’ve learned so far to program Zumi to drive in a square around a block. A square has four sides of equal length and right-angle turns. You can use either all right turns or all left turns. If you get stuck, refer to the image below for inspiration. Scroll down to see the solution when you’re finished.

image

Solution

Congratulations, if you have a code similar to the one shown below! Here’s a pop quiz for you: how can you adjust the size of the square?

image

To resize the square, you would have to modify the duration for all the “forward” blocks. While this method works, there is a more efficient way to achieve this, but you’ll learn about it later.

Step 7: U-Turns

What should Zumi do if she makes a wrong turn? In the real world, reversing down the street is not a good option. To practice a safer way of turning around, use the U-turn blocks. There is a new parameter for speed, which can range from 0 to 100. It is recommended to perform U-turns at lower speeds, just like in real life!

image

Activity: Create your own “street” using paper or household objects. Have Zumi drive down the street and make a left U-turn at the end, followed by driving back. Add a wait block before your U-turn to check for oncoming traffic. Check out the example code below.

image

Step 8: Parallel Park

One of the essential skills for a driver and an autonomous car is parking. Parking can be tricky, especially parallel parking, which involves parking on the side of the road between two cars or objects.

image

**Activity:** Set up two objects or Zumis to act as parked cars on the side of the road ahead of Zumi. Use the drive forward command to approach the parking space, then use the parallel parking block to park. It may take some practice to adjust the parameters correctly.

image

Step 9: Calibrate the Gyroscope

A gyroscope is a sensor that helps Zumi drive straight. If you feel like your Zumi is driving a little bit sideways, use the calibrate gyro block at the beginning of your program.

image

Step 10: Shapes and Sequences

You already know how to program your own square using drive commands, but you can use some of the shape blocks as well. Open the “Shapes” menu to access them. You can change whether the shape turns left or right, but you cannot modify the speed or size. You can take that up as a challenge!

image

There are two blocks in this list that you might not be familiar with yet: the figure-8 and J-curve turns. Here’s what those movements look like:

image

image

Use these blocks to demonstrate your driving skills!

Step 11: Review

Congratulations! You have learned all about how to use the junior basic driving commands. We have not discussed the “stop” block yet, but you will learn how to use it in a later lesson. Before proceeding to the next lesson, make sure you understand what each block does and which parameters you can change.

* `forward`
* `reverse`
* `turn left`
* `turn right`
* `left U-turn`
* `right U-turn`
* `parallel park`
* `calibrate gyro`
* `triangle`
* `square`
* `rectangle`
* `circle`
* `figure-8`
* `J-turn`

 

Demo Video

 

Questions

License

Share This Book