Class ChassisRequest.FieldCentricFacingAngle

java.lang.Object
com.marswars.swerve_lib.ChassisRequest.FieldCentricFacingAngle
All Implemented Interfaces:
ChassisRequest
Enclosing interface:
ChassisRequest

public static class ChassisRequest.FieldCentricFacingAngle extends Object implements ChassisRequest
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.

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

  • Field Details

    • Speeds

      public ChassisSpeeds Speeds
      The desired chassis speeds (field-relative, rotation component ignored)
    • TargetDirection

      public Rotation2d TargetDirection
      The direction the robot should face. 0 Degrees is defined as in the direction of the X axis.
    • Deadband

      public double Deadband
      The allowable deadband of the request.
    • RotationalDeadband

      public double RotationalDeadband
      The rotational deadband of the request.
    • MaxAbsRotationalRate

      public double MaxAbsRotationalRate
      The maximum absolute rotational rate of the request.
    • HeadingFeedforward

      public double HeadingFeedforward
      Feedforward rotational velocity in rad/s to add to the PID output.
    • 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 Module.DriveControlMode DriveRequestType
      The type of control request to use for the drive motor.
    • SteerRequestType

      public Module.SteerControlMode SteerRequestType
      The type of control request to use for the steer motor.
    • 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.

    • XPositiveReference

      public ChassisRequest.XPositiveReference XPositiveReference
      The perspective to use when determining which direction is forward.
  • Constructor Details

    • FieldCentricFacingAngle

      public FieldCentricFacingAngle()
  • Method Details

    • apply

      public void apply(ChassisRequest.ChassisRequestParameters parameters, Module... modulesToApply)
      Applies this swerve request to the given modules. This is typically called by the SwerveDrivetrain.
      Specified by:
      apply in interface ChassisRequest
      Parameters:
      parameters - Parameters the control request needs to calculate the module state
      modulesToApply - Modules to which the control request is applied
    • withSpeeds

      The linear velocity to apply to the drivetrain, specified as ChassisSpeeds. Only the translational components are used; rotation is controlled by the target heading. These speeds are assumed to be field-relative.
      Parameters:
      speeds - Field-relative chassis speeds (only vx and vy are used)
      Returns:
      this request
    • withTargetHeading

      public ChassisRequest.FieldCentricFacingAngle withTargetHeading(Rotation2d targetDirection)
      Sets 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:
      targetDirection - Desired direction to face
      Returns:
      this request
    • withDeadband

      public ChassisRequest.FieldCentricFacingAngle withDeadband(double deadband)
      Sets the allowable deadband of the request.
      Parameters:
      deadband - Allowable deadband of the request
      Returns:
      this request
    • withRotationalDeadband

      public ChassisRequest.FieldCentricFacingAngle withRotationalDeadband(double rotationalDeadband)
      Sets the rotational deadband of the request.
      Parameters:
      rotationalDeadband - Rotational deadband of the request
      Returns:
      this request
    • withMaxAbsRotationalRate

      public ChassisRequest.FieldCentricFacingAngle withMaxAbsRotationalRate(double maxAbsRotationalRate)
      Sets the maximum absolute rotational rate of the request.
      Parameters:
      maxAbsRotationalRate - The maximum absolute rotational rate of the
      Returns:
      this request
    • withCenterOfRotation

      public ChassisRequest.FieldCentricFacingAngle withCenterOfRotation(Translation2d centerOfRotation)
      Sets the center of rotation of the request
      Parameters:
      centerOfRotation - The center of rotation the robot should rotate around.
      Returns:
      this request
    • withDriveRequestType

      public ChassisRequest.FieldCentricFacingAngle withDriveRequestType(Module.DriveControlMode driveRequestType)
      Sets the type of control request to use for the drive motor.
      Parameters:
      driveRequestType - The type of control request to use for the drive motor
      Returns:
      this request
    • withSteerRequestType

      public ChassisRequest.FieldCentricFacingAngle withSteerRequestType(Module.SteerControlMode steerRequestType)
      Sets the type of control request to use for the steer motor.
      Parameters:
      steerRequestType - The type of control request to use for the steer motor
      Returns:
      this request
    • withXPositiveReference

      public ChassisRequest.FieldCentricFacingAngle withXPositiveReference(ChassisRequest.XPositiveReference xPositiveReference)
      Sets the perspective to use when determining which direction is forward.
      Parameters:
      xPositiveReference - The perspective to use when determining which direction is forward.
      Returns:
      this request
    • withHeadingController

      public ChassisRequest.FieldCentricFacingAngle withHeadingController(PhoenixPIDController headingController)
      Sets the PID controller used to maintain the desired heading. Users can specify the PID gains to change how aggressively to maintain heading.
      Parameters:
      headingController - The PID controller used to maintain the desired heading.
      Returns:
      this request
    • withHeadingFeedforward

      public ChassisRequest.FieldCentricFacingAngle withHeadingFeedforward(double headingFeedforward)
      Sets the feedforward rotational velocity to add to the PID output. This improves tracking performance when the target heading is changing.
      Parameters:
      headingFeedforward - Feedforward rotational velocity in rad/s
      Returns:
      this request