blob: 7351130e222495d11933d304fbb33ae8c436e68d [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>
James Kuszmaul7077d342021-06-09 20:23:58 -07005
Tyler Chatow4fedeea2019-03-10 15:33:36 -07006#include <chrono>
Sabina Davis91b23602019-01-21 00:06:01 -08007
8#include "aos/actions/actions.h"
9#include "aos/init.h"
Sabina Davis91b23602019-01-21 00:06:01 -080010#include "aos/logging/logging.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080011#include "aos/network/team_number.h"
Sabina Davis91b23602019-01-21 00:06:01 -080012#include "aos/util/log_interval.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080013#include "aos/vision/events/udp.h"
14#include "external/com_google_protobuf/src/google/protobuf/stubs/stringprintf.h"
Sabina Davis91b23602019-01-21 00:06:01 -080015#include "frc971/autonomous/base_autonomous_actor.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070016#include "frc971/control_loops/drivetrain/localizer_generated.h"
James Kuszmaul7077d342021-06-09 20:23:58 -070017#include "frc971/input/action_joystick_input.h"
18#include "frc971/input/driver_station_data.h"
19#include "frc971/input/drivetrain_input.h"
20#include "frc971/input/joystick_input.h"
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;
Alex Perrycb7da4b2019-08-28 19:35:56 -070030using frc971::CreateProfileParameters;
31using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal;
32using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
33using frc971::control_loops::drivetrain::LocalizerControl;
James Kuszmaul7077d342021-06-09 20:23:58 -070034using frc971::input::driver_station::ButtonLocation;
35using frc971::input::driver_station::ControlBit;
36using frc971::input::driver_station::JoystickAxis;
37using frc971::input::driver_station::POVLocation;
James Kuszmaul2457eb72019-12-15 15:37:18 -080038using y2019::control_loops::superstructure::CreateSuctionGoal;
James Kuszmaul7077d342021-06-09 20:23:58 -070039using y2019::control_loops::superstructure::SuctionGoal;
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
James Kuszmaul7077d342021-06-09 20:23:58 -0700141class Reader : public ::frc971::input::ActionJoystickInput {
Sabina Davis91b23602019-01-21 00:06:01 -0800142 public:
143 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -0700144 : ::frc971::input::ActionJoystickInput(
Sabina Davis91b23602019-01-21 00:06:01 -0800145 event_loop,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700146 ::y2019::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -0700147 ::frc971::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
James Kuszmaul7077d342021-06-09 20:23:58 -0700189 void HandleTeleop(
190 const ::frc971::input::driver_station::Data &data) override {
Austin Schuhaab7e162019-03-13 22:44:58 -0700191 ::aos::monotonic_clock::time_point monotonic_now =
192 ::aos::monotonic_clock::now();
Austin Schuh170f4952019-06-29 18:58:30 -0700193 superstructure_position_fetcher_.Fetch();
194 superstructure_status_fetcher_.Fetch();
195 if (!superstructure_status_fetcher_.get() ||
196 !superstructure_position_fetcher_.get()) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700197 AOS_LOG(ERROR, "Got no superstructure status or position packet.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800198 return;
199 }
200
Alex Perrycb7da4b2019-08-28 19:35:56 -0700201 CHECK(superstructure_status_fetcher_->has_stilts());
202
203 if (!superstructure_status_fetcher_->has_piece()) {
Austin Schuhaab7e162019-03-13 22:44:58 -0700204 last_not_has_piece_ = monotonic_now;
205 }
206
Alex Perrycb7da4b2019-08-28 19:35:56 -0700207 auto main_superstructure_goal_builder =
208 superstructure_goal_sender_.MakeBuilder();
209
210 flatbuffers::Offset<superstructure::Goal> superstructure_goal_offset;
Sabina Davis91b23602019-01-21 00:06:01 -0800211
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700212 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700213 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
214 elevator_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
215 *main_superstructure_goal_builder.fbb(), 0.0,
216 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
217 0.0, 0.0));
218
219 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
220 intake_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
221 *main_superstructure_goal_builder.fbb(), -1.2);
222
223 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
224 wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
225 *main_superstructure_goal_builder.fbb(), 0.0,
226 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
227 0.0, 0.0));
228
229 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
230 stilts_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
231 *main_superstructure_goal_builder.fbb(), 0.0,
232 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
233 0.0, 0.0));
234
James Kuszmaul2457eb72019-12-15 15:37:18 -0800235 flatbuffers::Offset<SuctionGoal> suction_offset =
236 CreateSuctionGoal(*main_superstructure_goal_builder.fbb(), false, 0);
237
Alex Perrycb7da4b2019-08-28 19:35:56 -0700238 superstructure::Goal::Builder superstructure_goal_builder =
239 main_superstructure_goal_builder.MakeBuilder<superstructure::Goal>();
240
241 superstructure_goal_builder.add_elevator(elevator_offset);
242 superstructure_goal_builder.add_intake(intake_offset);
243 superstructure_goal_builder.add_wrist(wrist_offset);
244 superstructure_goal_builder.add_stilts(stilts_offset);
James Kuszmaul2457eb72019-12-15 15:37:18 -0800245 superstructure_goal_builder.add_suction(suction_offset);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700246 superstructure_goal_builder.add_roller_voltage(0.0);
247
248 superstructure_goal_offset = superstructure_goal_builder.Finish();
249 }
James Kuszmaul2457eb72019-12-15 15:37:18 -0800250 superstructure::Goal *mutable_superstructure_goal = CHECK_NOTNULL(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700251 GetMutableTemporaryPointer(*main_superstructure_goal_builder.fbb(),
James Kuszmaul2457eb72019-12-15 15:37:18 -0800252 superstructure_goal_offset));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700253
254 {
255 auto builder = target_selector_hint_sender_.MakeBuilder();
256 control_loops::drivetrain::TargetSelectorHint::Builder
257 target_selector_hint_builder =
258 builder
259 .MakeBuilder<control_loops::drivetrain::TargetSelectorHint>();
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700260 if (data.IsPressed(kNearCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700261 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800262 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700263 } else if (data.IsPressed(kMidCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700264 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800265 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700266 } else if (data.IsPressed(kFarCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700267 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800268 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700269 } else {
James Kuszmaul518640d2019-04-13 15:50:50 -0700270 const double cargo_joy_y = data.GetAxis(kCargoSelectorY);
271 const double cargo_joy_x = data.GetAxis(kCargoSelectorX);
272 if (cargo_joy_y > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700273 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700274 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul1b822b42019-04-14 14:27:35 -0700275 } else if (cargo_joy_y < -0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700276 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800277 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700278 } else if (::std::abs(cargo_joy_x) > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700279 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700280 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700281 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700282 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700283 control_loops::drivetrain::SelectionHint::NONE);
James Kuszmaul518640d2019-04-13 15:50:50 -0700284 }
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700285 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700286 if (!builder.Send(target_selector_hint_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700287 AOS_LOG(ERROR, "Failed to send target selector hint.\n");
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700288 }
289 }
290
James Kuszmaul518640d2019-04-13 15:50:50 -0700291 if (data.PosEdge(kResetLocalizerLeft)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700292 auto builder = localizer_control_sender_.MakeBuilder();
James Kuszmaul518640d2019-04-13 15:50:50 -0700293 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700294 LocalizerControl::Builder localizer_control_builder =
295 builder.MakeBuilder<LocalizerControl>();
296 localizer_control_builder.add_x(0.6);
297 localizer_control_builder.add_y(3.4);
298 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700299
Alex Perrycb7da4b2019-08-28 19:35:56 -0700300 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700301 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700302 }
303 }
304
305 if (data.PosEdge(kResetLocalizerRight)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700306 auto builder = localizer_control_sender_.MakeBuilder();
307 // Start at the right feeder station.
308 LocalizerControl::Builder localizer_control_builder =
309 builder.MakeBuilder<LocalizerControl>();
310 localizer_control_builder.add_x(0.6);
311 localizer_control_builder.add_y(-3.4);
312 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700313
Alex Perrycb7da4b2019-08-28 19:35:56 -0700314 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700315 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700316 }
317 }
318
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700319 if (data.PosEdge(kResetLocalizerLeftForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700320 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700321 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700322 LocalizerControl::Builder localizer_control_builder =
323 builder.MakeBuilder<LocalizerControl>();
324 localizer_control_builder.add_x(0.4);
325 localizer_control_builder.add_y(3.4);
326 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700327
Alex Perrycb7da4b2019-08-28 19:35:56 -0700328 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700329 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700330 }
331 }
332
333 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700334 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700335 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700336 LocalizerControl::Builder localizer_control_builder =
337 builder.MakeBuilder<LocalizerControl>();
338 localizer_control_builder.add_x(0.4);
339 localizer_control_builder.add_y(3.4);
340 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700341
Alex Perrycb7da4b2019-08-28 19:35:56 -0700342 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700343 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700344 }
345 }
346
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700347 if (data.PosEdge(kResetLocalizerRightForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700348 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700349 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700350 LocalizerControl::Builder localizer_control_builder =
351 builder.MakeBuilder<LocalizerControl>();
352 localizer_control_builder.add_x(0.4);
353 localizer_control_builder.add_y(-3.4);
354 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700355
Alex Perrycb7da4b2019-08-28 19:35:56 -0700356 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700357 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700358 }
359 }
360
361 if (data.PosEdge(kResetLocalizerRightBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700362 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700363 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700364 LocalizerControl::Builder localizer_control_builder =
365 builder.MakeBuilder<LocalizerControl>();
366 localizer_control_builder.add_x(0.4);
367 localizer_control_builder.add_y(-3.4);
368 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700369
Alex Perrycb7da4b2019-08-28 19:35:56 -0700370 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700371 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmauld8deb682019-03-10 10:38:42 -0700372 }
373 }
374
James Kuszmaul13738862019-04-14 10:48:00 -0700375 if (data.PosEdge(kRelease) &&
376 monotonic_now >
377 last_release_button_press_ + ::std::chrono::milliseconds(500)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700378 if (superstructure_status_fetcher_->has_piece()) {
James Kuszmaul13738862019-04-14 10:48:00 -0700379 release_mode_ = ReleaseButtonMode::kRelease;
380 } else {
381 release_mode_ = ReleaseButtonMode::kBallIntake;
382 }
383 }
384
385 if (data.IsPressed(kRelease)) {
386 last_release_button_press_ = monotonic_now;
387 }
388
Alex Perrycb7da4b2019-08-28 19:35:56 -0700389 AOS_LOG(INFO, "has_piece: %d\n",
390 superstructure_status_fetcher_->has_piece());
Austin Schuh1a17e132019-02-17 15:05:06 -0800391 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800392 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800393 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800394 grab_piece_ = true;
James Kuszmaul13738862019-04-14 10:48:00 -0700395 } else if ((release_mode_ == ReleaseButtonMode::kRelease &&
396 data.IsPressed(kRelease)) ||
Tyler Chatow5eeee902019-04-12 20:47:48 -0700397 data.IsPressed(kReleaseButtonBoard) ||
Alex Perrycb7da4b2019-08-28 19:35:56 -0700398 !superstructure_status_fetcher_->has_piece()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800399 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700400 AOS_LOG(INFO, "releasing due to other thing\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800401 }
Sabina Davis91b23602019-01-21 00:06:01 -0800402
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800403 if (data.IsPressed(kRocketBackwardUnpressed)) {
404 elevator_wrist_pos_ = kStowPos;
405 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700406 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(-1.2);
407 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800408
James Kuszmaul13738862019-04-14 10:48:00 -0700409 const bool kDoBallIntake =
410 (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake &&
411 data.IsPressed(kRelease)) ||
412 data.GetAxis(kBallIntake) > 0.9;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800413 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
414
415 if (data.IsPressed(kPanelSwitch)) {
416 switch_ball_ = false;
417 } else if (data.IsPressed(kCargoSwitch)) {
418 switch_ball_ = true;
419 }
420
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800421 if (switch_ball_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700422 if (superstructure_status_fetcher_->has_piece()) {
423 mutable_superstructure_goal->mutable_wrist()
424 ->mutable_profile_params()
425 ->mutate_max_acceleration(20);
Austin Schuh1a17e132019-02-17 15:05:06 -0800426 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800427
428 // Go to intake position and apply vacuum
429 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800430 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800431 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
432 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800433 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800434 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
435 }
436
437 // Go to elevator/wrist position. Overrides intake position if pressed so
438 // we can re-grab the ball.
439 if (data.IsPressed(kRocketForwardLower)) {
440 elevator_wrist_pos_ = kBallForwardLowerPos;
441 } else if (data.IsPressed(kRocketBackwardLower)) {
442 elevator_wrist_pos_ = kBallBackwardLowerPos;
443 } else if (data.IsPressed(kRocketForwardMiddle)) {
444 elevator_wrist_pos_ = kBallForwardMiddlePos;
445 } else if (data.IsPressed(kRocketBackwardMiddle)) {
446 elevator_wrist_pos_ = kBallBackwardMiddlePos;
447 } else if (data.IsPressed(kRocketForwardUpper)) {
448 elevator_wrist_pos_ = kBallForwardUpperPos;
449 } else if (data.IsPressed(kRocketBackwardUpper)) {
450 elevator_wrist_pos_ = kBallBackwardUpperPos;
451 } else if (data.IsPressed(kCargoForward)) {
452 elevator_wrist_pos_ = kBallCargoForwardPos;
453 } else if (data.IsPressed(kCargoBackward)) {
454 elevator_wrist_pos_ = kBallCargoBackwardPos;
455 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800456 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800457 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800458 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800459 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
460 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800461 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800462 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
463 }
464
465 // Go to elevator/wrist position. Overrides intake position if pressed so
466 // we can re-grab the panel.
467 if (data.IsPressed(kRocketForwardLower)) {
468 elevator_wrist_pos_ = kPanelForwardLowerPos;
469 } else if (data.IsPressed(kRocketBackwardLower)) {
470 elevator_wrist_pos_ = kPanelBackwardLowerPos;
471 } else if (data.IsPressed(kRocketForwardMiddle)) {
472 elevator_wrist_pos_ = kPanelForwardMiddlePos;
473 } else if (data.IsPressed(kRocketBackwardMiddle)) {
474 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
475 } else if (data.IsPressed(kRocketForwardUpper)) {
476 elevator_wrist_pos_ = kPanelForwardUpperPos;
477 } else if (data.IsPressed(kRocketBackwardUpper)) {
478 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800479 } else if (data.IsPressed(kCargoForward)) {
480 elevator_wrist_pos_ = kPanelCargoForwardPos;
481 } else if (data.IsPressed(kCargoBackward)) {
482 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800483 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800484 }
485
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800486 if (switch_ball_) {
487 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700488 (kDoBallIntake &&
Austin Schuh20dc0502019-03-30 07:24:07 -0700489 monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700490 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(0.83);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800491 }
Austin Schuh23a51632019-02-19 16:50:36 -0800492
Alex Perrycb7da4b2019-08-28 19:35:56 -0700493 if (kDoBallIntake && !superstructure_status_fetcher_->has_piece()) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800494 elevator_wrist_pos_ = kBallIntakePos;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700495 mutable_superstructure_goal->mutate_roller_voltage(9.0);
Sabina Davisc6329342019-03-01 20:44:42 -0800496 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800497 } else {
498 if (kDoBallOutake) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700499 mutable_superstructure_goal->mutate_roller_voltage(-6.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800500 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700501 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800502 }
503 }
Austin Schuh23a51632019-02-19 16:50:36 -0800504 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800505
Austin Schuh457bde32019-03-17 18:16:41 -0700506 constexpr double kDeployStiltPosition = 0.5;
507
Austin Schuh457bde32019-03-17 18:16:41 -0700508 if (data.IsPressed(kFallOver)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700509 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.71);
510 mutable_superstructure_goal->mutable_stilts()
511 ->mutable_profile_params()
512 ->mutate_max_velocity(0.65);
513 mutable_superstructure_goal->mutable_stilts()
514 ->mutable_profile_params()
515 ->mutate_max_acceleration(1.25);
Austin Schuhe2f22482019-04-13 23:05:43 -0700516 } else if (data.IsPressed(kHalfStilt)) {
517 was_above_ = false;
James Kuszmaul7077d342021-06-09 20:23:58 -0700518 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.345);
519 mutable_superstructure_goal->mutable_stilts()
520 ->mutable_profile_params()
521 ->mutate_max_velocity(0.65);
Austin Schuhe2f22482019-04-13 23:05:43 -0700522 } else if (data.IsPressed(kDeployStilt) || was_above_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700523 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(
524 kDeployStiltPosition);
525 mutable_superstructure_goal->mutable_stilts()
526 ->mutable_profile_params()
527 ->mutate_max_velocity(0.65);
528 mutable_superstructure_goal->mutable_stilts()
529 ->mutable_profile_params()
530 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700531 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700532 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.005);
533 mutable_superstructure_goal->mutable_stilts()
534 ->mutable_profile_params()
535 ->mutate_max_velocity(0.65);
536 mutable_superstructure_goal->mutable_stilts()
537 ->mutable_profile_params()
538 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700539 }
540
Alex Perrycb7da4b2019-08-28 19:35:56 -0700541 if (superstructure_status_fetcher_->stilts()->position() > 0.1) {
Austin Schuh02be8b92019-03-24 16:04:14 -0700542 elevator_wrist_pos_ = kClimbPos;
James Kuszmaul13738862019-04-14 10:48:00 -0700543 climbed_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700544 mutable_superstructure_goal->mutable_wrist()
545 ->mutable_profile_params()
546 ->mutate_max_acceleration(10);
547 mutable_superstructure_goal->mutable_elevator()
548 ->mutable_profile_params()
549 ->mutate_max_acceleration(6);
Austin Schuh02be8b92019-03-24 16:04:14 -0700550 }
551
Austin Schuhe2f22482019-04-13 23:05:43 -0700552 // If we've been asked to go above deploy and made it up that high, latch
553 // was_above.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700554 if (mutable_superstructure_goal->stilts()->unsafe_goal() >
555 kDeployStiltPosition &&
556 superstructure_status_fetcher_->stilts()->position() >=
Austin Schuh170f4952019-06-29 18:58:30 -0700557 kDeployStiltPosition) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700558 was_above_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700559 } else if ((superstructure_position_fetcher_->platform_left_detect() &&
560 superstructure_position_fetcher_->platform_right_detect()) &&
Austin Schuhe2f22482019-04-13 23:05:43 -0700561 !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700562 was_above_ = false;
563 }
564
Alex Perrycb7da4b2019-08-28 19:35:56 -0700565 if (superstructure_status_fetcher_->stilts()->position() >
Austin Schuh170f4952019-06-29 18:58:30 -0700566 kDeployStiltPosition &&
Alex Perrycb7da4b2019-08-28 19:35:56 -0700567 mutable_superstructure_goal->stilts()->unsafe_goal() ==
568 kDeployStiltPosition) {
569 mutable_superstructure_goal->mutable_stilts()
570 ->mutable_profile_params()
571 ->mutate_max_velocity(0.30);
572 mutable_superstructure_goal->mutable_stilts()
573 ->mutable_profile_params()
574 ->mutate_max_acceleration(0.75);
Austin Schuh457bde32019-03-17 18:16:41 -0700575 }
576
James Kuszmaul13738862019-04-14 10:48:00 -0700577 if ((release_mode_ == ReleaseButtonMode::kRelease &&
578 data.IsPressed(kRelease)) ||
579 data.IsPressed(kReleaseButtonBoard)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800580 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700581 AOS_LOG(INFO, "Releasing due to button\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800582 }
583
Sabina Davisc6329342019-03-01 20:44:42 -0800584 if (switch_ball_) {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800585 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
586 ->mutate_gamepiece_mode(0);
Sabina Davisc6329342019-03-01 20:44:42 -0800587 } else {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800588 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
589 ->mutate_gamepiece_mode(1);
Sabina Davisc6329342019-03-01 20:44:42 -0800590 }
591
Tyler Chatowe0241452019-03-08 21:07:50 -0800592 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
593
James Kuszmaul2457eb72019-12-15 15:37:18 -0800594 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
595 ->mutate_grab_piece(grab_piece_);
Sabina Davis91b23602019-01-21 00:06:01 -0800596
Alex Perrycb7da4b2019-08-28 19:35:56 -0700597 mutable_superstructure_goal->mutable_elevator()->mutate_unsafe_goal(
598 elevator_wrist_pos_.elevator);
599 mutable_superstructure_goal->mutable_wrist()->mutate_unsafe_goal(
600 elevator_wrist_pos_.wrist);
Sabina Davis91b23602019-01-21 00:06:01 -0800601
Alex Perrycb7da4b2019-08-28 19:35:56 -0700602 if (!main_superstructure_goal_builder.Send(superstructure_goal_offset)) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700603 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800604 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800605
Austin Schuhaab7e162019-03-13 22:44:58 -0700606 if (monotonic_now >
607 last_vision_control_ + ::std::chrono::milliseconds(50)) {
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700608 video_tx_->Send(vision_control_);
Austin Schuhaab7e162019-03-13 22:44:58 -0700609 last_vision_control_ = monotonic_now;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700610 }
Austin Schuh4e2629d2019-03-28 14:44:37 -0700611
612 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700613 auto builder = camera_log_sender_.MakeBuilder();
614 builder.Send(CreateCameraLog(*builder.fbb(), data.IsPressed(kCameraLog)));
Austin Schuh4e2629d2019-03-28 14:44:37 -0700615 }
Sabina Davis91b23602019-01-21 00:06:01 -0800616 }
617
618 private:
Austin Schuhc087b102019-05-12 15:33:12 -0700619 ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
620 target_selector_hint_sender_;
621
Alex Perrycb7da4b2019-08-28 19:35:56 -0700622 ::aos::Sender<LocalizerControl> localizer_control_sender_;
Austin Schuheb99d072019-05-12 21:03:38 -0700623
Austin Schuh5671a8c2019-05-19 17:01:04 -0700624 ::aos::Sender<::y2019::CameraLog> camera_log_sender_;
625
Alex Perrycb7da4b2019-08-28 19:35:56 -0700626 ::aos::Fetcher<superstructure::Goal> superstructure_goal_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700627
Alex Perrycb7da4b2019-08-28 19:35:56 -0700628 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
Austin Schuh170f4952019-06-29 18:58:30 -0700629
Alex Perrycb7da4b2019-08-28 19:35:56 -0700630 ::aos::Fetcher<superstructure::Position> superstructure_position_fetcher_;
631 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700632
Austin Schuhe2f22482019-04-13 23:05:43 -0700633 // Bool to track if we've been above the deploy position. Once this bool is
634 // set, don't let the stilts retract until we see the platform.
635 bool was_above_ = false;
636
Sabina Davis91b23602019-01-21 00:06:01 -0800637 // Current goals here.
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800638 ElevatorWristPosition elevator_wrist_pos_ = kStowPos;
Sabina Davisc6329342019-03-01 20:44:42 -0800639 bool grab_piece_ = false;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800640
641 bool switch_ball_ = false;
Tyler Chatowe0241452019-03-08 21:07:50 -0800642
James Kuszmaul13738862019-04-14 10:48:00 -0700643 bool climbed_ = false;
644
645 enum class ReleaseButtonMode {
646 kBallIntake,
647 kRelease,
648 };
649
650 ReleaseButtonMode release_mode_ = ReleaseButtonMode::kRelease;
651 aos::monotonic_clock::time_point last_release_button_press_ =
652 aos::monotonic_clock::min_time;
653
Tyler Chatowe0241452019-03-08 21:07:50 -0800654 VisionControl vision_control_;
655 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700656 ::aos::monotonic_clock::time_point last_vision_control_ =
657 ::aos::monotonic_clock::time_point::min();
Austin Schuhaab7e162019-03-13 22:44:58 -0700658
659 // Time at which we last did not have a game piece.
660 ::aos::monotonic_clock::time_point last_not_has_piece_ =
661 ::aos::monotonic_clock::time_point::min();
Sabina Davis91b23602019-01-21 00:06:01 -0800662};
663
664} // namespace joysticks
665} // namespace input
666} // namespace y2019
667
Austin Schuh094d09b2020-11-20 23:26:52 -0800668int main(int argc, char **argv) {
669 ::aos::InitGoogle(&argc, &argv);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700670
Alex Perrycb7da4b2019-08-28 19:35:56 -0700671 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
672 aos::configuration::ReadConfig("config.json");
673
674 ::aos::ShmEventLoop event_loop(&config.message());
Sabina Davis91b23602019-01-21 00:06:01 -0800675 ::y2019::input::joysticks::Reader reader(&event_loop);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700676
677 event_loop.Run();
678
Austin Schuhae87e312020-08-01 16:15:01 -0700679 return 0;
Sabina Davis91b23602019-01-21 00:06:01 -0800680}