Class LegacySwerveRequest.FieldCentricFacingAngle
java.lang.Object
com.ctre.phoenix6.mechanisms.swerve.LegacySwerveRequest.FieldCentricFacingAngle
- All Implemented Interfaces:
LegacySwerveRequest
- Enclosing interface:
- LegacySwerveRequest
public static class LegacySwerveRequest.FieldCentricFacingAngle
extends Object
implements LegacySwerveRequest
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.ctre.phoenix6.mechanisms.swerve.LegacySwerveRequest
LegacySwerveRequest.ApplyChassisSpeeds, LegacySwerveRequest.FieldCentric, LegacySwerveRequest.FieldCentricFacingAngle, LegacySwerveRequest.ForwardReference, LegacySwerveRequest.Idle, LegacySwerveRequest.LegacySwerveControlRequestParameters, LegacySwerveRequest.PointWheelsAt, LegacySwerveRequest.RobotCentric, LegacySwerveRequest.SwerveDriveBrake, LegacySwerveRequest.SysIdSwerveRotation, LegacySwerveRequest.SysIdSwerveSteerGains, LegacySwerveRequest.SysIdSwerveTranslation
-
Field Summary
Modifier and TypeFieldDescriptionThe center of rotation the robot should rotate around.double
The allowable deadband of the request.boolean
Whether to desaturate wheel speeds before applying.The type of control request to use for the drive motor.The perspective to use when determining which direction is forward.The PID controller used to maintain the desired heading.double
The rotational deadband of the request.The type of control request to use for the steer motor.The desired direction to face.double
The velocity in the X direction, in m/s.double
The velocity in the Y direction, in m/s. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionapply
(LegacySwerveRequest.LegacySwerveControlRequestParameters parameters, LegacySwerveModule... modulesToApply) Applies this swerve request to the given modules.withCenterOfRotation
(Translation2d centerOfRotation) Sets the center of rotation of the requestwithDeadband
(double deadband) Sets the allowable deadband of the request.withDesaturateWheelSpeeds
(boolean desaturateWheelSpeeds) Sets whether to desaturate wheel speeds before applying.withDriveRequestType
(LegacySwerveModule.DriveRequestType driveRequestType) Sets the type of control request to use for the drive motor.withRotationalDeadband
(double rotationalDeadband) Sets the rotational deadband of the request.withSteerRequestType
(LegacySwerveModule.SteerRequestType steerRequestType) Sets the type of control request to use for the steer motor.withTargetDirection
(Rotation2d targetDirection) Sets the desired direction to face.withVelocityX
(double velocityX) Sets the velocity in the X direction, in m/s.withVelocityY
(double velocityY) Sets the velocity in the Y direction, in m/s.
-
Field Details
-
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
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
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. -
Deadband
The allowable deadband of the request. -
RotationalDeadband
The rotational deadband of the request. -
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
The type of control request to use for the drive motor. -
SteerRequestType
The type of control request to use for the steer motor. -
DesaturateWheelSpeeds
Whether to desaturate wheel speeds before applying. For more information, see the documentation ofSwerveDriveKinematics.desaturateWheelSpeeds(edu.wpi.first.math.kinematics.SwerveModuleState[], double)
. -
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.
-
ForwardReference
The perspective to use when determining which direction is forward.
-
-
Constructor Details
-
FieldCentricFacingAngle
public FieldCentricFacingAngle()
-
-
Method Details
-
apply
public StatusCode apply(LegacySwerveRequest.LegacySwerveControlRequestParameters parameters, LegacySwerveModule... modulesToApply) Description copied from interface:LegacySwerveRequest
Applies this swerve request to the given modules. This is typically called by the SwerveDrivetrain.- Specified by:
apply
in interfaceLegacySwerveRequest
- Parameters:
parameters
- Parameters the control request needs to calculate the module statemodulesToApply
- Modules to which the control request is applied- Returns:
- Status code of sending the request
-
withVelocityX
Sets 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:
velocityX
- Velocity in the X direction, in m/s- Returns:
- this request
-
withVelocityY
Sets 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:
velocityY
- Velocity in the Y direction, in m/s- Returns:
- this request
-
withTargetDirection
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
Sets the allowable deadband of the request.- Parameters:
deadband
- Allowable deadband of the request- Returns:
- this request
-
withRotationalDeadband
public LegacySwerveRequest.FieldCentricFacingAngle withRotationalDeadband(double rotationalDeadband) Sets the rotational deadband of the request.- Parameters:
rotationalDeadband
- Rotational deadband of the request- Returns:
- this request
-
withCenterOfRotation
public LegacySwerveRequest.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 LegacySwerveRequest.FieldCentricFacingAngle withDriveRequestType(LegacySwerveModule.DriveRequestType 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 LegacySwerveRequest.FieldCentricFacingAngle withSteerRequestType(LegacySwerveModule.SteerRequestType 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
-
withDesaturateWheelSpeeds
public LegacySwerveRequest.FieldCentricFacingAngle withDesaturateWheelSpeeds(boolean desaturateWheelSpeeds) Sets whether to desaturate wheel speeds before applying. For more information, see the documentation ofSwerveDriveKinematics.desaturateWheelSpeeds(edu.wpi.first.math.kinematics.SwerveModuleState[], double)
.- Parameters:
desaturateWheelSpeeds
- Whether to desaturate wheel speeds- Returns:
- this request
-