Package xbot.common.subsystems.pose
Class BasePoseSubsystem
java.lang.Object
edu.wpi.first.wpilibj2.command.SubsystemBase
xbot.common.command.BaseSubsystem
xbot.common.subsystems.pose.BasePoseSubsystem
- All Implemented Interfaces:
Sendable
,Subsystem
,DataFrameRefreshable
,IPropertySupport
,ISwerveAdvisorPoseSupport
- Direct Known Subclasses:
MockBasePoseSubsystem
public abstract class BasePoseSubsystem
extends BaseSubsystem
implements DataFrameRefreshable, ISwerveAdvisorPoseSupport
-
Field Summary
Modifier and TypeFieldDescriptionprotected final double
protected WrappedRotation2d
static final double
static final double
static Distance
protected boolean
protected double
final XGyro
static final double
protected final DoubleProperty
protected final DoubleProperty
protected boolean
protected double
protected double
protected double
protected double
protected double
protected BooleanProperty
protected double
protected double
protected double
protected double
double
double
Fields inherited from class xbot.common.command.BaseSubsystem
aKitLog, dataFrameRefreshables, log
-
Constructor Summary
ConstructorDescriptionBasePoseSubsystem
(XGyro.XGyroFactory gyroFactory, PropertyFactory propManager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
static Pose2d
convertBluetoRed
(Pose2d blueCoordinates) Converts a pose from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.static Rotation2d
convertBlueToRed
(Rotation2d blueHeading) Converts a Rotation2d from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.static Translation2d
convertBlueToRed
(Translation2d blueCoordinates) Converts a Translation2d from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.static Pose2d
convertBlueToRedIfNeeded
(Pose2d blueCoordinates) Converts a Pose2d from blue to red alliance, if and ONLY IF you are currently on the Red alliance.static Rotation2d
convertBlueToRedIfNeeded
(Rotation2d blueHeading) static Translation2d
convertBlueToRedIfNeeded
(Translation2d blueCoordinates) Converts a Translation2d from blue to red alliance, if and ONLY IF you are currently on the Red alliance.static DriverStation.Alliance
protected double
getCompassHeading
(Rotation2d standardHeading) double
boolean
protected abstract double
boolean
protected abstract double
double
Returns the distance the robot has traveled forward.double
double
protected WrappedRotation2d
If the RoboRIO is mounted in a position other than "flat" (e.g.protected XYPair
protected double
protected double
double
void
periodic()
This method is called on eachCommandScheduler
loop.void
Consumes and processes inputs from the device or subsystem.void
static Rotation2d
rotateAngleBasedOnAlliance
(Rotation2d rotation) void
setCurrentHeading
(double headingInDegrees) void
setCurrentPosition
(double newXPosition, double newYPosition) protected void
protected void
protected void
This should be called as often as reasonably possible, to increase accuracy of the "distance traveled" calculation.Methods inherited from class xbot.common.command.BaseSubsystem
getPrefix, registerDataFrameRefreshable
Methods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystem
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface edu.wpi.first.wpilibj2.command.Subsystem
defer, getCurrentCommand, getDefaultCommand, register, removeDefaultCommand, run, runEnd, runOnce, setDefaultCommand, simulationPeriodic, startEnd, startRun
-
Field Details
-
imu
-
leftDriveDistance
protected double leftDriveDistance -
rightDriveDistance
protected double rightDriveDistance -
totalDistanceX
protected double totalDistanceX -
totalDistanceY
protected double totalDistanceY -
totalDistanceYRobotPerspective
protected double totalDistanceYRobotPerspective -
velocityX
public double velocityX -
velocityY
public double velocityY -
totalVelocity
protected double totalVelocity -
currentHeading
-
headingOffset
protected double headingOffset -
FACING_AWAY_FROM_DRIVERS
public static final double FACING_AWAY_FROM_DRIVERS- See Also:
-
FACING_TOWARDS_DRIVERS
public static final double FACING_TOWARDS_DRIVERS- See Also:
-
INCHES_IN_A_METER
public static final double INCHES_IN_A_METER- See Also:
-
inherentRioPitch
-
inherentRioRoll
-
previousLeftDistance
protected double previousLeftDistance -
previousRightDistance
protected double previousRightDistance -
classInstantiationTime
protected final double classInstantiationTime -
rioRotated
-
firstUpdate
protected boolean firstUpdate -
lastSetHeadingTime
protected double lastSetHeadingTime -
fieldXMidpointInMeters
-
-
Constructor Details
-
BasePoseSubsystem
-
-
Method Details
-
getCompassHeading
-
updateCurrentHeading
protected void updateCurrentHeading() -
updateOdometry
protected void updateOdometry() -
getCurrentHeading
- Specified by:
getCurrentHeading
in interfaceISwerveAdvisorPoseSupport
- Returns:
- Current heading but if the navX is still booting up it will return 0
-
getFieldOrientedTotalDistanceTraveled
-
getTravelVector
-
getCurrentFieldPose
-
getCurrentPose2d
- Specified by:
getCurrentPose2d
in interfaceISwerveAdvisorPoseSupport
-
getCurrentVelocity
-
getCurrentHeadingAngularVelocity
public double getCurrentHeadingAngularVelocity() -
getRobotOrientedTotalDistanceTraveled
public double getRobotOrientedTotalDistanceTraveled()Returns the distance the robot has traveled forward. Rotations are ignored - if you drove forward 100 inches, then turned 180 degrees and drove another 100 inches, this would tell you that you have traveled 200 inches.- Returns:
- Distance in inches traveled forward from the robot perspective
-
resetDistanceTraveled
public void resetDistanceTraveled() -
setCurrentHeading
public void setCurrentHeading(double headingInDegrees) -
setCurrentPosition
public void setCurrentPosition(double newXPosition, double newYPosition) -
getHeadingResetRecently
public boolean getHeadingResetRecently()- Specified by:
getHeadingResetRecently
in interfaceISwerveAdvisorPoseSupport
-
updatePose
protected void updatePose()This should be called as often as reasonably possible, to increase accuracy of the "distance traveled" calculation. The PoseSubsystem can't directly own positional sensors, so some command will need to feed in the distance values coming from the DriveSubsystem. In order to have accurate calculations, these values need to be in inches, and should never be reset - any resetting should be done here in the PoseSubsystem -
getLeftDriveDistance
protected abstract double getLeftDriveDistance() -
getRightDriveDistance
protected abstract double getRightDriveDistance() -
getRobotPitch
public double getRobotPitch() -
getRobotRoll
public double getRobotRoll() -
getRobotYaw
If the RoboRIO is mounted in a position other than "flat" (e.g. with the pins facing upward) then this method will need to be overridden. -
getUntrimmedPitch
protected double getUntrimmedPitch() -
getUntrimmedRoll
protected double getUntrimmedRoll() -
calibrateInherentRioOrientation
public void calibrateInherentRioOrientation() -
getYawAngularVelocity
public double getYawAngularVelocity() -
convertBluetoRed
Converts a pose from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.- Parameters:
blueCoordinates
- Blue Pose2d to convert to Red Pose2d- Returns:
- Red Pose2d
-
convertBlueToRed
Converts a Translation2d from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.- Parameters:
blueCoordinates
- Blue Translation2d to convert to Red Translation2d- Returns:
- Red Translation2d
-
convertBlueToRed
Converts a Rotation2d from blue to red alliance, by mirroring across the field midline at an assumed X coordinate. Note that this means that in some cases the heading won't change; a heading of 90 degrees will remain 90 degrees, as both are facing the positive Y direction.- Parameters:
blueHeading
- Blue Rotation2d to convert to Red Rotation2d- Returns:
- Red Rotation2d
-
convertBlueToRedIfNeeded
Converts a Translation2d from blue to red alliance, if and ONLY IF you are currently on the Red alliance.- Parameters:
blueCoordinates
- Blue Translation2d to possibly convert to Red Translation2d- Returns:
- Red Translation2d if on Red alliance, otherwise the original Blue Translation2d
-
convertBlueToRedIfNeeded
Converts a Pose2d from blue to red alliance, if and ONLY IF you are currently on the Red alliance.- Parameters:
blueCoordinates
- Blue Pose2d to possibly convert to Red Pose2d- Returns:
- Red Pose2d if on Red alliance, otherwise the original Blue Pose2d
-
convertBlueToRedIfNeeded
-
rotateAngleBasedOnAlliance
-
getAlliance
-
periodic
public void periodic()Description copied from class:BaseSubsystem
This method is called on eachCommandScheduler
loop.- Specified by:
periodic
in interfaceSubsystem
- Overrides:
periodic
in classBaseSubsystem
-
refreshDataFrame
public void refreshDataFrame()Description copied from interface:DataFrameRefreshable
Consumes and processes inputs from the device or subsystem.- Specified by:
refreshDataFrame
in interfaceDataFrameRefreshable
- Overrides:
refreshDataFrame
in classBaseSubsystem
-
getSimulatedFieldPose
-