Remove kDefaultPeriod from IterativeRobot (#232)

* Remove kDefaultPeriod from IterativeRobot

* Remove period

* Remove NextPeriodReady
This commit is contained in:
Austin Shalit
2016-10-09 16:58:30 -04:00
committed by Peter Johnson
parent 4896a77c86
commit 27bf94fd06
4 changed files with 11 additions and 107 deletions

View File

@@ -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();

View File

@@ -13,8 +13,6 @@
#include "SmartDashboard/SmartDashboard.h"
#include "networktables/NetworkTable.h"
constexpr double IterativeRobot::kDefaultPeriod;
/**
* Provide an alternate "main loop" via StartCompetition().
*

View File

@@ -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;
};

View File

@@ -17,47 +17,6 @@
#include <unistd.h>
#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.
*