mirror of
https://github.com/trc492/FtcTemplate.git
synced 2025-07-01 13:01:24 -07:00
Code reviewed everything and cleaned up.
This commit is contained in:
@ -67,14 +67,9 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
@Override
|
@Override
|
||||||
public void robotInit()
|
public void robotInit()
|
||||||
{
|
{
|
||||||
//
|
|
||||||
// Create and initialize robot object.
|
// Create and initialize robot object.
|
||||||
//
|
|
||||||
robot = new Robot(TrcRobot.getRunMode());
|
robot = new Robot(TrcRobot.getRunMode());
|
||||||
|
|
||||||
//
|
|
||||||
// Open trace log.
|
// Open trace log.
|
||||||
//
|
|
||||||
if (RobotParams.Preferences.useTraceLog)
|
if (RobotParams.Preferences.useTraceLog)
|
||||||
{
|
{
|
||||||
String filePrefix = Robot.matchInfo != null?
|
String filePrefix = Robot.matchInfo != null?
|
||||||
@ -82,9 +77,7 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
"Unknown_TeleOp";
|
"Unknown_TeleOp";
|
||||||
TrcDbgTrace.openTraceLog(RobotParams.Robot.LOG_FOLDER_PATH, filePrefix);
|
TrcDbgTrace.openTraceLog(RobotParams.Robot.LOG_FOLDER_PATH, filePrefix);
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// Create and initialize Gamepads.
|
// Create and initialize Gamepads.
|
||||||
//
|
|
||||||
driverGamepad = new FtcGamepad("DriverGamepad", gamepad1);
|
driverGamepad = new FtcGamepad("DriverGamepad", gamepad1);
|
||||||
driverGamepad.setButtonEventHandler(this::driverButtonEvent);
|
driverGamepad.setButtonEventHandler(this::driverButtonEvent);
|
||||||
driverGamepad.setLeftStickInverted(false, true);
|
driverGamepad.setLeftStickInverted(false, true);
|
||||||
@ -258,7 +251,7 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
*
|
*
|
||||||
* @param orientation specifies the drive orientation (FIELD, ROBOT, INVERTED).
|
* @param orientation specifies the drive orientation (FIELD, ROBOT, INVERTED).
|
||||||
*/
|
*/
|
||||||
public void setDriveOrientation(TrcDriveBase.DriveOrientation orientation)
|
private void setDriveOrientation(TrcDriveBase.DriveOrientation orientation)
|
||||||
{
|
{
|
||||||
if (robot.robotDrive != null)
|
if (robot.robotDrive != null)
|
||||||
{
|
{
|
||||||
@ -322,23 +315,17 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case B:
|
case B:
|
||||||
|
break;
|
||||||
|
|
||||||
case X:
|
case X:
|
||||||
|
if (pressed)
|
||||||
|
{
|
||||||
|
robot.globalTracer.traceInfo(moduleName, ">>>>> Turtle mode.");
|
||||||
|
robot.turtle();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Y:
|
case Y:
|
||||||
if (pressed)
|
|
||||||
{
|
|
||||||
if (driverAltFunc)
|
|
||||||
{
|
|
||||||
robot.globalTracer.traceInfo(moduleName, ">>>>> Cancel all.");
|
|
||||||
robot.cancelAll();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
robot.globalTracer.traceInfo(moduleName, ">>>>> Turtle mode.");
|
|
||||||
robot.turtle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LeftBumper:
|
case LeftBumper:
|
||||||
@ -347,15 +334,7 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RightBumper:
|
case RightBumper:
|
||||||
if (driverAltFunc)
|
if (!driverAltFunc)
|
||||||
{
|
|
||||||
if (!RobotParams.Preferences.updateDashboard)
|
|
||||||
{
|
|
||||||
// Toggle status update ON/OFF.
|
|
||||||
statusUpdateOn = !statusUpdateOn;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
// Press and hold for slow drive.
|
// Press and hold for slow drive.
|
||||||
if (pressed)
|
if (pressed)
|
||||||
@ -371,6 +350,14 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
turnPowerScale = RobotParams.Robot.TURN_NORMAL_SCALE;
|
turnPowerScale = RobotParams.Robot.TURN_NORMAL_SCALE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (pressed)
|
||||||
|
{
|
||||||
|
if (!RobotParams.Preferences.updateDashboard)
|
||||||
|
{
|
||||||
|
// Toggle status update ON/OFF.
|
||||||
|
statusUpdateOn = !statusUpdateOn;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DpadUp:
|
case DpadUp:
|
||||||
@ -382,29 +369,40 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
case Back:
|
case Back:
|
||||||
if (pressed)
|
if (pressed)
|
||||||
{
|
{
|
||||||
robot.globalTracer.traceInfo(moduleName, ">>>>> ZeroCalibrating.");
|
if (!driverAltFunc)
|
||||||
robot.cancelAll();
|
|
||||||
robot.zeroCalibrate(moduleName, null);
|
|
||||||
if (robot.robotDrive != null && robot.robotDrive instanceof FtcSwerveDrive)
|
|
||||||
{
|
{
|
||||||
// Drive base is a Swerve Drive, align all steering wheels forward.
|
// Cancel all operations and zero calibrate all subsystems (arm, elevator and turret).
|
||||||
robot.globalTracer.traceInfo(moduleName, ">>>>> Set SteerAngle to zero.");
|
robot.globalTracer.traceInfo(moduleName, ">>>>> ZeroCalibrating.");
|
||||||
((FtcSwerveDrive) robot.robotDrive).setSteerAngle(0.0, false, false);
|
robot.cancelAll();
|
||||||
|
robot.zeroCalibrate(moduleName, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If drive base is SwerveDrive, set all wheels pointing forward.
|
||||||
|
if (robot.robotDrive != null && robot.robotDrive instanceof FtcSwerveDrive)
|
||||||
|
{
|
||||||
|
// Drive base is a Swerve Drive, align all steering wheels forward.
|
||||||
|
robot.globalTracer.traceInfo(moduleName, ">>>>> Set SteerAngle to zero.");
|
||||||
|
((FtcSwerveDrive) robot.robotDrive).setSteerAngle(0.0, false, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Start:
|
case Start:
|
||||||
|
// Do AprilTag Vision re-localization.
|
||||||
if (robot.vision != null && robot.robotDrive != null)
|
if (robot.vision != null && robot.robotDrive != null)
|
||||||
{
|
{
|
||||||
boolean hasAprilTagVision = robot.vision.isAprilTagVisionEnabled();
|
boolean hasAprilTagVision = robot.vision.isAprilTagVisionEnabled();
|
||||||
|
// If Webcam AprilTag vision is not enabled, check if we have Limelight since Limelight has
|
||||||
|
// AprilTag pipeline as well.
|
||||||
if (!hasAprilTagVision && robot.vision.limelightVision != null)
|
if (!hasAprilTagVision && robot.vision.limelightVision != null)
|
||||||
{
|
{
|
||||||
hasAprilTagVision = true;
|
hasAprilTagVision = true;
|
||||||
if (pressed)
|
if (pressed)
|
||||||
{
|
{
|
||||||
// Webcam AprilTag vision is not enable, enable Limelight AprilTag pipeline instead.
|
// Webcam AprilTag vision is not enable, enable Limelight AprilTag pipeline instead.
|
||||||
|
// Note: we assume pipeline 0 is the AprilTag pipeline.
|
||||||
savedLimelightPipeline = robot.vision.limelightVision.getPipeline();
|
savedLimelightPipeline = robot.vision.limelightVision.getPipeline();
|
||||||
robot.vision.setLimelightVisionEnabled(0, true);
|
robot.vision.setLimelightVisionEnabled(0, true);
|
||||||
}
|
}
|
||||||
@ -475,7 +473,7 @@ public class FtcTeleOp extends FtcOpMode
|
|||||||
case Back:
|
case Back:
|
||||||
if (pressed)
|
if (pressed)
|
||||||
{
|
{
|
||||||
// Zero calibrate all subsystems (arm, elevator and turret).
|
// Cancel all operations and zero calibrate all subsystems (arm, elevator and turret).
|
||||||
robot.globalTracer.traceInfo(moduleName, ">>>>> ZeroCalibrating.");
|
robot.globalTracer.traceInfo(moduleName, ">>>>> ZeroCalibrating.");
|
||||||
robot.cancelAll();
|
robot.cancelAll();
|
||||||
robot.zeroCalibrate(moduleName, null);
|
robot.zeroCalibrate(moduleName, null);
|
||||||
|
@ -265,11 +265,6 @@ public class FtcTest extends FtcTeleOp
|
|||||||
testCommand.cancel();
|
testCommand.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (robot.robotDrive != null)
|
|
||||||
{
|
|
||||||
robot.robotDrive.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
super.stopMode(prevMode, nextMode);
|
super.stopMode(prevMode, nextMode);
|
||||||
} //stopMode
|
} //stopMode
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ import trclib.robotcore.TrcEvent;
|
|||||||
import trclib.robotcore.TrcRobot;
|
import trclib.robotcore.TrcRobot;
|
||||||
import trclib.sensor.TrcDigitalInput;
|
import trclib.sensor.TrcDigitalInput;
|
||||||
import trclib.subsystem.TrcSubsystem;
|
import trclib.subsystem.TrcSubsystem;
|
||||||
import trclib.timer.TrcTimer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class creates the robot object that consists of sensors, indicators, drive base and all the subsystems.
|
* This class creates the robot object that consists of sensors, indicators, drive base and all the subsystems.
|
||||||
@ -55,7 +54,6 @@ public class Robot
|
|||||||
public final FtcDashboard dashboard;
|
public final FtcDashboard dashboard;
|
||||||
public static FtcMatchInfo matchInfo = null;
|
public static FtcMatchInfo matchInfo = null;
|
||||||
private static TrcPose2D endOfAutoRobotPose = null;
|
private static TrcPose2D endOfAutoRobotPose = null;
|
||||||
private static double nextStatusUpdateTime = 0.0;
|
|
||||||
// Robot Drive.
|
// Robot Drive.
|
||||||
public RobotBase robotBase;
|
public RobotBase robotBase;
|
||||||
public FtcRobotDrive.RobotInfo robotInfo;
|
public FtcRobotDrive.RobotInfo robotInfo;
|
||||||
@ -82,7 +80,6 @@ public class Robot
|
|||||||
opMode = FtcOpMode.getInstance();
|
opMode = FtcOpMode.getInstance();
|
||||||
globalTracer = TrcDbgTrace.getGlobalTracer();
|
globalTracer = TrcDbgTrace.getGlobalTracer();
|
||||||
dashboard = FtcDashboard.getInstance();
|
dashboard = FtcDashboard.getInstance();
|
||||||
nextStatusUpdateTime = TrcTimer.getCurrentTime();
|
|
||||||
speak("Init starting");
|
speak("Init starting");
|
||||||
// Create and initialize Robot Base.
|
// Create and initialize Robot Base.
|
||||||
robotBase = new RobotBase();
|
robotBase = new RobotBase();
|
||||||
@ -192,6 +189,8 @@ public class Robot
|
|||||||
*/
|
*/
|
||||||
public void stopMode(TrcRobot.RunMode runMode)
|
public void stopMode(TrcRobot.RunMode runMode)
|
||||||
{
|
{
|
||||||
|
// Cancel all operations.
|
||||||
|
cancelAll();
|
||||||
//
|
//
|
||||||
// Print all performance counters if there are any.
|
// Print all performance counters if there are any.
|
||||||
//
|
//
|
||||||
|
@ -49,7 +49,7 @@ public class RobotParams
|
|||||||
public static final boolean useLoopPerformanceMonitor = true;
|
public static final boolean useLoopPerformanceMonitor = true;
|
||||||
public static final boolean useBatteryMonitor = false;
|
public static final boolean useBatteryMonitor = false;
|
||||||
// Driver feedback
|
// Driver feedback
|
||||||
// Status Update: Status Update may affect robot loop time, don't do it when in competition.
|
// Status Update: Dashboard Update may affect robot loop time, don't do it when in competition.
|
||||||
public static final boolean updateDashboard = !inCompetition;
|
public static final boolean updateDashboard = !inCompetition;
|
||||||
public static final boolean showDriveBase = false;
|
public static final boolean showDriveBase = false;
|
||||||
public static final boolean showPidDrive = false;
|
public static final boolean showPidDrive = false;
|
||||||
|
Reference in New Issue
Block a user