blob: 1d93585f26b0711cb886de63ef2b80e417720086 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. All Rights Reserved. */
3/* Open Source Software - may be modified and shared by FRC teams. The code */
4/* must be accompanied by the FIRST BSD license file in $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6
7#ifndef ROBOT_H_
8#define ROBOT_H_
9
10#include "Base.h"
11#include "Task.h"
12#include "Watchdog.h"
13
14class DriverStation;
15
16#define START_ROBOT_CLASS(_ClassName_) \
17 RobotBase *FRC_userClassFactory() \
18 { \
19 return new _ClassName_(); \
20 } \
21 extern "C" { \
22 INT32 FRC_UserProgram_StartupLibraryInit() \
23 { \
24 RobotBase::startRobotTask((FUNCPTR)FRC_userClassFactory); \
25 return 0; \
26 } \
27 }
28
29/**
30 * Implement a Robot Program framework.
31 * The RobotBase class is intended to be subclassed by a user creating a robot program.
32 * Overridden Autonomous() and OperatorControl() methods are called at the appropriate time
33 * as the match proceeds. In the current implementation, the Autonomous code will run to
34 * completion before the OperatorControl code could start. In the future the Autonomous code
35 * might be spawned as a task, then killed at the end of the Autonomous period.
36 */
37class RobotBase {
38 friend class RobotDeleter;
39public:
40 static RobotBase &getInstance();
41 static void setInstance(RobotBase* robot);
42
43 bool IsEnabled();
44 bool IsDisabled();
45 bool IsAutonomous();
46 bool IsOperatorControl();
47 bool IsTest();
48 bool IsSystemActive();
49 bool IsNewDataAvailable();
50 Watchdog &GetWatchdog();
51 static void startRobotTask(FUNCPTR factory);
52 static void robotTask(FUNCPTR factory, Task *task);
53
54protected:
55 virtual ~RobotBase();
56 virtual void StartCompetition() = 0;
57 RobotBase();
58
59 Task *m_task;
60 Watchdog m_watchdog;
61 DriverStation *m_ds;
62
63private:
64 static RobotBase *m_instance;
65 DISALLOW_COPY_AND_ASSIGN(RobotBase);
66};
67
68#endif
69