Package com.marswars.mechanisms
Class ElevatorMech
java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.mechanisms.ElevatorMech
- All Implemented Interfaces:
SubsystemIoBase
Mechanism implementation for elevators with position, velocity, and duty cycle control.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumControl modes for the elevator mechanismNested classes/interfaces inherited from class com.marswars.mechanisms.MechBase
MechBase.ConstructedMotors -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected doubleprotected doubleprotected final DutyCycleOutprotected doubleprotected doubleprotected final com.marswars.mechanisms.MechInputsAutoLoggedprotected final MotionMagicVoltageprotected final Debouncer[]protected final Alert[]protected final Alert[]protected final CommonTalon[]protected final PositionVoltageprotected doubleprotected final BaseStatusSignal[]protected final VelocityVoltageprotected double -
Constructor Summary
ConstructorsConstructorDescriptionElevatorMech(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 ElevatorMechElevatorMech(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 ElevatorMechElevatorMech(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)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 ElevatorMechElevatorMech(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 -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyLoadTorque(double torque_nm) Applies a load torque to the elevator mechanism for simulation purposes.voidconfigSlot(int slot, SlotConfigs config) Configures the given slot with the given configdoubleGets the current position of the elevator in metersdoubleGets the current velocity of the elevator in meters 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) Sets the current position of the elevator (for zeroing purposes)voidsetTargetCurrent(double current_amps) Sets the target current of the elevator 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 elevatorvoidsetTargetPosition(double position_m) Sets the target position of the elevator in meters using standard position controlvoidsetTargetPositionMotionProfile(double position_m) Sets the target position of the elevator in meters using motion profile controlvoidsetTargetPositionMotionProfileWithFF(double position_m, double arbitrary_feedforward) Sets the target position of the elevator with arbitrary feed forward using motion profile control.voidsetTargetPositionWithFF(double position_m, double arbitrary_feedforward) Sets the target position of the elevator with arbitrary feed forward.voidsetTargetVelocity(double velocity_mps) Sets the target velocity of the elevator in meters per secondvoidwriteOutputs(double timestamp) Write outputs to hardware or simulationMethods inherited from class com.marswars.mechanisms.MechBase
configMotors, configMotors, getLoggingKey, getMechName, setMotorCurrentLimit
-
Field Details
-
motors_
-
position_request_
-
motion_magic_position_request_
-
velocity_request_
-
duty_cycle_request_
-
signals_
-
motor_disconnected_alerts_
-
motor_temp_alerts_
-
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 loggingmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationsdrum_radius- Radius of the drum in meterscarriage_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 loggingmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationsdrum_radius- Radius of the drum in meterscarriage_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 loggingmech_name- Name of the mechanismmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationsdrum_radius- Radius of the drum in meterscarriage_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 loggingmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationsdrum_radius- Radius of the drum in meterscarriage_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 elevatoris_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 loggingmech_name- Name of the mechanismmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationsdrum_radius- Radius of the drum in meterscarriage_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 elevatoris_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
Configures the given slot with the given config- Parameters:
slot- the slot to configureconfig- 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 metersarbitrary_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 metersarbitrary_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 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 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
Sets the current limits for all motors in the mechanism.- Parameters:
currentLimits- the current limits configuration to apply
-