Skip to content
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

System checks #227

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
6e2ec77
init commit
NikhilSuresh24 Jan 21, 2019
c74bbb4
more changes
NikhilSuresh24 Jan 21, 2019
2104781
added framework for Subsystem checks
NikhilSuresh24 Jan 21, 2019
606649c
added solenoid check and lower level system check
NikhilSuresh24 Jan 22, 2019
8365f8c
added compressor check
NikhilSuresh24 Jan 22, 2019
301071c
finished position and velocity motor checks
NikhilSuresh24 Jan 25, 2019
4e2dce2
motor checks, check framework
NikhilSuresh24 Jan 27, 2019
ab81588
made some changes
NikhilSuresh24 Jan 31, 2019
8e50165
added PID Check
NikhilSuresh24 Jan 31, 2019
18f7388
TURN PID CHECK
NikhilSuresh24 Feb 1, 2019
83c8606
made position and velocity motor check commands way coooler
NikhilSuresh24 Feb 1, 2019
fbad037
formatting is very important
NikhilSuresh24 Feb 1, 2019
25f2092
made checkgroup less jank
NikhilSuresh24 Feb 1, 2019
3737490
Merge branch 'master' into system-checks
NikhilSuresh24 Feb 1, 2019
a680ebf
reverted motioncontroller change
NikhilSuresh24 Feb 1, 2019
608fd37
some more stuff
NikhilSuresh24 Feb 3, 2019
7d813c1
syntax
NikhilSuresh24 Feb 5, 2019
5e70af6
changes
NikhilSuresh24 Feb 6, 2019
50aaf1a
overall review, documentation, and cleanup
NikhilSuresh24 Feb 12, 2019
01614e3
more formatting and docs
NikhilSuresh24 Feb 12, 2019
f6712f4
more formatting and docs
NikhilSuresh24 Feb 12, 2019
0a6aae7
fixes docs
NikhilSuresh24 Feb 12, 2019
b285dc0
more docs, added voltage and current checks for motors
NikhilSuresh24 Feb 14, 2019
0bf6654
pr changes
NikhilSuresh24 Feb 14, 2019
cbbf856
Merge branch 'master' into system-checks
NikhilSuresh24 Feb 19, 2019
d291aab
Merge branch 'master' into system-checks
NikhilSuresh24 Mar 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions commands/systemchecks/BaseCheck.java
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);
}
}
}
}
}
60 changes: 60 additions & 0 deletions commands/systemchecks/BatteryCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 name
* name of check
* @param timeout
* duration of check
*/
public BatteryCheck(double timeout) {
super("RobotControllerCheck", timeout);
}

/**
* Systemcheck of battery status
*
* @param name
* name of check
* @param timeout
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
* 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"));
}
}
}
54 changes: 54 additions & 0 deletions commands/systemchecks/CANCheck.java
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"));
}
}
}
72 changes: 72 additions & 0 deletions commands/systemchecks/Check.java
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();
}
28 changes: 28 additions & 0 deletions commands/systemchecks/CheckGroup.java
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);
}
}
}
}
}
Loading