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 15 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
75 changes: 75 additions & 0 deletions commands/systemchecks/BasicCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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;

public abstract class BasicCheck extends Command implements Check {
protected HashMap<String, StatusMessage> statuses;
protected final String[] systemNames;
protected static final double DEFAULT_TIMEOUT = 5;

public BasicCheck(String checkName, double timeout, String... systemNames) {
super(checkName, timeout);
this.systemNames = systemNames;
initStatuses();
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
}

public BasicCheck(double timeout, String... systemNames) {
this("Check", timeout, systemNames);
}

public BasicCheck(String... systemNames) {
this(DEFAULT_TIMEOUT, systemNames);
}

@Override
public boolean isFinished() {
return isTimedOut();
}

@Override
public void end() {
outputStatuses();
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
}

public void setStatus(String name, SystemStatus status, Exception... exceptions) {
statuses.put(name, new StatusMessage(status, exceptions));
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
}

public void initStatus(String name) {
setStatus(name, SystemStatus.PASS, new Exception("NO ERROR"));
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
}

public void initStatuses() {
for (String name : systemNames) {
initStatus(name);
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
}
}

public void updateStatus(String key, StatusMessage.SystemStatus status, Exception... exceptions) {
setStatus(key, status, Stream.concat(Arrays.stream(getStatusMessage(key).exceptions), Arrays.stream(exceptions))
.toArray(Exception[]::new));
}

public StatusMessage getStatusMessage(String key) {
return statuses.get(key);
}

public void outputStatuses() {
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
LogKitten.wtf(getName() + " Statuses:");
for (Map.Entry<String, StatusMessage> entry : statuses.entrySet()) {
String name = entry.getKey();
StatusMessage message = entry.getValue();
// TODO: Change Logkitten level if FAIL vs PASS
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
LogKitten.wtf("Subsystem: " + name + ", Status: "
+ (message.status == StatusMessage.SystemStatus.PASS ? "PASS" : "FAIL") + ", ERROR: " + message.exceptions);
// TODO:check if the logging of exceptions above works
}
}
}
26 changes: 26 additions & 0 deletions commands/systemchecks/Check.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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
public void setStatus(String key, StatusMessage.SystemStatus status, Exception... exceptions);

default void initStatus(String name) {
setStatus(name, SystemStatus.PASS, new Exception("NO ERROR"));
}

public void initStatuses();

public void updateStatus(String key, StatusMessage.SystemStatus status, Exception... exceptions);

default void setStatusFail(String key, Exception... exceptions) {
updateStatus(key, SystemStatus.FAIL, exceptions);
}

default void setStatusPass(String key, Exception... exceptions) {
updateStatus(key, SystemStatus.PASS, exceptions);
}

public void outputStatuses();
}
17 changes: 17 additions & 0 deletions commands/systemchecks/CheckGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


import edu.wpi.first.wpilibj.command.CommandGroup;

public class CheckGroup extends CommandGroup {
public CheckGroup(String name, BasicCheck... checks) {
for (BasicCheck check : checks) {
if (check instanceof SubsystemCheck) { //TODO: Think of better logic for this
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
addSequential(check);
}
else {
addParallel(check);
}
}
}
}
41 changes: 41 additions & 0 deletions commands/systemchecks/CompressorCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


import org.usfirst.frc4904.standard.commands.systemchecks.StatusMessage.SystemStatus;
import edu.wpi.first.wpilibj.Compressor;

public class CompressorCheck extends SystemCheck {
protected final Compressor[] compressors;

public CompressorCheck(String name, double timeout, Compressor... compressors) {
super("CompressorCheck", timeout, compressors);
this.compressors = compressors;
}

public CompressorCheck(String name, Compressor... compressors) {
this(name, DEFAULT_TIMEOUT, compressors);
}

public CompressorCheck(double timeout, Compressor... compressors) {
this("CompressorCheck", timeout, compressors);
}

public CompressorCheck(Compressor... compressors) {
this("CompressorCheck", compressors);
}

public void execute() {
for (Compressor compressor : compressors) {
if (compressor.getCompressorNotConnectedFault() || compressor.getCompressorNotConnectedStickyFault()
|| !compressor.enabled()) {
updateStatus(compressor.getName(), SystemStatus.FAIL, new Exception("COMPRESSOR NOT CONNECTED"));
} else if (compressor.getCompressorShortedFault() || compressor.getCompressorShortedStickyFault()) {
updateStatus(compressor.getName(), SystemStatus.FAIL, new Exception("COMPRESSOR SHORTED"));
} else if (compressor.getCompressorCurrentTooHighFault() || compressor.getCompressorCurrentTooHighStickyFault()) {
updateStatus(compressor.getName(), SystemStatus.FAIL, new Exception("CURRENT TOO HIGH"));
} else if (compressor.getPressureSwitchValue()) { // TODO: Check if this works as intended
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
updateStatus(compressor.getName(), SystemStatus.FAIL, new Exception("LOW PRESSURE"));
}
}
}
}
65 changes: 65 additions & 0 deletions commands/systemchecks/DrivePIDCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


import java.util.Arrays;
import java.util.HashMap;
import java.util.stream.Stream;
import org.usfirst.frc4904.standard.LogKitten;
import org.usfirst.frc4904.standard.commands.chassis.ChassisMoveDistance;
import org.usfirst.frc4904.standard.commands.systemchecks.StatusMessage.SystemStatus;
import org.usfirst.frc4904.standard.custom.motioncontrollers.MotionController;
import org.usfirst.frc4904.standard.custom.sensors.InvalidSensorException;
import org.usfirst.frc4904.standard.subsystems.chassis.Chassis;

public class DrivePIDCheck extends ChassisMoveDistance implements Check {
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
protected HashMap<String, StatusMessage> statuses;
protected static final String CHECK_NAME = "DrivePIDCheck";
protected final double distance;
protected static final double ERROR_THRESHOLD = 2.0; // TODO: CHANGE THIS
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
protected double position;

public DrivePIDCheck(Chassis chassis, double distance, MotionController motionController) {
super(chassis, distance, motionController);
this.distance = distance;
initStatuses();
}

public void end() {
try {
position = motionController.getInputSafely();
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
}
catch (InvalidSensorException e) {
position = 0;
updateStatus(CHECK_NAME, SystemStatus.FAIL, e);
}
if (Math.abs(motionController.getSetpoint() - position) > ERROR_THRESHOLD) {
updateStatus(CHECK_NAME, SystemStatus.FAIL, new Exception("DISTANCE DRIVEN NOT WITHIN ERROR THRESHOLD"));
}
chassisMove.cancel();
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
motionController.disable();
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
motionController.reset();
runOnce = false;
}

public void initStatuses() {
initStatus(CHECK_NAME);
}

public void setStatus(String name, SystemStatus status, Exception... exceptions) {
statuses.put(name, new StatusMessage(status, exceptions));
}

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));
}

public StatusMessage getStatusMessage(String key) {
return statuses.get(key);
}

public void outputStatuses() {
LogKitten.wtf(CHECK_NAME + ": " + getStatusMessage(CHECK_NAME).exceptions); // TODO: change logkitten level
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
}
}
49 changes: 49 additions & 0 deletions commands/systemchecks/NetworkTablesCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


import org.usfirst.frc4904.standard.commands.systemchecks.StatusMessage.SystemStatus;
import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.networktables.PersistentException;
import edu.wpi.first.networktables.NetworkTableEntry;

public class NetworkTablesCheck extends BasicCheck {
protected static final String SAVE_PATH = "/home/lvuser/logs/networktables";
protected static final String SAVE_FILE = SAVE_PATH + "testTable.log";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a very pythonic way of making a file path. when aj wrote monkeysee, which saved stuff to /home/lvuser/logs, and stored the path and file name in one string

protected static final String CHECK_NAME = "NetworkTables";
protected static final double DEFAULT_ENTRY = 4.904;
protected static NetworkTableInstance inst;
protected static NetworkTable table;
protected static NetworkTableEntry entry;
protected static String[] entries;

public NetworkTablesCheck(double timeout) {
super("NetworkTableCheck", timeout, CHECK_NAME);
}

public NetworkTablesCheck() {
this(DEFAULT_TIMEOUT);
}

public void initialize() {
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
inst = NetworkTableInstance.getDefault();
table = inst.getTable("table");
entry = table.getEntry("entry");
entry.setDefaultDouble(DEFAULT_ENTRY);
try {
table.saveEntries(SAVE_FILE);
entries = table.loadEntries(SAVE_FILE);
}
catch (PersistentException e) {
updateStatus(CHECK_NAME, SystemStatus.FAIL, e);
}
if (entries[0] != Double.toString(DEFAULT_ENTRY)) { // TODO: Check formatting of the entries array
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
updateStatus(CHECK_NAME, SystemStatus.FAIL, new Exception("LOADED ARRAY NOT EQUAL TO SAVED ARRAY"));
}
}

@Override
public boolean isFinished() {
return true;
}
}
29 changes: 29 additions & 0 deletions commands/systemchecks/SolenoidCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


import org.usfirst.frc4904.standard.commands.systemchecks.StatusMessage.SystemStatus;
import edu.wpi.first.wpilibj.DoubleSolenoid;

public class SolenoidCheck extends SystemCheck {
protected final DoubleSolenoid[] solenoids;

public SolenoidCheck(String name, DoubleSolenoid... solenoids) {
super(name, solenoids);
this.solenoids = solenoids;
}

public SolenoidCheck(DoubleSolenoid... solenoids) {
this("SolenoidCheck", solenoids);
}

public void initialize() {
for (DoubleSolenoid solenoid : solenoids) {
try {
solenoid.set(DoubleSolenoid.Value.kForward);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe repeat this to set it reverse as well?

Also, it's important to notice that because this actively fires pistons, we might want to bind each check to a different button

}
catch (Exception e) {
updateStatus(solenoid.getName(), SystemStatus.FAIL, e);
}
}
}
}
16 changes: 16 additions & 0 deletions commands/systemchecks/StatusMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


public class StatusMessage {
protected SystemStatus status;
protected Exception[] exceptions;

public StatusMessage(SystemStatus status, Exception... exceptions) {
this.status = status;
this.exceptions = exceptions;
}

public enum SystemStatus {
PASS, FAIL;
}
}
25 changes: 25 additions & 0 deletions commands/systemchecks/SubsystemCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


import edu.wpi.first.wpilibj.command.Subsystem;

public abstract class SubsystemCheck extends SystemCheck {
public SubsystemCheck(String name, double timeout, Subsystem... subsystems) {
super(name, timeout, subsystems);
for (Subsystem system : subsystems) {
requires(system);
}
}

public SubsystemCheck(String name, Subsystem... systems) {
this(name, DEFAULT_TIMEOUT, systems);
}

public SubsystemCheck(double timeout, Subsystem... systems) {
this("SubsystemCheck", timeout, systems);
}

public SubsystemCheck(Subsystem... systems) {
this("SubsystemCheck", systems);
}
}
30 changes: 30 additions & 0 deletions commands/systemchecks/SystemCheck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.usfirst.frc4904.standard.commands.systemchecks;


import java.util.Arrays;
import java.util.HashMap;
import java.util.stream.Collectors;
import edu.wpi.first.wpilibj.SendableBase;

public abstract class SystemCheck extends BasicCheck {
protected HashMap<String, StatusMessage> statuses;
protected SendableBase[] systems;

public SystemCheck(String name, double timeout, SendableBase... systems) {
super(name, timeout, Arrays.asList(systems).stream().map(system -> system.getName()).collect(Collectors.toList())
NikhilSuresh24 marked this conversation as resolved.
Show resolved Hide resolved
.toArray(String[]::new));
this.systems = systems;
}

public SystemCheck(double timeout, SendableBase... systems) {
this("SystemCheck", timeout, systems);
}

public SystemCheck(String name, SendableBase... systems) {
this(name, DEFAULT_TIMEOUT, systems);
}

public SystemCheck(SendableBase... systems) {
this("SystemCheck", systems);
}
}
Loading