Learn 2: Classes and Instances
This is the first challenge within the Robotics with GoPiGo and Python Curriculum.
Your task is to program your robot to navigate an area of previously unseen terrain to reach its destination, passing through a number of waypoints.
1. Classes and Instances
To make things really easy for us we can instruct our robot using functions that have been written for us in a class library. These functions will result in robot actions such as moving and turning.
What is a class library?
A class library is a blueprint for creating objects of a specific type (e.g. cars) and describing their properties (e.g. make, model, color) and the things that they can do (e.g. drive forward). It tells us what we can instruct the object to do and usefully hides all the complicated details of how it does it from us.
For example, to drive a go-kart the driver doesn't need to know how the steering wheel and pedals are connected to the motor and wheels in order to make it move. They just need to know the effects of the motion of the steering wheel and pedals and how to use them.
What is an instance?
To work with an example of an object we use a constructor function to create and name an instance of a class and instruct this instance using the functions defined in the class library. We can create and use many instances of a class in our code at the same time if we wish. Just imagine what you could do with a whole army of robots at your command!