Migrating from loop based code - ThunderboltsRobotics/EZ-WPILibJ GitHub Wiki
Migrating from Iterative
Refactor package (Optional)
The package name org.usfirst.frc.teamXXXX
no longer reflects the FIRST website. This API uses org.firstinspires.frc.framework.*
and recommends org.firstinspires.frc._XXXX
(where XXXX is your team number) for teams.
Main class
Somewhere in your project, there will be a class (called Robot
by default) that extends IterativeRobot
. In this class, among other things, there may be various methods:
robotInit()
disabledInit()
anddisabledPeriodic()
autonomousInit()
andautonomousPeriodic()
teleopInit()
andteleopPeriodic()
testInit()
andtestPeriodic()
To start, change extends IterativeRobot
to extends BetterRobot
(you may have to import org.firstinspires.frc.framework.granulation.BetterRobot
manually). Then shorten robotInit()
to init()
, shorten autonomous*()
to auto*()
, and finally replace *Init()
with *Start()
and *Periodic()
with *Loop()
. The new list of functions is:
initialize()
(orinit()
)disabledStart()
anddisabledLoop()
autoStart()
andautoLoop()
teleopStart()
andteleopLoop()
testStart()
andtestLoop()
...and they get run by the FMS (or DS, locally) in the same way.
Motors
Next, motors. WPILibJ's motor controller classes are overflowing with methods, and you need to know how the motors are plugged in. To fix this, find where you've got one of:
Jaguar
someName= new Jaguar(
someNumber);
SD540
someName= new SD540(
someNumber);
Spark
someName= new Spark(
someNumber);
Talon
someName= new Talon(
someNumber);
TalonSRX
someName= new TalonSRX(
someNumber);
Victor
someName= new Victor(
someNumber);
VictorSP
someName= new VictorSP(
someNumber);
...and replace it with MotorController
someName = new MotorController(RioHWPort.PWM_
someNumber, MotorControllerType.
someType);
, where the name can be whatever you'd like (e.g. tankDriveRight, lifterArm), the number is the same PWM port number, and the type is the type of speed controller (note that WPILibJ's Talon class is for the Talon and TalonSR models).
Using CAN, not PWM? Replace any of:
CANJaguar
someName= new CANJaguar(
someNumber);
CANTalon
someName= new CANTalon(
someNumber);
...with MotorController
someName = new MotorController(new RioCANID(
someNumber), MotorControllerType.
someType);
(the type must be Jaguar or TalonSRX). Here, the CAN ID is an object instead of an enum because the IDs aren't limited to 0-9.
These MotorController objects have a few simple methods:
.setSpeed()
, to 'write' the desired value;.reverse()
, to reverse (put a - in front of it) — note that reversing it twice makes it go forward as expected;.isReversed()
, to see if it's reversed or not.