Field-Oriented Control Lesson

Field-Oriented Control

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.

What is Field-Oriented Control?

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 It Feels to Drive

  • Pushing the joystick forward always moves the robot downfield (towards the opposing alliance wall), no matter which way the robot is facing.
  • Pushing the joystick to the right always moves the robot to the right from the driver's perspective.
  • Twisting the joystick still rotates the robot, but this rotation does not affect the forward/sideways movement.

The Key Ingredient: The Gyroscope

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.

How it Works in the Code

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);
}
    

Test Your Knowledge

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?