Package com.marswars.mechanisms
Class ArmMech
java.lang.Object
com.marswars.mechanisms.MechBase
com.marswars.mechanisms.ArmMech
- All Implemented Interfaces:
SubsystemIoBase
Mechanism implementation for a single-jointed arm with position, velocity, and duty control.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumControl modes for the arm 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 Debouncer[]protected final Alert[]protected final Alert[]protected doubleprotected final BaseStatusSignal[]protected double -
Constructor Summary
ConstructorsConstructorDescriptionArmMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle) Constructs a new FxArmMech with a mechanism name and gravity compensation enabled by defaultArmMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle, boolean gravity_compensate) Constructs a new FxArmMech with a mechanism name and configurable gravity compensationArmMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle) Constructs a new FxArmMech with gravity compensation enabled by defaultArmMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle, boolean gravity_compensate) Constructs a new FxArmMech with configurable gravity compensation -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyLoadTorque(double torque_nm) Applies an external load torque to the simulation model.voidconfigSlot(int slot, SlotConfigs config) Configures the given slot with the given configdoubleReturns the arm's current measured position.doubleReturns the arm's current measured velocity.doubleReturns the stator (motor-winding) current draw of the leader motor.doubleReturns the supply (battery-side) current draw of the leader motor.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) Seeds the arm's measured position, overwriting the leader motor's internal encoder reading with the given angle.voidsetTargetCurrent(double current_amps) Sets the target current of the arm in ampsvoidsetTargetCurrentWithFF(double current_amps, double feedforward) Sets the target current with a feedforward component.voidsetTargetDutyCycle(double duty_cycle) Commands the arm with an open-loop duty cycle.voidsetTargetPosition(double position_rad) Commands the arm to a target position using the standard position controller, clearing any feedforward.voidsetTargetPositionMotionProfile(double position_rad) Commands the arm to a target position using the Motion Magic motion profile, clearing any feedforward.voidsetTargetPositionMotionProfileWithFF(double position_rad, double arbitrary_feedforward) Commands the arm to a target position using the Motion Magic motion profile with an arbitrary feedforward applied.voidsetTargetPositionWithFF(double position_rad, double arbitrary_feedforward) Commands the arm to a target position using the standard position controller with an arbitrary feedforward applied.voidsetTargetVelocity(double velocity_rad_per_sec) Commands the arm to a target velocity using the velocity controller.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_position_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
-
ArmMech
public ArmMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle) Constructs a new FxArmMech with gravity compensation enabled by default- Parameters:
logging_prefix- String prefix for loggingmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationslength- Length of the arm in meters (Simulation only)mass_kg- Mass of the arm in kg (Simulation only)min_angle- Minimum angle of the arm in radians (Simulation only)max_angle- Maximum angle of the arm in radians (Simulation only)
-
ArmMech
public ArmMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle) Constructs a new FxArmMech with a mechanism name and gravity compensation enabled by default- Parameters:
logging_prefix- String prefix for loggingmech_name- Name of the mechanismmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationslength- Length of the arm in meters (Simulation only)mass_kg- Mass of the arm in kg (Simulation only)min_angle- Minimum angle of the arm in radians (Simulation only)max_angle- Maximum angle of the arm in radians (Simulation only)
-
ArmMech
public ArmMech(String logging_prefix, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle, boolean gravity_compensate) Constructs a new FxArmMech with configurable gravity compensation- Parameters:
logging_prefix- String prefix for loggingmotor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationslength- Length of the arm in meters (Simulation only)mass_kg- Mass of the arm in kg (Simulation only)min_angle- Minimum angle of the arm in radians (Simulation only)max_angle- Maximum angle of the arm in radians (Simulation only)gravity_compensate- true to enable gravity compensation, false otherwise
-
ArmMech
public ArmMech(String logging_prefix, String mech_name, List<MotorConfig> motor_configs, double gear_ratio, double length, double mass_kg, double min_angle, double max_angle, boolean gravity_compensate) Constructs a new FxArmMech with a mechanism name and configurable gravity compensation- Parameters:
logging_prefix- String prefix for loggingmech_name- Name of the mechanism (used for multiple instances of the same mech)motor_configs- List of motor configurationsgear_ratio- Gear ratio as motor rotations / mechanism rotationslength- Length of the arm in meters (Simulation only)mass_kg- Mass of the arm in kg (Simulation only)min_angle- Minimum angle of the arm in radians (Simulation only)max_angle- Maximum angle of the arm in radians (Simulation only)gravity_compensate- true to enable gravity compensation, false otherwise
-
-
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 config to apply
-
setCurrentPosition
public void setCurrentPosition(double position_rad) Seeds the arm's measured position, overwriting the leader motor's internal encoder reading with the given angle.- Parameters:
position_rad- the position to seed, in radians
-
getCurrentPosition
public double getCurrentPosition()Returns the arm's current measured position.- Returns:
- the position in radians
-
getCurrentVelocity
public double getCurrentVelocity()Returns the arm's current measured velocity.- Returns:
- the velocity in radians per second
-
getLeaderSupplyCurrent
public double getLeaderSupplyCurrent()Returns the supply (battery-side) current draw of the leader motor.- Returns:
- the leader supply current in amps
-
getLeaderStatorCurrent
public double getLeaderStatorCurrent()Returns the stator (motor-winding) current draw of the leader motor.- Returns:
- the leader stator current in amps
-
setTargetPosition
public void setTargetPosition(double position_rad) Commands the arm to a target position using the standard position controller, clearing any feedforward.- Parameters:
position_rad- the target position in radians
-
setTargetPositionWithFF
public void setTargetPositionWithFF(double position_rad, double arbitrary_feedforward) Commands the arm to a target position using the standard position controller with an arbitrary feedforward applied.- Parameters:
position_rad- the target position in radiansarbitrary_feedforward- the feedforward to apply to the position request
-
setTargetPositionMotionProfile
public void setTargetPositionMotionProfile(double position_rad) Commands the arm to a target position using the Motion Magic motion profile, clearing any feedforward.- Parameters:
position_rad- the target position in radians
-
setTargetPositionMotionProfileWithFF
public void setTargetPositionMotionProfileWithFF(double position_rad, double arbitrary_feedforward) Commands the arm to a target position using the Motion Magic motion profile with an arbitrary feedforward applied.- Parameters:
position_rad- the target position in radiansarbitrary_feedforward- the feedforward to apply to the motion profile request
-
setTargetVelocity
public void setTargetVelocity(double velocity_rad_per_sec) Commands the arm to a target velocity using the velocity controller.- Parameters:
velocity_rad_per_sec- the target velocity in radians per second
-
setTargetDutyCycle
public void setTargetDutyCycle(double duty_cycle) Commands the arm with an open-loop duty cycle.- Parameters:
duty_cycle- the target duty cycle, in the range [-1, 1]
-
setTargetCurrent
public void setTargetCurrent(double current_amps) Sets the target current of the arm 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 an external load torque to the simulation model. No effect on real hardware.- Parameters:
torque_nm- the load torque to apply, in newton-meters
-
setCurrentLimits
Sets the current limits for all motors in the mechanism.- Parameters:
currentLimits- the current limits configuration to apply
-