Op Modes - Thunderbots5604/LightningSDK GitHub Wiki
Op Modes
Op Modes in the Thunderbots SDK are easy to create and maintain. Most op modes should be a subclass of SimpleOpMode
, TeleOp
, or Autonomous
. The main procedure of any op mode should be implemented in the main()
method, or the mainLoop()
method if the OpMode is designed to be looping.
Op Mode Types
Op Modes are usually one of three types: Tele-Operated, Autonomous, or Test. TeleOp programs should extend TeleOp
, as the TeleOp class provides default functionality. Autonomous programs can extend TeleOp as well, but extending Autonomous
provides the same functionality and makes the purpose of the class more clear. Test programs should extend LightningOpMode
, as there is no need for a DriveSystem in an test program.
Drive motor setup
Every SimpleOpMode
must have a getDriveMotorNames()
method that takes no arguments and returns an array of strings with the names of motors. For example, consider a robot with four wheels, where the front left motor is named "front_left", the front right motor is named " front_right", the back left motor is named "back_left", and the back right motor is named " back_right". For this robot, the getDriveMotorNames()
method would look like this:
@Override
protected String[] getDriveMotorNames() {
String[] drivemotors = {"front_left", "front_right", " back_left", "back_right"};
return drivemotors;
}
This also works with robots that have two wheels. The format is the same, but the two wheels are both considered by the SDK to be 'front' motors, and the back motors are ommitted. The getDriveMotorNames()
method might look something like this for a two-wheeled robot:
@Override
protected String[] getDriveMotorNames() {
String[] drivemotors = {"left_motor", "right_motor"};
returm drivemotors;
}
The getDriveMotorNames()
method is the only method you really need to get your op mode up and running, but there is more customization available if you need it.
Robot initialization
Any custom initialization routines can be implememted by overriding the initializeRobot()
, as long as the super method is called on the first line.
@Override
protected void initializeRobot() {
super.initializeRobot();
// your code here
}
Changing the drive system
The SDK assumes that the robot uses a standard tank drive system. If you need to change this, override the createDriveSystem()
method. If your robot uses a tank drive, the default implementation will work fine, and you won't need to do anything here. You may choose to use any of the drive systems implemented here, or to write your own drive system functionality. Any new drive system must extend DriveSystem.
protected DriveSystem createDriveSystem() {
return new TankDrive(this.getDriveMotorNames());
}
This is the version that appears in SimpleOpMode
.
If your robot uses a Mecanum drive, your op mode should override this method to look like this:
protected DriveSystem createDriveSystem() {
return new MecanumDrive(this.getDriveMotorNames());
}
The key thing to note here is that TankDrive
and MecanumDrive
both extend DriveSystem
.