[wpilib] Add TimedRobot functions for running code on mode exit (#3499)

Currently, we have functions like TeleopInit() for running code on mode
entry, but no such functions for running code on mode exit, and it's
cumbersome to add those in user code without making a custom robot
class. This PR adds exit functions to TimedRobot.

Some example use cases include DisabledExit() for operations when the
robot enables (whether that be into teleop, autonomous, or test) and
AutonomousExit() for disabling feedback controllers.
This commit is contained in:
Tyler Veness
2021-08-05 19:08:29 -07:00
committed by GitHub
parent 94e0db7963
commit fb2ee8ec34
5 changed files with 603 additions and 98 deletions

View File

@@ -25,22 +25,32 @@ namespace frc {
* RobotInit() -- provide for initialization at robot power-on
*
* Init() functions -- each of the following functions is called once when the
* appropriate mode is entered:
* - DisabledInit() -- called each and every time disabled is entered from
* another mode
* - AutonomousInit() -- called each and every time autonomous is entered from
* another mode
* - TeleopInit() -- called each and every time teleop is entered from
* another mode
* - TestInit() -- called each and every time test is entered from
* another mode
* appropriate mode is entered:
*
* \li DisabledInit() -- called each and every time disabled is entered from
* another mode
* \li AutonomousInit() -- called each and every time autonomous is entered from
* another mode
* \li TeleopInit() -- called each and every time teleop is entered from another
* mode
* \li TestInit() -- called each and every time test is entered from another
* mode
*
* Periodic() functions -- each of these functions is called on an interval:
* - RobotPeriodic()
* - DisabledPeriodic()
* - AutonomousPeriodic()
* - TeleopPeriodic()
* - TestPeriodic()
*
* \li RobotPeriodic()
* \li DisabledPeriodic()
* \li AutonomousPeriodic()
* \li TeleopPeriodic()
* \li TestPeriodic()
*
* Exit() functions -- each of the following functions is called once when the
* appropriate mode is exited:
*
* \li DisabledExit() -- called each and every time disabled is exited
* \li AutonomousExit() -- called each and every time autonomous is exited
* \li TeleopExit() -- called each and every time teleop is exited
* \li TestExit() -- called each and every time test is exited
*/
class IterativeRobotBase : public RobotBase {
public:
@@ -152,6 +162,38 @@ class IterativeRobotBase : public RobotBase {
*/
virtual void TestPeriodic();
/**
* Exit code for disabled mode should go here.
*
* Users should override this method for code which will be called each time
* the robot exits disabled mode.
*/
virtual void DisabledExit();
/**
* Exit code for autonomous mode should go here.
*
* Users should override this method for code which will be called each time
* the robot exits autonomous mode.
*/
virtual void AutonomousExit();
/**
* Exit code for teleop mode should go here.
*
* Users should override this method for code which will be called each time
* the robot exits teleop mode.
*/
virtual void TeleopExit();
/**
* Exit code for test mode should go here.
*
* Users should override this method for code which will be called each time
* the robot exits test mode.
*/
virtual void TestExit();
/**
* Enables or disables flushing NetworkTables every loop iteration.
* By default, this is disabled.