blob: 427fc6d4c2d85d5c02d0bf69c3a33f8f326fef78 [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"
Tyler Chatowe0241452019-03-08 21:07:50 -080014#include "aos/network/team_number.h"
Sabina Davis91b23602019-01-21 00:06:01 -080015#include "aos/util/log_interval.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080016#include "aos/vision/events/udp.h"
17#include "external/com_google_protobuf/src/google/protobuf/stubs/stringprintf.h"
Sabina Davis91b23602019-01-21 00:06:01 -080018#include "frc971/autonomous/base_autonomous_actor.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070019#include "frc971/control_loops/drivetrain/localizer_generated.h"
Sabina Davis91b23602019-01-21 00:06:01 -080020
Austin Schuhed5b26d2019-12-05 20:51:59 -080021#include "y2019/camera_log_generated.h"
Sabina Davis91b23602019-01-21 00:06:01 -080022#include "y2019/control_loops/drivetrain/drivetrain_base.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070023#include "y2019/control_loops/drivetrain/target_selector_generated.h"
24#include "y2019/control_loops/superstructure/superstructure_goal_generated.h"
25#include "y2019/control_loops/superstructure/superstructure_position_generated.h"
26#include "y2019/control_loops/superstructure/superstructure_status_generated.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080027#include "y2019/vision.pb.h"
Sabina Davis91b23602019-01-21 00:06:01 -080028
Alex Perrycb7da4b2019-08-28 19:35:56 -070029using aos::events::ProtoTXUdpSocket;
30using aos::input::driver_station::ButtonLocation;
31using aos::input::driver_station::ControlBit;
32using aos::input::driver_station::JoystickAxis;
33using aos::input::driver_station::POVLocation;
34using frc971::CreateProfileParameters;
35using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal;
36using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
37using frc971::control_loops::drivetrain::LocalizerControl;
James Kuszmaul2457eb72019-12-15 15:37:18 -080038using y2019::control_loops::superstructure::SuctionGoal;
39using y2019::control_loops::superstructure::CreateSuctionGoal;
Sabina Davis91b23602019-01-21 00:06:01 -080040
Austin Schuhaab7e162019-03-13 22:44:58 -070041namespace chrono = ::std::chrono;
42
Sabina Davis91b23602019-01-21 00:06:01 -080043namespace y2019 {
44namespace input {
45namespace joysticks {
46
Alex Perrycb7da4b2019-08-28 19:35:56 -070047namespace superstructure = y2019::control_loops::superstructure;
48
Tyler Chatowe0241452019-03-08 21:07:50 -080049using google::protobuf::StringPrintf;
50
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 Chatow5eeee902019-04-12 20:47:48 -070056const ButtonLocation kSuctionBall(4, 2);
57const ButtonLocation kSuctionHatch(3, 15);
58const ButtonLocation kDeployStilt(4, 1);
59const ButtonLocation kHalfStilt(4, 3);
60const ButtonLocation kFallOver(3, 16);
61
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080062const ButtonLocation kRocketForwardLower(5, 1);
63const ButtonLocation kRocketForwardMiddle(5, 2);
64const ButtonLocation kRocketForwardUpper(5, 4);
65const ButtonLocation kCargoForward(5, 3);
66
67const POVLocation kRocketBackwardUnpressed(5, -1);
68const POVLocation kRocketBackwardLower(5, 180);
69const POVLocation kRocketBackwardMiddle(5, 90);
70const POVLocation kRocketBackwardUpper(5, 0);
71const POVLocation kCargoBackward(5, 270);
72
73const ButtonLocation kPanelSwitch(5, 7);
74const ButtonLocation kCargoSwitch(5, 8);
75
76const ButtonLocation kBallHPIntakeForward(5, 6);
77const ButtonLocation kBallHPIntakeBackward(5, 5);
78const JoystickAxis kBallOutake(5, 3);
79const JoystickAxis kBallIntake(5, 4);
80
81const ButtonLocation kPanelHPIntakeForward(5, 6);
82const ButtonLocation kPanelHPIntakeBackward(5, 5);
83
84const ButtonLocation kRelease(2, 4);
James Kuszmaulccc368b2019-04-11 20:00:07 -070085// Reuse quickturn for the cancel button.
86const ButtonLocation kCancelAutoMode(2, 3);
Tyler Chatow5eeee902019-04-12 20:47:48 -070087const ButtonLocation kReleaseButtonBoard(3, 4);
88const ButtonLocation kResetLocalizerLeftForwards(3, 10);
89const ButtonLocation kResetLocalizerLeftBackwards(3, 9);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080090
Tyler Chatow5eeee902019-04-12 20:47:48 -070091const ButtonLocation kResetLocalizerRightForwards(3, 8);
92const ButtonLocation kResetLocalizerRightBackwards(3, 7);
Tyler Chatow07c906b2019-03-09 21:29:06 -080093
James Kuszmaul518640d2019-04-13 15:50:50 -070094const ButtonLocation kResetLocalizerLeft(3, 11);
95const ButtonLocation kResetLocalizerRight(3, 13);
96
Tyler Chatow5eeee902019-04-12 20:47:48 -070097const ButtonLocation kNearCargoHint(3, 3);
98const ButtonLocation kMidCargoHint(3, 5);
99const ButtonLocation kFarCargoHint(3, 6);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700100
James Kuszmaul518640d2019-04-13 15:50:50 -0700101const JoystickAxis kCargoSelectorY(5, 6);
102const JoystickAxis kCargoSelectorX(5, 5);
103
Tyler Chatow5eeee902019-04-12 20:47:48 -0700104const ButtonLocation kCameraLog(3, 14);
Austin Schuh4e2629d2019-03-28 14:44:37 -0700105
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800106const ElevatorWristPosition kStowPos{0.36, 0.0};
Austin Schuh02be8b92019-03-24 16:04:14 -0700107const ElevatorWristPosition kClimbPos{0.0, M_PI / 4.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800108
Austin Schuh139f59d2019-03-17 18:16:13 -0700109const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
110const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800111
112const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0};
113const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0};
114
Sabina Davise48004f2019-03-02 23:15:24 -0800115const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
116const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800117
Sabina Davise48004f2019-03-02 23:15:24 -0800118const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0};
119const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800120
Sabina Davise6fe6c52019-03-03 15:48:51 -0800121const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0};
122const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
123
Austin Schuh6c5deb12019-03-24 16:48:32 -0700124const ElevatorWristPosition kBallForwardLowerPos{0.21, 1.27};
Austin Schuh20dc0502019-03-30 07:24:07 -0700125const ElevatorWristPosition kBallBackwardLowerPos{0.43, -1.99};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800126
Austin Schuh20dc0502019-03-30 07:24:07 -0700127const ElevatorWristPosition kBallForwardMiddlePos{0.925, 1.21};
128const ElevatorWristPosition kBallBackwardMiddlePos{1.19, -1.98};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800129
Austin Schuh139f59d2019-03-17 18:16:13 -0700130const ElevatorWristPosition kBallForwardUpperPos{1.51, 0.961};
131const ElevatorWristPosition kBallBackwardUpperPos{1.44, -1.217};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800132
Austin Schuh20dc0502019-03-30 07:24:07 -0700133const ElevatorWristPosition kBallCargoForwardPos{0.59, 1.2};
134const ElevatorWristPosition kBallCargoBackwardPos{0.868265, -2.1};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800135
Sabina Davise6fe6c52019-03-03 15:48:51 -0800136const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097};
137const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800138
Austin Schuh20dc0502019-03-30 07:24:07 -0700139const ElevatorWristPosition kBallIntakePos{0.309, 2.13};
Austin Schuh2cf16b82019-02-15 23:23:22 -0800140
Sabina Davis91b23602019-01-21 00:06:01 -0800141class Reader : public ::aos::input::ActionJoystickInput {
142 public:
143 Reader(::aos::EventLoop *event_loop)
144 : ::aos::input::ActionJoystickInput(
145 event_loop,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700146 ::y2019::control_loops::drivetrain::GetDrivetrainConfig(),
Austin Schuhbfb04122019-05-22 21:16:51 -0700147 ::aos::input::DrivetrainInputReader::InputType::kPistol,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700148 {.run_teleop_in_auto = true,
Austin Schuhc087b102019-05-12 15:33:12 -0700149 .cancel_auto_button = kCancelAutoMode}),
150 target_selector_hint_sender_(
151 event_loop->MakeSender<
152 ::y2019::control_loops::drivetrain::TargetSelectorHint>(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700153 "/drivetrain")),
Austin Schuheb99d072019-05-12 21:03:38 -0700154 localizer_control_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700155 event_loop->MakeSender<LocalizerControl>("/drivetrain")),
Austin Schuh5671a8c2019-05-19 17:01:04 -0700156 camera_log_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700157 event_loop->MakeSender<::y2019::CameraLog>("/camera")),
158 superstructure_goal_fetcher_(
159 event_loop->MakeFetcher<superstructure::Goal>("/superstructure")),
160 superstructure_goal_sender_(
161 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700162 superstructure_position_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700163 event_loop->MakeFetcher<superstructure::Position>(
164 "/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700165 superstructure_status_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700166 event_loop->MakeFetcher<superstructure::Status>(
167 "/superstructure")) {
Tyler Chatowe0241452019-03-08 21:07:50 -0800168 const uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuh170f4952019-06-29 18:58:30 -0700169 superstructure_goal_fetcher_.Fetch();
170 if (superstructure_goal_fetcher_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700171 grab_piece_ = superstructure_goal_fetcher_->has_suction()
172 ? superstructure_goal_fetcher_->suction()->grab_piece()
173 : false;
174 switch_ball_ =
175 superstructure_goal_fetcher_->has_suction()
176 ? (superstructure_goal_fetcher_->suction()->gamepiece_mode() == 0)
177 : true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800178 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800179 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
180 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800181 }
Sabina Davis91b23602019-01-21 00:06:01 -0800182
Austin Schuha78857f2019-03-13 22:43:41 -0700183 void AutoEnded() override {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700184 AOS_LOG(INFO, "Auto ended, assuming disc and have piece\n");
Austin Schuha78857f2019-03-13 22:43:41 -0700185 grab_piece_ = true;
186 switch_ball_ = false;
187 }
188
189 void HandleTeleop(const ::aos::input::driver_station::Data &data) override {
Austin Schuhaab7e162019-03-13 22:44:58 -0700190 ::aos::monotonic_clock::time_point monotonic_now =
191 ::aos::monotonic_clock::now();
Austin Schuh170f4952019-06-29 18:58:30 -0700192 superstructure_position_fetcher_.Fetch();
193 superstructure_status_fetcher_.Fetch();
194 if (!superstructure_status_fetcher_.get() ||
195 !superstructure_position_fetcher_.get()) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700196 AOS_LOG(ERROR, "Got no superstructure status or position packet.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800197 return;
198 }
199
Alex Perrycb7da4b2019-08-28 19:35:56 -0700200 CHECK(superstructure_status_fetcher_->has_stilts());
201
202 if (!superstructure_status_fetcher_->has_piece()) {
Austin Schuhaab7e162019-03-13 22:44:58 -0700203 last_not_has_piece_ = monotonic_now;
204 }
205
Alex Perrycb7da4b2019-08-28 19:35:56 -0700206 auto main_superstructure_goal_builder =
207 superstructure_goal_sender_.MakeBuilder();
208
209 flatbuffers::Offset<superstructure::Goal> superstructure_goal_offset;
Sabina Davis91b23602019-01-21 00:06:01 -0800210
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700211 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700212 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
213 elevator_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
214 *main_superstructure_goal_builder.fbb(), 0.0,
215 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
216 0.0, 0.0));
217
218 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
219 intake_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
220 *main_superstructure_goal_builder.fbb(), -1.2);
221
222 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
223 wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
224 *main_superstructure_goal_builder.fbb(), 0.0,
225 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
226 0.0, 0.0));
227
228 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
229 stilts_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
230 *main_superstructure_goal_builder.fbb(), 0.0,
231 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
232 0.0, 0.0));
233
James Kuszmaul2457eb72019-12-15 15:37:18 -0800234 flatbuffers::Offset<SuctionGoal> suction_offset =
235 CreateSuctionGoal(*main_superstructure_goal_builder.fbb(), false, 0);
236
Alex Perrycb7da4b2019-08-28 19:35:56 -0700237 superstructure::Goal::Builder superstructure_goal_builder =
238 main_superstructure_goal_builder.MakeBuilder<superstructure::Goal>();
239
240 superstructure_goal_builder.add_elevator(elevator_offset);
241 superstructure_goal_builder.add_intake(intake_offset);
242 superstructure_goal_builder.add_wrist(wrist_offset);
243 superstructure_goal_builder.add_stilts(stilts_offset);
James Kuszmaul2457eb72019-12-15 15:37:18 -0800244 superstructure_goal_builder.add_suction(suction_offset);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700245 superstructure_goal_builder.add_roller_voltage(0.0);
246
247 superstructure_goal_offset = superstructure_goal_builder.Finish();
248 }
James Kuszmaul2457eb72019-12-15 15:37:18 -0800249 superstructure::Goal *mutable_superstructure_goal = CHECK_NOTNULL(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700250 GetMutableTemporaryPointer(*main_superstructure_goal_builder.fbb(),
James Kuszmaul2457eb72019-12-15 15:37:18 -0800251 superstructure_goal_offset));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700252
253 {
254 auto builder = target_selector_hint_sender_.MakeBuilder();
255 control_loops::drivetrain::TargetSelectorHint::Builder
256 target_selector_hint_builder =
257 builder
258 .MakeBuilder<control_loops::drivetrain::TargetSelectorHint>();
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700259 if (data.IsPressed(kNearCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700260 target_selector_hint_builder.add_suggested_target(
261 control_loops::drivetrain::SelectionHint_NEAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700262 } else if (data.IsPressed(kMidCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700263 target_selector_hint_builder.add_suggested_target(
264 control_loops::drivetrain::SelectionHint_MID_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700265 } else if (data.IsPressed(kFarCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700266 target_selector_hint_builder.add_suggested_target(
267 control_loops::drivetrain::SelectionHint_FAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700268 } else {
James Kuszmaul518640d2019-04-13 15:50:50 -0700269 const double cargo_joy_y = data.GetAxis(kCargoSelectorY);
270 const double cargo_joy_x = data.GetAxis(kCargoSelectorX);
271 if (cargo_joy_y > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700272 target_selector_hint_builder.add_suggested_target(
273 control_loops::drivetrain::SelectionHint_NEAR_SHIP);
James Kuszmaul1b822b42019-04-14 14:27:35 -0700274 } else if (cargo_joy_y < -0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700275 target_selector_hint_builder.add_suggested_target(
276 control_loops::drivetrain::SelectionHint_FAR_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700277 } else if (::std::abs(cargo_joy_x) > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700278 target_selector_hint_builder.add_suggested_target(
279 control_loops::drivetrain::SelectionHint_MID_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700280 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700281 target_selector_hint_builder.add_suggested_target(
282 control_loops::drivetrain::SelectionHint_NONE);
James Kuszmaul518640d2019-04-13 15:50:50 -0700283 }
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700284 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700285 if (!builder.Send(target_selector_hint_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700286 AOS_LOG(ERROR, "Failed to send target selector hint.\n");
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700287 }
288 }
289
James Kuszmaul518640d2019-04-13 15:50:50 -0700290 if (data.PosEdge(kResetLocalizerLeft)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700291 auto builder = localizer_control_sender_.MakeBuilder();
James Kuszmaul518640d2019-04-13 15:50:50 -0700292 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700293 LocalizerControl::Builder localizer_control_builder =
294 builder.MakeBuilder<LocalizerControl>();
295 localizer_control_builder.add_x(0.6);
296 localizer_control_builder.add_y(3.4);
297 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700298
Alex Perrycb7da4b2019-08-28 19:35:56 -0700299 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700300 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700301 }
302 }
303
304 if (data.PosEdge(kResetLocalizerRight)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700305 auto builder = localizer_control_sender_.MakeBuilder();
306 // Start at the right feeder station.
307 LocalizerControl::Builder localizer_control_builder =
308 builder.MakeBuilder<LocalizerControl>();
309 localizer_control_builder.add_x(0.6);
310 localizer_control_builder.add_y(-3.4);
311 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700312
Alex Perrycb7da4b2019-08-28 19:35:56 -0700313 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700314 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700315 }
316 }
317
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700318 if (data.PosEdge(kResetLocalizerLeftForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700319 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700320 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700321 LocalizerControl::Builder localizer_control_builder =
322 builder.MakeBuilder<LocalizerControl>();
323 localizer_control_builder.add_x(0.4);
324 localizer_control_builder.add_y(3.4);
325 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700326
Alex Perrycb7da4b2019-08-28 19:35:56 -0700327 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700328 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700329 }
330 }
331
332 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700333 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700334 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700335 LocalizerControl::Builder localizer_control_builder =
336 builder.MakeBuilder<LocalizerControl>();
337 localizer_control_builder.add_x(0.4);
338 localizer_control_builder.add_y(3.4);
339 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700340
Alex Perrycb7da4b2019-08-28 19:35:56 -0700341 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700342 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700343 }
344 }
345
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700346 if (data.PosEdge(kResetLocalizerRightForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700347 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700348 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700349 LocalizerControl::Builder localizer_control_builder =
350 builder.MakeBuilder<LocalizerControl>();
351 localizer_control_builder.add_x(0.4);
352 localizer_control_builder.add_y(-3.4);
353 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700354
Alex Perrycb7da4b2019-08-28 19:35:56 -0700355 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700356 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700357 }
358 }
359
360 if (data.PosEdge(kResetLocalizerRightBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700361 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700362 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700363 LocalizerControl::Builder localizer_control_builder =
364 builder.MakeBuilder<LocalizerControl>();
365 localizer_control_builder.add_x(0.4);
366 localizer_control_builder.add_y(-3.4);
367 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700368
Alex Perrycb7da4b2019-08-28 19:35:56 -0700369 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700370 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmauld8deb682019-03-10 10:38:42 -0700371 }
372 }
373
James Kuszmaul13738862019-04-14 10:48:00 -0700374 if (data.PosEdge(kRelease) &&
375 monotonic_now >
376 last_release_button_press_ + ::std::chrono::milliseconds(500)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700377 if (superstructure_status_fetcher_->has_piece()) {
James Kuszmaul13738862019-04-14 10:48:00 -0700378 release_mode_ = ReleaseButtonMode::kRelease;
379 } else {
380 release_mode_ = ReleaseButtonMode::kBallIntake;
381 }
382 }
383
384 if (data.IsPressed(kRelease)) {
385 last_release_button_press_ = monotonic_now;
386 }
387
Alex Perrycb7da4b2019-08-28 19:35:56 -0700388 AOS_LOG(INFO, "has_piece: %d\n",
389 superstructure_status_fetcher_->has_piece());
Austin Schuh1a17e132019-02-17 15:05:06 -0800390 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800391 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800392 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800393 grab_piece_ = true;
James Kuszmaul13738862019-04-14 10:48:00 -0700394 } else if ((release_mode_ == ReleaseButtonMode::kRelease &&
395 data.IsPressed(kRelease)) ||
Tyler Chatow5eeee902019-04-12 20:47:48 -0700396 data.IsPressed(kReleaseButtonBoard) ||
Alex Perrycb7da4b2019-08-28 19:35:56 -0700397 !superstructure_status_fetcher_->has_piece()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800398 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700399 AOS_LOG(INFO, "releasing due to other thing\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800400 }
Sabina Davis91b23602019-01-21 00:06:01 -0800401
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800402 if (data.IsPressed(kRocketBackwardUnpressed)) {
403 elevator_wrist_pos_ = kStowPos;
404 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700405 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(-1.2);
406 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800407
James Kuszmaul13738862019-04-14 10:48:00 -0700408 const bool kDoBallIntake =
409 (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake &&
410 data.IsPressed(kRelease)) ||
411 data.GetAxis(kBallIntake) > 0.9;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800412 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
413
414 if (data.IsPressed(kPanelSwitch)) {
415 switch_ball_ = false;
416 } else if (data.IsPressed(kCargoSwitch)) {
417 switch_ball_ = true;
418 }
419
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800420 if (switch_ball_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700421 if (superstructure_status_fetcher_->has_piece()) {
422 mutable_superstructure_goal->mutable_wrist()
423 ->mutable_profile_params()
424 ->mutate_max_acceleration(20);
Austin Schuh1a17e132019-02-17 15:05:06 -0800425 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800426
427 // Go to intake position and apply vacuum
428 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800429 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800430 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
431 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800432 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800433 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
434 }
435
436 // Go to elevator/wrist position. Overrides intake position if pressed so
437 // we can re-grab the ball.
438 if (data.IsPressed(kRocketForwardLower)) {
439 elevator_wrist_pos_ = kBallForwardLowerPos;
440 } else if (data.IsPressed(kRocketBackwardLower)) {
441 elevator_wrist_pos_ = kBallBackwardLowerPos;
442 } else if (data.IsPressed(kRocketForwardMiddle)) {
443 elevator_wrist_pos_ = kBallForwardMiddlePos;
444 } else if (data.IsPressed(kRocketBackwardMiddle)) {
445 elevator_wrist_pos_ = kBallBackwardMiddlePos;
446 } else if (data.IsPressed(kRocketForwardUpper)) {
447 elevator_wrist_pos_ = kBallForwardUpperPos;
448 } else if (data.IsPressed(kRocketBackwardUpper)) {
449 elevator_wrist_pos_ = kBallBackwardUpperPos;
450 } else if (data.IsPressed(kCargoForward)) {
451 elevator_wrist_pos_ = kBallCargoForwardPos;
452 } else if (data.IsPressed(kCargoBackward)) {
453 elevator_wrist_pos_ = kBallCargoBackwardPos;
454 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800455 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800456 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800457 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800458 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
459 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800460 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800461 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
462 }
463
464 // Go to elevator/wrist position. Overrides intake position if pressed so
465 // we can re-grab the panel.
466 if (data.IsPressed(kRocketForwardLower)) {
467 elevator_wrist_pos_ = kPanelForwardLowerPos;
468 } else if (data.IsPressed(kRocketBackwardLower)) {
469 elevator_wrist_pos_ = kPanelBackwardLowerPos;
470 } else if (data.IsPressed(kRocketForwardMiddle)) {
471 elevator_wrist_pos_ = kPanelForwardMiddlePos;
472 } else if (data.IsPressed(kRocketBackwardMiddle)) {
473 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
474 } else if (data.IsPressed(kRocketForwardUpper)) {
475 elevator_wrist_pos_ = kPanelForwardUpperPos;
476 } else if (data.IsPressed(kRocketBackwardUpper)) {
477 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800478 } else if (data.IsPressed(kCargoForward)) {
479 elevator_wrist_pos_ = kPanelCargoForwardPos;
480 } else if (data.IsPressed(kCargoBackward)) {
481 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800482 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800483 }
484
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800485 if (switch_ball_) {
486 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700487 (kDoBallIntake &&
Austin Schuh20dc0502019-03-30 07:24:07 -0700488 monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700489 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(0.83);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800490 }
Austin Schuh23a51632019-02-19 16:50:36 -0800491
Alex Perrycb7da4b2019-08-28 19:35:56 -0700492 if (kDoBallIntake && !superstructure_status_fetcher_->has_piece()) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800493 elevator_wrist_pos_ = kBallIntakePos;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700494 mutable_superstructure_goal->mutate_roller_voltage(9.0);
Sabina Davisc6329342019-03-01 20:44:42 -0800495 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800496 } else {
497 if (kDoBallOutake) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700498 mutable_superstructure_goal->mutate_roller_voltage(-6.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800499 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700500 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800501 }
502 }
Austin Schuh23a51632019-02-19 16:50:36 -0800503 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800504
Austin Schuh457bde32019-03-17 18:16:41 -0700505 constexpr double kDeployStiltPosition = 0.5;
506
Austin Schuh457bde32019-03-17 18:16:41 -0700507 if (data.IsPressed(kFallOver)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700508 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.71);
509 mutable_superstructure_goal->mutable_stilts()
510 ->mutable_profile_params()
511 ->mutate_max_velocity(0.65);
512 mutable_superstructure_goal->mutable_stilts()
513 ->mutable_profile_params()
514 ->mutate_max_acceleration(1.25);
Austin Schuhe2f22482019-04-13 23:05:43 -0700515 } else if (data.IsPressed(kHalfStilt)) {
516 was_above_ = false;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700517 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal ( 0.345);
518 mutable_superstructure_goal->mutable_stilts()->mutable_profile_params()->mutate_max_velocity ( 0.65);
Austin Schuhe2f22482019-04-13 23:05:43 -0700519 } else if (data.IsPressed(kDeployStilt) || was_above_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700520 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(
521 kDeployStiltPosition);
522 mutable_superstructure_goal->mutable_stilts()
523 ->mutable_profile_params()
524 ->mutate_max_velocity(0.65);
525 mutable_superstructure_goal->mutable_stilts()
526 ->mutable_profile_params()
527 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700528 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700529 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.005);
530 mutable_superstructure_goal->mutable_stilts()
531 ->mutable_profile_params()
532 ->mutate_max_velocity(0.65);
533 mutable_superstructure_goal->mutable_stilts()
534 ->mutable_profile_params()
535 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700536 }
537
Alex Perrycb7da4b2019-08-28 19:35:56 -0700538 if (superstructure_status_fetcher_->stilts()->position() > 0.1) {
Austin Schuh02be8b92019-03-24 16:04:14 -0700539 elevator_wrist_pos_ = kClimbPos;
James Kuszmaul13738862019-04-14 10:48:00 -0700540 climbed_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700541 mutable_superstructure_goal->mutable_wrist()
542 ->mutable_profile_params()
543 ->mutate_max_acceleration(10);
544 mutable_superstructure_goal->mutable_elevator()
545 ->mutable_profile_params()
546 ->mutate_max_acceleration(6);
Austin Schuh02be8b92019-03-24 16:04:14 -0700547 }
548
Austin Schuhe2f22482019-04-13 23:05:43 -0700549 // If we've been asked to go above deploy and made it up that high, latch
550 // was_above.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700551 if (mutable_superstructure_goal->stilts()->unsafe_goal() >
552 kDeployStiltPosition &&
553 superstructure_status_fetcher_->stilts()->position() >=
Austin Schuh170f4952019-06-29 18:58:30 -0700554 kDeployStiltPosition) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700555 was_above_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700556 } else if ((superstructure_position_fetcher_->platform_left_detect() &&
557 superstructure_position_fetcher_->platform_right_detect()) &&
Austin Schuhe2f22482019-04-13 23:05:43 -0700558 !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700559 was_above_ = false;
560 }
561
Alex Perrycb7da4b2019-08-28 19:35:56 -0700562 if (superstructure_status_fetcher_->stilts()->position() >
Austin Schuh170f4952019-06-29 18:58:30 -0700563 kDeployStiltPosition &&
Alex Perrycb7da4b2019-08-28 19:35:56 -0700564 mutable_superstructure_goal->stilts()->unsafe_goal() ==
565 kDeployStiltPosition) {
566 mutable_superstructure_goal->mutable_stilts()
567 ->mutable_profile_params()
568 ->mutate_max_velocity(0.30);
569 mutable_superstructure_goal->mutable_stilts()
570 ->mutable_profile_params()
571 ->mutate_max_acceleration(0.75);
Austin Schuh457bde32019-03-17 18:16:41 -0700572 }
573
James Kuszmaul13738862019-04-14 10:48:00 -0700574 if ((release_mode_ == ReleaseButtonMode::kRelease &&
575 data.IsPressed(kRelease)) ||
576 data.IsPressed(kReleaseButtonBoard)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800577 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700578 AOS_LOG(INFO, "Releasing due to button\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800579 }
580
Sabina Davisc6329342019-03-01 20:44:42 -0800581 if (switch_ball_) {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800582 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
583 ->mutate_gamepiece_mode(0);
Sabina Davisc6329342019-03-01 20:44:42 -0800584 } else {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800585 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
586 ->mutate_gamepiece_mode(1);
Sabina Davisc6329342019-03-01 20:44:42 -0800587 }
588
Tyler Chatowe0241452019-03-08 21:07:50 -0800589 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
590
James Kuszmaul2457eb72019-12-15 15:37:18 -0800591 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
592 ->mutate_grab_piece(grab_piece_);
Sabina Davis91b23602019-01-21 00:06:01 -0800593
Alex Perrycb7da4b2019-08-28 19:35:56 -0700594 mutable_superstructure_goal->mutable_elevator()->mutate_unsafe_goal(
595 elevator_wrist_pos_.elevator);
596 mutable_superstructure_goal->mutable_wrist()->mutate_unsafe_goal(
597 elevator_wrist_pos_.wrist);
Sabina Davis91b23602019-01-21 00:06:01 -0800598
Alex Perrycb7da4b2019-08-28 19:35:56 -0700599 if (!main_superstructure_goal_builder.Send(superstructure_goal_offset)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700600 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800601 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800602
Austin Schuhaab7e162019-03-13 22:44:58 -0700603 if (monotonic_now >
604 last_vision_control_ + ::std::chrono::milliseconds(50)) {
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700605 video_tx_->Send(vision_control_);
Austin Schuhaab7e162019-03-13 22:44:58 -0700606 last_vision_control_ = monotonic_now;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700607 }
Austin Schuh4e2629d2019-03-28 14:44:37 -0700608
609 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700610 auto builder = camera_log_sender_.MakeBuilder();
611 builder.Send(CreateCameraLog(*builder.fbb(), data.IsPressed(kCameraLog)));
Austin Schuh4e2629d2019-03-28 14:44:37 -0700612 }
Sabina Davis91b23602019-01-21 00:06:01 -0800613 }
614
615 private:
Austin Schuhc087b102019-05-12 15:33:12 -0700616 ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
617 target_selector_hint_sender_;
618
Alex Perrycb7da4b2019-08-28 19:35:56 -0700619 ::aos::Sender<LocalizerControl> localizer_control_sender_;
Austin Schuheb99d072019-05-12 21:03:38 -0700620
Austin Schuh5671a8c2019-05-19 17:01:04 -0700621 ::aos::Sender<::y2019::CameraLog> camera_log_sender_;
622
Alex Perrycb7da4b2019-08-28 19:35:56 -0700623 ::aos::Fetcher<superstructure::Goal> superstructure_goal_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700624
Alex Perrycb7da4b2019-08-28 19:35:56 -0700625 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
Austin Schuh170f4952019-06-29 18:58:30 -0700626
Alex Perrycb7da4b2019-08-28 19:35:56 -0700627 ::aos::Fetcher<superstructure::Position> superstructure_position_fetcher_;
628 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700629
Austin Schuhe2f22482019-04-13 23:05:43 -0700630 // Bool to track if we've been above the deploy position. Once this bool is
631 // set, don't let the stilts retract until we see the platform.
632 bool was_above_ = false;
633
Sabina Davis91b23602019-01-21 00:06:01 -0800634 // Current goals here.
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800635 ElevatorWristPosition elevator_wrist_pos_ = kStowPos;
Sabina Davisc6329342019-03-01 20:44:42 -0800636 bool grab_piece_ = false;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800637
638 bool switch_ball_ = false;
Tyler Chatowe0241452019-03-08 21:07:50 -0800639
James Kuszmaul13738862019-04-14 10:48:00 -0700640 bool climbed_ = false;
641
642 enum class ReleaseButtonMode {
643 kBallIntake,
644 kRelease,
645 };
646
647 ReleaseButtonMode release_mode_ = ReleaseButtonMode::kRelease;
648 aos::monotonic_clock::time_point last_release_button_press_ =
649 aos::monotonic_clock::min_time;
650
Tyler Chatowe0241452019-03-08 21:07:50 -0800651 VisionControl vision_control_;
652 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700653 ::aos::monotonic_clock::time_point last_vision_control_ =
654 ::aos::monotonic_clock::time_point::min();
Austin Schuhaab7e162019-03-13 22:44:58 -0700655
656 // Time at which we last did not have a game piece.
657 ::aos::monotonic_clock::time_point last_not_has_piece_ =
658 ::aos::monotonic_clock::time_point::min();
Sabina Davis91b23602019-01-21 00:06:01 -0800659};
660
661} // namespace joysticks
662} // namespace input
663} // namespace y2019
664
665int main() {
Austin Schuh9fe68f72019-08-10 19:32:03 -0700666 ::aos::InitNRT(true);
667
Alex Perrycb7da4b2019-08-28 19:35:56 -0700668 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
669 aos::configuration::ReadConfig("config.json");
670
671 ::aos::ShmEventLoop event_loop(&config.message());
Sabina Davis91b23602019-01-21 00:06:01 -0800672 ::y2019::input::joysticks::Reader reader(&event_loop);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700673
674 event_loop.Run();
675
Sabina Davis91b23602019-01-21 00:06:01 -0800676 ::aos::Cleanup();
677}