blob: 40e8708e6f711de5385c91c57c15ba78c90692a0 [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 }
Austin Schuh6bdcc372024-06-27 14:49:11 -0700247 superstructure::Goal *mutable_superstructure_goal =
Alex Perrycb7da4b2019-08-28 19:35:56 -0700248 GetMutableTemporaryPointer(*main_superstructure_goal_builder.fbb(),
Austin Schuh6bdcc372024-06-27 14:49:11 -0700249 superstructure_goal_offset);
250 CHECK(mutable_superstructure_goal != nullptr);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700251
252 {
253 auto builder = target_selector_hint_sender_.MakeBuilder();
254 control_loops::drivetrain::TargetSelectorHint::Builder
255 target_selector_hint_builder =
256 builder
257 .MakeBuilder<control_loops::drivetrain::TargetSelectorHint>();
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700258 if (data.IsPressed(kNearCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700259 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800260 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700261 } else if (data.IsPressed(kMidCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700262 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800263 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700264 } else if (data.IsPressed(kFarCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700265 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800266 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700267 } else {
James Kuszmaul518640d2019-04-13 15:50:50 -0700268 const double cargo_joy_y = data.GetAxis(kCargoSelectorY);
269 const double cargo_joy_x = data.GetAxis(kCargoSelectorX);
270 if (cargo_joy_y > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700271 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700272 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul1b822b42019-04-14 14:27:35 -0700273 } else if (cargo_joy_y < -0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700274 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800275 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700276 } else if (::std::abs(cargo_joy_x) > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700277 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700278 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700279 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700280 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700281 control_loops::drivetrain::SelectionHint::NONE);
James Kuszmaul518640d2019-04-13 15:50:50 -0700282 }
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700283 }
milind1f1dca32021-07-03 13:50:07 -0700284 if (builder.Send(target_selector_hint_builder.Finish()) !=
285 aos::RawSender::Error::kOk) {
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
milind1f1dca32021-07-03 13:50:07 -0700299 if (builder.Send(localizer_control_builder.Finish()) !=
300 aos::RawSender::Error::kOk) {
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
milind1f1dca32021-07-03 13:50:07 -0700314 if (builder.Send(localizer_control_builder.Finish()) !=
315 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700316 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700317 }
318 }
319
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700320 if (data.PosEdge(kResetLocalizerLeftForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700321 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700322 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700323 LocalizerControl::Builder localizer_control_builder =
324 builder.MakeBuilder<LocalizerControl>();
325 localizer_control_builder.add_x(0.4);
326 localizer_control_builder.add_y(3.4);
327 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700328
milind1f1dca32021-07-03 13:50:07 -0700329 if (builder.Send(localizer_control_builder.Finish()) !=
330 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700331 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700332 }
333 }
334
335 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700336 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700337 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700338 LocalizerControl::Builder localizer_control_builder =
339 builder.MakeBuilder<LocalizerControl>();
340 localizer_control_builder.add_x(0.4);
341 localizer_control_builder.add_y(3.4);
342 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700343
milind1f1dca32021-07-03 13:50:07 -0700344 if (builder.Send(localizer_control_builder.Finish()) !=
345 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700346 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700347 }
348 }
349
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700350 if (data.PosEdge(kResetLocalizerRightForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700351 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700352 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700353 LocalizerControl::Builder localizer_control_builder =
354 builder.MakeBuilder<LocalizerControl>();
355 localizer_control_builder.add_x(0.4);
356 localizer_control_builder.add_y(-3.4);
357 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700358
milind1f1dca32021-07-03 13:50:07 -0700359 if (builder.Send(localizer_control_builder.Finish()) !=
360 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700361 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700362 }
363 }
364
365 if (data.PosEdge(kResetLocalizerRightBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700366 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700367 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700368 LocalizerControl::Builder localizer_control_builder =
369 builder.MakeBuilder<LocalizerControl>();
370 localizer_control_builder.add_x(0.4);
371 localizer_control_builder.add_y(-3.4);
372 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700373
milind1f1dca32021-07-03 13:50:07 -0700374 if (builder.Send(localizer_control_builder.Finish()) !=
375 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700376 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmauld8deb682019-03-10 10:38:42 -0700377 }
378 }
379
James Kuszmaul13738862019-04-14 10:48:00 -0700380 if (data.PosEdge(kRelease) &&
381 monotonic_now >
382 last_release_button_press_ + ::std::chrono::milliseconds(500)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700383 if (superstructure_status_fetcher_->has_piece()) {
James Kuszmaul13738862019-04-14 10:48:00 -0700384 release_mode_ = ReleaseButtonMode::kRelease;
385 } else {
386 release_mode_ = ReleaseButtonMode::kBallIntake;
387 }
388 }
389
390 if (data.IsPressed(kRelease)) {
391 last_release_button_press_ = monotonic_now;
392 }
393
Alex Perrycb7da4b2019-08-28 19:35:56 -0700394 AOS_LOG(INFO, "has_piece: %d\n",
395 superstructure_status_fetcher_->has_piece());
Austin Schuh1a17e132019-02-17 15:05:06 -0800396 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800397 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800398 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800399 grab_piece_ = true;
James Kuszmaul13738862019-04-14 10:48:00 -0700400 } else if ((release_mode_ == ReleaseButtonMode::kRelease &&
401 data.IsPressed(kRelease)) ||
Tyler Chatow5eeee902019-04-12 20:47:48 -0700402 data.IsPressed(kReleaseButtonBoard) ||
Alex Perrycb7da4b2019-08-28 19:35:56 -0700403 !superstructure_status_fetcher_->has_piece()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800404 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700405 AOS_LOG(INFO, "releasing due to other thing\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800406 }
Sabina Davis91b23602019-01-21 00:06:01 -0800407
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800408 if (data.IsPressed(kRocketBackwardUnpressed)) {
409 elevator_wrist_pos_ = kStowPos;
410 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700411 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(-1.2);
412 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800413
James Kuszmaul13738862019-04-14 10:48:00 -0700414 const bool kDoBallIntake =
415 (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake &&
416 data.IsPressed(kRelease)) ||
417 data.GetAxis(kBallIntake) > 0.9;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800418 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
419
420 if (data.IsPressed(kPanelSwitch)) {
421 switch_ball_ = false;
422 } else if (data.IsPressed(kCargoSwitch)) {
423 switch_ball_ = true;
424 }
425
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800426 if (switch_ball_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700427 if (superstructure_status_fetcher_->has_piece()) {
428 mutable_superstructure_goal->mutable_wrist()
429 ->mutable_profile_params()
430 ->mutate_max_acceleration(20);
Austin Schuh1a17e132019-02-17 15:05:06 -0800431 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800432
433 // Go to intake position and apply vacuum
434 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800435 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800436 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
437 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800438 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800439 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
440 }
441
442 // Go to elevator/wrist position. Overrides intake position if pressed so
443 // we can re-grab the ball.
444 if (data.IsPressed(kRocketForwardLower)) {
445 elevator_wrist_pos_ = kBallForwardLowerPos;
446 } else if (data.IsPressed(kRocketBackwardLower)) {
447 elevator_wrist_pos_ = kBallBackwardLowerPos;
448 } else if (data.IsPressed(kRocketForwardMiddle)) {
449 elevator_wrist_pos_ = kBallForwardMiddlePos;
450 } else if (data.IsPressed(kRocketBackwardMiddle)) {
451 elevator_wrist_pos_ = kBallBackwardMiddlePos;
452 } else if (data.IsPressed(kRocketForwardUpper)) {
453 elevator_wrist_pos_ = kBallForwardUpperPos;
454 } else if (data.IsPressed(kRocketBackwardUpper)) {
455 elevator_wrist_pos_ = kBallBackwardUpperPos;
456 } else if (data.IsPressed(kCargoForward)) {
457 elevator_wrist_pos_ = kBallCargoForwardPos;
458 } else if (data.IsPressed(kCargoBackward)) {
459 elevator_wrist_pos_ = kBallCargoBackwardPos;
460 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800461 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800462 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800463 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800464 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
465 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800466 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800467 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
468 }
469
470 // Go to elevator/wrist position. Overrides intake position if pressed so
471 // we can re-grab the panel.
472 if (data.IsPressed(kRocketForwardLower)) {
473 elevator_wrist_pos_ = kPanelForwardLowerPos;
474 } else if (data.IsPressed(kRocketBackwardLower)) {
475 elevator_wrist_pos_ = kPanelBackwardLowerPos;
476 } else if (data.IsPressed(kRocketForwardMiddle)) {
477 elevator_wrist_pos_ = kPanelForwardMiddlePos;
478 } else if (data.IsPressed(kRocketBackwardMiddle)) {
479 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
480 } else if (data.IsPressed(kRocketForwardUpper)) {
481 elevator_wrist_pos_ = kPanelForwardUpperPos;
482 } else if (data.IsPressed(kRocketBackwardUpper)) {
483 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800484 } else if (data.IsPressed(kCargoForward)) {
485 elevator_wrist_pos_ = kPanelCargoForwardPos;
486 } else if (data.IsPressed(kCargoBackward)) {
487 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800488 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800489 }
490
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800491 if (switch_ball_) {
492 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700493 (kDoBallIntake &&
Austin Schuh20dc0502019-03-30 07:24:07 -0700494 monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700495 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(0.83);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800496 }
Austin Schuh23a51632019-02-19 16:50:36 -0800497
Alex Perrycb7da4b2019-08-28 19:35:56 -0700498 if (kDoBallIntake && !superstructure_status_fetcher_->has_piece()) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800499 elevator_wrist_pos_ = kBallIntakePos;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700500 mutable_superstructure_goal->mutate_roller_voltage(9.0);
Sabina Davisc6329342019-03-01 20:44:42 -0800501 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800502 } else {
503 if (kDoBallOutake) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700504 mutable_superstructure_goal->mutate_roller_voltage(-6.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800505 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700506 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800507 }
508 }
Austin Schuh23a51632019-02-19 16:50:36 -0800509 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800510
Austin Schuh457bde32019-03-17 18:16:41 -0700511 constexpr double kDeployStiltPosition = 0.5;
512
Austin Schuh457bde32019-03-17 18:16:41 -0700513 if (data.IsPressed(kFallOver)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700514 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.71);
515 mutable_superstructure_goal->mutable_stilts()
516 ->mutable_profile_params()
517 ->mutate_max_velocity(0.65);
518 mutable_superstructure_goal->mutable_stilts()
519 ->mutable_profile_params()
520 ->mutate_max_acceleration(1.25);
Austin Schuhe2f22482019-04-13 23:05:43 -0700521 } else if (data.IsPressed(kHalfStilt)) {
522 was_above_ = false;
James Kuszmaul7077d342021-06-09 20:23:58 -0700523 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.345);
524 mutable_superstructure_goal->mutable_stilts()
525 ->mutable_profile_params()
526 ->mutate_max_velocity(0.65);
Austin Schuhe2f22482019-04-13 23:05:43 -0700527 } else if (data.IsPressed(kDeployStilt) || was_above_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700528 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(
529 kDeployStiltPosition);
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 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700537 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.005);
538 mutable_superstructure_goal->mutable_stilts()
539 ->mutable_profile_params()
540 ->mutate_max_velocity(0.65);
541 mutable_superstructure_goal->mutable_stilts()
542 ->mutable_profile_params()
543 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700544 }
545
Alex Perrycb7da4b2019-08-28 19:35:56 -0700546 if (superstructure_status_fetcher_->stilts()->position() > 0.1) {
Austin Schuh02be8b92019-03-24 16:04:14 -0700547 elevator_wrist_pos_ = kClimbPos;
James Kuszmaul13738862019-04-14 10:48:00 -0700548 climbed_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700549 mutable_superstructure_goal->mutable_wrist()
550 ->mutable_profile_params()
551 ->mutate_max_acceleration(10);
552 mutable_superstructure_goal->mutable_elevator()
553 ->mutable_profile_params()
554 ->mutate_max_acceleration(6);
Austin Schuh02be8b92019-03-24 16:04:14 -0700555 }
556
Austin Schuhe2f22482019-04-13 23:05:43 -0700557 // If we've been asked to go above deploy and made it up that high, latch
558 // was_above.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700559 if (mutable_superstructure_goal->stilts()->unsafe_goal() >
560 kDeployStiltPosition &&
561 superstructure_status_fetcher_->stilts()->position() >=
Austin Schuh170f4952019-06-29 18:58:30 -0700562 kDeployStiltPosition) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700563 was_above_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700564 } else if ((superstructure_position_fetcher_->platform_left_detect() &&
565 superstructure_position_fetcher_->platform_right_detect()) &&
Austin Schuhe2f22482019-04-13 23:05:43 -0700566 !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700567 was_above_ = false;
568 }
569
Alex Perrycb7da4b2019-08-28 19:35:56 -0700570 if (superstructure_status_fetcher_->stilts()->position() >
Austin Schuh170f4952019-06-29 18:58:30 -0700571 kDeployStiltPosition &&
Alex Perrycb7da4b2019-08-28 19:35:56 -0700572 mutable_superstructure_goal->stilts()->unsafe_goal() ==
573 kDeployStiltPosition) {
574 mutable_superstructure_goal->mutable_stilts()
575 ->mutable_profile_params()
576 ->mutate_max_velocity(0.30);
577 mutable_superstructure_goal->mutable_stilts()
578 ->mutable_profile_params()
579 ->mutate_max_acceleration(0.75);
Austin Schuh457bde32019-03-17 18:16:41 -0700580 }
581
James Kuszmaul13738862019-04-14 10:48:00 -0700582 if ((release_mode_ == ReleaseButtonMode::kRelease &&
583 data.IsPressed(kRelease)) ||
584 data.IsPressed(kReleaseButtonBoard)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800585 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700586 AOS_LOG(INFO, "Releasing due to button\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800587 }
588
Austin Schuh6bdcc372024-06-27 14:49:11 -0700589 auto mutable_suction = mutable_superstructure_goal->mutable_suction();
590 CHECK(mutable_suction != nullptr);
Sabina Davisc6329342019-03-01 20:44:42 -0800591 if (switch_ball_) {
Austin Schuh6bdcc372024-06-27 14:49:11 -0700592 mutable_suction->mutate_gamepiece_mode(0);
Sabina Davisc6329342019-03-01 20:44:42 -0800593 } else {
Austin Schuh6bdcc372024-06-27 14:49:11 -0700594 mutable_suction->mutate_gamepiece_mode(1);
Sabina Davisc6329342019-03-01 20:44:42 -0800595 }
596
Tyler Chatowe0241452019-03-08 21:07:50 -0800597 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
598
Austin Schuh6bdcc372024-06-27 14:49:11 -0700599 mutable_suction->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}