Class SwerveRequest.FieldCentricFacingAngle

java.lang.Object
com.ctre.phoenix6.swerve.SwerveRequest.FieldCentricFacingAngle
All Implemented Interfaces:
SwerveRequest
Enclosing interface:
SwerveRequest

public static class SwerveRequest.FieldCentricFacingAngle extends Object implements SwerveRequest
Drives the swerve drivetrain in a field-centric manner, maintaining a specified heading angle to ensure the robot is facing the desired direction

When users use this request, they specify the direction the robot should travel oriented against the field, and the direction the robot should be facing.

An example scenario is that the robot is oriented to the east, the VelocityX is +5 m/s, VelocityY is 0 m/s, and TargetDirection is 180 degrees. In this scenario, the robot would drive northward at 5 m/s and turn clockwise to a target of 180 degrees.

This control request is especially useful for autonomous control, where the robot should be facing a changing direction throughout the motion.

  • Field Details

    • VelocityX

      public double VelocityX
      The velocity in the X direction, in m/s. X is defined as forward according to WPILib convention, so this determines how fast to travel forward.
    • VelocityY

      public double VelocityY
      The velocity in the Y direction, in m/s. Y is defined as to the left according to WPILib convention, so this determines how fast to travel to the left.
    • TargetDirection

      public Rotation2d TargetDirection
      The desired direction to face. 0 Degrees is defined as in the direction of the X axis. As a result, a TargetDirection of 90 degrees will point along the Y axis, or to the left.
    • TargetRateFeedforward

      public double TargetRateFeedforward
      The rotational rate feedforward to add to the output of the heading controller, in radians per second. When using a motion profile for the target direction, this can be set to the current velocity reference of the profile.
    • Deadband

      public double Deadband
      The allowable deadband of the request, in m/s.
    • RotationalDeadband

      public double RotationalDeadband
      The rotational deadband of the request, in radians per second.
    • MaxAbsRotationalRate

      public double MaxAbsRotationalRate
      The maximum absolute rotational rate to allow, in radians per second. Setting this to 0 results in no cap to rotational rate.
    • CenterOfRotation

      public Translation2d CenterOfRotation
      The center of rotation the robot should rotate around. This is (0,0) by default, which will rotate around the center of the robot.
    • DriveRequestType

      public SwerveModule.DriveRequestType DriveRequestType
      The type of control request to use for the drive motor.
    • SteerRequestType

      public SwerveModule.SteerRequestType SteerRequestType
      The type of control request to use for the steer motor.
    • DesaturateWheelVelocities

      public boolean DesaturateWheelVelocities
      Whether to desaturate wheel velocities before applying. For more information, see the documentation of SwerveDriveKinematics.desaturateWheelVelocities(SwerveModuleVelocity[], double).
    • ForwardPerspective

      public SwerveRequest.ForwardPerspectiveValue ForwardPerspective
      The perspective to use when determining which direction is forward.
    • TargetDirectionPerspective

      public SwerveRequest.TargetDirectionPerspectiveValue TargetDirectionPerspective
      The perspective to use when determining which direction is forward for the TargetDirection. This allows for the heading control to use a different perspective from the translation control.
    • HeadingController

      public PhoenixPIDController HeadingController
      The PID controller used to maintain the desired heading. Users can specify the PID gains to change how aggressively to maintain heading.

      This PID controller operates on heading radians and outputs a target rotational rate in radians per second. Note that continuous input should be enabled on the range [-pi, pi].

  • Constructor Details

    • FieldCentricFacingAngle

      public FieldCentricFacingAngle()
  • Method Details

    • apply

      public StatusCode apply(SwerveDrivetrain.SwerveControlParameters parameters, SwerveModule<?,?,?>... modulesToApply)
      Description copied from interface: SwerveRequest
      Applies this swerve request to the given modules. This is typically called by the SwerveDrivetrain odometry thread.

      For native swerve requests, this API can be called from a non-native request's apply to compose the two together.

      Specified by:
      apply in interface SwerveRequest
      Parameters:
      parameters - Parameters the control request needs to calculate the module state
      modulesToApply - Modules to which the control request is applied
      Returns:
      Status code of sending the request
    • withHeadingPID

      public final SwerveRequest.FieldCentricFacingAngle withHeadingPID(double kP, double kI, double kD)
      Modifies the PID gains of the HeadingController parameter and returns itself.

      Sets the proportional, integral, and differential coefficients used to maintain the desired heading. Users can specify the PID gains to change how aggressively to maintain heading.

      This PID controller operates on heading radians and outputs a target rotational rate in radians per second.

      Parameters:
      kP - The proportional coefficient; must be >= 0
      kI - The integral coefficient; must be >= 0
      kD - The differential coefficient; must be >= 0
      Returns:
      this object
    • withVelocityX

      public final SwerveRequest.FieldCentricFacingAngle withVelocityX(double newVelocityX)
      Modifies the VelocityX parameter and returns itself.

      The velocity in the X direction, in m/s. X is defined as forward according to WPILib convention, so this determines how fast to travel forward.

      Parameters:
      newVelocityX - Parameter to modify
      Returns:
      this object
    • withVelocityX

      public final SwerveRequest.FieldCentricFacingAngle withVelocityX(LinearVelocity newVelocityX)
      Modifies the VelocityX parameter and returns itself.

      The velocity in the X direction, in m/s. X is defined as forward according to WPILib convention, so this determines how fast to travel forward.

      Parameters:
      newVelocityX - Parameter to modify
      Returns:
      this object
    • withVelocityY

      public final SwerveRequest.FieldCentricFacingAngle withVelocityY(double newVelocityY)
      Modifies the VelocityY parameter and returns itself.

      The velocity in the Y direction, in m/s. Y is defined as to the left according to WPILib convention, so this determines how fast to travel to the left.

      Parameters:
      newVelocityY - Parameter to modify
      Returns:
      this object
    • withVelocityY

      public final SwerveRequest.FieldCentricFacingAngle withVelocityY(LinearVelocity newVelocityY)
      Modifies the VelocityY parameter and returns itself.

      The velocity in the Y direction, in m/s. Y is defined as to the left according to WPILib convention, so this determines how fast to travel to the left.

      Parameters:
      newVelocityY - Parameter to modify
      Returns:
      this object
    • withTargetDirection

      public final SwerveRequest.FieldCentricFacingAngle withTargetDirection(Rotation2d newTargetDirection)
      Modifies the TargetDirection parameter and returns itself.

      The desired direction to face. 0 Degrees is defined as in the direction of the X axis. As a result, a TargetDirection of 90 degrees will point along the Y axis, or to the left.

      Parameters:
      newTargetDirection - Parameter to modify
      Returns:
      this object
    • withTargetRateFeedforward

      public final SwerveRequest.FieldCentricFacingAngle withTargetRateFeedforward(double newTargetRateFeedforward)
      Modifies the TargetRateFeedforward parameter and returns itself.

      The rotational rate feedforward to add to the output of the heading controller, in radians per second. When using a motion profile for the target direction, this can be set to the current velocity reference of the profile.

      Parameters:
      newTargetRateFeedforward - Parameter to modify
      Returns:
      this object
    • withTargetRateFeedforward

      public final SwerveRequest.FieldCentricFacingAngle withTargetRateFeedforward(AngularVelocity newTargetRateFeedforward)
      Modifies the TargetRateFeedforward parameter and returns itself.

      The rotational rate feedforward to add to the output of the heading controller, in radians per second. When using a motion profile for the target direction, this can be set to the current velocity reference of the profile.

      Parameters:
      newTargetRateFeedforward - Parameter to modify
      Returns:
      this object
    • withDeadband

      public final SwerveRequest.FieldCentricFacingAngle withDeadband(double newDeadband)
      Modifies the Deadband parameter and returns itself.

      The allowable deadband of the request, in m/s.

      Parameters:
      newDeadband - Parameter to modify
      Returns:
      this object
    • withDeadband

      public final SwerveRequest.FieldCentricFacingAngle withDeadband(LinearVelocity newDeadband)
      Modifies the Deadband parameter and returns itself.

      The allowable deadband of the request, in m/s.

      Parameters:
      newDeadband - Parameter to modify
      Returns:
      this object
    • withRotationalDeadband

      public final SwerveRequest.FieldCentricFacingAngle withRotationalDeadband(double newRotationalDeadband)
      Modifies the RotationalDeadband parameter and returns itself.

      The rotational deadband of the request, in radians per second.

      Parameters:
      newRotationalDeadband - Parameter to modify
      Returns:
      this object
    • withRotationalDeadband

      public final SwerveRequest.FieldCentricFacingAngle withRotationalDeadband(AngularVelocity newRotationalDeadband)
      Modifies the RotationalDeadband parameter and returns itself.

      The rotational deadband of the request, in radians per second.

      Parameters:
      newRotationalDeadband - Parameter to modify
      Returns:
      this object
    • withMaxAbsRotationalRate

      public final SwerveRequest.FieldCentricFacingAngle withMaxAbsRotationalRate(double newMaxAbsRotationalRate)
      Modifies the MaxAbsRotationalRate parameter and returns itself.

      The maximum absolute rotational rate to allow, in radians per second. Setting this to 0 results in no cap to rotational rate.

      Parameters:
      newMaxAbsRotationalRate - Parameter to modify
      Returns:
      this object
    • withMaxAbsRotationalRate

      public final SwerveRequest.FieldCentricFacingAngle withMaxAbsRotationalRate(AngularVelocity newMaxAbsRotationalRate)
      Modifies the MaxAbsRotationalRate parameter and returns itself.

      The maximum absolute rotational rate to allow, in radians per second. Setting this to 0 results in no cap to rotational rate.

      Parameters:
      newMaxAbsRotationalRate - Parameter to modify
      Returns:
      this object
    • withCenterOfRotation

      public final SwerveRequest.FieldCentricFacingAngle withCenterOfRotation(Translation2d newCenterOfRotation)
      Modifies the CenterOfRotation parameter and returns itself.

      The center of rotation the robot should rotate around. This is (0,0) by default, which will rotate around the center of the robot.

      Parameters:
      newCenterOfRotation - Parameter to modify
      Returns:
      this object
    • withDriveRequestType

      public final SwerveRequest.FieldCentricFacingAngle withDriveRequestType(SwerveModule.DriveRequestType newDriveRequestType)
      Modifies the DriveRequestType parameter and returns itself.

      The type of control request to use for the drive motor.

      Parameters:
      newDriveRequestType - Parameter to modify
      Returns:
      this object
    • withSteerRequestType

      public final SwerveRequest.FieldCentricFacingAngle withSteerRequestType(SwerveModule.SteerRequestType newSteerRequestType)
      Modifies the SteerRequestType parameter and returns itself.

      The type of control request to use for the drive motor.

      Parameters:
      newSteerRequestType - Parameter to modify
      Returns:
      this object
    • withDesaturateWheelVelocities

      public final SwerveRequest.FieldCentricFacingAngle withDesaturateWheelVelocities(boolean newDesaturateWheelVelocities)
      Modifies the DesaturateWheelVelocities parameter and returns itself.

      Whether to desaturate wheel velocities before applying. For more information, see the documentation of SwerveDriveKinematics.desaturateWheelVelocities(SwerveModuleVelocity[], double).

      Parameters:
      newDesaturateWheelVelocities - Parameter to modify
      Returns:
      this object
    • withForwardPerspective

      public final SwerveRequest.FieldCentricFacingAngle withForwardPerspective(SwerveRequest.ForwardPerspectiveValue newForwardPerspective)
      Modifies the ForwardPerspective parameter and returns itself.

      The perspective to use when determining which direction is forward.

      Parameters:
      newForwardPerspective - Parameter to modify
      Returns:
      this object
    • withTargetDirectionPerspective

      public final SwerveRequest.FieldCentricFacingAngle withTargetDirectionPerspective(SwerveRequest.TargetDirectionPerspectiveValue newTargetDirectionPerspective)
      Modifies the TargetDirectionPerspective parameter and returns itself.

      The perspective to use when determining which direction is forward for the TargetDirection. This allows for the heading control to use a different perspective from the translation control.

      Parameters:
      newTargetDirectionPerspective - Parameter to modify
      Returns:
      this object