mirror of
https://github.com/TimeCrafters/CenterStage
synced 2025-12-15 08:42:35 +00:00
WIP: RevHubTestSuite: Refactored a bit, servo testing works
This commit is contained in:
@@ -12,6 +12,7 @@ import com.qualcomm.robotcore.hardware.HardwareMap;
|
||||
|
||||
import org.firstinspires.ftc.robotcore.external.navigation.AngleUnit;
|
||||
import org.timecrafters.Library.Robot;
|
||||
import org.timecrafters.diagnostics.rev_hub_test_suite.states.RevTestSuiteTestState;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -22,6 +23,8 @@ public class RevHubTestSuiteRobot extends Robot {
|
||||
|
||||
private HardwareMap hardwareMap;
|
||||
public boolean testingControlHub = true;
|
||||
public RevTestSuiteTestState.STAGE stage = RevTestSuiteTestState.STAGE.NONE;
|
||||
public final ArrayList<String> reports = new ArrayList<>();
|
||||
public ArrayList<MotorEx> controlHubMotors = new ArrayList<>(), expansionHubMotors = new ArrayList<>();
|
||||
public ArrayList<ServoEx> controlHubServos = new ArrayList<>(), expansionHubServos = new ArrayList<>();
|
||||
public ArrayList<AnalogInput> controlHubAnalogSensors = new ArrayList<>(), expansionHubAnalogSensors = new ArrayList<>();
|
||||
@@ -43,12 +46,12 @@ public class RevHubTestSuiteRobot extends Robot {
|
||||
controlHubMotors.add(new MotorEx(hardwareMap, "c_motor_3"));
|
||||
|
||||
// // SERVOS
|
||||
// controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_0", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
// controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_1", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
// controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_2", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
// controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_3", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
// controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_4", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
// controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_5", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_0", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_1", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_2", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_3", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_4", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
controlHubServos.add(new SimpleServo(hardwareMap, "c_servo_5", 0.0, 180.0, AngleUnit.DEGREES));
|
||||
//
|
||||
// // ANALOG SENSORS
|
||||
// controlHubAnalogSensors.add(hardwareMap.analogInput.get("c_analog_0"));
|
||||
|
||||
@@ -28,7 +28,7 @@ public class RevHubTestSuiteAnalogTestsState extends RevTestSuiteTestState {
|
||||
report("-"); // Add newline
|
||||
}
|
||||
|
||||
if (stage.ordinal() > STAGE.ANALOG_SENSOR.ordinal()) {
|
||||
if (robot.stage.ordinal() > STAGE.ANALOG_SENSOR.ordinal()) {
|
||||
testComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class RevHubTestSuiteDigitalTestsState extends RevTestSuiteTestState {
|
||||
report("-"); // Add newline
|
||||
}
|
||||
|
||||
if (stage.ordinal() > STAGE.DIGITAL_SENSOR.ordinal()) {
|
||||
if (robot.stage.ordinal() > STAGE.DIGITAL_SENSOR.ordinal()) {
|
||||
testComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class RevHubTestSuiteI2CTestsState extends RevTestSuiteTestState {
|
||||
report("-"); // Add newline
|
||||
}
|
||||
|
||||
if (stage.ordinal() > STAGE.I2C_SENSOR.ordinal()) {
|
||||
if (robot.stage.ordinal() > STAGE.I2C_SENSOR.ordinal()) {
|
||||
testComplete = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class RevHubTestSuiteMotorTestsState extends RevTestSuiteTestState {
|
||||
if (testComplete)
|
||||
return;
|
||||
|
||||
switch (stage) {
|
||||
switch (robot.stage) {
|
||||
case MOTOR_ENCODER_STEADY: {
|
||||
test_encoder_steady();
|
||||
break;
|
||||
@@ -70,7 +70,7 @@ public class RevHubTestSuiteMotorTestsState extends RevTestSuiteTestState {
|
||||
}
|
||||
}
|
||||
|
||||
if (stage.ordinal() > STAGE.MOTOR_BRAKING_MODE.ordinal()) {
|
||||
if (robot.stage.ordinal() > STAGE.MOTOR_BRAKING_MODE.ordinal()) {
|
||||
testComplete = true;
|
||||
}
|
||||
}
|
||||
@@ -242,7 +242,7 @@ public class RevHubTestSuiteMotorTestsState extends RevTestSuiteTestState {
|
||||
|
||||
@Override
|
||||
public void buttonUp(Gamepad gamepad, String button) {
|
||||
if (stage != STAGE.MOTOR_BRAKING_MODE) {
|
||||
if (robot.stage != STAGE.MOTOR_BRAKING_MODE) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -283,7 +283,7 @@ public class RevHubTestSuiteMotorTestsState extends RevTestSuiteTestState {
|
||||
engine.telemetry.addLine();
|
||||
}
|
||||
|
||||
if (stage == STAGE.MOTOR_BRAKING_MODE) {
|
||||
if (robot.stage == STAGE.MOTOR_BRAKING_MODE) {
|
||||
engine.telemetry.addLine("MANUAL TEST");
|
||||
engine.telemetry.addLine("PRESS `A` if Motor " + motor_index + " is BRAKING.");
|
||||
engine.telemetry.addLine();
|
||||
|
||||
@@ -29,7 +29,7 @@ public class RevHubTestSuiteServoTestsState extends RevTestSuiteTestState {
|
||||
|
||||
test_servos();
|
||||
|
||||
if (stage.ordinal() > STAGE.SERVO_SWEEP.ordinal()) {
|
||||
if (robot.stage.ordinal() > STAGE.SERVO_SWEEP.ordinal()) {
|
||||
testComplete = true;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public class RevHubTestSuiteServoTestsState extends RevTestSuiteTestState {
|
||||
}
|
||||
|
||||
public void buttonUp(Gamepad gamepad, String button) {
|
||||
if (stage != STAGE.SERVO_SWEEP) {
|
||||
if (robot.stage != STAGE.SERVO_SWEEP) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class RevHubTestSuiteServoTestsState extends RevTestSuiteTestState {
|
||||
engine.telemetry.addLine("SERVO CONTROLLER TESTING");
|
||||
engine.telemetry.addLine();
|
||||
|
||||
if (stage == STAGE.SERVO_SWEEP) {
|
||||
if (robot.stage == STAGE.SERVO_SWEEP) {
|
||||
engine.telemetry.addLine("MANUAL TEST");
|
||||
engine.telemetry.addLine("PRESS `A` if Servo " + servo_index + " is ROTATING.");
|
||||
engine.telemetry.addLine();
|
||||
|
||||
@@ -27,8 +27,6 @@ public class RevTestSuiteTestState extends CyberarmState {
|
||||
|
||||
final String TAG = "RevTestSuite|State";
|
||||
RevHubTestSuiteRobot robot;
|
||||
protected STAGE stage = STAGE.NONE;
|
||||
protected final ArrayList<String> reports = new ArrayList<>();
|
||||
protected boolean testComplete = false;
|
||||
public RevTestSuiteTestState(RevHubTestSuiteRobot robot) {
|
||||
super();
|
||||
@@ -40,36 +38,37 @@ public class RevTestSuiteTestState extends CyberarmState {
|
||||
public void exec() {
|
||||
if (testComplete && engine.gamepad1.guide) {
|
||||
setHasFinished(true);
|
||||
testComplete = false;
|
||||
}
|
||||
}
|
||||
|
||||
void report(String reason) {
|
||||
synchronized (reports) {
|
||||
reports.add(reason);
|
||||
synchronized (robot.reports) {
|
||||
robot.reports.add(reason);
|
||||
}
|
||||
}
|
||||
|
||||
public void nextStage() {
|
||||
if (stage == STAGE.COMPLETE)
|
||||
if (robot.stage == STAGE.COMPLETE)
|
||||
return;
|
||||
|
||||
stage = STAGE.values()[stage.ordinal() + 1];
|
||||
robot.stage = STAGE.values()[robot.stage.ordinal() + 1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void telemetry() {
|
||||
if (testComplete) {
|
||||
engine.telemetry.addLine("TESTING");
|
||||
} else {
|
||||
engine.telemetry.addLine("PRESS `GUIDE` TO CONTINUE");
|
||||
} else {
|
||||
engine.telemetry.addLine("TESTING");
|
||||
}
|
||||
engine.telemetry.addLine();
|
||||
engine.telemetry.addData("STAGE", stage);
|
||||
engine.telemetry.addData("STAGE", robot.stage);
|
||||
engine.telemetry.addLine();
|
||||
engine.telemetry.addLine("REPORTS");
|
||||
|
||||
synchronized (reports) {
|
||||
for (String report : reports) {
|
||||
synchronized (robot.reports) {
|
||||
for (String report : robot.reports) {
|
||||
engine.telemetry.addLine(report);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user