Package ca.team3161.lib.robot
Class TitanBot
- java.lang.Object
-
- edu.wpi.first.wpilibj.RobotBase
-
- edu.wpi.first.wpilibj.IterativeRobotBase
-
- edu.wpi.first.wpilibj.TimedRobot
-
- ca.team3161.lib.robot.TitanBot
-
- All Implemented Interfaces:
LifecycleListener
,java.lang.AutoCloseable
public abstract class TitanBot extends edu.wpi.first.wpilibj.TimedRobot implements LifecycleListener
A subclass of TimedRobot. Autonomous is run in a new Thread, leaving the main robot thread responsible (generally) solely for handling FMS events, Watchdog, etc. This allows autonomous scripts to use convenient semantics such as Thread sleeping rather than periodically checking Timer objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TitanBot.AutonomousPeriodTimer
static class
TitanBot.LifecycleShifter
-
Constructor Summary
Constructors Constructor Description TitanBot()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
autonomousInit()
DO NOT CALL THIS MANUALLY! At the start of the autonomous period, start a new background task using the behaviour described in the concrete subclass implementation's autonomousRoutine() method.void
autonomousPeriodic()
abstract void
autonomousRoutine(TitanBot.AutonomousPeriodTimer timer)
The one-shot autonomous "script" to be run in a new Thread.abstract void
autonomousSetup()
Called once each time beforeautonomousRoutine(AutonomousPeriodTimer timer)
is called.void
disabledInit()
DO NOT CALL THIS MANUALLY!void
disabledPeriodic()
abstract void
disabledRoutine()
abstract void
disabledSetup()
Called once when the robot enters the disabled state.abstract int
getAutonomousPeriodLengthSeconds()
Define the length of the Autonomous period, in seconds.void
onLifecycleChange(LifecycleEvent event)
<T extends LifecycleListener>
voidregisterLifecycleComponent(T lifecycleListener)
void
robotInit()
DO NOT CALL THIS MANUALLY!abstract void
robotSetup()
Called once each time the robot is turned on.void
teleopInit()
DO NOT CALL THIS MANUALLY!void
teleopPeriodic()
DO NOT CALL THIS MANUALLY! Handles running teleopRoutine periodically.abstract void
teleopRoutine()
Periodically called during robot teleop mode to enable operator control.abstract void
teleopSetup()
Called once when the robot enters the teleop mode.void
testInit()
void
testPeriodic()
abstract void
testRoutine()
abstract void
testSetup()
-
Methods inherited from class edu.wpi.first.wpilibj.TimedRobot
addPeriodic, addPeriodic, endCompetition, finalize, startCompetition
-
Methods inherited from class edu.wpi.first.wpilibj.IterativeRobotBase
autonomousExit, disabledExit, getPeriod, loopFunc, robotPeriodic, setNetworkTablesFlushEnabled, simulationInit, simulationPeriodic, teleopExit, testExit
-
Methods inherited from class edu.wpi.first.wpilibj.RobotBase
close, getBooleanProperty, getMainThreadId, getRuntimeType, isAutonomous, isAutonomousEnabled, isDisabled, isEnabled, isNewDataAvailable, isOperatorControl, isOperatorControlEnabled, isReal, isSimulation, isTeleop, isTeleopEnabled, isTest, startRobot, suppressExitWarning
-
-
-
-
Method Detail
-
robotInit
public final void robotInit()
DO NOT CALL THIS MANUALLY!- Overrides:
robotInit
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
robotSetup
public abstract void robotSetup()
Called once each time the robot is turned on.
-
autonomousInit
public final void autonomousInit()
DO NOT CALL THIS MANUALLY! At the start of the autonomous period, start a new background task using the behaviour described in the concrete subclass implementation's autonomousRoutine() method. This new background task allows us to use Thread.sleep rather than a timer, while also not disrupting normal background functions of the robot such as feeding the Watchdog or responding to FMS events. modeLock is used to ensure that the robot is never simultaneously executing both autonomous and teleop routines at the same time.- Overrides:
autonomousInit
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
autonomousSetup
public abstract void autonomousSetup()
Called once each time beforeautonomousRoutine(AutonomousPeriodTimer timer)
is called.
-
autonomousPeriodic
public final void autonomousPeriodic()
- Overrides:
autonomousPeriodic
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
autonomousRoutine
public abstract void autonomousRoutine(TitanBot.AutonomousPeriodTimer timer) throws java.lang.Exception
The one-shot autonomous "script" to be run in a new Thread.- Parameters:
timer
- anTitanBot.AutonomousPeriodTimer
instance to be used for causing the autonomous routine thread to sleep/wait. This should always be used over "bare" Thread.sleep() or Timer.delay().- Throws:
java.lang.Exception
- this method failing should never catch the caller unaware - may lead to unpredictable behaviour if so
-
teleopInit
public final void teleopInit()
DO NOT CALL THIS MANUALLY!- Overrides:
teleopInit
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
teleopSetup
public abstract void teleopSetup()
Called once when the robot enters the teleop mode.
-
teleopPeriodic
public final void teleopPeriodic()
DO NOT CALL THIS MANUALLY! Handles running teleopRoutine periodically. Do not override this in subclasses, or else there may be no guarantee that the autonomous thread and the main robot thread, executing teleop code, will not attempt to run concurrently.- Overrides:
teleopPeriodic
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
teleopRoutine
public abstract void teleopRoutine()
Periodically called during robot teleop mode to enable operator control. This is the only way teleop mode should be handled - do not directly call teleopPeriodic from within this method or unbounded recursion will occur, resulting in a stack overflow and crashed robot code. teleopContinuous is likewise unsupported.
-
disabledInit
public final void disabledInit()
DO NOT CALL THIS MANUALLY!- Overrides:
disabledInit
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
disabledSetup
public abstract void disabledSetup()
Called once when the robot enters the disabled state.
-
disabledPeriodic
public final void disabledPeriodic()
- Overrides:
disabledPeriodic
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
disabledRoutine
public abstract void disabledRoutine()
-
testInit
public final void testInit()
- Overrides:
testInit
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
testSetup
public abstract void testSetup()
-
testPeriodic
public final void testPeriodic()
- Overrides:
testPeriodic
in classedu.wpi.first.wpilibj.IterativeRobotBase
-
testRoutine
public abstract void testRoutine()
-
getAutonomousPeriodLengthSeconds
public abstract int getAutonomousPeriodLengthSeconds()
Define the length of the Autonomous period, in seconds.- Returns:
- the length of the Autonomous period, in seconds.
-
registerLifecycleComponent
public <T extends LifecycleListener> void registerLifecycleComponent(T lifecycleListener)
-
onLifecycleChange
public void onLifecycleChange(LifecycleEvent event)
- Specified by:
onLifecycleChange
in interfaceLifecycleListener
-
-