From 27bf94fd0653efd9deeee81683fbf3105f397b2e Mon Sep 17 00:00:00 2001 From: Austin Shalit Date: Sun, 9 Oct 2016 16:58:30 -0400 Subject: [PATCH] Remove kDefaultPeriod from IterativeRobot (#232) * Remove kDefaultPeriod from IterativeRobot * Remove period * Remove NextPeriodReady --- wpilibc/athena/include/IterativeRobot.h | 8 --- wpilibc/athena/src/IterativeRobot.cpp | 2 - wpilibc/sim/include/IterativeRobot.h | 24 +------ wpilibc/sim/src/IterativeRobot.cpp | 84 +++---------------------- 4 files changed, 11 insertions(+), 107 deletions(-) diff --git a/wpilibc/athena/include/IterativeRobot.h b/wpilibc/athena/include/IterativeRobot.h index 07d1a01c3e..a41881b319 100644 --- a/wpilibc/athena/include/IterativeRobot.h +++ b/wpilibc/athena/include/IterativeRobot.h @@ -8,7 +8,6 @@ #pragma once #include "RobotBase.h" -#include "Timer.h" /** * IterativeRobot implements a specific type of Robot Program framework, @@ -45,13 +44,6 @@ class IterativeRobot : public RobotBase { public: - /* - * The default period for the periodic function calls (seconds) - * Setting the period to 0.0 will cause the periodic functions to follow - * the Driver Station packet rate of about 50Hz. - */ - static constexpr double kDefaultPeriod = 0.0; - virtual void StartCompetition(); virtual void RobotInit(); diff --git a/wpilibc/athena/src/IterativeRobot.cpp b/wpilibc/athena/src/IterativeRobot.cpp index 48ce493c47..b8916bae99 100644 --- a/wpilibc/athena/src/IterativeRobot.cpp +++ b/wpilibc/athena/src/IterativeRobot.cpp @@ -13,8 +13,6 @@ #include "SmartDashboard/SmartDashboard.h" #include "networktables/NetworkTable.h" -constexpr double IterativeRobot::kDefaultPeriod; - /** * Provide an alternate "main loop" via StartCompetition(). * diff --git a/wpilibc/sim/include/IterativeRobot.h b/wpilibc/sim/include/IterativeRobot.h index a3503c28a7..a41881b319 100644 --- a/wpilibc/sim/include/IterativeRobot.h +++ b/wpilibc/sim/include/IterativeRobot.h @@ -8,7 +8,6 @@ #pragma once #include "RobotBase.h" -#include "Timer.h" /** * IterativeRobot implements a specific type of Robot Program framework, @@ -33,11 +32,9 @@ * - TestInit() -- called each and every time test is entered from * another mode * - * Periodic() functions -- each of these functions is called iteratively at the - * appropriate periodic rate (aka the "slow loop"). The - * default period of the iterative robot is synced to - * the driver station control packets, giving a periodic - * frequency of about 50Hz (50 times per second). + * Periodic() functions -- each of these functions is called each time a + * new packet is received from the driver station: + * - RobotPeriodic() * - DisabledPeriodic() * - AutonomousPeriodic() * - TeleopPeriodic() @@ -47,13 +44,6 @@ class IterativeRobot : public RobotBase { public: - /* - * The default period for the periodic function calls (seconds). - * Setting the period to 0.0 will cause the periodic functions to follow - * the Driver Station packet rate of about 50Hz. - */ - static const double kDefaultPeriod; - virtual void StartCompetition(); virtual void RobotInit(); @@ -68,21 +58,13 @@ class IterativeRobot : public RobotBase { virtual void TeleopPeriodic(); virtual void TestPeriodic(); - void SetPeriod(double period); - double GetPeriod(); - double GetLoopsPerSec(); - protected: virtual ~IterativeRobot() = default; IterativeRobot() = default; private: - bool NextPeriodReady(); - bool m_disabledInitialized = false; bool m_autonomousInitialized = false; bool m_teleopInitialized = false; bool m_testInitialized = false; - double m_period = kDefaultPeriod; - Timer m_mainLoopTimer; }; diff --git a/wpilibc/sim/src/IterativeRobot.cpp b/wpilibc/sim/src/IterativeRobot.cpp index 062a711e8d..0339152359 100644 --- a/wpilibc/sim/src/IterativeRobot.cpp +++ b/wpilibc/sim/src/IterativeRobot.cpp @@ -17,47 +17,6 @@ #include #endif -const double IterativeRobot::kDefaultPeriod = 0; - -/** - * Set the period for the periodic functions. - * - * @param period The period of the periodic function calls. 0.0 means sync to - * driver station control data. - */ -void IterativeRobot::SetPeriod(double period) { - if (period > 0.0) { - // Not syncing with the DS, so start the timer for the main loop - m_mainLoopTimer.Reset(); - m_mainLoopTimer.Start(); - } else { - // Syncing with the DS, don't need the timer - m_mainLoopTimer.Stop(); - } - m_period = period; -} - -/** - * Get the period for the periodic functions. - * - * Returns 0.0 if configured to syncronize with DS control data packets. - * - * @return Period of the periodic function calls - */ -double IterativeRobot::GetPeriod() { return m_period; } - -/** - * Get the number of loops per second for the IterativeRobot. - * - * @return Frequency of the periodic function calls - */ -double IterativeRobot::GetLoopsPerSec() { - // If syncing to the driver station, we don't know the rate, - // so guess something close. - if (m_period <= 0.0) return 50.0; - return 1.0 / m_period; -} - /** * Provide an alternate "main loop" via StartCompetition(). * @@ -91,10 +50,8 @@ void IterativeRobot::StartCompetition() { m_teleopInitialized = false; m_testInitialized = false; } - if (NextPeriodReady()) { - // TODO: HALNetworkCommunicationObserveUserProgramDisabled(); - DisabledPeriodic(); - } + // TODO: HALNetworkCommunicationObserveUserProgramDisabled(); + DisabledPeriodic(); } else if (IsAutonomous()) { // call AutonomousInit() if we are now just entering autonomous mode from // either a different mode or from power-on @@ -107,10 +64,8 @@ void IterativeRobot::StartCompetition() { m_teleopInitialized = false; m_testInitialized = false; } - if (NextPeriodReady()) { - // TODO: HALNetworkCommunicationObserveUserProgramAutonomous(); - AutonomousPeriodic(); - } + // TODO: HALNetworkCommunicationObserveUserProgramAutonomous(); + AutonomousPeriodic(); } else if (IsTest()) { // call TestInit() if we are now just entering test mode from // either a different mode or from power-on @@ -123,10 +78,8 @@ void IterativeRobot::StartCompetition() { m_autonomousInitialized = false; m_teleopInitialized = false; } - if (NextPeriodReady()) { - // TODO: HALNetworkCommunicationObserveUserProgramTest(); - TestPeriodic(); - } + // TODO: HALNetworkCommunicationObserveUserProgramTest(); + TestPeriodic(); } else { // call TeleopInit() if we are now just entering teleop mode from // either a different mode or from power-on @@ -140,35 +93,14 @@ void IterativeRobot::StartCompetition() { m_testInitialized = false; Scheduler::GetInstance()->SetEnabled(true); } - if (NextPeriodReady()) { - // TODO: HALNetworkCommunicationObserveUserProgramTeleop(); - TeleopPeriodic(); - } + // TODO: HALNetworkCommunicationObserveUserProgramTeleop(); + TeleopPeriodic(); } // wait for driver station data so the loop doesn't hog the CPU m_ds.WaitForData(); } } -/** - * Determine if the periodic functions should be called. - * - * If m_period > 0.0, call the periodic function every m_period as compared - * to Timer.Get(). If m_period == 0.0, call the periodic functions whenever - * a packet is received from the Driver Station, or about every 20ms. - * - * @todo Decide what this should do if it slips more than one cycle. - */ - -bool IterativeRobot::NextPeriodReady() { - if (m_period > 0.0) { - return m_mainLoopTimer.HasPeriodPassed(m_period); - } else { - // XXX: BROKEN! return m_ds->IsNewControlData(); - } - return true; -} - /** * Robot-wide initialization code should go here. *