Unit 7: Advanced FRC Coding
While we primarily use Field-Oriented Control in competition, understanding Robot-Oriented Control is a critical first step. It is the foundational layer upon which our advanced control systems are built and serves as an essential fallback system.
Robot-Oriented Control is the most direct way of driving a swerve robot. In this mode, the joystick controls are always relative to the robot's frame of reference.
Think of it exactly like playing a first-person video game or driving a car. "Forward" is always "forward" from your current perspective.
The implementation is beautifully simple. We take the raw values from the driver's controller and use them to create a `ChassisSpeeds` object directly. This object represents the robot's desired velocity relative to its own frame.
// In a command that controls driving...
public void execute() {
// 1. Read the joystick axes.
// We get forward/backward speed (vx), sideways speed (vy), and turning speed (omega).
double vx = -m_joystick.getY(); // Forward/Backward
double vy = -m_joystick.getX(); // Left/Right (Strafe)
double omega = -m_joystick.getZ(); // Rotation
// 2. Create a ChassisSpeeds object directly from joystick values.
// Notice what's missing: the gyroscope is NOT used here for translating the driver's commands.
ChassisSpeeds robotCentricSpeeds = new ChassisSpeeds(vx, vy, omega);
// 3. Send these speeds to the drivetrain subsystem.
// The drivetrain will use inverse kinematics to calculate the module states.
m_drivetrain.drive(robotCentricSpeeds);
}
While we prefer Field-Oriented for its massive strategic advantages, Robot-Oriented Control is still vital for two key reasons:
Question: In Robot-Oriented Control, if the robot is facing sideways relative to the field and the driver pushes the joystick straight forward, which way will the robot move?