2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2017-08-23 22:06:13 -07:00
|
|
|
/* Copyright (c) 2008-2017 FIRST. All Rights Reserved. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
2016-01-02 03:02:34 -08:00
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
2013-12-15 18:30:16 -05:00
|
|
|
/*----------------------------------------------------------------------------*/
|
2016-01-02 03:02:34 -08:00
|
|
|
|
2014-05-02 17:54:01 -04:00
|
|
|
#pragma once
|
2013-12-15 18:30:16 -05:00
|
|
|
|
2016-12-21 21:58:42 -08:00
|
|
|
#include <thread>
|
2016-06-19 00:13:18 -07:00
|
|
|
|
2017-08-27 00:11:52 -07:00
|
|
|
#include <HAL/HAL.h>
|
|
|
|
|
#include <llvm/raw_ostream.h>
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
#include "Base.h"
|
|
|
|
|
|
2016-11-01 22:33:12 -07:00
|
|
|
namespace frc {
|
|
|
|
|
|
2013-12-15 18:30:16 -05:00
|
|
|
class DriverStation;
|
|
|
|
|
|
2017-06-30 22:33:43 -04:00
|
|
|
#define START_ROBOT_CLASS(_ClassName_) \
|
|
|
|
|
int main() { \
|
2017-07-01 00:43:06 -07:00
|
|
|
if (!HAL_Initialize(500, 0)) { \
|
2017-06-30 22:33:43 -04:00
|
|
|
llvm::errs() << "FATAL ERROR: HAL could not be initialized\n"; \
|
|
|
|
|
return -1; \
|
|
|
|
|
} \
|
|
|
|
|
HAL_Report(HALUsageReporting::kResourceType_Language, \
|
|
|
|
|
HALUsageReporting::kLanguage_CPlusPlus); \
|
|
|
|
|
llvm::outs() << "\n********** Robot program starting **********\n"; \
|
2017-07-08 10:50:56 -04:00
|
|
|
static _ClassName_ robot; \
|
2017-06-30 22:33:43 -04:00
|
|
|
robot.StartCompetition(); \
|
2015-06-25 15:07:55 -04:00
|
|
|
}
|
2013-12-15 18:30:16 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implement a Robot Program framework.
|
2017-11-16 00:33:51 -08:00
|
|
|
*
|
2015-06-25 15:07:55 -04:00
|
|
|
* The RobotBase class is intended to be subclassed by a user creating a robot
|
2016-05-20 17:30:37 -07:00
|
|
|
* program. Overridden Autonomous() and OperatorControl() methods are called at
|
|
|
|
|
* the appropriate time as the match proceeds. In the current implementation,
|
|
|
|
|
* the Autonomous code will run to completion before the OperatorControl code
|
|
|
|
|
* could start. In the future the Autonomous code might be spawned as a task,
|
|
|
|
|
* then killed at the end of the Autonomous period.
|
2013-12-15 18:30:16 -05:00
|
|
|
*/
|
2015-06-25 15:07:55 -04:00
|
|
|
class RobotBase {
|
|
|
|
|
public:
|
|
|
|
|
bool IsEnabled() const;
|
|
|
|
|
bool IsDisabled() const;
|
|
|
|
|
bool IsAutonomous() const;
|
|
|
|
|
bool IsOperatorControl() const;
|
|
|
|
|
bool IsTest() const;
|
|
|
|
|
bool IsNewDataAvailable() const;
|
2016-12-21 21:58:42 -08:00
|
|
|
static std::thread::id GetThreadId();
|
2015-06-25 15:07:55 -04:00
|
|
|
virtual void StartCompetition() = 0;
|
|
|
|
|
|
2017-12-08 22:47:21 -08:00
|
|
|
static constexpr bool IsReal() {
|
|
|
|
|
#ifdef __FRC_ROBORIO__
|
|
|
|
|
return true;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static constexpr bool IsSimulation() { return !IsReal(); }
|
|
|
|
|
|
2015-06-25 15:07:55 -04:00
|
|
|
protected:
|
|
|
|
|
RobotBase();
|
2016-06-19 00:13:18 -07:00
|
|
|
virtual ~RobotBase() = default;
|
2015-07-21 01:23:34 -07:00
|
|
|
|
|
|
|
|
RobotBase(const RobotBase&) = delete;
|
|
|
|
|
RobotBase& operator=(const RobotBase&) = delete;
|
2015-06-25 15:07:55 -04:00
|
|
|
|
2016-05-20 17:30:37 -07:00
|
|
|
DriverStation& m_ds;
|
2016-12-21 21:58:42 -08:00
|
|
|
|
|
|
|
|
static std::thread::id m_threadId;
|
2013-12-15 18:30:16 -05:00
|
|
|
};
|
2016-11-01 22:33:12 -07:00
|
|
|
|
|
|
|
|
} // namespace frc
|