Skip to content

Commit

Permalink
Sync'd with latest changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
trc492 committed Sep 18, 2023
1 parent 0fa0477 commit 7e5370d
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 151 deletions.
2 changes: 1 addition & 1 deletion TeamCode/src/main/java/TrcCommonLib
2 changes: 1 addition & 1 deletion TeamCode/src/main/java/TrcFtcLib
2 changes: 1 addition & 1 deletion TeamCode/src/main/java/TrcFtcSamples
47 changes: 14 additions & 33 deletions TeamCode/src/main/java/teamcode/FtcTeleOp.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import TrcFtcLib.ftclib.FtcGamepad;
import TrcFtcLib.ftclib.FtcOpMode;
import teamcode.drivebases.SwerveDrive;
import teamcode.subsystems.BlinkinLEDs;

/**
* This class contains the TeleOp Mode program.
Expand Down Expand Up @@ -80,6 +79,7 @@ public void robotInit()
operatorGamepad = new FtcGamepad("OperatorGamepad", gamepad2, this::operatorButtonEvent);
driverGamepad.setYInverted(true);
operatorGamepad.setYInverted(true);
setDriveOrientation(TrcDriveBase.DriveOrientation.ROBOT);
} //robotInit

//
Expand Down Expand Up @@ -107,7 +107,6 @@ public void startMode(TrcRobot.RunMode prevMode, TrcRobot.RunMode nextMode)
// Tell robot object opmode is about to start so it can do the necessary start initialization for the mode.
//
robot.startMode(nextMode);
updateDriveModeLEDs();
} //startMode

/**
Expand Down Expand Up @@ -180,33 +179,22 @@ public void periodic(double elapsedTime, boolean slowPeriodicLoop)
} //periodic

/**
* This method updates the blinkin LEDs to show the drive orientation mode.
* This method sets the drive orientation mode and updates the LED to indicate so.
*
* @param orientation specifies the drive orientation (FIELD, ROBOT, INVERTED).
*/
private void updateDriveModeLEDs()
public void setDriveOrientation(TrcDriveBase.DriveOrientation orientation)
{
if (robot.blinkin != null && robot.robotDrive != null)
if (robot.robotDrive != null)
{
TrcDriveBase.DriveOrientation orientation = robot.robotDrive.driveBase.getDriveOrientation();

robot.blinkin.setPatternState(BlinkinLEDs.DRIVE_ORIENTATION_FIELD, false);
robot.blinkin.setPatternState(BlinkinLEDs.DRIVE_ORIENTATION_ROBOT, false);
robot.blinkin.setPatternState(BlinkinLEDs.DRIVE_ORIENTATION_INVERTED, false);
switch (orientation)
robot.robotDrive.driveBase.setDriveOrientation(
orientation, orientation == TrcDriveBase.DriveOrientation.FIELD);
if (robot.blinkin != null)
{
case FIELD:
robot.blinkin.setPatternState(BlinkinLEDs.DRIVE_ORIENTATION_FIELD, true);
break;

case ROBOT:
robot.blinkin.setPatternState(BlinkinLEDs.DRIVE_ORIENTATION_ROBOT, true);
break;

case INVERTED:
robot.blinkin.setPatternState(BlinkinLEDs.DRIVE_ORIENTATION_INVERTED, true);
break;
robot.blinkin.setDriveOrientation(orientation);
}
}
} //updateDriveModeLEDs
} //setDriveOrientation

//
// Implements TrcGameController.ButtonHandler interface.
Expand All @@ -222,10 +210,6 @@ private void updateDriveModeLEDs()
public void driverButtonEvent(TrcGameController gamepad, int button, boolean pressed)
{
robot.dashboard.displayPrintf(7, "%s: %04x->%s", gamepad, button, pressed? "Pressed": "Released");
if (robot.robotDrive != null)
{
robot.dashboard.displayPrintf(8, "Drive Mode:%s", robot.robotDrive.driveBase.getDriveOrientation());
}

switch (button)
{
Expand Down Expand Up @@ -256,17 +240,14 @@ public void driverButtonEvent(TrcGameController gamepad, int button, boolean pre
// Toggle between field or robot oriented driving, only applicable for holonomic drive base.
if (pressed && robot.robotDrive != null && robot.robotDrive.driveBase.supportsHolonomicDrive())
{
TrcDriveBase.DriveOrientation orientation = robot.robotDrive.driveBase.getDriveOrientation();
if (orientation != TrcDriveBase.DriveOrientation.FIELD)
if (robot.robotDrive.driveBase.getDriveOrientation() != TrcDriveBase.DriveOrientation.FIELD)
{
orientation = TrcDriveBase.DriveOrientation.FIELD;
setDriveOrientation(TrcDriveBase.DriveOrientation.FIELD);
}
else
{
orientation = TrcDriveBase.DriveOrientation.ROBOT;
setDriveOrientation(TrcDriveBase.DriveOrientation.ROBOT);
}
robot.robotDrive.driveBase.setDriveOrientation(orientation, true);
updateDriveModeLEDs();
}
break;

Expand Down
17 changes: 17 additions & 0 deletions TeamCode/src/main/java/teamcode/FtcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import TrcFtcLib.ftclib.FtcVisionTensorFlow;
import teamcode.drivebases.RobotDrive;
import teamcode.drivebases.SwerveDrive;
import teamcode.subsystems.BlinkinLEDs;

/**
* This class contains the Test Mode program. It extends FtcTeleOp so that we can teleop control the robot for
Expand Down Expand Up @@ -956,6 +957,10 @@ private void doVisionTest()
robot.vision.aprilTagVision.getBestDetectedTargetInfo(null);
robot.dashboard.displayPrintf(
lineNum++, "AprilTag: %s", aprilTagInfo != null? aprilTagInfo: "Not found.");
if (robot.blinkin != null)
{
robot.blinkin.setPatternState(BlinkinLEDs.APRIL_TAG, aprilTagInfo != null);
}
}

if (robot.vision.redBlobVision != null)
Expand All @@ -965,6 +970,10 @@ private void doVisionTest()
robot.vision.redBlobVision.getBestDetectedTargetInfo(null, null, 0.0, 0.0);
robot.dashboard.displayPrintf(
lineNum++, "RedBlob: %s", redBlobInfo != null? redBlobInfo: "Not found.");
if (robot.blinkin != null)
{
robot.blinkin.setPatternState(BlinkinLEDs.RED_BLOB, redBlobInfo != null);
}
}

if (robot.vision.blueBlobVision != null)
Expand All @@ -974,6 +983,10 @@ private void doVisionTest()
robot.vision.blueBlobVision.getBestDetectedTargetInfo(null, null, 0.0, 0.0);
robot.dashboard.displayPrintf(
lineNum++, "BlueBlob: %s", blueBlobInfo != null? blueBlobInfo: "Not found.");
if (robot.blinkin != null)
{
robot.blinkin.setPatternState(BlinkinLEDs.BLUE_BLOB, blueBlobInfo != null);
}
}

if (robot.vision.tensorFlowVision != null)
Expand All @@ -982,6 +995,10 @@ private void doVisionTest()
robot.vision.tensorFlowVision.getBestDetectedTargetInfo(null, null, null, 0.0, 0.0);
robot.dashboard.displayPrintf(
lineNum++, "TensorFlow: %s", tensorFlowInfo != null? tensorFlowInfo: "Not found.");
if (robot.blinkin != null)
{
robot.blinkin.setPatternState(BlinkinLEDs.TENSOR_FLOW, tensorFlowInfo != null);
}
}
}
} //doVisionTest
Expand Down
3 changes: 1 addition & 2 deletions TeamCode/src/main/java/teamcode/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import TrcFtcLib.ftclib.FtcDashboard;
import TrcFtcLib.ftclib.FtcMatchInfo;
import TrcFtcLib.ftclib.FtcOpMode;
import TrcFtcLib.ftclib.FtcRevBlinkin;
import TrcFtcLib.ftclib.FtcRobotBattery;
import teamcode.drivebases.MecanumDrive;
import teamcode.drivebases.RobotDrive;
Expand Down Expand Up @@ -59,7 +58,7 @@ public class Robot
//
// Sensors and indicators.
//
public FtcRevBlinkin blinkin;
public BlinkinLEDs blinkin;
public FtcRobotBattery battery;
//
// Subsystems.
Expand Down
54 changes: 43 additions & 11 deletions TeamCode/src/main/java/teamcode/subsystems/BlinkinLEDs.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package teamcode.subsystems;

import TrcCommonLib.trclib.TrcDriveBase;
import TrcCommonLib.trclib.TrcRevBlinkin;
import TrcFtcLib.ftclib.FtcRevBlinkin;

Expand All @@ -32,13 +33,14 @@
public class BlinkinLEDs extends FtcRevBlinkin
{
// LED pattern names.
public static final String IMAGE1_NAME = "Image1";
public static final String IMAGE2_NAME = "Image2";
public static final String IMAGE3_NAME = "Image3";
public static final String IMAGE4_NAME = "Image4";
public static final String APRIL_TAG = "AprilTag";
public static final String RED_BLOB = "RedBlob";
public static final String BLUE_BLOB = "BlueBlob";
public static final String TENSOR_FLOW = "TensorFlow";
public static final String DRIVE_ORIENTATION_FIELD = "FieldMode";
public static final String DRIVE_ORIENTATION_ROBOT = "RobotMode";
public static final String DRIVE_ORIENTATION_INVERTED = "InvertedMode";
public static final String OFF_PATTERN = "Off";

/**
* Constructor: Create an instance of the object.
Expand All @@ -51,16 +53,46 @@ public BlinkinLEDs(String instanceName)
// LED Patterns are sorted in decreasing priority order.
final TrcRevBlinkin.Pattern[] ledPatternPriorities = {
// Highest priority.
new TrcRevBlinkin.Pattern(IMAGE1_NAME, RevLedPattern.FixedLightChaseRed),
new TrcRevBlinkin.Pattern(IMAGE2_NAME, RevLedPattern.FixedLightChaseBlue),
new TrcRevBlinkin.Pattern(IMAGE3_NAME, RevLedPattern.FixedBreathRed),
new TrcRevBlinkin.Pattern(IMAGE4_NAME, RevLedPattern.FixedBreathBlue),
new TrcRevBlinkin.Pattern(DRIVE_ORIENTATION_FIELD, TrcRevBlinkin.RevLedPattern.SolidViolet),
new TrcRevBlinkin.Pattern(DRIVE_ORIENTATION_ROBOT, TrcRevBlinkin.RevLedPattern.SolidWhite),
new TrcRevBlinkin.Pattern(DRIVE_ORIENTATION_INVERTED, TrcRevBlinkin.RevLedPattern.SolidGray)
new TrcRevBlinkin.Pattern(APRIL_TAG, RevLedPattern.SolidAqua),
new TrcRevBlinkin.Pattern(RED_BLOB, RevLedPattern.SolidRed),
new TrcRevBlinkin.Pattern(BLUE_BLOB, RevLedPattern.SolidBlue),
new TrcRevBlinkin.Pattern(TENSOR_FLOW, RevLedPattern.SolidYellow),
new TrcRevBlinkin.Pattern(DRIVE_ORIENTATION_FIELD, RevLedPattern.SolidViolet),
new TrcRevBlinkin.Pattern(DRIVE_ORIENTATION_ROBOT, RevLedPattern.SolidWhite),
new TrcRevBlinkin.Pattern(DRIVE_ORIENTATION_INVERTED, RevLedPattern.SolidGray),
new TrcRevBlinkin.Pattern(OFF_PATTERN, RevLedPattern.SolidBlack)
// Lowest priority.
};
setPatternPriorities(ledPatternPriorities);
} //BlinkinLEDs

/**
* This method sets the LED to indicate the drive orientation mode of the robot.
*
* @param orientation specifies the drive orientation mode.
*/
public void setDriveOrientation(TrcDriveBase.DriveOrientation orientation)
{
switch (orientation)
{
case INVERTED:
setPatternState(DRIVE_ORIENTATION_INVERTED, true);
setPatternState(DRIVE_ORIENTATION_ROBOT, false);
setPatternState(DRIVE_ORIENTATION_FIELD, false);
break;

case ROBOT:
setPatternState(DRIVE_ORIENTATION_INVERTED, false);
setPatternState(DRIVE_ORIENTATION_ROBOT, true);
setPatternState(DRIVE_ORIENTATION_FIELD, false);
break;

case FIELD:
setPatternState(DRIVE_ORIENTATION_INVERTED, false);
setPatternState(DRIVE_ORIENTATION_ROBOT, false);
setPatternState(DRIVE_ORIENTATION_FIELD, true);
break;
}
} //setDriveOrientation

} //class BlinkinLEDs
Loading

0 comments on commit 7e5370d

Please sign in to comment.