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 classTitanBot.AutonomousPeriodTimerstatic classTitanBot.LifecycleShifter
-
Constructor Summary
Constructors Constructor Description TitanBot()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidautonomousInit()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.voidautonomousPeriodic()abstract voidautonomousRoutine(TitanBot.AutonomousPeriodTimer timer)The one-shot autonomous "script" to be run in a new Thread.abstract voidautonomousSetup()Called once each time beforeautonomousRoutine(AutonomousPeriodTimer timer)is called.voiddisabledInit()DO NOT CALL THIS MANUALLY!voiddisabledPeriodic()abstract voiddisabledRoutine()abstract voiddisabledSetup()Called once when the robot enters the disabled state.abstract intgetAutonomousPeriodLengthSeconds()Define the length of the Autonomous period, in seconds.voidonLifecycleChange(LifecycleEvent event)<T extends LifecycleListener>
voidregisterLifecycleComponent(T lifecycleListener)voidrobotInit()DO NOT CALL THIS MANUALLY!abstract voidrobotSetup()Called once each time the robot is turned on.voidteleopInit()DO NOT CALL THIS MANUALLY!voidteleopPeriodic()DO NOT CALL THIS MANUALLY! Handles running teleopRoutine periodically.abstract voidteleopRoutine()Periodically called during robot teleop mode to enable operator control.abstract voidteleopSetup()Called once when the robot enters the teleop mode.voidtestInit()voidtestPeriodic()abstract voidtestRoutine()abstract voidtestSetup()-
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:
robotInitin 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:
autonomousInitin 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:
autonomousPeriodicin 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.AutonomousPeriodTimerinstance 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:
teleopInitin 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:
teleopPeriodicin 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:
disabledInitin 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:
disabledPeriodicin classedu.wpi.first.wpilibj.IterativeRobotBase
-
disabledRoutine
public abstract void disabledRoutine()
-
testInit
public final void testInit()
- Overrides:
testInitin classedu.wpi.first.wpilibj.IterativeRobotBase
-
testSetup
public abstract void testSetup()
-
testPeriodic
public final void testPeriodic()
- Overrides:
testPeriodicin 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:
onLifecycleChangein interfaceLifecycleListener
-
-