-
Notifications
You must be signed in to change notification settings - Fork 3
System checks #227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NikhilSuresh24
wants to merge
26
commits into
main
Choose a base branch
from
system-checks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
System checks #227
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
6e2ec77
init commit
NikhilSuresh24 c74bbb4
more changes
NikhilSuresh24 2104781
added framework for Subsystem checks
NikhilSuresh24 606649c
added solenoid check and lower level system check
NikhilSuresh24 8365f8c
added compressor check
NikhilSuresh24 301071c
finished position and velocity motor checks
NikhilSuresh24 4e2dce2
motor checks, check framework
NikhilSuresh24 ab81588
made some changes
NikhilSuresh24 8e50165
added PID Check
NikhilSuresh24 18f7388
TURN PID CHECK
NikhilSuresh24 83c8606
made position and velocity motor check commands way coooler
NikhilSuresh24 fbad037
formatting is very important
NikhilSuresh24 25f2092
made checkgroup less jank
NikhilSuresh24 3737490
Merge branch 'master' into system-checks
NikhilSuresh24 a680ebf
reverted motioncontroller change
NikhilSuresh24 608fd37
some more stuff
NikhilSuresh24 7d813c1
syntax
NikhilSuresh24 5e70af6
changes
NikhilSuresh24 50aaf1a
overall review, documentation, and cleanup
NikhilSuresh24 01614e3
more formatting and docs
NikhilSuresh24 f6712f4
more formatting and docs
NikhilSuresh24 0a6aae7
fixes docs
NikhilSuresh24 b285dc0
more docs, added voltage and current checks for motors
NikhilSuresh24 0bf6654
pr changes
NikhilSuresh24 cbbf856
Merge branch 'master' into system-checks
NikhilSuresh24 d291aab
Merge branch 'master' into system-checks
NikhilSuresh24 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| package org.usfirst.frc4904.standard.commands.systemchecks; | ||
|
|
||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.stream.Stream; | ||
| import java.util.Arrays; | ||
| import org.usfirst.frc4904.standard.LogKitten; | ||
| import org.usfirst.frc4904.standard.commands.systemchecks.StatusMessage.SystemStatus; | ||
| import edu.wpi.first.wpilibj.command.Command; | ||
|
|
||
| /** | ||
| * BaseCheck is the base class for system checks. | ||
| * Creates a hashmap between systems and their respective statuses | ||
| * that can be updated depending on the results of system checks. | ||
| */ | ||
| public abstract class BaseCheck extends Command implements Check { | ||
| protected static final double DEFAULT_TIMEOUT = 5; | ||
| protected HashMap<String, StatusMessage> statuses; | ||
| protected final String[] systemNames; | ||
|
|
||
| /** | ||
| * @param checkName | ||
| * The name of the command | ||
| * @param timeout | ||
| * Duration of the command | ||
| * @param systemNames | ||
| * Names of the systems being checked | ||
| */ | ||
| public BaseCheck(String checkName, double timeout, String... systemNames) { | ||
| super(checkName, timeout); | ||
| this.systemNames = systemNames; | ||
| initStatuses(); | ||
| } | ||
|
|
||
| /** | ||
| * @param timeout | ||
| * Duration of the command | ||
| * @param systemNames | ||
| * Names of the systems being checked | ||
| */ | ||
| public BaseCheck(double timeout, String... systemNames) { | ||
| this("Check", timeout, systemNames); | ||
| } | ||
|
|
||
| /** | ||
| * @param systemNames | ||
| * Names of the systems being checked | ||
| */ | ||
| public BaseCheck(String... systemNames) { | ||
| this(DEFAULT_TIMEOUT, systemNames); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isFinished() { | ||
| return isTimedOut(); | ||
| } | ||
|
|
||
| @Override | ||
| public void end() { | ||
| outputStatuses(); | ||
| } | ||
|
|
||
| /** | ||
| * Sets status of a system given: | ||
| * | ||
| * @param key | ||
| * name of the system | ||
| * @param status | ||
| * pass or fail status | ||
| * @param exceptions | ||
| * any exception that the class causes | ||
| * | ||
| * Status should be SystemStatus.FAIL if exceptions given. | ||
| */ | ||
| public void setStatus(String key, SystemStatus status, Exception... exceptions) { | ||
| statuses.put(key, new StatusMessage(status, exceptions)); | ||
| } | ||
|
|
||
| /** | ||
| * Initializes a name-status pair to have a PASS status and no exceptions | ||
| * | ||
| * @param key | ||
| * name of the system | ||
| */ | ||
| public void initStatus(String key) { | ||
| setStatus(key, SystemStatus.PASS); | ||
| } | ||
|
|
||
| /** | ||
| * Initializes all systems in systemNames using initStatus | ||
| */ | ||
| public void initStatuses() { | ||
| for (String name : systemNames) { | ||
| initStatus(name); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Updates the status of a name-status pair by adding on exceptions | ||
| * | ||
| * @param name | ||
| * name of the system | ||
| * @param status | ||
| * pass or fail status | ||
| * @param exceptions | ||
| * any exception that the class causes | ||
| */ | ||
| public void updateStatus(String key, SystemStatus status, Exception... exceptions) { | ||
| setStatus(key, status, Stream.concat(Arrays.stream(getStatusMessage(key).exceptions), Arrays.stream(exceptions)) | ||
| .toArray(Exception[]::new)); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the StatusMessage (SystemStatus + exceptions) of a system given its name | ||
| * | ||
| * @param key | ||
| * name of system | ||
| * @return StatusMessage of system | ||
| */ | ||
| public StatusMessage getStatusMessage(String key) { | ||
| return statuses.get(key); | ||
| } | ||
|
|
||
| /** | ||
| * Logs the statuses of all systems with variable severity | ||
| * depending on the status of the system | ||
| */ | ||
| public void outputStatuses() { | ||
| LogKitten.d(getName() + " Statuses:"); | ||
| for (Map.Entry<String, StatusMessage> entry : statuses.entrySet()) { | ||
| String name = entry.getKey(); | ||
| StatusMessage message = entry.getValue(); | ||
| if (message.status == SystemStatus.PASS) { | ||
| LogKitten.d("Subsystem: " + name + ", Status: PASS"); | ||
| } else { | ||
| LogKitten.wtf("Subsystem: " + name + ", Status: FAIL"); | ||
| for (Exception e : message.exceptions) { | ||
| LogKitten.wtf(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package org.usfirst.frc4904.standard.commands.systemchecks; | ||
|
|
||
|
|
||
| import edu.wpi.first.hal.can.CANStatus; | ||
| import edu.wpi.first.wpilibj.RobotController; | ||
|
|
||
| /** | ||
| * Systemcheck of battery status | ||
| */ | ||
| public class BatteryCheck extends BaseCheck { | ||
| protected final double MIN_VOLTAGE = 9.0; | ||
| protected CANStatus status; | ||
| protected static final String systemName = "BATTERY"; | ||
|
|
||
| /** | ||
| * Systemcheck of battery status | ||
| * | ||
| * @param name | ||
| * name of check | ||
| * @param timeout | ||
| * duration of check | ||
| */ | ||
| public BatteryCheck(String name, double timeout) { | ||
| super(name, timeout, systemName); | ||
| } | ||
|
|
||
| /** | ||
| * Systemcheck of battery status | ||
| * | ||
| * @param timeout | ||
| * duration of check | ||
| */ | ||
| public BatteryCheck(double timeout) { | ||
| super("RobotControllerCheck", timeout); | ||
| } | ||
|
|
||
| /** | ||
| * Systemcheck of battery status | ||
| * | ||
| * @param name | ||
| * name of check | ||
| * @param timeout | ||
| * duration of check | ||
| */ | ||
| public BatteryCheck(String name) { | ||
| super(name, DEFAULT_TIMEOUT); | ||
| } | ||
|
|
||
| public void execute() { | ||
| status = RobotController.getCANStatus(); | ||
| if (RobotController.getBatteryVoltage() < MIN_VOLTAGE) { | ||
| updateStatusFail(systemName, new Exception("BATTERY VOLTAGE LESS THAN MIN VOLTAGE REQUIREMENT")); | ||
| } | ||
| if (RobotController.isBrownedOut()) { | ||
| updateStatusFail(systemName, new Exception("BROWNED OUT")); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package org.usfirst.frc4904.standard.commands.systemchecks; | ||
|
|
||
|
|
||
| import edu.wpi.first.hal.can.CANStatus; | ||
| import edu.wpi.first.wpilibj.RobotController; | ||
|
|
||
| /** | ||
| * System check of CAN | ||
| */ | ||
| public class CANCheck extends BaseCheck { | ||
| protected final int MAX_ERROR_COUNT = 127; | ||
| protected final int MAX_OFF_COUNT = 0; | ||
| protected static final String systemName = "CAN"; | ||
| protected CANStatus status; | ||
|
|
||
| /** | ||
| * @param name | ||
| * name of check | ||
| * @param timeout | ||
| * duration of check | ||
| */ | ||
| public CANCheck(String name, double timeout) { | ||
| super(name, timeout, systemName); | ||
| } | ||
|
|
||
| /** | ||
| * @param timeout | ||
| * duration of check | ||
| */ | ||
| public CANCheck(double timeout) { | ||
| super("CANCheck", timeout); | ||
| } | ||
|
|
||
| /** | ||
| * @param name | ||
| * name of check | ||
| */ | ||
| public CANCheck(String name) { | ||
| super(name, DEFAULT_TIMEOUT); | ||
| } | ||
|
|
||
| public void execute() { | ||
| status = RobotController.getCANStatus(); | ||
| if (status.receiveErrorCount > MAX_ERROR_COUNT) { | ||
| updateStatusFail(systemName, new Exception("TOO MANY RECEIVE ERRORS")); | ||
| } | ||
| if (status.transmitErrorCount > MAX_ERROR_COUNT) { | ||
| updateStatusFail(systemName, new Exception("TOO MANY TRANSMISSION ERRORS")); | ||
| } | ||
| if (status.busOffCount > MAX_OFF_COUNT) { | ||
| updateStatusFail(systemName, new Exception("TOO MANY CANBUS OFF OCCURANCES")); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package org.usfirst.frc4904.standard.commands.systemchecks; | ||
|
|
||
|
|
||
| import org.usfirst.frc4904.standard.commands.systemchecks.StatusMessage.SystemStatus; | ||
|
|
||
| public interface Check { | ||
NikhilSuresh24 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Sets the status of a system, overriding previous exceptions | ||
| * | ||
| * @param key | ||
| * name of system | ||
| * @param status | ||
| * PASS or FAIL | ||
| * @param exceptions | ||
| * exceptions caused by the system | ||
| */ | ||
| public void setStatus(String key, SystemStatus status, Exception... exceptions); | ||
|
|
||
| /** | ||
| * Initializes the status of system to PASS | ||
| * | ||
| * @param key | ||
| * name of system | ||
| */ | ||
| default void initStatus(String key) { | ||
| setStatus(key, SystemStatus.PASS); | ||
| } | ||
|
|
||
| /** | ||
| * Initializes statuses of all systems | ||
| */ | ||
| public void initStatuses(); | ||
|
|
||
| /** | ||
| * Sets the status of a system, preserving past exceptions | ||
| * | ||
| * @param key | ||
| * name of system | ||
| * @param status | ||
| * PASS or FAIL | ||
| * @param exceptions | ||
| * exceptions caused by the system | ||
| */ | ||
| public void updateStatus(String key, SystemStatus status, Exception... exceptions); | ||
|
|
||
| /** | ||
| * Sets the status of a system to FAIL | ||
| * | ||
| * @param key | ||
| * name of system | ||
| * @param exceptions | ||
| * exceptions caused by the system | ||
| */ | ||
| default void updateStatusFail(String key, Exception... exceptions) { | ||
| updateStatus(key, SystemStatus.FAIL, exceptions); | ||
| } | ||
|
|
||
| /** | ||
| * Sets the status of a system to PASS | ||
| * | ||
| * @param key | ||
| * name of system | ||
| */ | ||
| default void setStatusPass(String key) { | ||
| setStatus(key, SystemStatus.PASS); | ||
| } | ||
|
|
||
| /** | ||
| * Outputs the statuses of all systems of check | ||
| */ | ||
| public void outputStatuses(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.usfirst.frc4904.standard.commands.systemchecks; | ||
|
|
||
|
|
||
| import edu.wpi.first.wpilibj.command.Command; | ||
| import edu.wpi.first.wpilibj.command.CommandGroup; | ||
|
|
||
| /** | ||
| * Runs a series of robot system checks | ||
| */ | ||
| public class CheckGroup extends CommandGroup { | ||
| /** | ||
| * @param name | ||
| * name of commandgroup | ||
| * @param checks | ||
| * systemchecks to run | ||
| */ | ||
| public CheckGroup(String name, Check... checks) { | ||
| for (Check check : checks) { | ||
| if (check instanceof Command) { | ||
| if (check instanceof SubsystemCheck) { // TODO: Think of better logic for this | ||
| addSequential((SubsystemCheck) check); | ||
| } else { | ||
| addParallel((Command) check); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.