Class Arm

All Implemented Interfaces:
CommandMechanism

public class Arm extends Arm implements CommandMechanism
Command-based extension of Arm that adds the Mechanism binding and Command/Trigger factories.

Usage Example

// Build and construct
SmartMotorController motor = new SparkWrapper(
    new SparkMax(1, MotorType.kBrushless), DCMotor.getNEO(1),
    new
SmartMotorControllerConfig(this).withClosedLoopController(0.2,0,0).withStatorCurrentLimit(Amps.of(40)));
ArmConfig armConfig = new ArmConfig().withLength(Meters.of(0.5));
Arm arm = new Arm(armConfig, motor);

// Schedule a setpoint command
Command moveToScore = arm.setAngle(Degrees.of(80));
Command holdAtZero = arm.runTo(Degrees.of(0), Degrees.of(2));

// Bind triggers
arm.near(Degrees.of(80), Degrees.of(2)).onTrue(indexer.run());
arm.max().onTrue(Command.noRequirements(co -> System.out.println("Arm at max!")).named("Print"));

// Call in robotPeriodic() or a subsystem's periodic():
arm.simIterate();
arm.updateTelemetry();
  • Constructor Details

  • Method Details

    • getMechanism

      public org.wpilib.command3.Mechanism getMechanism()
      Description copied from interface: CommandMechanism
      Mechanism the mechanism's commands should require.
      Specified by:
      getMechanism in interface CommandMechanism
      Returns:
      Mechanism for the mechanism.
    • setAngle

      public org.wpilib.command3.Command setAngle(org.wpilib.units.measure.Angle angle)
      Set the arm to the given angle.
      Parameters:
      angle - Arm angle to go to.
      Returns:
      Command that sets the arm to the desired angle.
    • setAngle

      public org.wpilib.command3.Command setAngle(Supplier<org.wpilib.units.measure.Angle> angle)
      Set the arm to the given angle via a supplier.
      Parameters:
      angle - Supplier for the arm angle to go to.
      Returns:
      Command that sets the arm to the desired angle.
    • run

      public org.wpilib.command3.Command run(org.wpilib.units.measure.Angle angle)
      Set the arm to the given angle.
      Parameters:
      angle - Arm angle to go to.
      Returns:
      Command that sets the arm to the desired angle.
    • run

      public org.wpilib.command3.Command run(Supplier<org.wpilib.units.measure.Angle> angle)
      Set the arm to the given angle via a supplier.
      Parameters:
      angle - Supplier for the arm angle to go to.
      Returns:
      Command that sets the arm to the desired angle.
    • runTo

      public org.wpilib.command3.Command runTo(org.wpilib.units.measure.Angle angle, org.wpilib.units.measure.Angle tolerance)
      Set the arm to the given angle then end the command.
      Parameters:
      angle - Angle to go to.
      tolerance - Tolerance Angle
      Returns:
      Command that sets the arm to the desired angle.
      Implementation Note:
      This command will not stop. It should NOT be used when there is a default command on the Mechanism.
    • runTo

      public org.wpilib.command3.Command runTo(Supplier<org.wpilib.units.measure.Angle> angle, org.wpilib.units.measure.Angle tolerance)
      Set the arm to the given angle then end the command.
      Parameters:
      angle - Angle to go to.
      tolerance - Tolerance Angle
      Returns:
      Command that sets the arm to the desired angle.
      Implementation Note:
      This command will stop, but the last control request to the motor controller will continue. It should NOT be used when there is a default command on the Mechanism.
    • near

      public org.wpilib.command3.Trigger near(org.wpilib.units.measure.Angle angle, org.wpilib.units.measure.Angle within)
      Arm is near an angle.
      Parameters:
      angle - Angle to be near.
      within - Angle within.
      Returns:
      Trigger on when the arm is near another angle.
    • max

      public org.wpilib.command3.Trigger max()
      Arm is at max, defined by the soft limit or hard limit on the arm.
      Returns:
      Trigger on maximum of the arm.
      Throws:
      ArmConfigurationException - when the returned trigger is evaluated, if neither a motor controller upper soft limit nor an arm upper hard limit is configured.
    • min

      public org.wpilib.command3.Trigger min()
      Minimum angle of the arm given by the soft limit or hard limit of the arm.
      Returns:
      Trigger on minimum of the arm.
      Throws:
      ArmConfigurationException - when the returned trigger is evaluated, if neither a motor controller lower soft limit nor an arm lower hard limit is configured.
    • between

      public org.wpilib.command3.Trigger between(org.wpilib.units.measure.Angle start, org.wpilib.units.measure.Angle end)
      Between two angles.
      Parameters:
      start - Start angle.
      end - End angle
      Returns:
      Trigger
    • lte

      public org.wpilib.command3.Trigger lte(org.wpilib.units.measure.Angle angle)
      Less than or equal to angle
      Parameters:
      angle - Angle to check against
      Returns:
      Trigger
    • gte

      public org.wpilib.command3.Trigger gte(org.wpilib.units.measure.Angle angle)
      Greater than or equal to angle.
      Parameters:
      angle - Angle to check against.
      Returns:
      Trigger for Arm.