Class FlywheelMech

java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.mechanisms.FlywheelMech
All Implemented Interfaces:
SubsystemIoBase

public class FlywheelMech extends MechBase
TalonFX-based mechanism implementation for flywheels with velocity and duty cycle control.
  • Field Details

    • motion_magic_velocity_request_

      protected final MotionMagicVelocityVoltage motion_magic_velocity_request_
    • signals_

      protected final BaseStatusSignal[] signals_
    • motor_disconnected_alerts_

      protected final Alert[] motor_disconnected_alerts_
    • motor_temp_alerts_

      protected final Alert[] motor_temp_alerts_
    • motor_conn_debouncers_

      protected final Debouncer[] motor_conn_debouncers_
    • flywheel_sim_

      protected final FlywheelSim 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 logging
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      wheel_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 logging
      mech_name - Name of the mechanism
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      wheel_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

      public void configSlot(int slot, SlotConfigs config)
      Configures the given slot with the given config
      Parameters:
      slot - the slot index to configure
      config - 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 second
      arbitrary_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 amps
      feedforward - 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

      public void setCurrentLimits(CurrentLimitsConfigs currentLimits)
      Sets the current limits for all motors in the mechanism.
      Parameters:
      currentLimits - the current limits configuration to apply