Package tagalong.subsystems.micro
Class Pivot
java.lang.Object
tagalong.subsystems.micro.Microsystem
tagalong.subsystems.micro.Pivot
Pivot microsystem
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal double
Absolute range of pivot movement in rotationsfinal double
Default lower tolerance of the pivot in rotations, Default upper tolerance of the pivot in rotationsfinal double
Default lower tolerance of the pivot in rotations, Default upper tolerance of the pivot in rotationsprotected double
Gear ratio from the encoder to pivot mechanism (conversion g.t.final double
Offset value for the target positionfinal double
Maximum velocity of the pivot in rotations per second, Maximum acceleration of the pivot in rotations per second squaredfinal double
Minimum position of the pivot in rotations, Maximum position of the pivot in rotationsfinal double
Maximum velocity of the pivot in rotations per second, Maximum acceleration of the pivot in rotations per second squaredfinal double
Minimum position of the pivot in rotations, Maximum position of the pivot in rotationsprotected double
Gear ratio from the motor to encoder (conversion g.t.com.ctre.phoenix6.hardware.CANcoder
CANcoder deviceprotected com.ctre.phoenix6.configs.CANcoderConfiguration
Configuration for the CANcoderprotected com.ctre.phoenix6.sim.CANcoderSimState
CANcoder simulationfinal PivotConf
Configuration for the pivotprotected ArmFeedforward
Feedforward model for the pivotprotected MechanismLigament2d
Simulated arm of the pivotprotected SingleJointedArmSim
Single jointed arm simulation for the pivotfinal double
Offset value for the target positionprotected double
Acceleration of the simulated pivot in rotations per second squaredprotected double
Position of the simulated pivot in rotationsprotected double
Velocity of the simulated pivot in rotations per secondFields inherited from class tagalong.subsystems.micro.Microsystem
_allMotors, _conf, _configuredMicrosystemDisable, _currentPositionEntry, _currentVelocityEntry, _curState, _followProfile, _goalState, _isFFTuningMicro, _isMicrosystemDisabled, _isPIDTuningMicro, _isShuffleboardMicro, _KAEntry, _KGEntry, _KSEntry, _KVEntry, _mechanism, _primaryMotor, _primaryMotorSim, _profileTimer, _requestedPositionVoltage, _requestedTorqueCurrent, _requestedVelocityVoltage, _root, _slot0DFactorEntry, _slot0IFactorEntry, _slot0PFactorEntry, _slot1DFactorEntry, _slot1IFactorEntry, _slot1PFactorEntry, _slot2DFactorEntry, _slot2IFactorEntry, _slot2PFactorEntry, _targetPositionEntry, _targetVelocityEntry, _toleranceTimer, _trapProfile, _tuningTabCounter
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondouble
absoluteClamp
(double value) Directs the pivot to its maximum position, current goal position, or minimum positiondouble
clampPivotPosition
(double target) Clamps the goal pivot position to be within rotational limitsvoid
Configure shuffleboard for the pivotvoid
Calculates the next state according to the trapezoidal profile and requests the pivot motor(s) to arrive at the next position with feedforwarddouble
Gets the position offset for feedforward (to account for a shifted center of mass) in rotationscom.ctre.phoenix6.hardware.TalonFX
getMotor()
Gets the primary motor of the pivotRetrieves ligament attached to pivot Mechanism2ddouble
Gets the current position of the pivot in rotationsdouble
Gets the power of the primary motordouble
Gets the current velocity of the pivot in rotations per secondvoid
Sets the power of the primary motor to zeroboolean
isPivotInAbsoluteTolerance
(double lowerBound, double upperBound) Bounds checking function that uses the absolute current pivot position (modulo one rotation)boolean
isPivotInTolerance
(double lowerBound, double upperBound) Bounds checking function that uses the current pivot positionboolean
Checks whether or not it's safe for the pivot to moveboolean
Resets devices if resets have occurreddouble
motorToPivotRot
(double motorRot) Converts motor rotations to rotations of the pivot mechanismvoid
returns nothing if micro system is disabledvoid
onEnable()
Executes logic for when the robot is first enabledvoid
periodic()
Periodic update functiondouble
pivotRotToMotor
(double pivotRot) Converts rotations of the pivot mechanism to motor rotationsdouble
placePivotInClosestRot
(double scopeReferenceRot, double newAngleRot) Returns the new pivot angle in the closest scope of the reference pivot anglevoid
setPivotPower
(double power) Sets the power of the primary motorvoid
setPivotProfile
(double goalPositionRot) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(double goalPositionRot, double goalVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2, boolean setCurrentState) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(Angle goalPosition) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(Angle goalPosition, double goalVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2) Creates a new trapezoidal profile for the pivot to followvoid
setPivotProfile
(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2, boolean setCurrentState) Creates a new trapezoidal profile for the pivot to followvoid
setPivotVelocity
(double rps, boolean withFF) Sets the velocity of the pivot in RPSvoid
Initializes the pivot simulationvoid
Runs the pivot simulation--sets motor and cancoder simulation fields and updates the visualvoid
Updates shuffleboard with the pivot's current position and velocityMethods inherited from class tagalong.subsystems.micro.Microsystem
checkInitStatus, checkToleranceTime, configAllDevices, configTuningModes, disableMicrosystem, getPrimaryMotor, getPrimaryMotorPosition, getPrimaryMotorPower, getPrimaryMotorVelocity, getRoot, isProfileFinished, onTeleopDisable, resetToleranceTimer, setBrakeMode, setFollowProfile, setHoldPosition, setPrimaryPower, updateAllPIDSGVA, waitForInitialization
-
Field Details
-
_pivotConf
Configuration for the pivot -
_pivotCancoder
CANcoder device -
_pivotCancoderConfiguration
Configuration for the CANcoder -
_motorToEncoderRatio
Gear ratio from the motor to encoder (conversion g.t. 1 represents a reduction) -
_encoderToPivotRatio
Gear ratio from the encoder to pivot mechanism (conversion g.t. 1 represents a reduction) -
_defaultPivotLowerToleranceRot
Default lower tolerance of the pivot in rotations, Default upper tolerance of the pivot in rotations -
_defaultPivotUpperToleranceRot
Default lower tolerance of the pivot in rotations, Default upper tolerance of the pivot in rotations -
_absoluteRangeRot
Absolute range of pivot movement in rotations -
_minPositionRot
Minimum position of the pivot in rotations, Maximum position of the pivot in rotations -
_maxPositionRot
Minimum position of the pivot in rotations, Maximum position of the pivot in rotations -
_maxVelocityRPS
Maximum velocity of the pivot in rotations per second, Maximum acceleration of the pivot in rotations per second squared -
_maxAccelerationRPS2
Maximum velocity of the pivot in rotations per second, Maximum acceleration of the pivot in rotations per second squared -
_profileTargetOffset
Offset value for the target position -
_pivotFF
Feedforward model for the pivot -
_ffCenterOfMassOffsetRad
Offset value for the target position -
_pivotSim
Single jointed arm simulation for the pivot -
_pivotCancoderSim
CANcoder simulation -
_simRotations
Position of the simulated pivot in rotations -
_simVeloRPS
Velocity of the simulated pivot in rotations per second -
_simAccelRPS2
Acceleration of the simulated pivot in rotations per second squared -
_pivotLigament
Simulated arm of the pivot
-
-
Constructor Details
-
Pivot
Constructs a pivot microsystem with the below configurations- Parameters:
conf
- Configurations for the pivot
-
-
Method Details
-
periodic
Periodic update function- Overrides:
periodic
in classMicrosystem
-
getMotor
Gets the primary motor of the pivot- Returns:
- primary motor
-
onEnable
Executes logic for when the robot is first enabled- Overrides:
onEnable
in classMicrosystem
-
onDisable
Description copied from class:Microsystem
returns nothing if micro system is disabled- Overrides:
onDisable
in classMicrosystem
-
updateShuffleboard
Updates shuffleboard with the pivot's current position and velocity- Overrides:
updateShuffleboard
in classMicrosystem
-
motorToPivotRot
Converts motor rotations to rotations of the pivot mechanism- Parameters:
motorRot
- position of the motor in rotations- Returns:
- position of the pivot in rotations
-
pivotRotToMotor
Converts rotations of the pivot mechanism to motor rotations- Parameters:
pivotRot
- position of the pivot in rotations- Returns:
- position of the motor in rotations
-
configShuffleboard
Configure shuffleboard for the pivot- Overrides:
configShuffleboard
in classMicrosystem
-
followLastProfile
Calculates the next state according to the trapezoidal profile and requests the pivot motor(s) to arrive at the next position with feedforward -
getFFPositionRad
Gets the position offset for feedforward (to account for a shifted center of mass) in rotations- Returns:
- offset position in rotations
-
setPivotPower
Sets the power of the primary motor- Parameters:
power
- desired power
-
getPivotPower
Gets the power of the primary motor- Returns:
- the current power
-
setPivotVelocity
Sets the velocity of the pivot in RPS- Parameters:
rps
- Desired velocity in rotations per secondwithFF
- with feedforward
-
getPivotPosition
Gets the current position of the pivot in rotations- Returns:
- the position of the primary motor which is the same as the position of the pivot when they are fused
-
getPivotVelocity
Gets the current velocity of the pivot in rotations per second- Returns:
- the velocity of the primary motor which is the same as the velocity of the pivot when they are fused
-
placePivotInClosestRot
Returns the new pivot angle in the closest scope of the reference pivot angle- Parameters:
scopeReferenceRot
- reference angle in rotationsnewAngleRot
- angle to be scoped in rotations- Returns:
- scoped newAngleRot
-
setPivotProfile
Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPosition
- goal position in rotations
-
setPivotProfile
Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPosition
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per second
-
setPivotProfile
Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPosition
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per secondmaxVelocityRPS
- maximum velocity in rotations per second
-
setPivotProfile
public void setPivotProfile(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2) Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPosition
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per secondmaxVelocityRPS
- maximum velocity in rotations per secondmaxAccelerationRPS2
- maximum acceleration in rotations per second squared
-
setPivotProfile
public void setPivotProfile(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2, boolean setCurrentState) Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPosition
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per secondmaxVelocityRPS
- maximum velocity in rotations per secondmaxAccelerationRPS2
- maximum acceleration in rotations per second squaredsetCurrentState
- True if the profiles current state should base itself off sensor values rather than continue from the existing state
-
setPivotProfile
Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPositionRot
- goal position in rotations
-
setPivotProfile
Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPositionRot
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per second
-
setPivotProfile
Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPositionRot
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per secondmaxVelocityRPS
- maximum velocity in rotations per second
-
setPivotProfile
public void setPivotProfile(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2) Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPositionRot
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per secondmaxVelocityRPS
- maximum velocity in rotations per secondmaxAccelerationRPS2
- maximum acceleration in rotations per second squared
-
setPivotProfile
public void setPivotProfile(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2, boolean setCurrentState) Creates a new trapezoidal profile for the pivot to follow- Parameters:
goalPositionRot
- goal position in rotationsgoalVelocityRPS
- goal velocity in rotations per secondmaxVelocityRPS
- maximum velocity in rotations per secondmaxAccelerationRPS2
- maximum acceleration in rotations per second squaredsetCurrentState
- True if the profiles current state should base itself off sensor values rather than continue from the existing state
-
clampPivotPosition
Clamps the goal pivot position to be within rotational limits- Parameters:
target
- goal position in rotations- Returns:
- clamped goal position in rotations
-
motorResetConfig
Resets devices if resets have occurred- Overrides:
motorResetConfig
in classMicrosystem
- Returns:
- boolean (micro system is enabled and the primary motor has been reset and if successful, it reconfigures the devices and returns true)
-
simulationInit
Initializes the pivot simulation- Overrides:
simulationInit
in classMicrosystem
-
simulationPeriodic
Runs the pivot simulation--sets motor and cancoder simulation fields and updates the visual- Overrides:
simulationPeriodic
in classMicrosystem
-
isSafeToMove
Checks whether or not it's safe for the pivot to move- Returns:
- whether or not it's safe to move
-
absoluteClamp
Directs the pivot to its maximum position, current goal position, or minimum position- Parameters:
value
- goal position- Returns:
- redirected goal position
-
isPivotInTolerance
Bounds checking function that uses the current pivot position- Parameters:
lowerBound
- minimum of acceptable rangeupperBound
- maximum of acceptable range- Returns:
- if the current position is greater than or equal to the lower bound and less than or equal to the upper bound
-
isPivotInAbsoluteTolerance
Bounds checking function that uses the absolute current pivot position (modulo one rotation)- Parameters:
lowerBound
- minimum of acceptable rangeupperBound
- maximum of acceptable range- Returns:
- if the absolute current position is in absolute acceptable range
-
holdCurrentPosition
Description copied from class:Microsystem
Sets the power of the primary motor to zero- Overrides:
holdCurrentPosition
in classMicrosystem
-
getPivotLigament
Retrieves ligament attached to pivot Mechanism2d- Returns:
- pivot ligament
-