Simple Driving Tutorial - ThunderboltsRobotics/EZ-WPILibJ GitHub Wiki
Note: This article will guide you through programming an FRC robot's computer (the RoboRIO) to drive. It assumes that the robot is assembled and wired correctly, you've updated the RoboRIO firmware, flashed the RoboRIO, installed the latest Java, flashed the radio, correctly set up your development environment (DS and libs; choose IDEA or Eclipse), and know how to use your chosen IDE.
Outlining your project
Create a new package under org.firstinspires.frc
called _XXXX
, where XXXX is your team number (e.g. org.firstinspires.frc._4739
for FRC 4739 Thunderbolts Robotics). In this package, create a new class called RobotMain
or something similar. Modify this class to extend BetterRobot (following the example of RobotMain
): public class RobotMain extends BetterRobot
. You may need to manually import org.firstinspires.frc.framework.granulation.BetterRobot
. If they were not added automatically, your main class must implement the following methods:
public void disabledStart() {}
public void disabledLoop() {}
public void autoStart() {}
public void autoLoop() {}
public void teleopStart() {}
public void teleopLoop() {}
public void testStart() {}
public void testLoop() {}
These methods are where you put the code you'd like to have run during the various match phases: disabled, autonomous, teleoperated, and test (off the field).
Optionally, create a subpackage for your various routines: org.firstinspires.frc._XXXX.routines
or similar.
Hardware setup
Create a new class Hardware
(either in its own file or as a subclass of RobotMain
). This class should contain all your hardware, to be statically referenced by the rest of your codebase.
Motors / Speed Controllers / Motor Controllers
Motors are controlled by instances of MotorController. Add:
private static final MotorController
name = new MotorController(
p,
t);
where name is the variable name; p is either a RioHWPort
enum (for PWM-wired controllers) or an instance of RioCANID
(for CAN-wired controllers); and t is a MotorControllerType
enum. For example:
private static final MotorController leftDrive = new MotorController(RioHWPort.PWM_0, MotorControllerType.TalonSR);
for a motor controlled by a TalonSR wired into PWM port #0 on the Rio.