forked from FRC2994/TestProg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyRobot.cpp
203 lines (170 loc) · 6.52 KB
/
MyRobot.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#include "WPILib.h"
#include "EGamepad.h"
#include "test/base.h"
/**
* This is a demo program showing the use of the RobotBase class.
* The SimpleRobot class is the base of a robot application that will automatically call your
* Autonomous and OperatorControl methods at the right time as controlled by the switches on
* the driver station or the field controls.
*/
// This demo progam has been modified to include code that runs in test mode. The intent of this
// code is to enable the manipulation of individual channels on any of the modules using a menu-
// driven interface which uses a few gamepad buttons and the LCD screen as its interface
class RobotDemo : public SimpleRobot
{
EGamepad gamepad; // for test mode
DriverStationLCD *dsLCD;
public:
RobotDemo(void):
gamepad(3)
{
dsLCD = DriverStationLCD::GetInstance();
// Output the program name and build date/time in the hope that this will help
// us catch cases where we are downloading a program other than the one
// we think we are downloading. Keep in mind that if this source file
// does not change (and you don't do a complete rebuild) the timestamp
// will not change.
dsLCD->Clear();
dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "2013 Test Menu");
dsLCD->PrintfLine(DriverStationLCD::kUser_Line2, __DATE__ " "__TIME__);
dsLCD->UpdateLCD();
}
/**
* Output a message to the LCD to let users know they have strayed
* into a useless mode
*/
void Autonomous(void)
{
dsLCD->Clear();
dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "2013 Test Fix");
dsLCD->PrintfLine(DriverStationLCD::kUser_Line2, "Autonomous Mode");
dsLCD->UpdateLCD();
}
/**
* Output a message to the LCD to let users know they have strayed
* into a useless mode
*/
void OperatorControl(void)
{
// Loop counter to ensure that the program us running (debug helper
// that can be removed when things get more stable)
int sanity, bigSanity = 0;
while (IsOperatorControl() && IsEnabled())
{
dsLCD->Clear();
dsLCD->PrintfLine(DriverStationLCD::kUser_Line1, "2013 Test Fix");
dsLCD->PrintfLine(DriverStationLCD::kUser_Line2, "Teleop Mode");
dsLCD->PrintfLine(DriverStationLCD::kUser_Line6, "bigSanity: %d", sanity);
dsLCD->UpdateLCD();
sanity++;
if (0 == sanity % 20)
{
bigSanity++;
}
Wait(1.0); // wait for a motor update time
}
}
/**
* Run the test program
*/
// The test program is organized as a set of hierarchical menus that are
// displayed on the LCD on the driver station. Each menu is either a set
// of submenus or is a menu controlling the use of a port (or ports) on
// one of the IO modules plugged into the cRIO.
// See base.h for a description of the test menu hierarchy
// Simplified User's guide:
// dpad up : move the cursor up one menu item
// dpad down : move the cursor down one menu item
// dpad left : decrement the value in the selected menu item or
// return to the previous menu if the menu item is "Back"
// dpad right: increment the value in the selected menu item or
// enter a submenu (as appropriate)
// gamepad right joystick: control the configured and enabled PWM ports
// (Top->Digital->PWM)
void Test()
{
menuType currentMenu = TOP;
menuType newMenu = TOP;
BaseMenu * menus[NUM_MENU_TYPE];
menus[TOP] = new TopMenu;
menus[ANALOG] = new AnalogMenu;
menus[DIGITAL_TOP] = new DigitalMenu;
menus[SOLENOID] = new SolenoidMenu;
menus[DIGITAL_PWM] = new PWMMenu;
menus[DIGITAL_IO] = new DigitalIOMenu;
menus[DIGITAL_RELAY] = new RelayMenu;
menus[DIGITAL_IO_STATE] = new DigitalIOStateMenu;
menus[DIGITAL_IO_CLOCK] = new DigitalIOClockMenu;
menus[DIGITAL_IO_ENCODER] = new DigitalIOEncoderMenu;
// Write out the TOP menu for the first time
menus[currentMenu]->UpdateDisplay();
// Initialize the button states on the gamepad
gamepad.Update();
// Loop counter to ensure that the program us running (debug helper
// that can be removed when things get more stable)
int sanity = 0;
while (IsTest())
{
// The dpad "up" button is used to move the menu pointer up one line
// on the LCD display
if (kEventClosed == gamepad.GetDPadEvent(Gamepad::kUp))
{
menus[currentMenu]->HandleIndexUp();
}
// The dpad "down" button is used to move the menu pointer down one line
// on the LCD display
if (kEventClosed == gamepad.GetDPadEvent(Gamepad::kDown))
{
menus[currentMenu]->HandleIndexDown();
}
// The dpad left button is used to exit a submenu when the menu pointer
// points to the "back" menu item and to decrease a value (where
// appropriate) on any other menu item.
if (kEventClosed == gamepad.GetDPadEvent(Gamepad::kLeft))
{
newMenu = menus[currentMenu]->HandleSelectLeft();
}
// Theoretically, both the select buttons could be pressed in the
// same 10 msec window. However, if using the dpad on the game
// game controller this is physically impossible so we don't
// need to worry about a previous value of newMenu being
// overwritten in the next bit of code.
// The dpad right button is used to enter a submenu when the menu pointer
// points to a submenu item and to increase a value (where appropriate)
// on any other menu item.
if (kEventClosed == gamepad.GetDPadEvent(Gamepad::kRight))
{
newMenu = menus[currentMenu]->HandleSelectRight();
// Handle change from one menu to a sub menu
if (newMenu != currentMenu)
{
// When we enter a menu we need to set the record the
// menu to return to. We do *not* want to do this when
// returning from a menu to its calling menu.
menus[newMenu]->SetCallingMenu(currentMenu);
}
}
// Handle change from one menu to another
if (newMenu != currentMenu)
{
menus[newMenu]->UpdateDisplay();
currentMenu = newMenu;
}
// Set the motor speed(s) (if any have been enabled via the Digital PWM menu)
menus[DIGITAL_PWM]->SetSpeed(-1.0 * gamepad.GetRightY());
// Update gamepad button states
gamepad.Update();
// Update the display (we do this on every loop pass because some menus
// (analog, for example) need to have values updated even when there are
// no dpad events to handle)
menus[currentMenu]->UpdateDisplay();
// Dump the sanity time value to the LCD
dsLCD->PrintfLine(DriverStationLCD::kUser_Line6, "Sanity: %d", sanity);
dsLCD->UpdateLCD();
sanity++;
// Run the loop every 50 msec (20 times per second)
Wait(0.050);
}
}
};
START_ROBOT_CLASS(RobotDemo);