Learn 3: Create Your First Class

This is the fifth challenge within the Robotics with GoPiGo and Python Curriculum.

Your task is to design a robot program to deliver a selection of mail to the residents of GoPiGo Drive, a small cul-de-sac containing 3 houses.

Learn how to how to use and calibrate the color sensor.

5. Init All the Things!

Let’s now create a basic class instance within our global init(  ) function (not the __init__() that is part of the GlobalVariables class)  a 

We do this by instantiating the container class

          • Find the Variable Initialization Cell
          • Add the following code.
          • Pay attention to indentation! (check against the image to be sure)

global var    
var = GlobalVariables()

You may have noticed that we haven’t passed the self argument to the GlobalVariables( ) class constructor function. self is a special class attribute. It references the current class instance. All class functions (or methods) use this as an implicit first argument. This means that you don’t need to state it when you call the function, it’s automatically added for you by the class definition. This makes the instance’s attributes and other methods accessible within the function definition.