Class ElevatorMech

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

public class ElevatorMech extends MechBase
Mechanism implementation for elevators with position, velocity, and duty cycle control.
  • Field Details

    • motors_

      protected final CommonTalon[] motors_
    • position_request_

      protected final PositionVoltage position_request_
    • motion_magic_position_request_

      protected final MotionMagicVoltage motion_magic_position_request_
    • velocity_request_

      protected final VelocityVoltage velocity_request_
    • duty_cycle_request_

      protected final DutyCycleOut duty_cycle_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_
    • 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_
    • inputs_

      protected final com.marswars.mechanisms.MechInputsAutoLogged inputs_
  • Constructor Details

    • ElevatorMech

      public ElevatorMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double drum_radius, double carriage_mass_kg, double max_extension)
      Constructs a new ElevatorMech (assumes vertical elevator)
      Parameters:
      logging_prefix - String prefix for logging
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      drum_radius - Radius of the drum in meters
      carriage_mass_kg - Mass of the elevator carriage in kg (Simulation only)
      max_extension - Maximum extension of the elevator in meters (Simulation only)
    • ElevatorMech

      public ElevatorMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double drum_radius, double carriage_mass_kg, double max_extension, double rigging_ratio)
      Constructs a new ElevatorMech
      Parameters:
      logging_prefix - String prefix for logging
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      drum_radius - Radius of the drum in meters
      carriage_mass_kg - Mass of the elevator carriage in kg (Simulation only)
      max_extension - Maximum extension of the elevator in meters (Simulation only)
      rigging_ratio - Rigging ratio of the elevator
    • ElevatorMech

      public ElevatorMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double drum_radius, double carriage_mass_kg, double max_extension, double rigging_ratio)
      Constructs a new ElevatorMech
      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
      drum_radius - Radius of the drum in meters
      carriage_mass_kg - Mass of the elevator carriage in kg (Simulation only)
      max_extension - Maximum extension of the elevator in meters (Simulation only)
      rigging_ratio - Rigging ratio of the elevator
    • ElevatorMech

      public ElevatorMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double drum_radius, double carriage_mass_kg, double max_extension, double rigging_ratio, boolean is_vertical)
      Constructs a new ElevatorMech
      Parameters:
      logging_prefix - String prefix for logging
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      drum_radius - Radius of the drum in meters
      carriage_mass_kg - Mass of the elevator carriage in kg (Simulation only)
      max_extension - Maximum extension of the elevator in meters (Simulation only)
      rigging_ratio - Rigging ratio of the elevator
      is_vertical - Whether the elevator is vertical (affects gravity compensation in simulation)
    • ElevatorMech

      public ElevatorMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double drum_radius, double carriage_mass_kg, double max_extension, double rigging_ratio, boolean is_vertical)
      Constructs a new ElevatorMech
      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
      drum_radius - Radius of the drum in meters
      carriage_mass_kg - Mass of the elevator carriage in kg (Simulation only)
      max_extension - Maximum extension of the elevator in meters (Simulation only)
      rigging_ratio - Rigging ratio of the elevator
      is_vertical - Whether the elevator is vertical (affects gravity compensation in simulation)
  • 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 to configure
      config - the slot config to apply
    • setCurrentPosition

      public void setCurrentPosition(double position)
      Sets the current position of the elevator (for zeroing purposes)
      Parameters:
      position - the position to set in meters
    • getCurrentPosition

      public double getCurrentPosition()
      Gets the current position of the elevator in meters
      Returns:
      the current position in meters
    • getCurrentVelocity

      public double getCurrentVelocity()
      Gets the current velocity of the elevator in meters per second
      Returns:
      the current velocity in meters 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_m)
      Sets the target position of the elevator in meters using standard position control
      Parameters:
      position_m - the target position in meters
    • setTargetPositionWithFF

      public void setTargetPositionWithFF(double position_m, double arbitrary_feedforward)
      Sets the target position of the elevator with arbitrary feed forward. This allows additional control output while holding a position.
      Parameters:
      position_m - the target position in meters
      arbitrary_feedforward - arbitrary feed forward value (units depend on slot gains configuration)
    • setTargetPositionMotionProfile

      public void setTargetPositionMotionProfile(double position_m)
      Sets the target position of the elevator in meters using motion profile control
      Parameters:
      position_m - the target position in meters
    • setTargetPositionMotionProfileWithFF

      public void setTargetPositionMotionProfileWithFF(double position_m, double arbitrary_feedforward)
      Sets the target position of the elevator with arbitrary feed forward using motion profile control. This allows additional control output while holding a position.
      Parameters:
      position_m - the target position in meters
      arbitrary_feedforward - arbitrary feed forward value (units depend on slot gains configuration)
    • setTargetVelocity

      public void setTargetVelocity(double velocity_mps)
      Sets the target velocity of the elevator in meters per second
      Parameters:
      velocity_mps - the target velocity in meters per second
    • setTargetDutyCycle

      public void setTargetDutyCycle(double duty_cycle)
      Sets the target duty cycle of the elevator
      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 elevator 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 elevator 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 drum 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