blob: b44d084cbd502fed0b6784ddb37a366404c4791b [file] [log] [blame]
Sabina Davis91b23602019-01-21 00:06:01 -08001#include <unistd.h>
James Kuszmaul7077d342021-06-09 20:23:58 -07002
Tyler Chatow4fedeea2019-03-10 15:33:36 -07003#include <chrono>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cmath>
5#include <cstdio>
6#include <cstring>
Sabina Davis91b23602019-01-21 00:06:01 -08007
Adam Snaider13d48d92023-08-03 12:20:15 -07008#include "absl/strings/str_format.h"
Philipp Schrader790cb542023-07-05 21:06:52 -07009
Sabina Davis91b23602019-01-21 00:06:01 -080010#include "aos/actions/actions.h"
11#include "aos/init.h"
Sabina Davis91b23602019-01-21 00:06:01 -080012#include "aos/logging/logging.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080013#include "aos/network/team_number.h"
Sabina Davis91b23602019-01-21 00:06:01 -080014#include "aos/util/log_interval.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080015#include "aos/vision/events/udp.h"
Sabina Davis91b23602019-01-21 00:06:01 -080016#include "frc971/autonomous/base_autonomous_actor.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070017#include "frc971/control_loops/drivetrain/localizer_generated.h"
James Kuszmaul7077d342021-06-09 20:23:58 -070018#include "frc971/input/action_joystick_input.h"
19#include "frc971/input/driver_station_data.h"
20#include "frc971/input/drivetrain_input.h"
21#include "frc971/input/joystick_input.h"
Austin Schuhed5b26d2019-12-05 20:51:59 -080022#include "y2019/camera_log_generated.h"
Sabina Davis91b23602019-01-21 00:06:01 -080023#include "y2019/control_loops/drivetrain/drivetrain_base.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070024#include "y2019/control_loops/drivetrain/target_selector_generated.h"
25#include "y2019/control_loops/superstructure/superstructure_goal_generated.h"
26#include "y2019/control_loops/superstructure/superstructure_position_generated.h"
27#include "y2019/control_loops/superstructure/superstructure_status_generated.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080028#include "y2019/vision.pb.h"
Sabina Davis91b23602019-01-21 00:06:01 -080029
Alex Perrycb7da4b2019-08-28 19:35:56 -070030using aos::events::ProtoTXUdpSocket;
Alex Perrycb7da4b2019-08-28 19:35:56 -070031using frc971::CreateProfileParameters;
32using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal;
33using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
34using frc971::control_loops::drivetrain::LocalizerControl;
James Kuszmaul7077d342021-06-09 20:23:58 -070035using frc971::input::driver_station::ButtonLocation;
36using frc971::input::driver_station::ControlBit;
37using frc971::input::driver_station::JoystickAxis;
38using frc971::input::driver_station::POVLocation;
James Kuszmaul2457eb72019-12-15 15:37:18 -080039using y2019::control_loops::superstructure::CreateSuctionGoal;
James Kuszmaul7077d342021-06-09 20:23:58 -070040using y2019::control_loops::superstructure::SuctionGoal;
Sabina Davis91b23602019-01-21 00:06:01 -080041
Austin Schuhaab7e162019-03-13 22:44:58 -070042namespace chrono = ::std::chrono;
43
Stephan Pleinesf63bde82024-01-13 15:59:33 -080044namespace y2019::input::joysticks {
Sabina Davis91b23602019-01-21 00:06:01 -080045
Alex Perrycb7da4b2019-08-28 19:35:56 -070046namespace superstructure = y2019::control_loops::superstructure;
47
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080048struct ElevatorWristPosition {
49 double elevator;
50 double wrist;
51};
Sabina Davis91b23602019-01-21 00:06:01 -080052
Tyler Chatow5eeee902019-04-12 20:47:48 -070053const ButtonLocation kSuctionBall(4, 2);
54const ButtonLocation kSuctionHatch(3, 15);
55const ButtonLocation kDeployStilt(4, 1);
56const ButtonLocation kHalfStilt(4, 3);
57const ButtonLocation kFallOver(3, 16);
58
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080059const ButtonLocation kRocketForwardLower(5, 1);
60const ButtonLocation kRocketForwardMiddle(5, 2);
61const ButtonLocation kRocketForwardUpper(5, 4);
62const ButtonLocation kCargoForward(5, 3);
63
64const POVLocation kRocketBackwardUnpressed(5, -1);
65const POVLocation kRocketBackwardLower(5, 180);
66const POVLocation kRocketBackwardMiddle(5, 90);
67const POVLocation kRocketBackwardUpper(5, 0);
68const POVLocation kCargoBackward(5, 270);
69
70const ButtonLocation kPanelSwitch(5, 7);
71const ButtonLocation kCargoSwitch(5, 8);
72
73const ButtonLocation kBallHPIntakeForward(5, 6);
74const ButtonLocation kBallHPIntakeBackward(5, 5);
75const JoystickAxis kBallOutake(5, 3);
76const JoystickAxis kBallIntake(5, 4);
77
78const ButtonLocation kPanelHPIntakeForward(5, 6);
79const ButtonLocation kPanelHPIntakeBackward(5, 5);
80
81const ButtonLocation kRelease(2, 4);
James Kuszmaulccc368b2019-04-11 20:00:07 -070082// Reuse quickturn for the cancel button.
83const ButtonLocation kCancelAutoMode(2, 3);
Tyler Chatow5eeee902019-04-12 20:47:48 -070084const ButtonLocation kReleaseButtonBoard(3, 4);
85const ButtonLocation kResetLocalizerLeftForwards(3, 10);
86const ButtonLocation kResetLocalizerLeftBackwards(3, 9);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080087
Tyler Chatow5eeee902019-04-12 20:47:48 -070088const ButtonLocation kResetLocalizerRightForwards(3, 8);
89const ButtonLocation kResetLocalizerRightBackwards(3, 7);
Tyler Chatow07c906b2019-03-09 21:29:06 -080090
James Kuszmaul518640d2019-04-13 15:50:50 -070091const ButtonLocation kResetLocalizerLeft(3, 11);
92const ButtonLocation kResetLocalizerRight(3, 13);
93
Tyler Chatow5eeee902019-04-12 20:47:48 -070094const ButtonLocation kNearCargoHint(3, 3);
95const ButtonLocation kMidCargoHint(3, 5);
96const ButtonLocation kFarCargoHint(3, 6);
James Kuszmaul7d1ef442019-03-23 20:20:50 -070097
James Kuszmaul518640d2019-04-13 15:50:50 -070098const JoystickAxis kCargoSelectorY(5, 6);
99const JoystickAxis kCargoSelectorX(5, 5);
100
Tyler Chatow5eeee902019-04-12 20:47:48 -0700101const ButtonLocation kCameraLog(3, 14);
Austin Schuh4e2629d2019-03-28 14:44:37 -0700102
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800103const ElevatorWristPosition kStowPos{0.36, 0.0};
Austin Schuh02be8b92019-03-24 16:04:14 -0700104const ElevatorWristPosition kClimbPos{0.0, M_PI / 4.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800105
Austin Schuh139f59d2019-03-17 18:16:13 -0700106const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
107const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800108
109const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0};
110const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0};
111
Sabina Davise48004f2019-03-02 23:15:24 -0800112const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
113const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800114
Sabina Davise48004f2019-03-02 23:15:24 -0800115const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0};
116const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800117
Sabina Davise6fe6c52019-03-03 15:48:51 -0800118const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0};
119const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
120
Austin Schuh6c5deb12019-03-24 16:48:32 -0700121const ElevatorWristPosition kBallForwardLowerPos{0.21, 1.27};
Austin Schuh20dc0502019-03-30 07:24:07 -0700122const ElevatorWristPosition kBallBackwardLowerPos{0.43, -1.99};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800123
Austin Schuh20dc0502019-03-30 07:24:07 -0700124const ElevatorWristPosition kBallForwardMiddlePos{0.925, 1.21};
125const ElevatorWristPosition kBallBackwardMiddlePos{1.19, -1.98};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800126
Austin Schuh139f59d2019-03-17 18:16:13 -0700127const ElevatorWristPosition kBallForwardUpperPos{1.51, 0.961};
128const ElevatorWristPosition kBallBackwardUpperPos{1.44, -1.217};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800129
Austin Schuh20dc0502019-03-30 07:24:07 -0700130const ElevatorWristPosition kBallCargoForwardPos{0.59, 1.2};
131const ElevatorWristPosition kBallCargoBackwardPos{0.868265, -2.1};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800132
Sabina Davise6fe6c52019-03-03 15:48:51 -0800133const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097};
134const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800135
Austin Schuh20dc0502019-03-30 07:24:07 -0700136const ElevatorWristPosition kBallIntakePos{0.309, 2.13};
Austin Schuh2cf16b82019-02-15 23:23:22 -0800137
James Kuszmaul7077d342021-06-09 20:23:58 -0700138class Reader : public ::frc971::input::ActionJoystickInput {
Sabina Davis91b23602019-01-21 00:06:01 -0800139 public:
140 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -0700141 : ::frc971::input::ActionJoystickInput(
Sabina Davis91b23602019-01-21 00:06:01 -0800142 event_loop,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700143 ::y2019::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -0700144 ::frc971::input::DrivetrainInputReader::InputType::kPistol,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700145 {.run_teleop_in_auto = true,
Austin Schuhc087b102019-05-12 15:33:12 -0700146 .cancel_auto_button = kCancelAutoMode}),
147 target_selector_hint_sender_(
148 event_loop->MakeSender<
149 ::y2019::control_loops::drivetrain::TargetSelectorHint>(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700150 "/drivetrain")),
Austin Schuheb99d072019-05-12 21:03:38 -0700151 localizer_control_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700152 event_loop->MakeSender<LocalizerControl>("/drivetrain")),
Austin Schuh5671a8c2019-05-19 17:01:04 -0700153 camera_log_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700154 event_loop->MakeSender<::y2019::CameraLog>("/camera")),
155 superstructure_goal_fetcher_(
156 event_loop->MakeFetcher<superstructure::Goal>("/superstructure")),
157 superstructure_goal_sender_(
158 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700159 superstructure_position_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700160 event_loop->MakeFetcher<superstructure::Position>(
161 "/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700162 superstructure_status_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700163 event_loop->MakeFetcher<superstructure::Status>(
164 "/superstructure")) {
Tyler Chatowe0241452019-03-08 21:07:50 -0800165 const uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuh170f4952019-06-29 18:58:30 -0700166 superstructure_goal_fetcher_.Fetch();
167 if (superstructure_goal_fetcher_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700168 grab_piece_ = superstructure_goal_fetcher_->has_suction()
169 ? superstructure_goal_fetcher_->suction()->grab_piece()
170 : false;
171 switch_ball_ =
172 superstructure_goal_fetcher_->has_suction()
173 ? (superstructure_goal_fetcher_->suction()->gamepiece_mode() == 0)
174 : true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800175 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800176 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
Adam Snaider13d48d92023-08-03 12:20:15 -0700177 absl::StrFormat("10.%d.%d.179", team / 100, team % 100), 5000));
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800178 }
Sabina Davis91b23602019-01-21 00:06:01 -0800179
Austin Schuha78857f2019-03-13 22:43:41 -0700180 void AutoEnded() override {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700181 AOS_LOG(INFO, "Auto ended, assuming disc and have piece\n");
Austin Schuha78857f2019-03-13 22:43:41 -0700182 grab_piece_ = true;
183 switch_ball_ = false;
184 }
185
James Kuszmaul7077d342021-06-09 20:23:58 -0700186 void HandleTeleop(
187 const ::frc971::input::driver_station::Data &data) override {
Austin Schuhaab7e162019-03-13 22:44:58 -0700188 ::aos::monotonic_clock::time_point monotonic_now =
189 ::aos::monotonic_clock::now();
Austin Schuh170f4952019-06-29 18:58:30 -0700190 superstructure_position_fetcher_.Fetch();
191 superstructure_status_fetcher_.Fetch();
192 if (!superstructure_status_fetcher_.get() ||
193 !superstructure_position_fetcher_.get()) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700194 AOS_LOG(ERROR, "Got no superstructure status or position packet.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800195 return;
196 }
197
Alex Perrycb7da4b2019-08-28 19:35:56 -0700198 CHECK(superstructure_status_fetcher_->has_stilts());
199
200 if (!superstructure_status_fetcher_->has_piece()) {
Austin Schuhaab7e162019-03-13 22:44:58 -0700201 last_not_has_piece_ = monotonic_now;
202 }
203
Alex Perrycb7da4b2019-08-28 19:35:56 -0700204 auto main_superstructure_goal_builder =
205 superstructure_goal_sender_.MakeBuilder();
206
207 flatbuffers::Offset<superstructure::Goal> superstructure_goal_offset;
Sabina Davis91b23602019-01-21 00:06:01 -0800208
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700209 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700210 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
211 elevator_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
212 *main_superstructure_goal_builder.fbb(), 0.0,
213 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
214 0.0, 0.0));
215
216 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
217 intake_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
218 *main_superstructure_goal_builder.fbb(), -1.2);
219
220 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
221 wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
222 *main_superstructure_goal_builder.fbb(), 0.0,
223 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
224 0.0, 0.0));
225
226 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
227 stilts_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
228 *main_superstructure_goal_builder.fbb(), 0.0,
229 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
230 0.0, 0.0));
231
James Kuszmaul2457eb72019-12-15 15:37:18 -0800232 flatbuffers::Offset<SuctionGoal> suction_offset =
233 CreateSuctionGoal(*main_superstructure_goal_builder.fbb(), false, 0);
234
Alex Perrycb7da4b2019-08-28 19:35:56 -0700235 superstructure::Goal::Builder superstructure_goal_builder =
236 main_superstructure_goal_builder.MakeBuilder<superstructure::Goal>();
237
238 superstructure_goal_builder.add_elevator(elevator_offset);
239 superstructure_goal_builder.add_intake(intake_offset);
240 superstructure_goal_builder.add_wrist(wrist_offset);
241 superstructure_goal_builder.add_stilts(stilts_offset);
James Kuszmaul2457eb72019-12-15 15:37:18 -0800242 superstructure_goal_builder.add_suction(suction_offset);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700243 superstructure_goal_builder.add_roller_voltage(0.0);
244
245 superstructure_goal_offset = superstructure_goal_builder.Finish();
246 }
James Kuszmaul2457eb72019-12-15 15:37:18 -0800247 superstructure::Goal *mutable_superstructure_goal = CHECK_NOTNULL(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700248 GetMutableTemporaryPointer(*main_superstructure_goal_builder.fbb(),
James Kuszmaul2457eb72019-12-15 15:37:18 -0800249 superstructure_goal_offset));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700250
251 {
252 auto builder = target_selector_hint_sender_.MakeBuilder();
253 control_loops::drivetrain::TargetSelectorHint::Builder
254 target_selector_hint_builder =
255 builder
256 .MakeBuilder<control_loops::drivetrain::TargetSelectorHint>();
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700257 if (data.IsPressed(kNearCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700258 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800259 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700260 } else if (data.IsPressed(kMidCargoHint)) {
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::MID_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700263 } else if (data.IsPressed(kFarCargoHint)) {
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::FAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700266 } else {
James Kuszmaul518640d2019-04-13 15:50:50 -0700267 const double cargo_joy_y = data.GetAxis(kCargoSelectorY);
268 const double cargo_joy_x = data.GetAxis(kCargoSelectorX);
269 if (cargo_joy_y > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700270 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700271 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul1b822b42019-04-14 14:27:35 -0700272 } else if (cargo_joy_y < -0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700273 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800274 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700275 } else if (::std::abs(cargo_joy_x) > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700276 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700277 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700278 } else {
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::NONE);
James Kuszmaul518640d2019-04-13 15:50:50 -0700281 }
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700282 }
milind1f1dca32021-07-03 13:50:07 -0700283 if (builder.Send(target_selector_hint_builder.Finish()) !=
284 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700285 AOS_LOG(ERROR, "Failed to send target selector hint.\n");
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700286 }
287 }
288
James Kuszmaul518640d2019-04-13 15:50:50 -0700289 if (data.PosEdge(kResetLocalizerLeft)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700290 auto builder = localizer_control_sender_.MakeBuilder();
James Kuszmaul518640d2019-04-13 15:50:50 -0700291 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700292 LocalizerControl::Builder localizer_control_builder =
293 builder.MakeBuilder<LocalizerControl>();
294 localizer_control_builder.add_x(0.6);
295 localizer_control_builder.add_y(3.4);
296 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700297
milind1f1dca32021-07-03 13:50:07 -0700298 if (builder.Send(localizer_control_builder.Finish()) !=
299 aos::RawSender::Error::kOk) {
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
milind1f1dca32021-07-03 13:50:07 -0700313 if (builder.Send(localizer_control_builder.Finish()) !=
314 aos::RawSender::Error::kOk) {
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
milind1f1dca32021-07-03 13:50:07 -0700328 if (builder.Send(localizer_control_builder.Finish()) !=
329 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700330 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700331 }
332 }
333
334 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700335 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700336 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700337 LocalizerControl::Builder localizer_control_builder =
338 builder.MakeBuilder<LocalizerControl>();
339 localizer_control_builder.add_x(0.4);
340 localizer_control_builder.add_y(3.4);
341 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700342
milind1f1dca32021-07-03 13:50:07 -0700343 if (builder.Send(localizer_control_builder.Finish()) !=
344 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700345 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700346 }
347 }
348
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700349 if (data.PosEdge(kResetLocalizerRightForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700350 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700351 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700352 LocalizerControl::Builder localizer_control_builder =
353 builder.MakeBuilder<LocalizerControl>();
354 localizer_control_builder.add_x(0.4);
355 localizer_control_builder.add_y(-3.4);
356 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700357
milind1f1dca32021-07-03 13:50:07 -0700358 if (builder.Send(localizer_control_builder.Finish()) !=
359 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700360 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700361 }
362 }
363
364 if (data.PosEdge(kResetLocalizerRightBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700365 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700366 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700367 LocalizerControl::Builder localizer_control_builder =
368 builder.MakeBuilder<LocalizerControl>();
369 localizer_control_builder.add_x(0.4);
370 localizer_control_builder.add_y(-3.4);
371 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700372
milind1f1dca32021-07-03 13:50:07 -0700373 if (builder.Send(localizer_control_builder.Finish()) !=
374 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700375 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmauld8deb682019-03-10 10:38:42 -0700376 }
377 }
378
James Kuszmaul13738862019-04-14 10:48:00 -0700379 if (data.PosEdge(kRelease) &&
380 monotonic_now >
381 last_release_button_press_ + ::std::chrono::milliseconds(500)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700382 if (superstructure_status_fetcher_->has_piece()) {
James Kuszmaul13738862019-04-14 10:48:00 -0700383 release_mode_ = ReleaseButtonMode::kRelease;
384 } else {
385 release_mode_ = ReleaseButtonMode::kBallIntake;
386 }
387 }
388
389 if (data.IsPressed(kRelease)) {
390 last_release_button_press_ = monotonic_now;
391 }
392
Alex Perrycb7da4b2019-08-28 19:35:56 -0700393 AOS_LOG(INFO, "has_piece: %d\n",
394 superstructure_status_fetcher_->has_piece());
Austin Schuh1a17e132019-02-17 15:05:06 -0800395 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800396 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800397 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800398 grab_piece_ = true;
James Kuszmaul13738862019-04-14 10:48:00 -0700399 } else if ((release_mode_ == ReleaseButtonMode::kRelease &&
400 data.IsPressed(kRelease)) ||
Tyler Chatow5eeee902019-04-12 20:47:48 -0700401 data.IsPressed(kReleaseButtonBoard) ||
Alex Perrycb7da4b2019-08-28 19:35:56 -0700402 !superstructure_status_fetcher_->has_piece()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800403 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700404 AOS_LOG(INFO, "releasing due to other thing\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800405 }
Sabina Davis91b23602019-01-21 00:06:01 -0800406
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800407 if (data.IsPressed(kRocketBackwardUnpressed)) {
408 elevator_wrist_pos_ = kStowPos;
409 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700410 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(-1.2);
411 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800412
James Kuszmaul13738862019-04-14 10:48:00 -0700413 const bool kDoBallIntake =
414 (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake &&
415 data.IsPressed(kRelease)) ||
416 data.GetAxis(kBallIntake) > 0.9;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800417 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
418
419 if (data.IsPressed(kPanelSwitch)) {
420 switch_ball_ = false;
421 } else if (data.IsPressed(kCargoSwitch)) {
422 switch_ball_ = true;
423 }
424
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800425 if (switch_ball_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700426 if (superstructure_status_fetcher_->has_piece()) {
427 mutable_superstructure_goal->mutable_wrist()
428 ->mutable_profile_params()
429 ->mutate_max_acceleration(20);
Austin Schuh1a17e132019-02-17 15:05:06 -0800430 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800431
432 // Go to intake position and apply vacuum
433 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800434 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800435 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
436 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800437 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800438 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
439 }
440
441 // Go to elevator/wrist position. Overrides intake position if pressed so
442 // we can re-grab the ball.
443 if (data.IsPressed(kRocketForwardLower)) {
444 elevator_wrist_pos_ = kBallForwardLowerPos;
445 } else if (data.IsPressed(kRocketBackwardLower)) {
446 elevator_wrist_pos_ = kBallBackwardLowerPos;
447 } else if (data.IsPressed(kRocketForwardMiddle)) {
448 elevator_wrist_pos_ = kBallForwardMiddlePos;
449 } else if (data.IsPressed(kRocketBackwardMiddle)) {
450 elevator_wrist_pos_ = kBallBackwardMiddlePos;
451 } else if (data.IsPressed(kRocketForwardUpper)) {
452 elevator_wrist_pos_ = kBallForwardUpperPos;
453 } else if (data.IsPressed(kRocketBackwardUpper)) {
454 elevator_wrist_pos_ = kBallBackwardUpperPos;
455 } else if (data.IsPressed(kCargoForward)) {
456 elevator_wrist_pos_ = kBallCargoForwardPos;
457 } else if (data.IsPressed(kCargoBackward)) {
458 elevator_wrist_pos_ = kBallCargoBackwardPos;
459 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800460 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800461 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800462 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800463 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
464 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800465 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800466 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
467 }
468
469 // Go to elevator/wrist position. Overrides intake position if pressed so
470 // we can re-grab the panel.
471 if (data.IsPressed(kRocketForwardLower)) {
472 elevator_wrist_pos_ = kPanelForwardLowerPos;
473 } else if (data.IsPressed(kRocketBackwardLower)) {
474 elevator_wrist_pos_ = kPanelBackwardLowerPos;
475 } else if (data.IsPressed(kRocketForwardMiddle)) {
476 elevator_wrist_pos_ = kPanelForwardMiddlePos;
477 } else if (data.IsPressed(kRocketBackwardMiddle)) {
478 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
479 } else if (data.IsPressed(kRocketForwardUpper)) {
480 elevator_wrist_pos_ = kPanelForwardUpperPos;
481 } else if (data.IsPressed(kRocketBackwardUpper)) {
482 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800483 } else if (data.IsPressed(kCargoForward)) {
484 elevator_wrist_pos_ = kPanelCargoForwardPos;
485 } else if (data.IsPressed(kCargoBackward)) {
486 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800487 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800488 }
489
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800490 if (switch_ball_) {
491 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700492 (kDoBallIntake &&
Austin Schuh20dc0502019-03-30 07:24:07 -0700493 monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700494 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(0.83);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800495 }
Austin Schuh23a51632019-02-19 16:50:36 -0800496
Alex Perrycb7da4b2019-08-28 19:35:56 -0700497 if (kDoBallIntake && !superstructure_status_fetcher_->has_piece()) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800498 elevator_wrist_pos_ = kBallIntakePos;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700499 mutable_superstructure_goal->mutate_roller_voltage(9.0);
Sabina Davisc6329342019-03-01 20:44:42 -0800500 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800501 } else {
502 if (kDoBallOutake) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700503 mutable_superstructure_goal->mutate_roller_voltage(-6.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800504 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700505 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800506 }
507 }
Austin Schuh23a51632019-02-19 16:50:36 -0800508 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800509
Austin Schuh457bde32019-03-17 18:16:41 -0700510 constexpr double kDeployStiltPosition = 0.5;
511
Austin Schuh457bde32019-03-17 18:16:41 -0700512 if (data.IsPressed(kFallOver)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700513 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.71);
514 mutable_superstructure_goal->mutable_stilts()
515 ->mutable_profile_params()
516 ->mutate_max_velocity(0.65);
517 mutable_superstructure_goal->mutable_stilts()
518 ->mutable_profile_params()
519 ->mutate_max_acceleration(1.25);
Austin Schuhe2f22482019-04-13 23:05:43 -0700520 } else if (data.IsPressed(kHalfStilt)) {
521 was_above_ = false;
James Kuszmaul7077d342021-06-09 20:23:58 -0700522 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.345);
523 mutable_superstructure_goal->mutable_stilts()
524 ->mutable_profile_params()
525 ->mutate_max_velocity(0.65);
Austin Schuhe2f22482019-04-13 23:05:43 -0700526 } else if (data.IsPressed(kDeployStilt) || was_above_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700527 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(
528 kDeployStiltPosition);
529 mutable_superstructure_goal->mutable_stilts()
530 ->mutable_profile_params()
531 ->mutate_max_velocity(0.65);
532 mutable_superstructure_goal->mutable_stilts()
533 ->mutable_profile_params()
534 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700535 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700536 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.005);
537 mutable_superstructure_goal->mutable_stilts()
538 ->mutable_profile_params()
539 ->mutate_max_velocity(0.65);
540 mutable_superstructure_goal->mutable_stilts()
541 ->mutable_profile_params()
542 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700543 }
544
Alex Perrycb7da4b2019-08-28 19:35:56 -0700545 if (superstructure_status_fetcher_->stilts()->position() > 0.1) {
Austin Schuh02be8b92019-03-24 16:04:14 -0700546 elevator_wrist_pos_ = kClimbPos;
James Kuszmaul13738862019-04-14 10:48:00 -0700547 climbed_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700548 mutable_superstructure_goal->mutable_wrist()
549 ->mutable_profile_params()
550 ->mutate_max_acceleration(10);
551 mutable_superstructure_goal->mutable_elevator()
552 ->mutable_profile_params()
553 ->mutate_max_acceleration(6);
Austin Schuh02be8b92019-03-24 16:04:14 -0700554 }
555
Austin Schuhe2f22482019-04-13 23:05:43 -0700556 // If we've been asked to go above deploy and made it up that high, latch
557 // was_above.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700558 if (mutable_superstructure_goal->stilts()->unsafe_goal() >
559 kDeployStiltPosition &&
560 superstructure_status_fetcher_->stilts()->position() >=
Austin Schuh170f4952019-06-29 18:58:30 -0700561 kDeployStiltPosition) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700562 was_above_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700563 } else if ((superstructure_position_fetcher_->platform_left_detect() &&
564 superstructure_position_fetcher_->platform_right_detect()) &&
Austin Schuhe2f22482019-04-13 23:05:43 -0700565 !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700566 was_above_ = false;
567 }
568
Alex Perrycb7da4b2019-08-28 19:35:56 -0700569 if (superstructure_status_fetcher_->stilts()->position() >
Austin Schuh170f4952019-06-29 18:58:30 -0700570 kDeployStiltPosition &&
Alex Perrycb7da4b2019-08-28 19:35:56 -0700571 mutable_superstructure_goal->stilts()->unsafe_goal() ==
572 kDeployStiltPosition) {
573 mutable_superstructure_goal->mutable_stilts()
574 ->mutable_profile_params()
575 ->mutate_max_velocity(0.30);
576 mutable_superstructure_goal->mutable_stilts()
577 ->mutable_profile_params()
578 ->mutate_max_acceleration(0.75);
Austin Schuh457bde32019-03-17 18:16:41 -0700579 }
580
James Kuszmaul13738862019-04-14 10:48:00 -0700581 if ((release_mode_ == ReleaseButtonMode::kRelease &&
582 data.IsPressed(kRelease)) ||
583 data.IsPressed(kReleaseButtonBoard)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800584 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700585 AOS_LOG(INFO, "Releasing due to button\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800586 }
587
Sabina Davisc6329342019-03-01 20:44:42 -0800588 if (switch_ball_) {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800589 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
590 ->mutate_gamepiece_mode(0);
Sabina Davisc6329342019-03-01 20:44:42 -0800591 } else {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800592 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
593 ->mutate_gamepiece_mode(1);
Sabina Davisc6329342019-03-01 20:44:42 -0800594 }
595
Tyler Chatowe0241452019-03-08 21:07:50 -0800596 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
597
James Kuszmaul2457eb72019-12-15 15:37:18 -0800598 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
599 ->mutate_grab_piece(grab_piece_);
Sabina Davis91b23602019-01-21 00:06:01 -0800600
Alex Perrycb7da4b2019-08-28 19:35:56 -0700601 mutable_superstructure_goal->mutable_elevator()->mutate_unsafe_goal(
602 elevator_wrist_pos_.elevator);
603 mutable_superstructure_goal->mutable_wrist()->mutate_unsafe_goal(
604 elevator_wrist_pos_.wrist);
Sabina Davis91b23602019-01-21 00:06:01 -0800605
milind1f1dca32021-07-03 13:50:07 -0700606 if (main_superstructure_goal_builder.Send(superstructure_goal_offset) !=
607 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700608 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800609 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800610
Austin Schuhaab7e162019-03-13 22:44:58 -0700611 if (monotonic_now >
612 last_vision_control_ + ::std::chrono::milliseconds(50)) {
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700613 video_tx_->Send(vision_control_);
Austin Schuhaab7e162019-03-13 22:44:58 -0700614 last_vision_control_ = monotonic_now;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700615 }
Austin Schuh4e2629d2019-03-28 14:44:37 -0700616
617 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700618 auto builder = camera_log_sender_.MakeBuilder();
milind1f1dca32021-07-03 13:50:07 -0700619 (void)builder.Send(
620 CreateCameraLog(*builder.fbb(), data.IsPressed(kCameraLog)));
Austin Schuh4e2629d2019-03-28 14:44:37 -0700621 }
Sabina Davis91b23602019-01-21 00:06:01 -0800622 }
623
624 private:
Austin Schuhc087b102019-05-12 15:33:12 -0700625 ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
626 target_selector_hint_sender_;
627
Alex Perrycb7da4b2019-08-28 19:35:56 -0700628 ::aos::Sender<LocalizerControl> localizer_control_sender_;
Austin Schuheb99d072019-05-12 21:03:38 -0700629
Austin Schuh5671a8c2019-05-19 17:01:04 -0700630 ::aos::Sender<::y2019::CameraLog> camera_log_sender_;
631
Alex Perrycb7da4b2019-08-28 19:35:56 -0700632 ::aos::Fetcher<superstructure::Goal> superstructure_goal_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700633
Alex Perrycb7da4b2019-08-28 19:35:56 -0700634 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
Austin Schuh170f4952019-06-29 18:58:30 -0700635
Alex Perrycb7da4b2019-08-28 19:35:56 -0700636 ::aos::Fetcher<superstructure::Position> superstructure_position_fetcher_;
637 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700638
Austin Schuhe2f22482019-04-13 23:05:43 -0700639 // Bool to track if we've been above the deploy position. Once this bool is
640 // set, don't let the stilts retract until we see the platform.
641 bool was_above_ = false;
642
Sabina Davis91b23602019-01-21 00:06:01 -0800643 // Current goals here.
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800644 ElevatorWristPosition elevator_wrist_pos_ = kStowPos;
Sabina Davisc6329342019-03-01 20:44:42 -0800645 bool grab_piece_ = false;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800646
647 bool switch_ball_ = false;
Tyler Chatowe0241452019-03-08 21:07:50 -0800648
James Kuszmaul13738862019-04-14 10:48:00 -0700649 bool climbed_ = false;
650
651 enum class ReleaseButtonMode {
652 kBallIntake,
653 kRelease,
654 };
655
656 ReleaseButtonMode release_mode_ = ReleaseButtonMode::kRelease;
657 aos::monotonic_clock::time_point last_release_button_press_ =
658 aos::monotonic_clock::min_time;
659
Tyler Chatowe0241452019-03-08 21:07:50 -0800660 VisionControl vision_control_;
661 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700662 ::aos::monotonic_clock::time_point last_vision_control_ =
663 ::aos::monotonic_clock::time_point::min();
Austin Schuhaab7e162019-03-13 22:44:58 -0700664
665 // Time at which we last did not have a game piece.
666 ::aos::monotonic_clock::time_point last_not_has_piece_ =
667 ::aos::monotonic_clock::time_point::min();
Sabina Davis91b23602019-01-21 00:06:01 -0800668};
669
Stephan Pleinesf63bde82024-01-13 15:59:33 -0800670} // namespace y2019::input::joysticks
Sabina Davis91b23602019-01-21 00:06:01 -0800671
Austin Schuh094d09b2020-11-20 23:26:52 -0800672int main(int argc, char **argv) {
673 ::aos::InitGoogle(&argc, &argv);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700674
Alex Perrycb7da4b2019-08-28 19:35:56 -0700675 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -0800676 aos::configuration::ReadConfig("aos_config.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700677
678 ::aos::ShmEventLoop event_loop(&config.message());
Sabina Davis91b23602019-01-21 00:06:01 -0800679 ::y2019::input::joysticks::Reader reader(&event_loop);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700680
681 event_loop.Run();
682
Austin Schuhae87e312020-08-01 16:15:01 -0700683 return 0;
Sabina Davis91b23602019-01-21 00:06:01 -0800684}