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