01 Mission Instructions

5. Code

You may have built a nice garage for your GoPiGo, but now your robot is sitting forlornly on the ground where you left it, refusing to come out and explore the world. If you want this robot to listen to you, you are going to need to learn to program.

Make sure your computer is connected to your wifi network, turn on the GoPiGo, and connect to the robot.

Once you connect, click on the "Code in Bloxter" button.

When you are ready to program, make sure your GoPiGo is in a safe place. It can be easy to accidentally turn on the motors when you are programming. So choose one of these safe robot positions:

      1. Set your GoPiGo on the floor, with plenty of room to move around safely, or 
      2. Flip it upside down onto its back, so that the wheels can spin freely without moving the robot.

Image shows the Bloxter blocks available in the programming menu. It is labeled with explanations of what each block does.

Go back to your plan from the Design phase of this mission.

Now you will rewrite your plan in language the GoPiGo can understand. Here's an image that might help you turn your written plan into code.

Your exact program will depend on the location of your garage and finish line, but you may come up with something similar to this.

You might notice some interesting numbers in our example code. When we tell the robot to turn LEFT, we tell it to keep doing that for 0.5 seconds instead of one second. Why? In our case, a one second turn would be far too long. 

We’d like to turn for about half as long. In Bloxter, we can’t type in a fraction like ½. We have to turn it into a decimal and type 0.5. (It'll look just like the way Americans write down cents instead of dollars). If your robot needs to make quick turns, or travel some short distances, try using decimals instead of whole numbers!

Make sure to add a “stop GoPiGo” at the end!

Whenever you change your program, save it! Otherwise it will be deleted when you turn off your robot. You can save it on the SD card or on a USB key. 

To save your program, click on the File button, then Save File. 

Use the dropdown menu to choose where to save your file (SD card or USB key). The name for your program cannot contain spaces.