blob: 3be7f8a60f3f7df368eed919489be48ffbf34b4e [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#include "SimpleRobot.h"
8
9#include "DriverStation.h"
10#include "NetworkCommunication/UsageReporting.h"
11#include "Timer.h"
12#include "SmartDashboard/SmartDashboard.h"
13#include "LiveWindow/LiveWindow.h"
14#include "networktables/NetworkTable.h"
15
16SimpleRobot::SimpleRobot()
17 : m_robotMainOverridden (true)
18{
19 m_watchdog.SetEnabled(false);
20}
21
22/**
23 * Robot-wide initialization code should go here.
24 *
25 * Programmers should override this method for default Robot-wide initialization which will
26 * be called each time the robot enters the disabled state.
27 */
28void SimpleRobot::RobotInit()
29{
30 printf("Default %s() method... Override me!\n", __FUNCTION__);
31}
32
33/**
34 * Disabled should go here.
35 * Programmers should override this method to run code that should run while the field is
36 * disabled.
37 */
38void SimpleRobot::Disabled()
39{
40 printf("Default %s() method... Override me!\n", __FUNCTION__);
41}
42
43/**
44 * Autonomous should go here.
45 * Programmers should override this method to run code that should run while the field is
46 * in the autonomous period. This will be called once each time the robot enters the
47 * autonomous state.
48 */
49void SimpleRobot::Autonomous()
50{
51 printf("Default %s() method... Override me!\n", __FUNCTION__);
52}
53
54/**
55 * Operator control (tele-operated) code should go here.
56 * Programmers should override this method to run code that should run while the field is
57 * in the Operator Control (tele-operated) period. This is called once each time the robot
58 * enters the teleop state.
59 */
60void SimpleRobot::OperatorControl()
61{
62 printf("Default %s() method... Override me!\n", __FUNCTION__);
63}
64
65/**
66 * Test program should go here.
67 * Programmers should override this method to run code that executes while the robot is
68 * in test mode. This will be called once whenever the robot enters test mode
69 */
70void SimpleRobot::Test()
71{
72 printf("Default %s() method... Override me!\n", __FUNCTION__);
73}
74
75/**
76 * Robot main program for free-form programs.
77 *
78 * This should be overridden by user subclasses if the intent is to not use the Autonomous() and
79 * OperatorControl() methods. In that case, the program is responsible for sensing when to run
80 * the autonomous and operator control functions in their program.
81 *
82 * This method will be called immediately after the constructor is called. If it has not been
83 * overridden by a user subclass (i.e. the default version runs), then the Autonomous() and
84 * OperatorControl() methods will be called.
85 */
86void SimpleRobot::RobotMain()
87{
88 m_robotMainOverridden = false;
89}
90
91/**
92 * Start a competition.
93 * This code needs to track the order of the field starting to ensure that everything happens
94 * in the right order. Repeatedly run the correct method, either Autonomous or OperatorControl
95 * or Test when the robot is enabled. After running the correct method, wait for some state to
96 * change, either the other mode starts or the robot is disabled. Then go back and wait for the
97 * robot to be enabled again.
98 */
99void SimpleRobot::StartCompetition()
100{
101 LiveWindow *lw = LiveWindow::GetInstance();
102
103 nUsageReporting::report(nUsageReporting::kResourceType_Framework, nUsageReporting::kFramework_Simple);
104
105 SmartDashboard::init();
106 NetworkTable::GetTable("LiveWindow")->GetSubTable("~STATUS~")->PutBoolean("LW Enabled", false);
107
108 RobotMain();
109
110 if (!m_robotMainOverridden)
111 {
112 // first and one-time initialization
113
114 lw->SetEnabled(false);
115
116 RobotInit();
117
118 while (true)
119 {
120 if (IsDisabled())
121 {
122 m_ds->InDisabled(true);
123 Disabled();
124 m_ds->InDisabled(false);
125 while (IsDisabled()) m_ds->WaitForData();
126 }
127 else if (IsAutonomous())
128 {
129 m_ds->InAutonomous(true);
130 Autonomous();
131 m_ds->InAutonomous(false);
132 while (IsAutonomous() && IsEnabled()) m_ds->WaitForData();
133 }
134 else if (IsTest())
135 {
136 lw->SetEnabled(true);
137 m_ds->InTest(true);
138 Test();
139 m_ds->InTest(false);
140 while (IsTest() && IsEnabled()) m_ds->WaitForData();
141 lw->SetEnabled(false);
142 }
143 else
144 {
145 m_ds->InOperatorControl(true);
146 OperatorControl();
147 m_ds->InOperatorControl(false);
148 while (IsOperatorControl() && IsEnabled()) m_ds->WaitForData();
149 }
150 }
151 }
152}