Updated frclib.

Updated trclib.
Fixed Gamepad support to conform to library changes.
This commit is contained in:
Titan Robotics Club
2024-08-22 01:28:16 -07:00
parent 98b0eb8008
commit 61d381e329
5 changed files with 103 additions and 114 deletions

View File

@ -30,7 +30,6 @@ import ftclib.drivebase.FtcSwerveDrive;
import ftclib.driverio.FtcGamepad; import ftclib.driverio.FtcGamepad;
import ftclib.robotcore.FtcOpMode; import ftclib.robotcore.FtcOpMode;
import trclib.drivebase.TrcDriveBase; import trclib.drivebase.TrcDriveBase;
import trclib.driverio.TrcGameController;
import trclib.pathdrive.TrcPose2D; import trclib.pathdrive.TrcPose2D;
import trclib.robotcore.TrcDbgTrace; import trclib.robotcore.TrcDbgTrace;
import trclib.robotcore.TrcRobot; import trclib.robotcore.TrcRobot;
@ -84,10 +83,12 @@ public class FtcTeleOp extends FtcOpMode
// //
// Create and initialize Gamepads. // Create and initialize Gamepads.
// //
driverGamepad = new FtcGamepad("DriverGamepad", gamepad1, this::driverButtonEvent); driverGamepad = new FtcGamepad("DriverGamepad", gamepad1);
operatorGamepad = new FtcGamepad("OperatorGamepad", gamepad2, this::operatorButtonEvent); driverGamepad.setButtonEventHandler(this::driverButtonEvent);
driverGamepad.setYInverted(true); operatorGamepad = new FtcGamepad("OperatorGamepad", gamepad2);
operatorGamepad.setYInverted(true); operatorGamepad.setButtonEventHandler(this::operatorButtonEvent);
driverGamepad.setLeftStickInverted(false, true);
operatorGamepad.setRightStickInverted(false, true);
setDriveOrientation(robot.robotInfo.driveOrientation); setDriveOrientation(robot.robotInfo.driveOrientation);
} //robotInit } //robotInit
@ -237,17 +238,16 @@ public class FtcTeleOp extends FtcOpMode
/** /**
* This method is called when driver gamepad button event is detected. * This method is called when driver gamepad button event is detected.
* *
* @param gamepad specifies the game controller object that generated the event. * @param button specifies the button that generates the event.
* @param button specifies the button ID that generates the event.
* @param pressed specifies true if the button is pressed, false otherwise. * @param pressed specifies true if the button is pressed, false otherwise.
*/ */
public void driverButtonEvent(TrcGameController gamepad, int button, boolean pressed) public void driverButtonEvent(FtcGamepad.ButtonType button, boolean pressed)
{ {
robot.dashboard.displayPrintf(8, "%s: %04x->%s", gamepad, button, pressed? "Pressed": "Released"); robot.dashboard.displayPrintf(8, "Driver: %s=%s", button, pressed? "Pressed": "Released");
switch (button) switch (button)
{ {
case FtcGamepad.GAMEPAD_A: case A:
if (pressed) if (pressed)
{ {
robot.globalTracer.traceInfo(moduleName, ">>>>> CancelAll is pressed."); robot.globalTracer.traceInfo(moduleName, ">>>>> CancelAll is pressed.");
@ -259,13 +259,13 @@ public class FtcTeleOp extends FtcOpMode
} }
break; break;
case FtcGamepad.GAMEPAD_B: case B:
break; break;
case FtcGamepad.GAMEPAD_X: case X:
break; break;
case FtcGamepad.GAMEPAD_Y: case Y:
if (pressed && robot.robotDrive != null) if (pressed && robot.robotDrive != null)
{ {
if (robot.robotDrive.driveBase.isGyroAssistEnabled()) if (robot.robotDrive.driveBase.isGyroAssistEnabled())
@ -283,7 +283,7 @@ public class FtcTeleOp extends FtcOpMode
} }
break; break;
case FtcGamepad.GAMEPAD_LBUMPER: case LeftBumper:
// Toggle between field or robot oriented driving, only applicable for holonomic drive base. // Toggle between field or robot oriented driving, only applicable for holonomic drive base.
if (pressed && robot.robotDrive != null && robot.robotDrive.driveBase.supportsHolonomicDrive()) if (pressed && robot.robotDrive != null && robot.robotDrive.driveBase.supportsHolonomicDrive())
{ {
@ -300,7 +300,7 @@ public class FtcTeleOp extends FtcOpMode
} }
break; break;
case FtcGamepad.GAMEPAD_RBUMPER: case RightBumper:
// Press and hold for slow drive. // Press and hold for slow drive.
if (pressed) if (pressed)
{ {
@ -316,19 +316,13 @@ public class FtcTeleOp extends FtcOpMode
} }
break; break;
case FtcGamepad.GAMEPAD_DPAD_UP: case DpadUp:
case DpadDown:
case DpadLeft:
case DpadRight:
break; break;
case FtcGamepad.GAMEPAD_DPAD_DOWN: case Start:
break;
case FtcGamepad.GAMEPAD_DPAD_LEFT:
break;
case FtcGamepad.GAMEPAD_DPAD_RIGHT:
break;
case FtcGamepad.GAMEPAD_START:
if (robot.vision != null && robot.vision.aprilTagVision != null && robot.robotDrive != null) if (robot.vision != null && robot.vision.aprilTagVision != null && robot.robotDrive != null)
{ {
// On press of the button, we will start looking for AprilTag for re-localization. // On press of the button, we will start looking for AprilTag for re-localization.
@ -352,7 +346,7 @@ public class FtcTeleOp extends FtcOpMode
} }
break; break;
case FtcGamepad.GAMEPAD_BACK: case Back:
if (pressed && robot.robotDrive != null && robot.robotDrive instanceof FtcSwerveDrive) if (pressed && robot.robotDrive != null && robot.robotDrive instanceof FtcSwerveDrive)
{ {
// Drive base is a Swerve Drive, align all steering wheels forward. // Drive base is a Swerve Drive, align all steering wheels forward.
@ -366,49 +360,34 @@ public class FtcTeleOp extends FtcOpMode
/** /**
* This method is called when operator gamepad button event is detected. * This method is called when operator gamepad button event is detected.
* *
* @param gamepad specifies the game controller object that generated the event. * @param button specifies the button that generates the event.
* @param button specifies the button ID that generates the event.
* @param pressed specifies true if the button is pressed, false otherwise. * @param pressed specifies true if the button is pressed, false otherwise.
*/ */
public void operatorButtonEvent(TrcGameController gamepad, int button, boolean pressed) public void operatorButtonEvent(FtcGamepad.ButtonType button, boolean pressed)
{ {
robot.dashboard.displayPrintf(8, "%s: %04x->%s", gamepad, button, pressed? "Pressed": "Released"); robot.dashboard.displayPrintf(8, "Operator: %s=%s", button, pressed? "Pressed": "Released");
switch (button) switch (button)
{ {
case FtcGamepad.GAMEPAD_A: case A:
case B:
case X:
case Y:
case LeftBumper:
break; break;
case FtcGamepad.GAMEPAD_B: case RightBumper:
break;
case FtcGamepad.GAMEPAD_X:
break;
case FtcGamepad.GAMEPAD_Y:
break;
case FtcGamepad.GAMEPAD_LBUMPER:
break;
case FtcGamepad.GAMEPAD_RBUMPER:
robot.globalTracer.traceInfo(moduleName, ">>>>> OperatorAltFunc=" + pressed); robot.globalTracer.traceInfo(moduleName, ">>>>> OperatorAltFunc=" + pressed);
operatorAltFunc = pressed; operatorAltFunc = pressed;
break; break;
case FtcGamepad.GAMEPAD_DPAD_UP: case DpadUp:
case DpadDown:
case DpadLeft:
case DpadRight:
break; break;
case FtcGamepad.GAMEPAD_DPAD_DOWN: case Back:
break;
case FtcGamepad.GAMEPAD_DPAD_LEFT:
break;
case FtcGamepad.GAMEPAD_DPAD_RIGHT:
break;
case FtcGamepad.GAMEPAD_BACK:
if (pressed) if (pressed)
{ {
// Zero calibrate all subsystems (arm, elevator and turret). // Zero calibrate all subsystems (arm, elevator and turret).
@ -416,6 +395,9 @@ public class FtcTeleOp extends FtcOpMode
robot.zeroCalibrate(moduleName); robot.zeroCalibrate(moduleName);
} }
break; break;
case Start:
break;
} }
} //operatorButtonEvent } //operatorButtonEvent

View File

@ -42,7 +42,6 @@ import trclib.command.CmdDriveMotorsTest;
import trclib.command.CmdPidDrive; import trclib.command.CmdPidDrive;
import trclib.command.CmdTimedDrive; import trclib.command.CmdTimedDrive;
import trclib.dataprocessor.TrcUtil; import trclib.dataprocessor.TrcUtil;
import trclib.driverio.TrcGameController;
import trclib.pathdrive.TrcPose2D; import trclib.pathdrive.TrcPose2D;
import trclib.robotcore.TrcDbgTrace; import trclib.robotcore.TrcDbgTrace;
import trclib.robotcore.TrcPidController; import trclib.robotcore.TrcPidController;
@ -527,24 +526,23 @@ public class FtcTest extends FtcTeleOp
// //
/** /**
* This method is called when a driver gamepad button event occurs. * This method is called when driver gamepad button event is detected.
* *
* @param gamepad specifies the game controller object that generated the event. * @param button specifies the button that generates the event.
* @param button specifies the button ID that generates the event
* @param pressed specifies true if the button is pressed, false otherwise. * @param pressed specifies true if the button is pressed, false otherwise.
*/ */
@Override @Override
public void driverButtonEvent(TrcGameController gamepad, int button, boolean pressed) public void driverButtonEvent(FtcGamepad.ButtonType button, boolean pressed)
{ {
boolean passToTeleOp = true; boolean passToTeleOp = true;
// //
// In addition to or instead of the gamepad controls handled by FtcTeleOp, we can add to or override the // In addition to or instead of the gamepad controls handled by FtcTeleOp, we can add to or override the
// FtcTeleOp gamepad actions. // FtcTeleOp gamepad actions.
// //
robot.dashboard.displayPrintf(8, "%s: %04x->%s", gamepad, button, pressed ? "Pressed" : "Released"); robot.dashboard.displayPrintf(8, "Driver: %s=%s", button, pressed? "Pressed": "Released");
switch (button) switch (button)
{ {
case FtcGamepad.GAMEPAD_A: case A:
if (testChoices.test == Test.CALIBRATE_SWERVE_STEERING) if (testChoices.test == Test.CALIBRATE_SWERVE_STEERING)
{ {
if (pressed && robot.robotDrive != null && robot.robotDrive instanceof FtcSwerveDrive) if (pressed && robot.robotDrive != null && robot.robotDrive instanceof FtcSwerveDrive)
@ -578,7 +576,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_B: case B:
if (testChoices.test == Test.TUNE_COLORBLOB_VISION && if (testChoices.test == Test.TUNE_COLORBLOB_VISION &&
robot.vision != null && robot.vision.rawColorBlobVision != null) robot.vision != null && robot.vision.rawColorBlobVision != null)
{ {
@ -601,7 +599,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_X: case X:
if (testChoices.test == Test.TUNE_COLORBLOB_VISION && if (testChoices.test == Test.TUNE_COLORBLOB_VISION &&
robot.vision != null && robot.vision.rawColorBlobVision != null) robot.vision != null && robot.vision.rawColorBlobVision != null)
{ {
@ -618,7 +616,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_Y: case Y:
if (testChoices.test == Test.TUNE_COLORBLOB_VISION && if (testChoices.test == Test.TUNE_COLORBLOB_VISION &&
robot.vision != null && robot.vision.rawColorBlobVision != null) robot.vision != null && robot.vision.rawColorBlobVision != null)
{ {
@ -631,7 +629,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_LBUMPER: case LeftBumper:
if (testChoices.test == Test.VISION_TEST && robot.vision != null) if (testChoices.test == Test.VISION_TEST && robot.vision != null)
{ {
if (pressed) if (pressed)
@ -643,7 +641,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_RBUMPER: case RightBumper:
if (testChoices.test == Test.VISION_TEST && robot.vision != null) if (testChoices.test == Test.VISION_TEST && robot.vision != null)
{ {
if (pressed) if (pressed)
@ -655,7 +653,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_DPAD_UP: case DpadUp:
if (testChoices.test == Test.SUBSYSTEMS_TEST) if (testChoices.test == Test.SUBSYSTEMS_TEST)
{ {
// If we are moving swerve steering, make sure TeleOp doesn't interfere. // If we are moving swerve steering, make sure TeleOp doesn't interfere.
@ -682,7 +680,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_DPAD_DOWN: case DpadDown:
if (testChoices.test == Test.SUBSYSTEMS_TEST) if (testChoices.test == Test.SUBSYSTEMS_TEST)
{ {
// If we are moving swerve steering, make sure TeleOp doesn't interfere. // If we are moving swerve steering, make sure TeleOp doesn't interfere.
@ -709,7 +707,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_DPAD_LEFT: case DpadLeft:
if (testChoices.test == Test.SUBSYSTEMS_TEST) if (testChoices.test == Test.SUBSYSTEMS_TEST)
{ {
// If we are moving swerve steering, make sure TeleOp doesn't interfere. // If we are moving swerve steering, make sure TeleOp doesn't interfere.
@ -733,7 +731,7 @@ public class FtcTest extends FtcTeleOp
} }
break; break;
case FtcGamepad.GAMEPAD_DPAD_RIGHT: case DpadRight:
if (testChoices.test == Test.SUBSYSTEMS_TEST) if (testChoices.test == Test.SUBSYSTEMS_TEST)
{ {
// If we are moving swerve steering, make sure TeleOp doesn't interfere. // If we are moving swerve steering, make sure TeleOp doesn't interfere.
@ -756,42 +754,11 @@ public class FtcTest extends FtcTeleOp
passToTeleOp = false; passToTeleOp = false;
} }
break; break;
}
//
// If the control was not processed by this method, pass it back to TeleOp.
//
if (passToTeleOp)
{
super.driverButtonEvent(gamepad, button, pressed);
}
} //driverButtonEvent
/** case Back:
* This method is called when an operator gamepad button event occurs. break;
*
* @param gamepad specifies the game controller object that generated the event. case Start:
* @param button specifies the button ID that generates the event
* @param pressed specifies true if the button is pressed, false otherwise.
*/
@Override
public void operatorButtonEvent(TrcGameController gamepad, int button, boolean pressed)
{
boolean passToTeleOp = true;
//
// In addition to or instead of the gamepad controls handled by FtcTeleOp, we can add to or override the
// FtcTeleOp gamepad actions.
//
robot.dashboard.displayPrintf(8, "%s: %04x->%s", gamepad, button, pressed ? "Pressed" : "Released");
switch (button)
{
case FtcGamepad.GAMEPAD_A:
case FtcGamepad.GAMEPAD_B:
case FtcGamepad.GAMEPAD_X:
case FtcGamepad.GAMEPAD_Y:
case FtcGamepad.GAMEPAD_DPAD_UP:
case FtcGamepad.GAMEPAD_DPAD_DOWN:
case FtcGamepad.GAMEPAD_DPAD_LEFT:
case FtcGamepad.GAMEPAD_DPAD_RIGHT:
break; break;
} }
// //
@ -799,7 +766,47 @@ public class FtcTest extends FtcTeleOp
// //
if (passToTeleOp) if (passToTeleOp)
{ {
super.operatorButtonEvent(gamepad, button, pressed); super.driverButtonEvent(button, pressed);
}
} //driverButtonEvent
/**
* This method is called when operator gamepad button event is detected.
*
* @param button specifies the button that generates the event.
* @param pressed specifies true if the button is pressed, false otherwise.
*/
@Override
public void operatorButtonEvent(FtcGamepad.ButtonType button, boolean pressed)
{
boolean passToTeleOp = true;
//
// In addition to or instead of the gamepad controls handled by FtcTeleOp, we can add to or override the
// FtcTeleOp gamepad actions.
//
robot.dashboard.displayPrintf(8, "Operator: %s=%s", button, pressed? "Pressed": "Released");
switch (button)
{
case A:
case B:
case X:
case Y:
case LeftBumper:
case RightBumper:
case DpadUp:
case DpadDown:
case DpadLeft:
case DpadRight:
case Back:
case Start:
break;
}
//
// If the control was not processed by this method, pass it back to TeleOp.
//
if (passToTeleOp)
{
super.operatorButtonEvent(button, pressed);
} }
} //operatorButtonEvent } //operatorButtonEvent

View File

@ -30,10 +30,10 @@ import org.openftc.easyopencv.OpenCvCameraRotation;
import ftclib.drivebase.FtcRobotDrive; import ftclib.drivebase.FtcRobotDrive;
import ftclib.drivebase.FtcSwerveDrive; import ftclib.drivebase.FtcSwerveDrive;
import ftclib.driverio.FtcGamepad.DriveMode;
import ftclib.motor.FtcMotorActuator.MotorType; import ftclib.motor.FtcMotorActuator.MotorType;
import trclib.dataprocessor.TrcUtil; import trclib.dataprocessor.TrcUtil;
import trclib.drivebase.TrcDriveBase.DriveOrientation; import trclib.drivebase.TrcDriveBase.DriveOrientation;
import trclib.driverio.TrcGameController;
import trclib.pathdrive.TrcPose2D; import trclib.pathdrive.TrcPose2D;
import trclib.robotcore.TrcPidController.PidCoefficients; import trclib.robotcore.TrcPidController.PidCoefficients;
import trclib.vision.TrcHomographyMapper; import trclib.vision.TrcHomographyMapper;
@ -241,7 +241,7 @@ public class RobotParams
ppdFollowingDistance = 6.0; ppdFollowingDistance = 6.0;
velPidCoeffs = new PidCoefficients(0.0, 0.0, 0.0, 1.0 / profiledMaxVelocity, 0.0); velPidCoeffs = new PidCoefficients(0.0, 0.0, 0.0, 1.0 / profiledMaxVelocity, 0.0);
// Robot Drive // Robot Drive
driveMode = DriveMode.ARCADE_MODE; driveMode = TrcGameController.DriveMode.ArcadeMode;
driveOrientation = DriveOrientation.ROBOT; driveOrientation = DriveOrientation.ROBOT;
driveSlowScale = 0.3; driveSlowScale = 0.3;
driveNormalScale = 1.0; driveNormalScale = 1.0;
@ -336,7 +336,7 @@ public class RobotParams
ppdFollowingDistance = 6.0; ppdFollowingDistance = 6.0;
velPidCoeffs = new PidCoefficients(0.0, 0.0, 0.0, 1.0 / profiledMaxVelocity, 0.0); velPidCoeffs = new PidCoefficients(0.0, 0.0, 0.0, 1.0 / profiledMaxVelocity, 0.0);
// Robot Drive // Robot Drive
driveMode = DriveMode.ARCADE_MODE; driveMode = TrcGameController.DriveMode.ArcadeMode;
driveOrientation = DriveOrientation.ROBOT; driveOrientation = DriveOrientation.ROBOT;
driveSlowScale = 0.3; driveSlowScale = 0.3;
driveNormalScale = 1.0; driveNormalScale = 1.0;
@ -428,7 +428,7 @@ public class RobotParams
ppdFollowingDistance = 6.0; ppdFollowingDistance = 6.0;
velPidCoeffs = new PidCoefficients(0.0, 0.0, 0.0, 1.0 / profiledMaxVelocity, 0.0); velPidCoeffs = new PidCoefficients(0.0, 0.0, 0.0, 1.0 / profiledMaxVelocity, 0.0);
// Robot Drive // Robot Drive
driveMode = DriveMode.ARCADE_MODE; driveMode = TrcGameController.DriveMode.ArcadeMode;
driveOrientation = DriveOrientation.ROBOT; driveOrientation = DriveOrientation.ROBOT;
driveSlowScale = 0.3; driveSlowScale = 0.3;
driveNormalScale = 1.0; driveNormalScale = 1.0;