Cleaned up robot startup and cleanup/shutdown code (#77)

Cleaned up RobotBase, removed singleton list from SensorBase, and removed unused typedefs and NULL_TASK macro from HAL's Task.hpp. Making the robot class instance static fixed non-POD statics used by the instance during destruction from being destroyed first.
This commit is contained in:
Tyler Veness
2016-06-19 00:13:18 -07:00
committed by Peter Johnson
parent ecc210f99a
commit d66c61a36e
10 changed files with 16 additions and 184 deletions

View File

@@ -7,8 +7,10 @@
#pragma once
#include <cstdio>
#include <iostream>
#include "Base.h"
#include "Task.h"
class DriverStation;
@@ -20,9 +22,9 @@ class DriverStation;
} \
HALReport(HALUsageReporting::kResourceType_Language, \
HALUsageReporting::kLanguage_CPlusPlus); \
_ClassName_* robot = new _ClassName_(); \
RobotBase::robotSetup(robot); \
return 0; \
static _ClassName_ robot; \
std::printf("\n********** Robot program starting **********\n"); \
robot.StartCompetition(); \
}
/**
@@ -35,34 +37,21 @@ class DriverStation;
* then killed at the end of the Autonomous period.
*/
class RobotBase {
friend class RobotDeleter;
public:
static RobotBase& getInstance();
static void setInstance(RobotBase* robot);
bool IsEnabled() const;
bool IsDisabled() const;
bool IsAutonomous() const;
bool IsOperatorControl() const;
bool IsTest() const;
bool IsNewDataAvailable() const;
static void startRobotTask(FUNCPTR factory);
static void robotTask(FUNCPTR factory, Task* task);
virtual void StartCompetition() = 0;
static void robotSetup(RobotBase* robot);
protected:
RobotBase();
virtual ~RobotBase();
virtual ~RobotBase() = default;
RobotBase(const RobotBase&) = delete;
RobotBase& operator=(const RobotBase&) = delete;
Task* m_task = nullptr;
DriverStation& m_ds;
private:
static RobotBase* m_instance;
};