blob: 54d269430387d8d096817d462f08d8de50684e84 [file] [log] [blame]
Sabina Davis91b23602019-01-21 00:06:01 -08001#include <math.h>
2#include <stdio.h>
3#include <string.h>
4#include <unistd.h>
Tyler Chatow4fedeea2019-03-10 15:33:36 -07005#include <chrono>
Sabina Davis91b23602019-01-21 00:06:01 -08006
7#include "aos/actions/actions.h"
8#include "aos/init.h"
9#include "aos/input/action_joystick_input.h"
10#include "aos/input/driver_station_data.h"
11#include "aos/input/drivetrain_input.h"
12#include "aos/input/joystick_input.h"
13#include "aos/logging/logging.h"
14#include "aos/logging/logging.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080015#include "aos/network/team_number.h"
Sabina Davis91b23602019-01-21 00:06:01 -080016#include "aos/util/log_interval.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080017#include "aos/vision/events/udp.h"
18#include "external/com_google_protobuf/src/google/protobuf/stubs/stringprintf.h"
Sabina Davis91b23602019-01-21 00:06:01 -080019#include "frc971/autonomous/auto.q.h"
20#include "frc971/autonomous/base_autonomous_actor.h"
21#include "frc971/control_loops/drivetrain/drivetrain.q.h"
James Kuszmauld8deb682019-03-10 10:38:42 -070022#include "frc971/control_loops/drivetrain/localizer.q.h"
Sabina Davis91b23602019-01-21 00:06:01 -080023
24#include "y2019/control_loops/drivetrain/drivetrain_base.h"
25#include "y2019/control_loops/superstructure/superstructure.q.h"
Sabina Davisc6329342019-03-01 20:44:42 -080026#include "y2019/status_light.q.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080027#include "y2019/vision.pb.h"
Sabina Davis91b23602019-01-21 00:06:01 -080028
29using ::y2019::control_loops::superstructure::superstructure_queue;
James Kuszmauld8deb682019-03-10 10:38:42 -070030using ::frc971::control_loops::drivetrain::localizer_control;
Sabina Davis91b23602019-01-21 00:06:01 -080031using ::aos::input::driver_station::ButtonLocation;
32using ::aos::input::driver_station::ControlBit;
33using ::aos::input::driver_station::JoystickAxis;
34using ::aos::input::driver_station::POVLocation;
Tyler Chatowe0241452019-03-08 21:07:50 -080035using ::aos::events::ProtoTXUdpSocket;
Sabina Davis91b23602019-01-21 00:06:01 -080036
Austin Schuhaab7e162019-03-13 22:44:58 -070037namespace chrono = ::std::chrono;
38
Sabina Davis91b23602019-01-21 00:06:01 -080039namespace y2019 {
40namespace input {
41namespace joysticks {
42
Tyler Chatowe0241452019-03-08 21:07:50 -080043using google::protobuf::StringPrintf;
44
Austin Schuh1a17e132019-02-17 15:05:06 -080045const ButtonLocation kSuctionBall(3, 13);
46const ButtonLocation kSuctionHatch(3, 12);
47const ButtonLocation kDeployStilt(3, 8);
Sabina Davis069cbca2019-03-08 23:35:18 -080048const ButtonLocation kHalfStilt(3, 6);
Austin Schuh1a17e132019-02-17 15:05:06 -080049const ButtonLocation kFallOver(3, 9);
Austin Schuh2cf16b82019-02-15 23:23:22 -080050
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080051struct ElevatorWristPosition {
52 double elevator;
53 double wrist;
54};
Sabina Davis91b23602019-01-21 00:06:01 -080055
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080056const ButtonLocation kRocketForwardLower(5, 1);
57const ButtonLocation kRocketForwardMiddle(5, 2);
58const ButtonLocation kRocketForwardUpper(5, 4);
59const ButtonLocation kCargoForward(5, 3);
60
61const POVLocation kRocketBackwardUnpressed(5, -1);
62const POVLocation kRocketBackwardLower(5, 180);
63const POVLocation kRocketBackwardMiddle(5, 90);
64const POVLocation kRocketBackwardUpper(5, 0);
65const POVLocation kCargoBackward(5, 270);
66
67const ButtonLocation kPanelSwitch(5, 7);
68const ButtonLocation kCargoSwitch(5, 8);
69
70const ButtonLocation kBallHPIntakeForward(5, 6);
71const ButtonLocation kBallHPIntakeBackward(5, 5);
72const JoystickAxis kBallOutake(5, 3);
73const JoystickAxis kBallIntake(5, 4);
74
75const ButtonLocation kPanelHPIntakeForward(5, 6);
76const ButtonLocation kPanelHPIntakeBackward(5, 5);
77
78const ButtonLocation kRelease(2, 4);
Austin Schuhbb1df6f2019-03-17 18:15:43 -070079const ButtonLocation kResetLocalizerLeftForwards(3, 14);
80const ButtonLocation kResetLocalizerLeftBackwards(4, 12);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080081
Austin Schuhbb1df6f2019-03-17 18:15:43 -070082const ButtonLocation kResetLocalizerRightForwards(4, 1);
83const ButtonLocation kResetLocalizerRightBackwards(4, 11);
Tyler Chatow07c906b2019-03-09 21:29:06 -080084
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080085const ElevatorWristPosition kStowPos{0.36, 0.0};
86
Austin Schuh139f59d2019-03-17 18:16:13 -070087const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
88const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080089
90const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0};
91const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0};
92
Sabina Davise48004f2019-03-02 23:15:24 -080093const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
94const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080095
Sabina Davise48004f2019-03-02 23:15:24 -080096const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0};
97const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080098
Sabina Davise6fe6c52019-03-03 15:48:51 -080099const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0};
100const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
101
Austin Schuh139f59d2019-03-17 18:16:13 -0700102const ElevatorWristPosition kBallForwardLowerPos{0.42, M_PI / 2.0};
103const ElevatorWristPosition kBallBackwardLowerPos{0.14, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800104
Sabina Davise48004f2019-03-02 23:15:24 -0800105const ElevatorWristPosition kBallForwardMiddlePos{1.16, 1.546};
Austin Schuh139f59d2019-03-17 18:16:13 -0700106const ElevatorWristPosition kBallBackwardMiddlePos{0.90, -1.546};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800107
Austin Schuh139f59d2019-03-17 18:16:13 -0700108const ElevatorWristPosition kBallForwardUpperPos{1.51, 0.961};
109const ElevatorWristPosition kBallBackwardUpperPos{1.44, -1.217};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800110
Austin Schuh139f59d2019-03-17 18:16:13 -0700111const ElevatorWristPosition kBallCargoForwardPos{0.739044, 1.353};
112const ElevatorWristPosition kBallCargoBackwardPos{0.868265, -1.999};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800113
Sabina Davise6fe6c52019-03-03 15:48:51 -0800114const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097};
115const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800116
117const ElevatorWristPosition kBallIntakePos{0.29, 2.14};
Austin Schuh2cf16b82019-02-15 23:23:22 -0800118
Sabina Davis91b23602019-01-21 00:06:01 -0800119class Reader : public ::aos::input::ActionJoystickInput {
120 public:
121 Reader(::aos::EventLoop *event_loop)
122 : ::aos::input::ActionJoystickInput(
123 event_loop,
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800124 ::y2019::control_loops::drivetrain::GetDrivetrainConfig()) {
Austin Schuh30cc40a2019-03-12 21:02:13 -0700125 // Set teleop to immediately resume after auto ends for sandstorm mode.
126 set_run_teleop_in_auto(true);
127
Tyler Chatowe0241452019-03-08 21:07:50 -0800128 const uint16_t team = ::aos::network::GetTeamNumber();
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800129 superstructure_queue.goal.FetchLatest();
130 if (superstructure_queue.goal.get()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800131 grab_piece_ = superstructure_queue.goal->suction.grab_piece;
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700132 switch_ball_ = superstructure_queue.goal->suction.gamepiece_mode == 0;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800133 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800134 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
135 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800136 }
Sabina Davis91b23602019-01-21 00:06:01 -0800137
Austin Schuha78857f2019-03-13 22:43:41 -0700138 void AutoEnded() override {
139 LOG(INFO, "Auto ended, assuming disc and have piece\n");
140 grab_piece_ = true;
141 switch_ball_ = false;
142 }
143
144 void HandleTeleop(const ::aos::input::driver_station::Data &data) override {
Austin Schuhaab7e162019-03-13 22:44:58 -0700145 ::aos::monotonic_clock::time_point monotonic_now =
146 ::aos::monotonic_clock::now();
Sabina Davis91b23602019-01-21 00:06:01 -0800147 superstructure_queue.position.FetchLatest();
148 superstructure_queue.status.FetchLatest();
149 if (!superstructure_queue.status.get() ||
150 !superstructure_queue.position.get()) {
151 LOG(ERROR, "Got no superstructure status packet.\n");
152 return;
153 }
154
Austin Schuhaab7e162019-03-13 22:44:58 -0700155 if (!superstructure_queue.status->has_piece) {
156 last_not_has_piece_ = monotonic_now;
157 }
158
Sabina Davis91b23602019-01-21 00:06:01 -0800159 auto new_superstructure_goal = superstructure_queue.goal.MakeMessage();
160
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700161 if (data.PosEdge(kResetLocalizerLeftForwards)) {
James Kuszmauld8deb682019-03-10 10:38:42 -0700162 auto localizer_resetter = localizer_control.MakeMessage();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700163 // Start at the left feeder station.
James Kuszmauld8deb682019-03-10 10:38:42 -0700164 localizer_resetter->x = 0.4;
165 localizer_resetter->y = 3.4;
166 localizer_resetter->theta = 0.0;
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700167
168 if (!localizer_resetter.Send()) {
169 LOG(ERROR, "Failed to reset localizer.\n");
170 }
171 }
172
173 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
174 auto localizer_resetter = localizer_control.MakeMessage();
175 // Start at the left feeder station.
176 localizer_resetter->x = 0.4;
177 localizer_resetter->y = 3.4;
178 localizer_resetter->theta = M_PI;
179
180 if (!localizer_resetter.Send()) {
181 LOG(ERROR, "Failed to reset localizer.\n");
182 }
183 }
184
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700185 if (data.PosEdge(kResetLocalizerRightForwards)) {
186 auto localizer_resetter = localizer_control.MakeMessage();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700187 // Start at the right feeder station.
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700188 localizer_resetter->x = 0.4;
189 localizer_resetter->y = -3.4;
190 localizer_resetter->theta = 0.0;
191
192 if (!localizer_resetter.Send()) {
193 LOG(ERROR, "Failed to reset localizer.\n");
194 }
195 }
196
197 if (data.PosEdge(kResetLocalizerRightBackwards)) {
198 auto localizer_resetter = localizer_control.MakeMessage();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700199 // Start at the right feeder station.
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700200 localizer_resetter->x = 0.4;
201 localizer_resetter->y = -3.4;
202 localizer_resetter->theta = M_PI;
203
James Kuszmauld8deb682019-03-10 10:38:42 -0700204 if (!localizer_resetter.Send()) {
205 LOG(ERROR, "Failed to reset localizer.\n");
206 }
207 }
208
Austin Schuh1a17e132019-02-17 15:05:06 -0800209 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800210 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800211 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800212 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800213 } else if (data.IsPressed(kRelease) ||
214 !superstructure_queue.status->has_piece) {
Sabina Davisc6329342019-03-01 20:44:42 -0800215 grab_piece_ = false;
Austin Schuh1a17e132019-02-17 15:05:06 -0800216 }
Sabina Davis91b23602019-01-21 00:06:01 -0800217
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800218 if (data.IsPressed(kRocketBackwardUnpressed)) {
219 elevator_wrist_pos_ = kStowPos;
220 }
221 new_superstructure_goal->intake.unsafe_goal = -1.2;
222 new_superstructure_goal->roller_voltage = 0.0;
223
224 const bool kDoBallIntake = data.GetAxis(kBallIntake) > 0.9;
225 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
226
227 if (data.IsPressed(kPanelSwitch)) {
228 switch_ball_ = false;
229 } else if (data.IsPressed(kCargoSwitch)) {
230 switch_ball_ = true;
231 }
232
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800233 if (switch_ball_) {
234 if (superstructure_queue.status->has_piece) {
235 new_superstructure_goal->wrist.profile_params.max_acceleration = 20;
Austin Schuh1a17e132019-02-17 15:05:06 -0800236 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800237
238 // Go to intake position and apply vacuum
239 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800240 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800241 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
242 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800243 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800244 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
245 }
246
247 // Go to elevator/wrist position. Overrides intake position if pressed so
248 // we can re-grab the ball.
249 if (data.IsPressed(kRocketForwardLower)) {
250 elevator_wrist_pos_ = kBallForwardLowerPos;
251 } else if (data.IsPressed(kRocketBackwardLower)) {
252 elevator_wrist_pos_ = kBallBackwardLowerPos;
253 } else if (data.IsPressed(kRocketForwardMiddle)) {
254 elevator_wrist_pos_ = kBallForwardMiddlePos;
255 } else if (data.IsPressed(kRocketBackwardMiddle)) {
256 elevator_wrist_pos_ = kBallBackwardMiddlePos;
257 } else if (data.IsPressed(kRocketForwardUpper)) {
258 elevator_wrist_pos_ = kBallForwardUpperPos;
259 } else if (data.IsPressed(kRocketBackwardUpper)) {
260 elevator_wrist_pos_ = kBallBackwardUpperPos;
261 } else if (data.IsPressed(kCargoForward)) {
262 elevator_wrist_pos_ = kBallCargoForwardPos;
263 } else if (data.IsPressed(kCargoBackward)) {
264 elevator_wrist_pos_ = kBallCargoBackwardPos;
265 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800266 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800267 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800268 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800269 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
270 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800271 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800272 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
273 }
274
275 // Go to elevator/wrist position. Overrides intake position if pressed so
276 // we can re-grab the panel.
277 if (data.IsPressed(kRocketForwardLower)) {
278 elevator_wrist_pos_ = kPanelForwardLowerPos;
279 } else if (data.IsPressed(kRocketBackwardLower)) {
280 elevator_wrist_pos_ = kPanelBackwardLowerPos;
281 } else if (data.IsPressed(kRocketForwardMiddle)) {
282 elevator_wrist_pos_ = kPanelForwardMiddlePos;
283 } else if (data.IsPressed(kRocketBackwardMiddle)) {
284 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
285 } else if (data.IsPressed(kRocketForwardUpper)) {
286 elevator_wrist_pos_ = kPanelForwardUpperPos;
287 } else if (data.IsPressed(kRocketBackwardUpper)) {
288 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800289 } else if (data.IsPressed(kCargoForward)) {
290 elevator_wrist_pos_ = kPanelCargoForwardPos;
291 } else if (data.IsPressed(kCargoBackward)) {
292 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800293 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800294 }
295
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800296 if (switch_ball_) {
297 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700298 (kDoBallIntake &&
299 monotonic_now < last_not_has_piece_ + chrono::milliseconds(100))) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800300 new_superstructure_goal->intake.unsafe_goal = 0.959327;
301 }
Austin Schuh23a51632019-02-19 16:50:36 -0800302
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800303 if (kDoBallIntake && !superstructure_queue.status->has_piece) {
304 elevator_wrist_pos_ = kBallIntakePos;
305 new_superstructure_goal->roller_voltage = 9.0;
Sabina Davisc6329342019-03-01 20:44:42 -0800306 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800307 } else {
308 if (kDoBallOutake) {
309 new_superstructure_goal->roller_voltage = -6.0;
310 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800311 new_superstructure_goal->roller_voltage = 0.0;
312 }
313 }
Austin Schuh23a51632019-02-19 16:50:36 -0800314 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800315
Austin Schuh457bde32019-03-17 18:16:41 -0700316 constexpr double kDeployStiltPosition = 0.5;
317
318 // TODO(sabina): max height please?
319 if (data.IsPressed(kFallOver)) {
320 new_superstructure_goal->stilts.unsafe_goal = 0.71;
321 new_superstructure_goal->stilts.profile_params.max_velocity = 0.65;
322 new_superstructure_goal->stilts.profile_params.max_acceleration = 1.25;
323 } else if (data.IsPressed(kDeployStilt)) {
324 new_superstructure_goal->stilts.unsafe_goal = kDeployStiltPosition;
325 new_superstructure_goal->stilts.profile_params.max_velocity = 0.65;
326 new_superstructure_goal->stilts.profile_params.max_acceleration = 2.0;
327 } else if (data.IsPressed(kHalfStilt)) {
328 new_superstructure_goal->stilts.unsafe_goal = 0.345;
329 new_superstructure_goal->stilts.profile_params.max_velocity = 0.65;
330 } else {
331 new_superstructure_goal->stilts.unsafe_goal = 0.005;
332 new_superstructure_goal->stilts.profile_params.max_velocity = 0.65;
333 new_superstructure_goal->stilts.profile_params.max_acceleration = 2.0;
334 }
335
336 if (superstructure_queue.status->stilts.position > kDeployStiltPosition &&
337 new_superstructure_goal->stilts.unsafe_goal == kDeployStiltPosition) {
338 new_superstructure_goal->stilts.profile_params.max_velocity = 0.30;
339 new_superstructure_goal->stilts.profile_params.max_acceleration = 0.75;
340 }
341
342
Austin Schuh1a17e132019-02-17 15:05:06 -0800343 if (data.IsPressed(kRelease)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800344 grab_piece_ = false;
Austin Schuh1a17e132019-02-17 15:05:06 -0800345 }
346
Sabina Davisc6329342019-03-01 20:44:42 -0800347 if (switch_ball_) {
348 new_superstructure_goal->suction.gamepiece_mode = 0;
349 } else {
350 new_superstructure_goal->suction.gamepiece_mode = 1;
351 }
352
Tyler Chatowe0241452019-03-08 21:07:50 -0800353 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
354
Sabina Davisc6329342019-03-01 20:44:42 -0800355 new_superstructure_goal->suction.grab_piece = grab_piece_;
Sabina Davis91b23602019-01-21 00:06:01 -0800356
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800357 new_superstructure_goal->elevator.unsafe_goal =
358 elevator_wrist_pos_.elevator;
359 new_superstructure_goal->wrist.unsafe_goal = elevator_wrist_pos_.wrist;
Sabina Davis91b23602019-01-21 00:06:01 -0800360
361 LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal);
362 if (!new_superstructure_goal.Send()) {
363 LOG(ERROR, "Sending superstructure goal failed.\n");
364 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800365
Austin Schuhaab7e162019-03-13 22:44:58 -0700366 if (monotonic_now >
367 last_vision_control_ + ::std::chrono::milliseconds(50)) {
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700368 video_tx_->Send(vision_control_);
Austin Schuhaab7e162019-03-13 22:44:58 -0700369 last_vision_control_ = monotonic_now;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700370 }
Sabina Davis91b23602019-01-21 00:06:01 -0800371 }
372
373 private:
374 // Current goals here.
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800375 ElevatorWristPosition elevator_wrist_pos_ = kStowPos;
Sabina Davisc6329342019-03-01 20:44:42 -0800376 bool grab_piece_ = false;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800377
378 bool switch_ball_ = false;
Tyler Chatowe0241452019-03-08 21:07:50 -0800379
380 VisionControl vision_control_;
381 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700382 ::aos::monotonic_clock::time_point last_vision_control_ =
383 ::aos::monotonic_clock::time_point::min();
Austin Schuhaab7e162019-03-13 22:44:58 -0700384
385 // Time at which we last did not have a game piece.
386 ::aos::monotonic_clock::time_point last_not_has_piece_ =
387 ::aos::monotonic_clock::time_point::min();
Sabina Davis91b23602019-01-21 00:06:01 -0800388};
389
390} // namespace joysticks
391} // namespace input
392} // namespace y2019
393
394int main() {
395 ::aos::Init(-1);
396 ::aos::ShmEventLoop event_loop;
397 ::y2019::input::joysticks::Reader reader(&event_loop);
398 reader.Run();
399 ::aos::Cleanup();
400}