diff --git a/wpilibc/athena/include/IterativeRobot.h b/wpilibc/athena/include/IterativeRobot.h index 634e258ad9..421a466c0e 100644 --- a/wpilibc/athena/include/IterativeRobot.h +++ b/wpilibc/athena/include/IterativeRobot.h @@ -62,6 +62,7 @@ class IterativeRobot : public RobotBase { virtual void TeleopInit(); virtual void TestInit(); + virtual void RobotPeriodic(); virtual void DisabledPeriodic(); virtual void AutonomousPeriodic(); virtual void TeleopPeriodic(); diff --git a/wpilibc/athena/src/IterativeRobot.cpp b/wpilibc/athena/src/IterativeRobot.cpp index 54d5d976f4..6ec24c36c9 100644 --- a/wpilibc/athena/src/IterativeRobot.cpp +++ b/wpilibc/athena/src/IterativeRobot.cpp @@ -98,6 +98,7 @@ void IterativeRobot::StartCompetition() { HAL_ObserveUserProgramTeleop(); TeleopPeriodic(); } + RobotPeriodic(); // wait for driver station data so the loop doesn't hog the CPU m_ds.WaitForData(); } @@ -160,6 +161,20 @@ void IterativeRobot::TestInit() { std::printf("Default %s() method... Overload me!\n", __FUNCTION__); } +/** + * Periodic code for all modes should go here. + * + * Users should override this method for code which will be called periodically + * at a regular rate while the robot is in any mode. + */ +void IterativeRobot::RobotPeriodic() { + static bool firstRun = true; + if (firstRun) { + std::printf("Default %s() method... Overload me!\n", __FUNCTION__); + firstRun = false; + } +} + /** * Periodic code for disabled mode should go here. * diff --git a/wpilibc/sim/include/IterativeRobot.h b/wpilibc/sim/include/IterativeRobot.h index 0d8ef1c783..a3503c28a7 100644 --- a/wpilibc/sim/include/IterativeRobot.h +++ b/wpilibc/sim/include/IterativeRobot.h @@ -62,6 +62,7 @@ class IterativeRobot : public RobotBase { virtual void TeleopInit(); virtual void TestInit(); + virtual void RobotPeriodic(); virtual void DisabledPeriodic(); virtual void AutonomousPeriodic(); virtual void TeleopPeriodic(); diff --git a/wpilibc/sim/src/IterativeRobot.cpp b/wpilibc/sim/src/IterativeRobot.cpp index 44fac4711d..062a711e8d 100644 --- a/wpilibc/sim/src/IterativeRobot.cpp +++ b/wpilibc/sim/src/IterativeRobot.cpp @@ -220,6 +220,20 @@ void IterativeRobot::TestInit() { std::printf("Default %s() method... Overload me!\n", __FUNCTION__); } +/** + * Periodic code for all modes should go here. + * + * Users should override this method for code which will be called periodically + * at a regular rate while the robot is in any mode. + */ +void IterativeRobot::RobotPeriodic() { + static bool firstRun = true; + if (firstRun) { + std::printf("Default %s() method... Overload me!\n", __FUNCTION__); + firstRun = false; + } +} + /** * Periodic code for disabled mode should go here. * diff --git a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java index c461e821f8..ef797bcf03 100644 --- a/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/src/athena/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -135,6 +135,7 @@ public class IterativeRobot extends RobotBase { teleopPeriodic(); } } + robotPeriodic(); m_ds.waitForData(); } } @@ -204,6 +205,22 @@ public class IterativeRobot extends RobotBase { } /* ----------- Overridable periodic code ----------------- */ + + private boolean m_rpFirstRun = true; + + /** + * Periodic code for all robot modes should go here. + * + *

Users should override this method for code which will be called periodically at a regular + * rate while the robot is in any mode. + */ + public void robotPeriodic() { + if (m_rpFirstRun) { + System.out.println("Default IterativeRobot.robotPeriodic() method... Overload me!"); + m_rpFirstRun = false; + } + Timer.delay(0.001); + } private boolean m_dpFirstRun = true; diff --git a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java index aae27f5010..740096c40d 100644 --- a/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java +++ b/wpilibj/src/sim/java/edu/wpi/first/wpilibj/IterativeRobot.java @@ -144,6 +144,7 @@ public class IterativeRobot extends RobotBase { didTeleopPeriodic = true; } } + robotPeriodic(); m_ds.waitForData(); } } @@ -209,6 +210,22 @@ public class IterativeRobot extends RobotBase { } /* ----------- Overridable periodic code -----------------*/ + + private boolean m_rpFirstRun = true; + + /** + * Periodic code for all robot modes should go here. + * + *

Users should override this method for code which will be called periodically at a regular + * rate while the robot is in any mode. + */ + public void robotPeriodic() { + if (m_rpFirstRun) { + System.out.println("Default IterativeRobot.robotPeriodic() method... Overload me!"); + m_rpFirstRun = false; + } + Timer.delay(0.001); + } private boolean dpFirstRun = true;