Package tagalong.subsystems.micro
Class Pivot
java.lang.Object
tagalong.subsystems.micro.Microsystem
tagalong.subsystems.micro.Pivot
Pivot microsystem
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal doubleAbsolute range of pivot movement in rotationsfinal doubleDefault lower tolerance of the pivot in rotations, Default upper tolerance of the pivot in rotationsfinal doubleDefault lower tolerance of the pivot in rotations, Default upper tolerance of the pivot in rotationsprotected doubleGear ratio from the encoder to pivot mechanism (conversion g.t.final doubleOffset value for the target positionfinal doubleMaximum velocity of the pivot in rotations per second, Maximum acceleration of the pivot in rotations per second squaredfinal doubleMinimum position of the pivot in rotations, Maximum position of the pivot in rotationsfinal doubleMaximum velocity of the pivot in rotations per second, Maximum acceleration of the pivot in rotations per second squaredfinal doubleMinimum position of the pivot in rotations, Maximum position of the pivot in rotationsprotected doubleGear ratio from the motor to encoder (conversion g.t.com.ctre.phoenix6.hardware.CANcoderCANcoder deviceprotected com.ctre.phoenix6.configs.CANcoderConfigurationConfiguration for the CANcoderprotected com.ctre.phoenix6.sim.CANcoderSimStateCANcoder simulationfinal PivotConfConfiguration for the pivotprotected ArmFeedforwardFeedforward model for the pivotprotected MechanismLigament2dSimulated arm of the pivotprotected SingleJointedArmSimSingle jointed arm simulation for the pivotfinal doubleOffset value for the target positionprotected doubleAcceleration of the simulated pivot in rotations per second squaredprotected doublePosition of the simulated pivot in rotationsprotected doubleVelocity 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 TypeMethodDescriptiondoubleabsoluteClamp(double value) Directs the pivot to its maximum position, current goal position, or minimum positiondoubleclampPivotPosition(double target) Clamps the goal pivot position to be within rotational limitsvoidConfigure shuffleboard for the pivotvoidCalculates the next state according to the trapezoidal profile and requests the pivot motor(s) to arrive at the next position with feedforwarddoubleGets the position offset for feedforward (to account for a shifted center of mass) in rotationscom.ctre.phoenix6.hardware.TalonFXgetMotor()Gets the primary motor of the pivotRetrieves ligament attached to pivot Mechanism2ddoubleGets the current position of the pivot in rotationsdoubleGets the power of the primary motordoubleGets the current velocity of the pivot in rotations per secondvoidSets the power of the primary motor to zerobooleanisPivotInAbsoluteTolerance(double lowerBound, double upperBound) Bounds checking function that uses the absolute current pivot position (modulo one rotation)booleanisPivotInTolerance(double lowerBound, double upperBound) Bounds checking function that uses the current pivot positionbooleanChecks whether or not it's safe for the pivot to movebooleanResets devices if resets have occurreddoublemotorToPivotRot(double motorRot) Converts motor rotations to rotations of the pivot mechanismvoidreturns nothing if micro system is disabledvoidonEnable()Executes logic for when the robot is first enabledvoidperiodic()Periodic update functiondoublepivotRotToMotor(double pivotRot) Converts rotations of the pivot mechanism to motor rotationsdoubleplacePivotInClosestRot(double scopeReferenceRot, double newAngleRot) Returns the new pivot angle in the closest scope of the reference pivot anglevoidsetPivotPower(double power) Sets the power of the primary motorvoidsetPivotProfile(double goalPositionRot) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(double goalPositionRot, double goalVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(double goalPositionRot, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2, boolean setCurrentState) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(Angle goalPosition) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(Angle goalPosition, double goalVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2) Creates a new trapezoidal profile for the pivot to followvoidsetPivotProfile(Angle goalPosition, double goalVelocityRPS, double maxVelocityRPS, double maxAccelerationRPS2, boolean setCurrentState) Creates a new trapezoidal profile for the pivot to followvoidsetPivotVelocity(double rps, boolean withFF) Sets the velocity of the pivot in RPSvoidInitializes the pivot simulationvoidRuns the pivot simulation--sets motor and cancoder simulation fields and updates the visualvoidUpdates 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:
periodicin classMicrosystem
-
getMotor
Gets the primary motor of the pivot- Returns:
- primary motor
-
onEnable
Executes logic for when the robot is first enabled- Overrides:
onEnablein classMicrosystem
-
onDisable
Description copied from class:Microsystemreturns nothing if micro system is disabled- Overrides:
onDisablein classMicrosystem
-
updateShuffleboard
Updates shuffleboard with the pivot's current position and velocity- Overrides:
updateShuffleboardin 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:
configShuffleboardin 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:
motorResetConfigin 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:
simulationInitin classMicrosystem
-
simulationPeriodic
Runs the pivot simulation--sets motor and cancoder simulation fields and updates the visual- Overrides:
simulationPeriodicin 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:MicrosystemSets the power of the primary motor to zero- Overrides:
holdCurrentPositionin classMicrosystem
-
getPivotLigament
Retrieves ligament attached to pivot Mechanism2d- Returns:
- pivot ligament
-