Skip to content

Commit 5b447d8

Browse files
authored
Merge pull request #83 from strykeforce/healthCheck
Initial Healthcheck Implementation
2 parents c838218 + 361e6c2 commit 5b447d8

File tree

9 files changed

+204
-7
lines changed

9 files changed

+204
-7
lines changed

src/main/java/frc/robot/RobotContainer.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import frc.robot.commands.robotState.SetGamePieceCommand;
4545
import frc.robot.commands.robotState.SetLevelAndColCommandGroup;
4646
import frc.robot.commands.robotState.ShelfPickupCommand;
47+
import frc.robot.commands.robotState.ShuffleBoardHealthCheckCommandGroup;
4748
import frc.robot.commands.robotState.StowRobotCommand;
4849
import frc.robot.commands.robotState.ToggleIntakeCommand;
4950
import frc.robot.commands.shoulder.ShoulderSpeedCommand;
@@ -587,6 +588,20 @@ private void configurePitDashboard() {
587588
gamePieceCommands
588589
.add("Set cube", new SetGamePieceCommand(robotStateSubsystem, GamePiece.CUBE))
589590
.withPosition(0, 1);
591+
592+
ShuffleboardLayout HealthCheck =
593+
pitTab.getLayout("HealthCheck", BuiltInLayouts.kGrid).withPosition(1, 0).withSize(1, 1);
594+
HealthCheck.add(
595+
"HealthCheck",
596+
new ShuffleBoardHealthCheckCommandGroup(
597+
elbowSubsystem,
598+
shoulderSubsystem,
599+
elevatorSubsystem,
600+
handSubsystem,
601+
driveSubsystem,
602+
intakeSubsystem,
603+
armSubsystem))
604+
.withPosition(0, 0);
590605
}
591606

592607
public void setAllianceColor(Alliance alliance) {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package frc.robot.commands.robotState;
2+
3+
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
4+
import frc.robot.commands.drive.LockZeroCommand;
5+
import frc.robot.subsystems.ArmSubsystem;
6+
import frc.robot.subsystems.DriveSubsystem;
7+
import frc.robot.subsystems.ElbowSubsystem;
8+
import frc.robot.subsystems.ElevatorSubsystem;
9+
import frc.robot.subsystems.HandSubsystem;
10+
import frc.robot.subsystems.IntakeSubsystem;
11+
import frc.robot.subsystems.ShoulderSubsystem;
12+
import org.strykeforce.healthcheck.HealthCheckCommand;
13+
14+
public class ShuffleBoardHealthCheckCommandGroup extends SequentialCommandGroup {
15+
public ShuffleBoardHealthCheckCommandGroup(
16+
ElbowSubsystem elbowSubsystem,
17+
ShoulderSubsystem shoulderSubsystem,
18+
ElevatorSubsystem elevatorSubsystem,
19+
HandSubsystem handSubsystem,
20+
DriveSubsystem driveSubsystem,
21+
IntakeSubsystem intakeSubsystem,
22+
ArmSubsystem armSubsystem) {
23+
addCommands(
24+
new toggleHealthBoolean(armSubsystem),
25+
new HealthCheckCommand(
26+
driveSubsystem,
27+
handSubsystem,
28+
elevatorSubsystem,
29+
elbowSubsystem,
30+
shoulderSubsystem,
31+
intakeSubsystem),
32+
new LockZeroCommand(driveSubsystem),
33+
new toggleHealthBoolean(armSubsystem));
34+
}
35+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package frc.robot.commands.robotState;
2+
3+
import edu.wpi.first.wpilibj2.command.InstantCommand;
4+
import frc.robot.subsystems.ArmSubsystem;
5+
6+
public class toggleHealthBoolean extends InstantCommand {
7+
ArmSubsystem armSubsystem;
8+
9+
public toggleHealthBoolean(ArmSubsystem armSubsystem) {
10+
this.armSubsystem = armSubsystem;
11+
}
12+
13+
@Override
14+
public void initialize() {
15+
armSubsystem.toggleHealthBoolean();
16+
}
17+
}

src/main/java/frc/robot/subsystems/ArmSubsystem.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ArmSubsystem extends MeasurableSubsystem {
3030
private boolean hasElbowZeroed = true;
3131
private boolean isElbowReinforced = true;
3232
private boolean doReinforceElevator = true;
33+
private boolean isHealthChecking = false;
3334

3435
public ArmSubsystem(
3536
ShoulderSubsystem shoulderSubsystem,
@@ -408,16 +409,23 @@ public boolean isFastStowing() {
408409
return shouldFastStowArm;
409410
}
410411

412+
public void toggleHealthBoolean() {
413+
isHealthChecking = !isHealthChecking;
414+
}
415+
411416
@Override
412417
public void periodic() {
413418
HandRegion currHandRegion = getHandRegion();
414419

415-
shoulderSubsystem.setSoftLimits(
416-
currHandRegion.minTicksShoulder, currHandRegion.maxTicksShoulder);
417-
elevatorSubsystem.setSoftLimits(
418-
currHandRegion.minTicksElevator, currHandRegion.maxTicksElevator);
419-
elbowSubsystem.setSoftLimits(currHandRegion.minTicksElbow, currHandRegion.maxTicksElbow);
420-
420+
if (!isHealthChecking) {
421+
shoulderSubsystem.setSoftLimits(
422+
currHandRegion.minTicksShoulder, currHandRegion.maxTicksShoulder);
423+
elevatorSubsystem.setSoftLimits(
424+
currHandRegion.minTicksElevator, currHandRegion.maxTicksElevator);
425+
elbowSubsystem.setSoftLimits(currHandRegion.minTicksElbow, currHandRegion.maxTicksElbow);
426+
} else {
427+
shoulderSubsystem.setSoftLimits(-500.0, 3_000.0);
428+
}
421429
switch (currState) {
422430
case STOW:
423431
if (!hasElbowZeroed

src/main/java/frc/robot/subsystems/ElbowSubsystem.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,23 @@
1010
import java.util.Set;
1111
import org.slf4j.Logger;
1212
import org.slf4j.LoggerFactory;
13+
import org.strykeforce.healthcheck.AfterHealthCheck;
14+
import org.strykeforce.healthcheck.BeforeHealthCheck;
15+
import org.strykeforce.healthcheck.HealthCheck;
16+
import org.strykeforce.healthcheck.Position;
1317
import org.strykeforce.telemetry.TelemetryService;
1418
import org.strykeforce.telemetry.measurable.CanifierMeasurable;
1519
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
1620
import org.strykeforce.telemetry.measurable.Measure;
1721

1822
public class ElbowSubsystem extends MeasurableSubsystem implements ArmComponent {
23+
24+
@HealthCheck
25+
@Position(
26+
percentOutput = {0.1, -0.1},
27+
encoderChange = 5000)
1928
private TalonFX elbowFalcon;
29+
2030
private double setPointTicks = 0;
2131
private CANifier remoteEncoder;
2232
private Logger logger = LoggerFactory.getLogger(ElbowSubsystem.class);
@@ -40,6 +50,18 @@ public ElbowSubsystem(Constants constants) {
4050
zeroElbow();
4151
}
4252

53+
@BeforeHealthCheck
54+
public boolean goToZero() {
55+
setPos(0.0);
56+
return isFinished();
57+
}
58+
59+
@AfterHealthCheck
60+
public boolean returnToZero() {
61+
setPos(0.0);
62+
return isFinished();
63+
}
64+
4365
private int getPulseWidthFor(PWMChannel channel) {
4466
double[] pulseWidthandPeriod = new double[2];
4567
remoteEncoder.getPWMInput(channel, pulseWidthandPeriod);

src/main/java/frc/robot/subsystems/ElevatorSubsystem.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@
88
import java.util.Set;
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
11+
import org.strykeforce.healthcheck.AfterHealthCheck;
12+
import org.strykeforce.healthcheck.BeforeHealthCheck;
13+
import org.strykeforce.healthcheck.Follow;
14+
import org.strykeforce.healthcheck.HealthCheck;
15+
import org.strykeforce.healthcheck.Position;
1116
import org.strykeforce.telemetry.TelemetryService;
1217
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
1318
import org.strykeforce.telemetry.measurable.Measure;
1419

1520
public class ElevatorSubsystem extends MeasurableSubsystem implements ArmComponent {
1621
private static final Logger logger = LoggerFactory.getLogger(ElevatorSubsystem.class);
22+
23+
@HealthCheck
24+
@Position(
25+
percentOutput = {-0.2, 0.2},
26+
encoderChange = 3_000)
1727
private TalonFX leftMainFalcon;
28+
29+
@HealthCheck
30+
@Follow(leader = ElevatorConstants.kLeftMainId)
1831
private TalonFX rightFollowFalcon;
32+
1933
private double desiredPosition;
2034
private ElevatorState elevatorState;
2135
private boolean hasZeroed = false;
@@ -45,6 +59,18 @@ public ElevatorSubsystem() {
4559
elevatorState = ElevatorState.IDLE;
4660
}
4761

62+
@BeforeHealthCheck
63+
public boolean goToZero() {
64+
setPos(ElevatorConstants.kStowElevator);
65+
return isFinished();
66+
}
67+
68+
@AfterHealthCheck
69+
public boolean returnToZero() {
70+
setPos(ElevatorConstants.kStowElevator);
71+
return isFinished();
72+
}
73+
4874
public void setPos(double location) {
4975
if (desiredPosition != location) logger.info("Elevator moving to {}", location);
5076
desiredPosition = location;

src/main/java/frc/robot/subsystems/HandSubsystem.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,28 @@
1111
import java.util.Set;
1212
import org.slf4j.Logger;
1313
import org.slf4j.LoggerFactory;
14+
import org.strykeforce.healthcheck.AfterHealthCheck;
15+
import org.strykeforce.healthcheck.BeforeHealthCheck;
16+
import org.strykeforce.healthcheck.HealthCheck;
17+
import org.strykeforce.healthcheck.Position;
18+
import org.strykeforce.healthcheck.Timed;
1419
import org.strykeforce.telemetry.TelemetryService;
1520
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
1621
import org.strykeforce.telemetry.measurable.Measure;
1722

1823
public class HandSubsystem extends MeasurableSubsystem {
1924
private final Logger logger = LoggerFactory.getLogger(this.getClass());
25+
26+
@HealthCheck
27+
@Position(
28+
percentOutput = {-0.2, 0.2},
29+
encoderChange = 300)
2030
private TalonSRX handLeftTalon;
31+
32+
@HealthCheck
33+
@Timed(
34+
percentOutput = {0.3, -0.3},
35+
duration = 5)
2136
private TalonSRX rollerTalon;
2237
// private TalonSRX handRightTalon;
2338

@@ -69,6 +84,18 @@ public HandSubsystem(Constants constants) {
6984
// handRightZeroStableCounts = 0;
7085
}
7186

87+
@BeforeHealthCheck
88+
public boolean goToZero() {
89+
setPos(HandConstants.kMaxFwd);
90+
return isFinished();
91+
}
92+
93+
@AfterHealthCheck
94+
public boolean returnToZero() {
95+
setPos(HandConstants.kMaxFwd);
96+
return isFinished();
97+
}
98+
7299
public void runRollers(double percent) {
73100
if (percent != lastPercent) logger.info("Running rollers at {}", percent);
74101
rollerTalon.set(TalonSRXControlMode.PercentOutput, percent);

src/main/java/frc/robot/subsystems/IntakeSubsystem.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
import java.util.Set;
1313
import org.slf4j.Logger;
1414
import org.slf4j.LoggerFactory;
15+
import org.strykeforce.healthcheck.AfterHealthCheck;
16+
import org.strykeforce.healthcheck.BeforeHealthCheck;
1517
import org.strykeforce.healthcheck.HealthCheck;
18+
import org.strykeforce.healthcheck.Position;
1619
import org.strykeforce.healthcheck.Timed;
1720
import org.strykeforce.telemetry.TelemetryService;
1821
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
@@ -21,13 +24,18 @@
2124
public class IntakeSubsystem extends MeasurableSubsystem {
2225
private IntakeState currIntakeState = IntakeState.RETRACTED;
2326

24-
@HealthCheck
27+
@HealthCheck(order = 1)
2528
@Timed(
2629
percentOutput = {0.5, -0.5},
2730
duration = 5)
2831
private TalonFX intakeFalcon;
2932

33+
@HealthCheck(order = 2)
34+
@Position(
35+
percentOutput = {-0.1, 0.5},
36+
encoderChange = 1000)
3037
private TalonSRX extendTalon;
38+
3139
private double intakeSetPointTicks;
3240
private boolean isIntakeExtended = false;
3341
private Timer ejectTimer = new Timer();
@@ -55,6 +63,18 @@ public IntakeSubsystem(Constants constants) {
5563
zeroIntake();
5664
}
5765

66+
@BeforeHealthCheck
67+
public boolean goToZero() {
68+
retractIntake();
69+
return isFinished();
70+
}
71+
72+
@AfterHealthCheck
73+
public boolean returnToZero() {
74+
retractIntake();
75+
return isFinished();
76+
}
77+
5878
public void intakeOpenLoop(double percentOutput) {
5979
intakeFalcon.set(ControlMode.PercentOutput, percentOutput);
6080
}

src/main/java/frc/robot/subsystems/ShoulderSubsystem.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,31 @@
44
import com.ctre.phoenix.motorcontrol.NeutralMode;
55
import com.ctre.phoenix.motorcontrol.can.TalonSRX;
66
import frc.robot.Constants;
7+
import frc.robot.Constants.ShoulderConstants;
78
import java.util.Set;
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
11+
import org.strykeforce.healthcheck.AfterHealthCheck;
12+
import org.strykeforce.healthcheck.BeforeHealthCheck;
13+
import org.strykeforce.healthcheck.Follow;
14+
import org.strykeforce.healthcheck.HealthCheck;
15+
import org.strykeforce.healthcheck.Position;
1016
import org.strykeforce.telemetry.TelemetryService;
1117
import org.strykeforce.telemetry.measurable.MeasurableSubsystem;
1218
import org.strykeforce.telemetry.measurable.Measure;
1319

1420
public class ShoulderSubsystem extends MeasurableSubsystem implements ArmComponent {
21+
22+
@HealthCheck
23+
@Position(
24+
percentOutput = {0.2, -0.2},
25+
encoderChange = 1000)
1526
private TalonSRX leftMainShoulderTalon;
27+
28+
@HealthCheck
29+
@Follow(leader = ShoulderConstants.kShoulderId)
1630
private TalonSRX rightFollowerShoulderTalon;
31+
1732
private double desiredPosition;
1833
private Constants constants;
1934

@@ -42,6 +57,18 @@ public ShoulderSubsystem(Constants constants) {
4257
desiredPosition = getPos();
4358
}
4459

60+
@BeforeHealthCheck
61+
public boolean goToZero() {
62+
setPos(0.0);
63+
return isFinished();
64+
}
65+
66+
@AfterHealthCheck
67+
public boolean returnToZero() {
68+
setPos(0.0);
69+
return isFinished();
70+
}
71+
4572
public void setPos(double location) {
4673
if (location != desiredPosition) logger.info("Moving Shoulder to: {}", location);
4774
desiredPosition = location;

0 commit comments

Comments
 (0)