-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
All/#305 self test framework
- Loading branch information
Showing
14 changed files
with
759 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
83 changes: 83 additions & 0 deletions
83
src/main/java/org/frc5687/powerup/robot/commands/testing/ArmMotorTest.java
This file contains 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,83 @@ | ||
package org.frc5687.powerup.robot.commands.testing; | ||
|
||
import edu.wpi.first.wpilibj.command.Command; | ||
import org.frc5687.powerup.robot.Constants; | ||
import org.frc5687.powerup.robot.RobotMap; | ||
import org.frc5687.powerup.robot.subsystems.Arm; | ||
import org.frc5687.powerup.robot.subsystems.Carriage; | ||
import org.frc5687.powerup.robot.utils.PDP; | ||
import org.frc5687.powerup.robot.commands.MoveCarriageToSetpointPID; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
|
||
import static java.lang.Math.abs; | ||
|
||
|
||
public class ArmMotorTest extends Command { | ||
private Arm arm; | ||
private Carriage carriage; | ||
private PDP pdp; | ||
private long upMillis; | ||
private long downMillis; | ||
private long stopMillis; | ||
private boolean finished; | ||
private double amps; | ||
private double bottomAngle; | ||
private double topAngle; | ||
private double startAngle; | ||
|
||
public ArmMotorTest(Arm arm, Carriage carriage){ | ||
requires(arm); | ||
requires(carriage); | ||
|
||
this.arm = arm; | ||
this.carriage = carriage; | ||
} | ||
|
||
@Override | ||
protected void initialize() { | ||
finished = false; | ||
upMillis = System.currentTimeMillis() + 125; | ||
stopMillis = System.currentTimeMillis() + 250; | ||
downMillis = System.currentTimeMillis() + 375; | ||
amps = 0; | ||
topAngle = 0; | ||
startAngle = arm.getAngle(); | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
if (System.currentTimeMillis()< upMillis){ | ||
arm.drive(0.75); | ||
amps = Math.max(amps, pdp.getCurrent(RobotMap.PDP.ARM_SP)); | ||
topAngle = Math.max(topAngle, arm.getAngle()); | ||
|
||
} | ||
else if (System.currentTimeMillis()< stopMillis){ | ||
arm.drive(0); | ||
bottomAngle = topAngle; | ||
} | ||
else { | ||
arm.drive(-0.75); | ||
amps = Math.max(amps, pdp.getCurrent(RobotMap.PDP.ARM_SP)); | ||
bottomAngle = Math.min(bottomAngle, arm.getAngle()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void end() { | ||
if (amps < Constants.Arm.MIN_AMPS) { | ||
DriverStation.reportError(amps + " amps drawn", false); | ||
} | ||
if (abs(startAngle - topAngle) < 20) { | ||
DriverStation.reportError("angle change " + (startAngle - topAngle), false); | ||
} | ||
if (abs(topAngle - bottomAngle) > 20) { | ||
DriverStation.reportError("angle change " + (bottomAngle - topAngle), false); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isFinished() { | ||
return System.currentTimeMillis() > downMillis; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/org/frc5687/powerup/robot/commands/testing/ConfirmTest.java
This file contains 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,61 @@ | ||
package org.frc5687.powerup.robot.commands.testing; | ||
|
||
import edu.wpi.first.wpilibj.DriverStation; | ||
import edu.wpi.first.wpilibj.command.Command; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
import org.frc5687.powerup.robot.OI; | ||
/** | ||
* Command to prompt the operator to confirm a result using the gamepad buttons. | ||
*/ | ||
public class ConfirmTest extends Command { | ||
|
||
private String _message; | ||
private String _success; | ||
private String _failure; | ||
private boolean _clear; | ||
private String _key; | ||
private OI _oi; | ||
|
||
public ConfirmTest(OI oi, String message, String success, String failure) { | ||
_oi = oi; | ||
_message = message; | ||
_success = success; | ||
_failure = failure; | ||
_clear = false; | ||
} | ||
|
||
public ConfirmTest(OI oi, String message, String key) { | ||
_oi = oi; | ||
_message = message; | ||
_key = key; | ||
_clear = false; | ||
} | ||
|
||
@Override | ||
protected void initialize() { | ||
DriverStation.reportError(_message, false); | ||
SmartDashboard.putString("SelfTest/Message", _message); | ||
} | ||
|
||
@Override | ||
protected void execute() { | ||
if (!_clear) { | ||
_clear = !_oi.isStartPressed(); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean isFinished() { | ||
if (_clear) { | ||
if (_oi.isStartPressed()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void end() { | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/org/frc5687/powerup/robot/commands/testing/FullSelfTest.java
This file contains 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,30 @@ | ||
package org.frc5687.powerup.robot.commands.testing; | ||
|
||
import edu.wpi.first.wpilibj.command.CommandGroup; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
|
||
import org.frc5687.powerup.robot.Robot; | ||
import org.frc5687.powerup.robot.subsystems.Intake; | ||
|
||
|
||
public class FullSelfTest extends CommandGroup { | ||
|
||
public FullSelfTest(Robot robot) { | ||
|
||
|
||
addSequential(new ConfirmTest(robot.getOI(), "Please ensure the robot is drydocked and press Start to continue.", "Test started.", "Test aborted.")); | ||
addSequential(new TestDriveTrain(robot.getDriveTrain(), robot.getPDP(), robot.getLights())); | ||
|
||
addSequential(new ConfirmTest(robot.getOI(), "Please be sure that the carriage is clear and press Start to continue.", "Test started.", "Test aborted.")); | ||
addSequential(new TestCarriage(robot.getCarriage(), robot.getPDP(), robot.getLights())); | ||
|
||
addSequential(new ConfirmTest(robot.getOI(), "Please be sure that the arm is clear and press Start to continue.", "Test started.", "Test aborted.")); | ||
|
||
addSequential(new ConfirmTest(robot.getOI(), "Please be sure that the intake is clear and press Start to continue.", "Test started.", "Test aborted.")); | ||
addSequential(new TestIntake(robot.getIntake(), robot.getPDP(), robot.getLights())); | ||
|
||
addSequential(new ConfirmTest(robot.getOI(), "Tests complete.", "Test started.", "Test aborted.")); | ||
|
||
|
||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/org/frc5687/powerup/robot/commands/testing/SelfTestBootstrapper.java
This file contains 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,35 @@ | ||
package org.frc5687.powerup.robot.commands.testing; | ||
|
||
import edu.wpi.first.wpilibj.command.Command; | ||
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard; | ||
import edu.wpi.first.wpilibj.command.Scheduler; | ||
import edu.wpi.first.wpilibj.command.Scheduler; | ||
import edu.wpi.first.wpilibj.DriverStation; | ||
|
||
import org.frc5687.powerup.robot.OI; | ||
import org.frc5687.powerup.robot.Robot; | ||
import org.frc5687.powerup.robot.subsystems.Intake; | ||
|
||
public class SelfTestBootstrapper extends Command { | ||
private Robot _robot; | ||
private boolean done = false; | ||
|
||
public SelfTestBootstrapper(Robot robot) { | ||
_robot = robot; | ||
} | ||
|
||
@Override | ||
protected void execute(){ | ||
|
||
if(!done && !DriverStation.getInstance().isFMSAttached()){ | ||
Scheduler.getInstance().add(new FullSelfTest(_robot)); | ||
done = true; | ||
} | ||
|
||
} | ||
|
||
@Override | ||
protected boolean isFinished() { | ||
return done; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/frc5687/powerup/robot/commands/testing/TestArm.java
This file contains 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,21 @@ | ||
package org.frc5687.powerup.robot.commands.testing; | ||
|
||
import edu.wpi.first.wpilibj.command.Command; | ||
import edu.wpi.first.wpilibj.command.CommandGroup; | ||
import org.frc5687.powerup.robot.Constants; | ||
import org.frc5687.powerup.robot.Robot; | ||
import org.frc5687.powerup.robot.subsystems.Arm; | ||
import org.frc5687.powerup.robot.subsystems.Carriage; | ||
import org.frc5687.powerup.robot.commands.testing.ArmMotorTest; | ||
import org.frc5687.powerup.robot.commands.MoveArmToSetpointPID; | ||
|
||
public class TestArm extends CommandGroup{ | ||
public TestArm(Robot robot){ | ||
addSequential(new ArmMotorTest(robot.getArm(), robot.getCarriage())); | ||
addSequential(new MoveArmToSetpointPID(robot.getArm(), Constants.Arm.Encoder.ENCODER_START)); | ||
addSequential(new MoveArmToSetpointPID(robot.getArm(), Constants.Arm.Encoder.ENCODER_TOP)); | ||
|
||
} | ||
|
||
|
||
} |
Oops, something went wrong.