Class ArmMech

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

public class ArmMech extends MechBase
Mechanism implementation for a single-jointed arm with position, velocity, and duty control.
  • Field Details

    • motion_magic_position_request_

      protected final MotionMagicVoltage motion_magic_position_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

    • 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 logging
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      length - 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 logging
      mech_name - Name of the mechanism
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      length - 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 logging
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      length - 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 logging
      mech_name - Name of the mechanism (used for multiple instances of the same mech)
      motor_configs - List of motor configurations
      gear_ratio - Gear ratio as motor rotations / mechanism rotations
      length - 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

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

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