Skip to content

Instantly share code, notes, and snippets.

@jhh
Last active April 12, 2022 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhh/5915260811b29d0ee0a0403eff73612f to your computer and use it in GitHub Desktop.
Save jhh/5915260811b29d0ee0a0403eff73612f to your computer and use it in GitHub Desktop.
Requirements for Third Coast Health Check

Requirements

  1. Configure using config.toml and limits.toml in deploy/healthcheck directory. Possibly combine into one file. What is the best way to deal with overwriting in deploy during deployment?
  2. Add a simple interface to Subsystems. This should be the only coding required.
  3. Scan limits.toml and add any missing tests from config.toml with sane limits automatically.
  4. Re-running healthcheck will load the config.toml and limits.toml for faster iterations while tuning tests.
  5. Create robotRIO embedded web server output directory automatically.
  6. Need to test things other than motors?

Tests

  • Talon timed test - run at specified percent output, measure speed and current
  • Talon follower test - same as timed test but specify leader and followers
  • Talon position test - run at specified percent output to specified encoder position, measure speed and current

Utility

  • Talon motion magic position - set setpoint to specified encoder position
@jhh
Copy link
Author

jhh commented Apr 12, 2022

My current thinking is to avoid using a config file and configuring health check right in the subsystem using annotations. You can have a simple health check that logs currents and speeds for a default set of conditions with a single @HealthCheck annotation or configure with @Timed, @Position, and/or @Limits.

Optionally set up talons for testing using @BeforeHealthCheck and restore after tests using @AfterHealthCheck. If something needs to happen between every test, use @BeforeEachHealthCheck.

public class SimpleSubsystem extends SubsystemBase {

  // default 5 sec timed test @ 0.25, 0.5, 0.75, no current or speed limits, just log measured values
  @HealthCheck
  private final TalonSRX talonOne = new TalonSRX(1);


  // timed tests - no current or speed limits
  @HealthCheck
  @Timed(percentOutput = { 0.5, 1.0, -0.5, -1.0 }, duration = 3.0)
  private final TalonFX talonTwo = new TalonFX(2);


  // position tests - no current or speed limits
  @HealthCheck
  @Position(percentOutput = { 0.25, -0.25 }, encoderChange = 20_000)
  private final TalonSRX talonThree = new TalonSRX(3);

  // timed tests - specify limits: currentMin, currentMax, speedMin, speedMax
  @HealthCheck
  @Limits({ 0.5, 1.5, 1000, 2500, 0.5, 1.5, -1000, -2500 })
  @Timed(percentOutput = { 0.5, -0.5 }, duration = 3.0)
  private final TalonFX talonFour = new TalonFX(4);

  // position test - specify limits
  @HealthCheck
  @Position(percentOutput = { 0.25 }, encoderChange = 20_000)
  @Limits({ 0.75, 2.0, 1500, 3500 })
  private final TalonSRX talonFive = new TalonSRX(5);
  
  // follower - just take measurements
  @HealthCheck
  @Follow(5)
  @Limits({ 0.5, 1.5, 1000, 2500 })
  private final TalonFX talonSix = new TalonFX(6);

  // this is broken so don't run it for now, but log as disabled
  @HealthCheck
  @Disabled
  private final TalonSRX talonSeven = new TalonSRX(7);

  ////////////////////////////////////////////////////////////
  // These Health Check lifecycle methods are all optional
  ////////////////////////////////////////////////////////////

  @BeforeHealthCheck
  private void setUpHealthCheck() {
    double slowRampForTests = 2.0;
    talonOne.configOpenloopRamp(slowRampForTests);
    talonOne.setNeutralMode(NeutralMode.Brake);
  }

  @AfterHealthCheck
  private void tearDownHealthCheck() {
    double configValue = 0.25; // get this from Constants class, etc...
    talonOne.configOpenloopRamp(configValue);
    talonOne.setNeutralMode(NeutralMode.Coast);

    // reposition after tests
    talonThree.set(TalonSRXControlMode.MotionMagic, 0);
    talonFive.set(TalonSRXControlMode.MotionMagic, 0);
  }

  @BeforeEachHealthCheck
  private void slowDownTalons() {
    talonOne.neutralOutput();
  }
}

Set up the HealthCheckCommand and the subsystems will be scanned for talons to check.

  public RobotContainer() {
    new Button().whenPressed(new HealthCheckCommand(simpleSubsystem, swerveDriveSubsystem));
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment