Package com.marswars.mechanisms
Class RollerMech
java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.mechanisms.RollerMech
- All Implemented Interfaces:
SubsystemIoBase
- Direct Known Subclasses:
TurretMech
TalonFX-based mechanism implementation for rollers with position, velocity, and duty cycle control.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumControl modes for the roller mechanismNested classes/interfaces inherited from class com.marswars.mechanisms.MechBase
MechBase.ConstructedMotors -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleprotected doubleprotected doubleprotected doubleprotected final com.marswars.mechanisms.MechInputsAutoLoggedprotected final MotionMagicVoltageprotected final MotionMagicVelocityVoltageprotected final Debouncer[]protected final Alert[]protected final Alert[]protected doubleprotected final BaseStatusSignal[]protected double -
Constructor Summary
ConstructorsConstructorDescriptionRollerMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio) Constructs a new RollerMechRollerMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double roller_inertia) Constructs a new RollerMechRollerMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio) Constructs a new RollerMech with a default inertia value.RollerMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double roller_inertia) Constructs a new RollerMech -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyLoadTorque(double torque_nm) Applies a load torque to the roller mechanism for simulation purposes.voidconfigSlot(int slot, SlotConfigs config) Configures the given slot with the given configdoubleGets the current position of the roller mechanism in radiansdoubleGets the current velocity of the roller mechanism in radians per seconddoubleGets the stator (motor-winding) current draw of the leader motor in amps.doubleGets the supply (battery-side) current draw of the leader motor in amps.voidlogData()Log data to NetworkTables or other logging systemsvoidreadInputs(double timestamp) Read inputs from hardware or simulationvoidsetCurrentLimits(CurrentLimitsConfigs currentLimits) Sets the current limits for all motors in the mechanism.voidsetCurrentPosition(double position_rad) Sets the current position of the roller mechanism (for resetting encoders, etc.)voidsetTargetCurrent(double current_amps) voidsetTargetCurrentWithFF(double current_amps, double feedforward) Sets the target current with a feedforward component.voidsetTargetDutyCycle(double duty_cycle) Sets the target duty cycle of the roller mechanismvoidsetTargetPosition(double position_rad) Sets the target position of the roller mechanism in radians using standard position controlvoidsetTargetPositionMotionProfile(double position_rad) Sets the target position of the roller mechanism in radians using motion profile controlvoidsetTargetPositionMotionProfileWithFF(double position_rad, double arbitrary_feedforward) Sets the target position of the roller mechanism with arbitrary feed forward using motion profile control.voidsetTargetPositionWithFF(double position_rad, double arbitrary_feedforward) Sets the target position of the roller mechanism with arbitrary feed forward.voidsetTargetVelocity(double velocity_rad_per_sec) Sets the target velocity of the roller mechanism in radians per second using standard velocity controlvoidsetTargetVelocityMotionProfile(double velocity_rad_per_sec) Sets the target velocity of the roller mechanism in radians per second using motion profile velocity controlvoidwriteOutputs(double timestamp) Write outputs to hardware or simulationMethods inherited from class com.marswars.mechanisms.MechBase
configMotors, configMotors, getLoggingKey, getMechName, setMotorCurrentLimit
-
Field Details
-
motion_magic_position_request_
-
motion_magic_velocity_request_
-
signals_
-
motor_disconnected_alerts_
-
motor_temp_alerts_
-
motor_conn_debouncers_
-
inputs_
protected final com.marswars.mechanisms.MechInputsAutoLogged inputs_ -
position_target_
protected double position_target_ -
velocity_target_
protected double velocity_target_ -
duty_cycle_target_
protected double duty_cycle_target_ -
current_target_
protected double current_target_ -
current_target_FF_
protected double current_target_FF_ -
filtered_torque_current_
protected double filtered_torque_current_
-
-
Constructor Details
-
RollerMech
Constructs a new RollerMech with a default inertia value.- Parameters:
logging_prefix- String prefix for loggingmotor_configs- Configuration for the roller motorgear_ratio- Gear ratio as motor rotations / mechanism rotations
-
RollerMech
public RollerMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio) Constructs a new RollerMech- Parameters:
logging_prefix- String prefix for loggingmech_name- Name of the mechanismmotor_configs- Configuration for the roller motorgear_ratio- Gear ratio as motor rotations / mechanism rotations
-
RollerMech
public RollerMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double roller_inertia) Constructs a new RollerMech- Parameters:
logging_prefix- String prefix for loggingmotor_configs- Configuration for the roller motorgear_ratio- Gear ratio as motor rotations / mechanism rotationsroller_inertia- Inertia of the roller in kg*m^2 (Simulation only)
-
RollerMech
public RollerMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double roller_inertia) Constructs a new RollerMech- Parameters:
logging_prefix- String prefix for loggingmech_name- Name of the mechanismmotor_configs- Configuration for the roller motorgear_ratio- Gear ratio as motor rotations / mechanism rotationsroller_inertia- Inertia of the roller in kg*m^2 (Simulation only)
-
-
Method Details
-
readInputs
public void readInputs(double timestamp) Read inputs from hardware or simulation- Parameters:
timestamp- the current timestamp
-
writeOutputs
public void writeOutputs(double timestamp) Write outputs to hardware or simulation- Parameters:
timestamp- the current timestamp
-
logData
public void logData()Log data to NetworkTables or other logging systems -
configSlot
Configures the given slot with the given config- Parameters:
slot- the slot index to configureconfig- the slot config to apply
-
setCurrentPosition
public void setCurrentPosition(double position_rad) Sets the current position of the roller mechanism (for resetting encoders, etc.)- Parameters:
position_rad- the position in radians
-
getCurrentPosition
public double getCurrentPosition()Gets the current position of the roller mechanism in radians- Returns:
- the position in radians
-
getCurrentVelocity
public double getCurrentVelocity()Gets the current velocity of the roller mechanism in radians per second- Returns:
- the velocity in radians per second
-
getLeaderSupplyCurrent
public double getLeaderSupplyCurrent()Gets the supply (battery-side) current draw of the leader motor in amps.- Returns:
- the leader supply current in amps
-
getLeaderStatorCurrent
public double getLeaderStatorCurrent()Gets the stator (motor-winding) current draw of the leader motor in amps.- Returns:
- the leader stator current in amps
-
setTargetPosition
public void setTargetPosition(double position_rad) Sets the target position of the roller mechanism in radians using standard position control- Parameters:
position_rad- the target position in radians
-
setTargetPositionWithFF
public void setTargetPositionWithFF(double position_rad, double arbitrary_feedforward) Sets the target position of the roller mechanism with arbitrary feed forward. This allows additional control output while holding a position (e.g., for a hood that adds backspin).- Parameters:
position_rad- the target position in radiansarbitrary_feedforward- arbitrary feed forward value (units depend on slot gains configuration)
-
setTargetPositionMotionProfile
public void setTargetPositionMotionProfile(double position_rad) Sets the target position of the roller mechanism in radians using motion profile control- Parameters:
position_rad- the target position in radians
-
setTargetPositionMotionProfileWithFF
public void setTargetPositionMotionProfileWithFF(double position_rad, double arbitrary_feedforward) Sets the target position of the roller mechanism with arbitrary feed forward using motion profile control. This allows additional control output while holding a position (e.g., for a hood that adds backspin).- Parameters:
position_rad- the target position in radiansarbitrary_feedforward- arbitrary feed forward value (units depend on slot gains configuration)
-
setTargetVelocity
public void setTargetVelocity(double velocity_rad_per_sec) Sets the target velocity of the roller mechanism in radians per second using standard velocity control- Parameters:
velocity_rad_per_sec- the target velocity in radians per second
-
setTargetVelocityMotionProfile
public void setTargetVelocityMotionProfile(double velocity_rad_per_sec) Sets the target velocity of the roller mechanism in radians per second using motion profile velocity control- Parameters:
velocity_rad_per_sec- the target velocity in radians per second
-
setTargetDutyCycle
public void setTargetDutyCycle(double duty_cycle) Sets the target duty cycle of the roller mechanism- Parameters:
duty_cycle- the target duty cycle (-1.0 to 1.0)
-
setTargetCurrent
public void setTargetCurrent(double current_amps) -
setTargetCurrentWithFF
public void setTargetCurrentWithFF(double current_amps, double feedforward) Sets the target current with a feedforward component.- Parameters:
current_amps- the target current in ampsfeedforward- the feedforward component in amps to add to the target current
-
applyLoadTorque
public void applyLoadTorque(double torque_nm) Applies a load torque to the roller mechanism for simulation purposes. This method should be called during the simulation update cycle to apply external loads (like friction, compression forces, etc.) to the mechanism.- Parameters:
torque_nm- The load torque in Newton-meters (Nm) at the roller output shaft. Positive values oppose motion in the positive direction.
-
setCurrentLimits
Sets the current limits for all motors in the mechanism.- Parameters:
currentLimits- the current limits configuration to apply
-