Robot-Oriented Control Lesson

Robot-Oriented Control

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.

What is Robot-Oriented Control?

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.

How It Feels to Drive

  • Pushing the joystick forward makes the robot move in the direction its front is pointing.
  • Pushing the joystick to the right makes the robot strafe directly to its own right side.
  • Twisting the joystick makes the robot rotate around its own center.

Think of it exactly like playing a first-person video game or driving a car. "Forward" is always "forward" from your current perspective.

How it Works in the Code

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

When is Robot-Oriented Control Useful?

While we prefer Field-Oriented for its massive strategic advantages, Robot-Oriented Control is still vital for two key reasons:

  1. As a Gyro Failsafe: If the gyroscope fails during a match, the driver can switch to this mode to continue playing effectively.
  2. For Simplicity and Testing: It's the simplest way to test if the basic swerve mechanics and kinematics are working correctly, as it removes the gyro as a variable.

Test Your Knowledge

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?