2 How to Move

Learning Outcomes

    • Introducing the concept of functions.
    • Demonstrate how to use functions to make Zumi move forward, backward, and turn.
    • Learning how to adjust the parameters of the functions to control the speed, duration, and direction of Zumi’s movements.
    • Providing a basic understanding of programming and robotics through hands-on experience with Zumi.

zumi blockly driving menu


What is a function?

Every block you see in Blockly makes Zumi do a different action. These blocks run code called functions. Think of functions as packages of code that you can use to write your programs. Functions can have inputs and outputs. Blocks that require inputs will have a space for you to input some values. These extra pieces of information are called parameters. Here are some sample blocks that have parameters:

zumi blockly examples with parameters

Drive forward

It’s time to make Zumi move! Open the “Driving” menu from the Junior blocks tab to see all of the Junior driving functions.
zumi blockly driving menu
Click and drag the forward block into the workspace and press the green “Run” button. Make sure Zumi has enough space!

zumi blockly forward block
Did Zumi drive forward? Now try changing the seconds parameter. Remember that a parameter is an input that can modify a function. Try driving forward for 3 seconds now.
zumi blockly forward with 3 seconds
You can also change the speed that Zumi drives at! Try changing the speed parameter to 20. Speed always ranges from 0 to 100. No, this is not in miles per hour! It is related to Zumi’s battery power.
zumi blockly drive change speed


Wait!

You can connect more than one forward block in a row. Attach some forward blocks together like this. Feel free to change the parameters!
zumi blockly three forwards in a row
Right now it’s hard to tell when one function ends and the next one begins. Sometimes you want to make the program wait between functions. Open the timing menu and find the “Wait” block.
zumi blockly timing menu
Then, add a wait for 1 second in between each drive command. Rerun your code and watch what happens. You can also try changing the seconds parameter in the “Wait” blocks to pause for longer between each drive command.
zumi blockly forwards with waits


Reverse

The reverse function works almost exactly the same as the forward function. It has a seconds parameter that you can change to set how long Zumi drives. Let’s drive forward for 2 seconds, wait for 2 seconds, then drive in reverse for 2 seconds to return to the start.
zumi blockly reverse example


Turning

Roads have curves, bends, and turns that Zumi should be able to navigate. There are two turn functions that you can use. One block is for right turns and one block is for left turns. For each turn that you want to make, you need to know how many degrees you want to turn.
zumi blockly turn left and right
Practice driving and turning! You can try different angles by changing the degrees parameter.
zumi blockly driving and turning
If you need some help figuring out the degrees, remember that a circle has 360 degrees. Use this chart to help you.
zumi turn angles


Test Your Knowledge


Review The Key Concepts


Solve The Problem

Scenario: Our autonomous vehicle needs to deliver a package safely from a storage depot and return to the original location. It is important to make sure the package receiver has enough time to take the package from the vehicle, before it returns to ensure no one is injured.

Problem: How can you run this program on Zumi using the Blockly application?


Sample Solution

There are many different ways that we can solve the problem listed above. Please watch the following video to review a sample solution completed by Ontario Tech University Engineering Students.

Demo

Code


Common Errors

Errors can also occur while creating a solution to the problem. Please review the video below to view some of the common errors that can occur.

Common Errors Video: Coming Soon.


Connecting The Dots

License

Foundations of programming with Blockly and Zumi Copyright © by Brandon Carson. All Rights Reserved.

Share This Book