Package frc.robot.localization
Class RobotState
java.lang.Object
frc.robot.localization.RobotState
Total state of the robot
-
Constructor Summary
ConstructorsConstructorDescriptionRobotState(SwerveModulePosition[] wheelPositions, Rotation2d gyroYaw) Creates a new swerve state estimator. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOdometryObservation(SwerveModulePosition[] wheelPositions, Rotation2d gyroYaw, double timestamp) Updates odometry and pose estimates using swerve module encoders and an optional gyro measurement.voidaddVisionObservation(VisionObservation observations) Add potentially asequent observation from camerabooleanaddVisionObservation(CameraConstants camera, org.photonvision.targeting.PhotonPipelineResult pipelineResult) Add potentially asequent observation from cameradoubledoubleReturns the current best estimate of the robot's global field pose.doubledoublegetTurretRobotToCamera(Transform3d turretToCamera, double timestamp) Get robot to camera for camera mounted on the turretstatic Transform3dgetTurretRobotToCamera(Transform3d turretToCamera, Rotation2d turretRotation) Get robot to camera for camera mounted on the turretvoidincTrims(double incUp, double incLeft) Increment trim values for autoshootingbooleanbooleanvoidlimitPosition(Pose2d pose, Consumer<Pose2d> resetPose) limits position of a given posevoidoverrideInit(Pose2d pose) Forcibly initializes the pose estimator using a known robot pose.voidvoidResets the internal pose estimate to a known field pose.voidsetFlywheelSpeed(double flywheelSpeed) voidsetTrims(double trimUp, double trimLeft) Set trim values for autoshootingvoidsetTurretRawAngle(double timestamp, Angle angle) Set the current turret anglevoidupdateMeasuredSpeeds(ChassisSpeeds speeds) Updates the robot's current chassis speeds.voidUpdate autoshoot target
-
Constructor Details
-
RobotState
Creates a new swerve state estimator.- Parameters:
wheelPositions- the initial swerve module positions used to seed odometrygyroYaw- the initial reported gyro yaw
-
-
Method Details
-
resetPose
Resets the internal pose estimate to a known field pose.This method forces the underlying swerve odometry to the specified pose, effectively redefining the robot's position on the field. It should be used when the robot pose is known with high confidence, such as:
- At the start of autonomous
- After a field-aligned reset
- Following a trusted vision-based localization event
This method updates only the pose estimator / odometry state owned by
RobotState. It does not update any associated simulation state or drivetrain model.Most code should prefer
Swerve.overridePose(java.util.function.Supplier<edu.wpi.first.math.geometry.Pose2d>)when resetting the robot pose, as that method ensures both the estimator and any simulated drivetrain pose remain consistent.Future odometry and vision updates will be applied relative to this new pose.
- Parameters:
pose- the desired robot pose in field coordinates
-
resetInit
public void resetInit() -
addOdometryObservation
public void addOdometryObservation(SwerveModulePosition[] wheelPositions, Rotation2d gyroYaw, double timestamp) Updates odometry and pose estimates using swerve module encoders and an optional gyro measurement.- Parameters:
wheelPositions- current swerve module positionsgyroYaw- current robot yaw, if availabletimestamp- measurement timestamp in seconds
-
updateMeasuredSpeeds
Updates the robot's current chassis speeds.- Parameters:
speeds- the current robot-relative chassis speeds
-
overrideInit
Forcibly initializes the pose estimator using a known robot pose.- Parameters:
pose- the known robot pose in field coordinates to initialize the estimator with
-
getTurretRobotToCamera
public static Transform3d getTurretRobotToCamera(Transform3d turretToCamera, Rotation2d turretRotation) Get robot to camera for camera mounted on the turret -
getTurretRobotToCamera
Get robot to camera for camera mounted on the turret -
setTurretRawAngle
Set the current turret angle -
addVisionObservation
Add potentially asequent observation from camera -
addVisionObservation
public boolean addVisionObservation(CameraConstants camera, org.photonvision.targeting.PhotonPipelineResult pipelineResult) Add potentially asequent observation from camera -
getGlobalPoseEstimate
Returns the current best estimate of the robot's global field pose.- Returns:
- estimated robot pose in field coordinates
-
getTurretCenterFieldFrame
-
getFieldRelativeSpeeds
-
setTrims
public void setTrims(double trimUp, double trimLeft) Set trim values for autoshooting -
incTrims
public void incTrims(double incUp, double incLeft) Increment trim values for autoshooting -
getTrimUp
public double getTrimUp() -
getTrimLeft
public double getTrimLeft() -
updateTargeting
public void updateTargeting()Update autoshoot target -
isInitted
public boolean isInitted() -
getDesiredFlywheelSpeed
public double getDesiredFlywheelSpeed() -
getDesiredHoodAngleDeg
public double getDesiredHoodAngleDeg() -
isOkayToShoot
public boolean isOkayToShoot() -
getDesiredTurretHeadingFieldRelative
-
setFlywheelSpeed
public void setFlywheelSpeed(double flywheelSpeed) -
limitPosition
limits position of a given pose- Parameters:
pose- new pose of robot reactangleresetPose- reset pose
-