1: Basic Drive Commands

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:It’s time to make Zumi move! Open the “Driving” menu from the Junior blocks tab to see all of the Junior driving functions.

Click and drag the forward block into the workspace and press the green “Run” button. Make sure Zumi has enough space!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.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.You can connect more than one forward block in a row. Attach some forward blocks together like this. Feel free to change the parameters!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.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.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.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.Practice driving and turning! You can try different angles by changing the degrees parameter.

If you need some help figuring out the degrees, remember that a circle has 360 degrees. Use this chart to help you.It’s time for your first challenge! Using what you know so far, program Zumi to drive in a square around the block. Remember, a square has four sides all the same length and right angle turns. You can use either all right turns or all left turns. If you are stuck, take a look at image below. When you’re done, scroll down to see the solution.If you have something similar to the code below, good job! Pop quiz! How would you make the square bigger or smaller?To make the square bigger or smaller, you would need to change all of the durations for the forward blocks. There is a way to make this code more efficient, but you will learn about that later.If Zumi makes a wrong turn, what should she do? In the real world, reversing down the street would not be a good idea. Practice doing a U-turn with the U-turn blocks. There is a new parameter for speed which can be anywhere from 0 to 100. Safe U-turns should be done at low speeds, just like real-life!

Activity: Build your own “street”. You can use paper to draw one or use household objects like pens and pencils to create a lane. Have Zumi drive down the street and make a left U-turn at the end of the street and drive back. Make sure to include a wait before your U-turn to check for oncoming traffic. See below for an example code.One of the most important skills for a driver and an autonomous car is parking. Parking can be tricky, especially parallel parking. Parallel parking is when you need to park on the side of the road in between two cars or objects.Activity: Set up two objects or Zumis to be cars parked on the side of the road a little bit ahead of where Zumi is. Use the drive forward command to drive up to the space, then use the parallel parking block to park. It may take some practice getting the parameters right.A gyroscope is a sensor that helps Zumi drive straight. You will learn about the gyroscope more later, but if you feel like your Zumi is driving a little bit sideways you can use the calibrate gyro block at the beginning of your program.You learned how to program your own square using drive commands, but you can use some of the shape blocks instead. Open the “Shapes” menu to access them. You can change if the shape turns left or right but you will not be able to change the speed or the size. You can do that as a challenge!There are two blocks in this list that you may not be familiar with yet: the figure-8 and J-curve turns. This is what those movements look like:Use these blocks when you want to show off your driving skills!You made it! You learned all about how to use the junior basic driving commands. We skipped the “stop” block for now, but you will learn how to use it in a later lesson. Before moving on to the next lesson, make sure you know what each block does and what 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