Module Classes (Step 2)
Programming Robot Modules
Implementation
Base Class
public abstract class Base extends LinearOpMode {
// Sensors
public IMU gyro;
// Module Classes
public Arm armModule = null; // This is an actual class with various methods
// Initialize Hardware Function
public void initHardware() throws InterruptedException {
// Hubs
List<LynxModule> allHubs;
allHubs = hardwareMap.getAll(LynxModule.class);
for (LynxModule hub : allHubs) {
hub.setBulkCachingMode(LynxModule.BulkCachingMode.AUTO);
}
// Motors
DcMotor armMotor = hardwareMap.get(DcMotor.class, "Drive Motor");
armMotor.setMode(DcMotor.RunMode.RUN_USING_ENCODER);
armMotor.setMode(DcMotor.RunMode.STOP_AND_RESET_ENCODER);
armMotor.setMode(DcMotor.RunMode.RUN_TO_POSITION);
// Init Module class
armModule = new Arm(armMotor);
}
//Utility Functions
public String formatDegrees(double degrees) {
return String.format(Locale.getDefault(), "%.1f", AngleUnit.DEGREES.normalize(degrees));
}
// Allows you to connect opModes to the base class
@Override
public abstract void runOpMode() throws InterruptedException;
}Module Class
Last updated