Package com.marswars.mechanisms
Class FlywheelMech
java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.mechanisms.FlywheelMech
- All Implemented Interfaces:
SubsystemIoBase
TalonFX-based mechanism implementation for flywheels with velocity and duty cycle control.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumControl modes for the flywheel mechanismNested classes/interfaces inherited from class com.marswars.mechanisms.MechBase
MechBase.ConstructedMotors -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleprotected doubleprotected doubleprotected doubleprotected final FlywheelSimprotected final doubleprotected final com.marswars.mechanisms.MechInputsAutoLoggedprotected final MotionMagicVelocityVoltageprotected final Debouncer[]protected final Alert[]protected final Alert[]protected final BaseStatusSignal[]protected doubleprotected final doubleprotected final double -
Constructor Summary
ConstructorsConstructorDescriptionFlywheelMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double wheel_inertia, double wheel_radius) Constructs a new FxFlywheelMechFlywheelMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double wheel_inertia, double wheel_radius) Constructs a new FxFlywheelMech -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyLoadTorque(double torque_nm) Applies a load torque to the flywheel mechanism for simulation purposes.voidconfigSlot(int slot, SlotConfigs config) Configures the given slot with the given configdoubledoubleGets 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.voidsetTargetCurrent(double current_amps) Sets the target current of the flywheel in ampsvoidsetTargetCurrentWithFF(double current_amps, double feedforward) Sets the target current with a feedforward component.voidsetTargetDutyCycle(double duty_cycle) Sets the target duty cycle of the flywheelvoidsetTargetVelocity(double velocity_rad_per_sec) Sets the target velocity of the flywheel in radians per second using standard velocity controlvoidsetTargetVelocityMotionProfile(double velocity_rad_per_sec) Sets the target velocity of the flywheel in radians per second using motion profile velocity controlvoidsetTargetVelocityWithFF(double velocity_rad_per_sec, double arbitrary_feedforward) Sets the target velocity of the flywheel with arbitrary feed forward.voidwriteOutputs(double timestamp) Write outputs to hardware or simulationMethods inherited from class com.marswars.mechanisms.MechBase
configMotors, configMotors, getLoggingKey, getMechName, setMotorCurrentLimit
-
Field Details
-
motion_magic_velocity_request_
-
signals_
-
motor_disconnected_alerts_
-
motor_temp_alerts_
-
motor_conn_debouncers_
-
flywheel_sim_
-
gear_ratio_
protected final double gear_ratio_ -
wheel_inertia_
protected final double wheel_inertia_ -
wheel_radius_
protected final double wheel_radius_ -
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_ -
inputs_
protected final com.marswars.mechanisms.MechInputsAutoLogged inputs_
-
-
Constructor Details
-
FlywheelMech
public FlywheelMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double wheel_inertia, double wheel_radius) Constructs a new FxFlywheelMech- Parameters:
logging_prefix- String prefix for loggingmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationswheel_inertia- Inertia of the flywheel in kg*m^2 (Simulation only)wheel_radius- Radius of the flywheel in meters (Simulation only)
-
FlywheelMech
public FlywheelMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double wheel_inertia, double wheel_radius) Constructs a new FxFlywheelMech- Parameters:
logging_prefix- String prefix for loggingmech_name- Name of the mechanismmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationswheel_inertia- Inertia of the flywheel in kg*m^2 (Simulation only)wheel_radius- Radius of the flywheel in meters (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
-
getCurrentVelocity
public double getCurrentVelocity()- Returns:
- The current velocity of the flywheel 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
-
setTargetVelocity
public void setTargetVelocity(double velocity_rad_per_sec) Sets the target velocity of the flywheel in radians per second using standard velocity control- Parameters:
velocity_rad_per_sec- the target velocity in radians per second
-
setTargetVelocityWithFF
public void setTargetVelocityWithFF(double velocity_rad_per_sec, double arbitrary_feedforward) Sets the target velocity of the flywheel with arbitrary feed forward. This allows additional control output while maintaining velocity.- Parameters:
velocity_rad_per_sec- the target velocity in radians per secondarbitrary_feedforward- arbitrary feed forward value (units depend on slot gains configuration)
-
setTargetVelocityMotionProfile
public void setTargetVelocityMotionProfile(double velocity_rad_per_sec) Sets the target velocity of the flywheel 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 flywheel- Parameters:
duty_cycle- the target duty cycle (-1.0 to 1.0)
-
setTargetCurrent
public void setTargetCurrent(double current_amps) Sets the target current of the flywheel in amps- Parameters:
current_amps- the target current in 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 flywheel 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 flywheel 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
-