Unit 7: Advanced FRC Coding
This is the control scheme that gives our robots their signature on-field agility. Field-Oriented Control decouples the robot's movement from its rotation, allowing for incredibly intuitive and fluid maneuvers that are a standard for high-level FRC play.
In Field-Oriented Control, the joystick inputs are always relative to the playing field, not the robot's own orientation. This dramatically lowers the cognitive load on the driver, allowing them to react faster and more precisely.
How does the robot know which way the field is? The secret is the gyroscope. A gyro continuously measures the robot's rotational angle, or heading. By knowing the robot's current heading, our code can mathematically adjust the driver's commands to be relative to the field.
The implementation adds one crucial step to the process we learned in Robot-Oriented Control. We use a WPILib helper method to translate the driver's field-relative commands into robot-relative commands that the kinematics can understand.
// In a command that controls driving...
public void execute() {
// 1. Read the joystick axes for desired field-relative speeds.
double vx = -m_joystick.getY(); // Desired speed DOWNFIELD
double vy = -m_joystick.getX(); // Desired speed to the RIGHT
double omega = -m_joystick.getZ(); // Desired rotation
// 2. This is the magic step!
// Use the gyro's current angle to convert field-relative speeds
// into robot-relative speeds.
ChassisSpeeds robotCentricSpeeds = ChassisSpeeds.fromFieldRelativeSpeeds(
vx,
vy,
omega,
m_drivetrain.getGyroRotation() // Get the robot's current heading from the gyro
);
// 3. Send the now-corrected, robot-centric speeds to the drivetrain.
m_drivetrain.drive(robotCentricSpeeds);
}
Question: In Field-Oriented Control, if the robot is facing sideways and the driver pushes the joystick straight forward, which way will the robot move?