Module Classes (Step 2)
Programming Robot Modules
Prerequisites
Consider the base class to be the empty skeleton of your robot, a base class with no module classes is an empty robot. Each of your module classes will represent a hardware module on your robot such as your drive system, linear slide system, claws, etc. And each of your modules will contain some combination of sensors, motors, and servos. The purpose of your module classes will contain functions that control these hardware mechanisms to perform your functions.
By organizing your modules with classes, executing the purpose of the module can be as simple as calling the function in your opMode, allowing you to have an organized codebase.
Implementation
Suppose that you have a robot with a singular arm, controlled by a motor connected to an encoder. Following the code structure outlined, you create an Arm class containing the functions needed to control the arm motor and a base class that contains the module.
Base Class
Here we initialize the arm module as a global variable and fully initialize the class within our initailizeHardware
function. Note that we also pass the motor needed for the class to function as a parameter within the class constructor.
Module Class
Here we will create the functions required for the arm to execute its purpose. Take for example making the arm motor move some amount of encoder ticks.
In the next module, you will learn how to integrate opModes with this type of code structure!
Last updated