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
FieldsModifier and TypeFieldDescriptionprotected final doublestatic final doublestatic final doublestatic Distancestatic Distanceprotected booleanprotected doublefinal XGyrostatic final doubleprotected final DoublePropertyprotected final DoublePropertyprotected booleanprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected BooleanPropertyprotected doubleprotected doubleprotected doubleprotected doubledoubledoubleFields inherited from class xbot.common.command.BaseSubsystem
aKitLog, dataFrameRefreshables, log -
Constructor Summary
ConstructorsConstructorDescriptionBasePoseSubsystem(XGyro.XGyroFactory gyroFactory, PropertyFactory propManager) BasePoseSubsystem(XGyro gyro, PropertyFactory propManager) -
Method Summary
Modifier and TypeMethodDescriptionvoidstatic Pose2dconvertBluetoRed(Pose2d blueCoordinates) Converts a pose from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.static Rotation2dconvertBlueToRed(Rotation2d blueHeading) Converts a Rotation2d from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.static Translation2dconvertBlueToRed(Translation2d blueCoordinates) Converts a Translation2d from blue to red alliance, by mirroring across the field midline at an assumed X coordinate.static Pose2dconvertBlueToRedIfNeeded(Pose2d blueCoordinates) Converts a Pose2d from blue to red alliance, if and ONLY IF you are currently on the Red alliance.static Rotation2dconvertBlueToRedIfNeeded(Rotation2d blueHeading) static Translation2dconvertBlueToRedIfNeeded(Translation2d blueCoordinates) Converts a Translation2d from blue to red alliance, if and ONLY IF you are currently on the Red alliance.static DriverStation.Allianceprotected doublegetCompassHeading(Rotation2d standardHeading) Can be overriden by subclasses to provide a different heading source (e.g.doublebooleanprotected abstract doublebooleanprotected abstract doubledoubleReturns the distance the robot has traveled forward.doubledoubleprotected WrappedRotation2dIf the RoboRIO is mounted in a position other than "flat" (e.g.protected XYPairprotected doubleprotected doubledoublevoidperiodic()This method is called on eachCommandSchedulerloop.voidConsumes and processes inputs from the device or subsystem.voidvoidsetCurrentHeading(double headingInDegrees) voidsetCurrentPosition(double newXPosition, double newYPosition) protected voidprotected voidprotected voidThis 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, registerDataFrameRefreshableMethods inherited from class edu.wpi.first.wpilibj2.command.SubsystemBase
addChild, getName, getSubsystem, initSendable, setName, setSubsystemMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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 -
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 -
fieldXMidpoint
-
fieldYHeight
-
-
Constructor Details
-
BasePoseSubsystem
-
BasePoseSubsystem
-
-
Method Details
-
getCompassHeading
-
updateCurrentHeading
protected void updateCurrentHeading() -
updateOdometry
protected void updateOdometry() -
getCurrentHeadingGyroOnly
- Returns:
- Current heading but if the navX is still booting up it will return 0
-
getCurrentHeading
Can be overriden by subclasses to provide a different heading source (e.g. a vision system, pose estimator, etc)- Specified by:
getCurrentHeadingin interfaceISwerveAdvisorPoseSupport- Returns:
- Current heading but if the navX is still booting up it will return 0
-
getFieldOrientedTotalDistanceTraveled
-
getTravelVector
-
getCurrentFieldPose
-
getCurrentPose2d
- Specified by:
getCurrentPose2din 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:
getHeadingResetRecentlyin 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
-
getAlliance
-
periodic
public void periodic()Description copied from class:BaseSubsystemThis method is called on eachCommandSchedulerloop.- Specified by:
periodicin interfaceSubsystem- Overrides:
periodicin classBaseSubsystem
-
refreshDataFrame
public void refreshDataFrame()Description copied from interface:DataFrameRefreshableConsumes and processes inputs from the device or subsystem.- Specified by:
refreshDataFramein interfaceDataFrameRefreshable- Overrides:
refreshDataFramein classBaseSubsystem
-
getSimulatedFieldPose
-