-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathlcdio.cpp
191 lines (173 loc) · 5.25 KB
/
lcdio.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
#include "lcdio.h"
#include "update.h"
#include "ports.h"
#include "vision_alt.h"
#include "trajectory.h"
#include <DriverStationLCD.h>
/* Format like this: */
const char * line_fmt[] = {
"Shoot: [SET] [CUR]",
" Speed- 00.00 00.00",
" Angle- 00.00 00.00",
"Targets dx 00.0 - ",
"Roll: - Brdg: - - - ",
"Turr: - - ",
};
lcdio& lcd() {
static lcdio obj;
return obj;
}
lcdio::lcdio() {
registry().register_func(lcdio::update_help, (void*)this);
lcdp = DriverStationLCD::GetInstance();
//put initial values:
lcdp->PrintfLine(DriverStationLCD::kUser_Line1, line_fmt[0]);
lcdp->PrintfLine(DriverStationLCD::kUser_Line2, line_fmt[1]);
lcdp->PrintfLine(DriverStationLCD::kUser_Line3, line_fmt[2]);
lcdp->PrintfLine(DriverStationLCD::kUser_Line4, line_fmt[3]);
lcdp->PrintfLine(DriverStationLCD::kUser_Line5, line_fmt[4]);
lcdp->PrintfLine(DriverStationLCD::kUser_Line6, line_fmt[5]);
}
lcdio::~lcdio() {
registry().unregister_func(lcdio::update_help, (void*)this);
}
void lcdio::update() {
update_set_angle(rad2deg(shooter_turret.Winch().get_set_angle()));
update_cur_angle(rad2deg(shooter_turret.Winch().get_cur_angle()));
update_set_speed(shooter_turret.Shooter().get_set_freq());
update_cur_speed(shooter_turret.Shooter().get_cur_freq());
#ifdef VISION_ALT_HEURISTIC
//targets
update_target_ok(top_basket.valid(), midleft_basket.valid(), midright_basket.valid(), bottom_basket.valid());
//calculate average dx
double acc = 0.0;
int div = 0;
if (top_basket.valid()) {
acc += top_basket.distance();
div++;
}
if (midleft_basket.valid()) {
acc += midleft_basket.distance();
div++;
}
if (midright_basket.valid()) {
acc += midright_basket.distance();
div++;
}
if (bottom_basket.valid()) {
acc += bottom_basket.distance();
div++;
}
if (div) {
update_target_dx(acc/div);
}
else {
update_target_dx_no_targets();
}
#elif defined VISION_ALT_ADHOC
//this could be better - just let the array corrospond to the targets
//this may not be clear to the driver
update_target_ok(target_arr[0].valid(), target_arr[1].valid(), target_arr[2].valid(), target_arr[3].valid());
double acc = 0.0;
int div = 0;
for (unsigned i = 0; i < numtargets; i++) {
if (target_arr[i].valid()) {
acc += target_arr[i].distance();
div++;
}
}
if (div) {
update_target_dx(acc/div);
}
else {
update_target_dx_no_targets();
}
#endif
direction dir;
roller_t::direction d = rollers.get_direction();
switch (d) {
case roller_t::UP:
dir = POSITIVE;
break;
case roller_t::DOWN:
dir = NEGATIVE;
break;
default:
dir = NEUTRAL;
break;
}
update_roller(dir);
bridge_arm_t::direction d2 = bridge_arm.get_direction();
switch (d2) {
case bridge_arm_t::UP:
dir = POSITIVE;
break;
case bridge_arm_t::DOWN:
dir = NEGATIVE;
break;
default:
dir = NEUTRAL;
break;
}
update_bridge(dir);
float f = shooter_turret.Susan().get_power();
if (f > 0.0) {
dir = POSITIVE;
}
else if (f < 0.0) {
dir = NEGATIVE;
}
else {
dir = NEUTRAL;
}
update_turret(dir);
lcdp->UpdateLCD();
}
void lcdio::update_help(void * obj) {
((lcdio*)obj)->update();
}
void lcdio::update_set_speed(float speed) {
lcdp->Printf(DriverStationLCD::kUser_Line2, 10, "%02.2f", speed);
}
void lcdio::update_cur_speed(float speed) {
lcdp->Printf(DriverStationLCD::kUser_Line2, 17, "%02.2f", speed);
}
void lcdio::update_set_angle(float angle) {
lcdp->Printf(DriverStationLCD::kUser_Line3, 10, "%02.2f", angle);
}
void lcdio::update_cur_angle(float angle) {
lcdp->Printf(DriverStationLCD::kUser_Line3, 17, "%02.2f", angle);
}
void lcdio::update_target_dx(float dist) {
lcdp->Printf(DriverStationLCD::kUser_Line4, 12, "%02.1f", dist);
}
void lcdio::update_target_dx_no_targets() {
lcdp->Printf(DriverStationLCD::kUser_Line4, 12, "NONE");
}
void lcdio::update_target_ok(bool top, bool left, bool right, bool bot) {
lcdp->Printf(DriverStationLCD::kUser_Line4, 19, (top ? "+" : "-"));
lcdp->Printf(DriverStationLCD::kUser_Line5, 18, (left ? "+" : "-"));
lcdp->Printf(DriverStationLCD::kUser_Line5, 20, (right ? "+" : "-"));
lcdp->Printf(DriverStationLCD::kUser_Line6, 19, (bot ? "+" : "-"));
}
const char * lcdio::direction2str(lcdio::direction dir, const char * pos, const char * neg, const char * zero) {
switch (dir) {
case lcdio::POSITIVE:
return pos;
case lcdio::NEGATIVE:
return neg;
default:
return zero;
}
}
void lcdio::update_roller(lcdio::direction dir) {
lcdp->Printf(DriverStationLCD::kUser_Line5, 7, direction2str(dir, "^", "v", "-"));
}
void lcdio::update_bridge(lcdio::direction dir) {
lcdp->Printf(DriverStationLCD::kUser_Line5, 15, direction2str(dir, "^", "v", "-"));
}
void lcdio::update_turret(lcdio::direction dir) {
lcdp->Printf(DriverStationLCD::kUser_Line6, 7, direction2str(dir, ">", "<", "|"));
}
//force instantiation of lcdio:
const lcdio& lcd_reference_force_ = lcd();