blob: 4e73f9e46cfef24af3791a466315e1d9906c351c [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
Philipp Schrader790cb542023-07-05 21:06:52 -07008#include "external/com_google_protobuf/src/google/protobuf/stubs/stringprintf.h"
9
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
Sabina Davis91b23602019-01-21 00:06:01 -080044namespace y2019 {
45namespace input {
46namespace joysticks {
47
Alex Perrycb7da4b2019-08-28 19:35:56 -070048namespace superstructure = y2019::control_loops::superstructure;
49
Tyler Chatowe0241452019-03-08 21:07:50 -080050using google::protobuf::StringPrintf;
51
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080052struct ElevatorWristPosition {
53 double elevator;
54 double wrist;
55};
Sabina Davis91b23602019-01-21 00:06:01 -080056
Tyler Chatow5eeee902019-04-12 20:47:48 -070057const ButtonLocation kSuctionBall(4, 2);
58const ButtonLocation kSuctionHatch(3, 15);
59const ButtonLocation kDeployStilt(4, 1);
60const ButtonLocation kHalfStilt(4, 3);
61const ButtonLocation kFallOver(3, 16);
62
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080063const ButtonLocation kRocketForwardLower(5, 1);
64const ButtonLocation kRocketForwardMiddle(5, 2);
65const ButtonLocation kRocketForwardUpper(5, 4);
66const ButtonLocation kCargoForward(5, 3);
67
68const POVLocation kRocketBackwardUnpressed(5, -1);
69const POVLocation kRocketBackwardLower(5, 180);
70const POVLocation kRocketBackwardMiddle(5, 90);
71const POVLocation kRocketBackwardUpper(5, 0);
72const POVLocation kCargoBackward(5, 270);
73
74const ButtonLocation kPanelSwitch(5, 7);
75const ButtonLocation kCargoSwitch(5, 8);
76
77const ButtonLocation kBallHPIntakeForward(5, 6);
78const ButtonLocation kBallHPIntakeBackward(5, 5);
79const JoystickAxis kBallOutake(5, 3);
80const JoystickAxis kBallIntake(5, 4);
81
82const ButtonLocation kPanelHPIntakeForward(5, 6);
83const ButtonLocation kPanelHPIntakeBackward(5, 5);
84
85const ButtonLocation kRelease(2, 4);
James Kuszmaulccc368b2019-04-11 20:00:07 -070086// Reuse quickturn for the cancel button.
87const ButtonLocation kCancelAutoMode(2, 3);
Tyler Chatow5eeee902019-04-12 20:47:48 -070088const ButtonLocation kReleaseButtonBoard(3, 4);
89const ButtonLocation kResetLocalizerLeftForwards(3, 10);
90const ButtonLocation kResetLocalizerLeftBackwards(3, 9);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080091
Tyler Chatow5eeee902019-04-12 20:47:48 -070092const ButtonLocation kResetLocalizerRightForwards(3, 8);
93const ButtonLocation kResetLocalizerRightBackwards(3, 7);
Tyler Chatow07c906b2019-03-09 21:29:06 -080094
James Kuszmaul518640d2019-04-13 15:50:50 -070095const ButtonLocation kResetLocalizerLeft(3, 11);
96const ButtonLocation kResetLocalizerRight(3, 13);
97
Tyler Chatow5eeee902019-04-12 20:47:48 -070098const ButtonLocation kNearCargoHint(3, 3);
99const ButtonLocation kMidCargoHint(3, 5);
100const ButtonLocation kFarCargoHint(3, 6);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700101
James Kuszmaul518640d2019-04-13 15:50:50 -0700102const JoystickAxis kCargoSelectorY(5, 6);
103const JoystickAxis kCargoSelectorX(5, 5);
104
Tyler Chatow5eeee902019-04-12 20:47:48 -0700105const ButtonLocation kCameraLog(3, 14);
Austin Schuh4e2629d2019-03-28 14:44:37 -0700106
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800107const ElevatorWristPosition kStowPos{0.36, 0.0};
Austin Schuh02be8b92019-03-24 16:04:14 -0700108const ElevatorWristPosition kClimbPos{0.0, M_PI / 4.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800109
Austin Schuh139f59d2019-03-17 18:16:13 -0700110const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
111const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800112
113const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0};
114const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0};
115
Sabina Davise48004f2019-03-02 23:15:24 -0800116const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
117const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800118
Sabina Davise48004f2019-03-02 23:15:24 -0800119const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0};
120const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800121
Sabina Davise6fe6c52019-03-03 15:48:51 -0800122const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0};
123const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
124
Austin Schuh6c5deb12019-03-24 16:48:32 -0700125const ElevatorWristPosition kBallForwardLowerPos{0.21, 1.27};
Austin Schuh20dc0502019-03-30 07:24:07 -0700126const ElevatorWristPosition kBallBackwardLowerPos{0.43, -1.99};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800127
Austin Schuh20dc0502019-03-30 07:24:07 -0700128const ElevatorWristPosition kBallForwardMiddlePos{0.925, 1.21};
129const ElevatorWristPosition kBallBackwardMiddlePos{1.19, -1.98};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800130
Austin Schuh139f59d2019-03-17 18:16:13 -0700131const ElevatorWristPosition kBallForwardUpperPos{1.51, 0.961};
132const ElevatorWristPosition kBallBackwardUpperPos{1.44, -1.217};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800133
Austin Schuh20dc0502019-03-30 07:24:07 -0700134const ElevatorWristPosition kBallCargoForwardPos{0.59, 1.2};
135const ElevatorWristPosition kBallCargoBackwardPos{0.868265, -2.1};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800136
Sabina Davise6fe6c52019-03-03 15:48:51 -0800137const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097};
138const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800139
Austin Schuh20dc0502019-03-30 07:24:07 -0700140const ElevatorWristPosition kBallIntakePos{0.309, 2.13};
Austin Schuh2cf16b82019-02-15 23:23:22 -0800141
James Kuszmaul7077d342021-06-09 20:23:58 -0700142class Reader : public ::frc971::input::ActionJoystickInput {
Sabina Davis91b23602019-01-21 00:06:01 -0800143 public:
144 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -0700145 : ::frc971::input::ActionJoystickInput(
Sabina Davis91b23602019-01-21 00:06:01 -0800146 event_loop,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700147 ::y2019::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -0700148 ::frc971::input::DrivetrainInputReader::InputType::kPistol,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700149 {.run_teleop_in_auto = true,
Austin Schuhc087b102019-05-12 15:33:12 -0700150 .cancel_auto_button = kCancelAutoMode}),
151 target_selector_hint_sender_(
152 event_loop->MakeSender<
153 ::y2019::control_loops::drivetrain::TargetSelectorHint>(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700154 "/drivetrain")),
Austin Schuheb99d072019-05-12 21:03:38 -0700155 localizer_control_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700156 event_loop->MakeSender<LocalizerControl>("/drivetrain")),
Austin Schuh5671a8c2019-05-19 17:01:04 -0700157 camera_log_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700158 event_loop->MakeSender<::y2019::CameraLog>("/camera")),
159 superstructure_goal_fetcher_(
160 event_loop->MakeFetcher<superstructure::Goal>("/superstructure")),
161 superstructure_goal_sender_(
162 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700163 superstructure_position_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700164 event_loop->MakeFetcher<superstructure::Position>(
165 "/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700166 superstructure_status_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700167 event_loop->MakeFetcher<superstructure::Status>(
168 "/superstructure")) {
Tyler Chatowe0241452019-03-08 21:07:50 -0800169 const uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuh170f4952019-06-29 18:58:30 -0700170 superstructure_goal_fetcher_.Fetch();
171 if (superstructure_goal_fetcher_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700172 grab_piece_ = superstructure_goal_fetcher_->has_suction()
173 ? superstructure_goal_fetcher_->suction()->grab_piece()
174 : false;
175 switch_ball_ =
176 superstructure_goal_fetcher_->has_suction()
177 ? (superstructure_goal_fetcher_->suction()->gamepiece_mode() == 0)
178 : true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800179 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800180 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
181 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800182 }
Sabina Davis91b23602019-01-21 00:06:01 -0800183
Austin Schuha78857f2019-03-13 22:43:41 -0700184 void AutoEnded() override {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700185 AOS_LOG(INFO, "Auto ended, assuming disc and have piece\n");
Austin Schuha78857f2019-03-13 22:43:41 -0700186 grab_piece_ = true;
187 switch_ball_ = false;
188 }
189
James Kuszmaul7077d342021-06-09 20:23:58 -0700190 void HandleTeleop(
191 const ::frc971::input::driver_station::Data &data) override {
Austin Schuhaab7e162019-03-13 22:44:58 -0700192 ::aos::monotonic_clock::time_point monotonic_now =
193 ::aos::monotonic_clock::now();
Austin Schuh170f4952019-06-29 18:58:30 -0700194 superstructure_position_fetcher_.Fetch();
195 superstructure_status_fetcher_.Fetch();
196 if (!superstructure_status_fetcher_.get() ||
197 !superstructure_position_fetcher_.get()) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700198 AOS_LOG(ERROR, "Got no superstructure status or position packet.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800199 return;
200 }
201
Alex Perrycb7da4b2019-08-28 19:35:56 -0700202 CHECK(superstructure_status_fetcher_->has_stilts());
203
204 if (!superstructure_status_fetcher_->has_piece()) {
Austin Schuhaab7e162019-03-13 22:44:58 -0700205 last_not_has_piece_ = monotonic_now;
206 }
207
Alex Perrycb7da4b2019-08-28 19:35:56 -0700208 auto main_superstructure_goal_builder =
209 superstructure_goal_sender_.MakeBuilder();
210
211 flatbuffers::Offset<superstructure::Goal> superstructure_goal_offset;
Sabina Davis91b23602019-01-21 00:06:01 -0800212
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700213 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700214 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
215 elevator_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
216 *main_superstructure_goal_builder.fbb(), 0.0,
217 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
218 0.0, 0.0));
219
220 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
221 intake_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
222 *main_superstructure_goal_builder.fbb(), -1.2);
223
224 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
225 wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
226 *main_superstructure_goal_builder.fbb(), 0.0,
227 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
228 0.0, 0.0));
229
230 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
231 stilts_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
232 *main_superstructure_goal_builder.fbb(), 0.0,
233 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
234 0.0, 0.0));
235
James Kuszmaul2457eb72019-12-15 15:37:18 -0800236 flatbuffers::Offset<SuctionGoal> suction_offset =
237 CreateSuctionGoal(*main_superstructure_goal_builder.fbb(), false, 0);
238
Alex Perrycb7da4b2019-08-28 19:35:56 -0700239 superstructure::Goal::Builder superstructure_goal_builder =
240 main_superstructure_goal_builder.MakeBuilder<superstructure::Goal>();
241
242 superstructure_goal_builder.add_elevator(elevator_offset);
243 superstructure_goal_builder.add_intake(intake_offset);
244 superstructure_goal_builder.add_wrist(wrist_offset);
245 superstructure_goal_builder.add_stilts(stilts_offset);
James Kuszmaul2457eb72019-12-15 15:37:18 -0800246 superstructure_goal_builder.add_suction(suction_offset);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700247 superstructure_goal_builder.add_roller_voltage(0.0);
248
249 superstructure_goal_offset = superstructure_goal_builder.Finish();
250 }
James Kuszmaul2457eb72019-12-15 15:37:18 -0800251 superstructure::Goal *mutable_superstructure_goal = CHECK_NOTNULL(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700252 GetMutableTemporaryPointer(*main_superstructure_goal_builder.fbb(),
James Kuszmaul2457eb72019-12-15 15:37:18 -0800253 superstructure_goal_offset));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700254
255 {
256 auto builder = target_selector_hint_sender_.MakeBuilder();
257 control_loops::drivetrain::TargetSelectorHint::Builder
258 target_selector_hint_builder =
259 builder
260 .MakeBuilder<control_loops::drivetrain::TargetSelectorHint>();
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700261 if (data.IsPressed(kNearCargoHint)) {
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::NEAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700264 } else if (data.IsPressed(kMidCargoHint)) {
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::MID_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700267 } else if (data.IsPressed(kFarCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700268 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800269 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700270 } else {
James Kuszmaul518640d2019-04-13 15:50:50 -0700271 const double cargo_joy_y = data.GetAxis(kCargoSelectorY);
272 const double cargo_joy_x = data.GetAxis(kCargoSelectorX);
273 if (cargo_joy_y > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700274 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700275 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul1b822b42019-04-14 14:27:35 -0700276 } else if (cargo_joy_y < -0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700277 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800278 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700279 } else if (::std::abs(cargo_joy_x) > 0.5) {
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::MID_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700282 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700283 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700284 control_loops::drivetrain::SelectionHint::NONE);
James Kuszmaul518640d2019-04-13 15:50:50 -0700285 }
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700286 }
milind1f1dca32021-07-03 13:50:07 -0700287 if (builder.Send(target_selector_hint_builder.Finish()) !=
288 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700289 AOS_LOG(ERROR, "Failed to send target selector hint.\n");
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700290 }
291 }
292
James Kuszmaul518640d2019-04-13 15:50:50 -0700293 if (data.PosEdge(kResetLocalizerLeft)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700294 auto builder = localizer_control_sender_.MakeBuilder();
James Kuszmaul518640d2019-04-13 15:50:50 -0700295 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700296 LocalizerControl::Builder localizer_control_builder =
297 builder.MakeBuilder<LocalizerControl>();
298 localizer_control_builder.add_x(0.6);
299 localizer_control_builder.add_y(3.4);
300 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700301
milind1f1dca32021-07-03 13:50:07 -0700302 if (builder.Send(localizer_control_builder.Finish()) !=
303 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700304 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700305 }
306 }
307
308 if (data.PosEdge(kResetLocalizerRight)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700309 auto builder = localizer_control_sender_.MakeBuilder();
310 // Start at the right feeder station.
311 LocalizerControl::Builder localizer_control_builder =
312 builder.MakeBuilder<LocalizerControl>();
313 localizer_control_builder.add_x(0.6);
314 localizer_control_builder.add_y(-3.4);
315 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700316
milind1f1dca32021-07-03 13:50:07 -0700317 if (builder.Send(localizer_control_builder.Finish()) !=
318 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700319 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700320 }
321 }
322
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700323 if (data.PosEdge(kResetLocalizerLeftForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700324 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700325 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700326 LocalizerControl::Builder localizer_control_builder =
327 builder.MakeBuilder<LocalizerControl>();
328 localizer_control_builder.add_x(0.4);
329 localizer_control_builder.add_y(3.4);
330 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700331
milind1f1dca32021-07-03 13:50:07 -0700332 if (builder.Send(localizer_control_builder.Finish()) !=
333 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700334 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700335 }
336 }
337
338 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700339 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700340 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700341 LocalizerControl::Builder localizer_control_builder =
342 builder.MakeBuilder<LocalizerControl>();
343 localizer_control_builder.add_x(0.4);
344 localizer_control_builder.add_y(3.4);
345 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700346
milind1f1dca32021-07-03 13:50:07 -0700347 if (builder.Send(localizer_control_builder.Finish()) !=
348 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700349 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700350 }
351 }
352
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700353 if (data.PosEdge(kResetLocalizerRightForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700354 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700355 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700356 LocalizerControl::Builder localizer_control_builder =
357 builder.MakeBuilder<LocalizerControl>();
358 localizer_control_builder.add_x(0.4);
359 localizer_control_builder.add_y(-3.4);
360 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700361
milind1f1dca32021-07-03 13:50:07 -0700362 if (builder.Send(localizer_control_builder.Finish()) !=
363 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700364 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700365 }
366 }
367
368 if (data.PosEdge(kResetLocalizerRightBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700369 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700370 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700371 LocalizerControl::Builder localizer_control_builder =
372 builder.MakeBuilder<LocalizerControl>();
373 localizer_control_builder.add_x(0.4);
374 localizer_control_builder.add_y(-3.4);
375 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700376
milind1f1dca32021-07-03 13:50:07 -0700377 if (builder.Send(localizer_control_builder.Finish()) !=
378 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700379 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmauld8deb682019-03-10 10:38:42 -0700380 }
381 }
382
James Kuszmaul13738862019-04-14 10:48:00 -0700383 if (data.PosEdge(kRelease) &&
384 monotonic_now >
385 last_release_button_press_ + ::std::chrono::milliseconds(500)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700386 if (superstructure_status_fetcher_->has_piece()) {
James Kuszmaul13738862019-04-14 10:48:00 -0700387 release_mode_ = ReleaseButtonMode::kRelease;
388 } else {
389 release_mode_ = ReleaseButtonMode::kBallIntake;
390 }
391 }
392
393 if (data.IsPressed(kRelease)) {
394 last_release_button_press_ = monotonic_now;
395 }
396
Alex Perrycb7da4b2019-08-28 19:35:56 -0700397 AOS_LOG(INFO, "has_piece: %d\n",
398 superstructure_status_fetcher_->has_piece());
Austin Schuh1a17e132019-02-17 15:05:06 -0800399 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800400 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800401 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800402 grab_piece_ = true;
James Kuszmaul13738862019-04-14 10:48:00 -0700403 } else if ((release_mode_ == ReleaseButtonMode::kRelease &&
404 data.IsPressed(kRelease)) ||
Tyler Chatow5eeee902019-04-12 20:47:48 -0700405 data.IsPressed(kReleaseButtonBoard) ||
Alex Perrycb7da4b2019-08-28 19:35:56 -0700406 !superstructure_status_fetcher_->has_piece()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800407 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700408 AOS_LOG(INFO, "releasing due to other thing\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800409 }
Sabina Davis91b23602019-01-21 00:06:01 -0800410
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800411 if (data.IsPressed(kRocketBackwardUnpressed)) {
412 elevator_wrist_pos_ = kStowPos;
413 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700414 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(-1.2);
415 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800416
James Kuszmaul13738862019-04-14 10:48:00 -0700417 const bool kDoBallIntake =
418 (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake &&
419 data.IsPressed(kRelease)) ||
420 data.GetAxis(kBallIntake) > 0.9;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800421 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
422
423 if (data.IsPressed(kPanelSwitch)) {
424 switch_ball_ = false;
425 } else if (data.IsPressed(kCargoSwitch)) {
426 switch_ball_ = true;
427 }
428
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800429 if (switch_ball_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700430 if (superstructure_status_fetcher_->has_piece()) {
431 mutable_superstructure_goal->mutable_wrist()
432 ->mutable_profile_params()
433 ->mutate_max_acceleration(20);
Austin Schuh1a17e132019-02-17 15:05:06 -0800434 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800435
436 // Go to intake position and apply vacuum
437 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800438 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800439 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
440 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800441 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800442 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
443 }
444
445 // Go to elevator/wrist position. Overrides intake position if pressed so
446 // we can re-grab the ball.
447 if (data.IsPressed(kRocketForwardLower)) {
448 elevator_wrist_pos_ = kBallForwardLowerPos;
449 } else if (data.IsPressed(kRocketBackwardLower)) {
450 elevator_wrist_pos_ = kBallBackwardLowerPos;
451 } else if (data.IsPressed(kRocketForwardMiddle)) {
452 elevator_wrist_pos_ = kBallForwardMiddlePos;
453 } else if (data.IsPressed(kRocketBackwardMiddle)) {
454 elevator_wrist_pos_ = kBallBackwardMiddlePos;
455 } else if (data.IsPressed(kRocketForwardUpper)) {
456 elevator_wrist_pos_ = kBallForwardUpperPos;
457 } else if (data.IsPressed(kRocketBackwardUpper)) {
458 elevator_wrist_pos_ = kBallBackwardUpperPos;
459 } else if (data.IsPressed(kCargoForward)) {
460 elevator_wrist_pos_ = kBallCargoForwardPos;
461 } else if (data.IsPressed(kCargoBackward)) {
462 elevator_wrist_pos_ = kBallCargoBackwardPos;
463 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800464 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800465 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800466 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800467 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
468 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800469 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800470 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
471 }
472
473 // Go to elevator/wrist position. Overrides intake position if pressed so
474 // we can re-grab the panel.
475 if (data.IsPressed(kRocketForwardLower)) {
476 elevator_wrist_pos_ = kPanelForwardLowerPos;
477 } else if (data.IsPressed(kRocketBackwardLower)) {
478 elevator_wrist_pos_ = kPanelBackwardLowerPos;
479 } else if (data.IsPressed(kRocketForwardMiddle)) {
480 elevator_wrist_pos_ = kPanelForwardMiddlePos;
481 } else if (data.IsPressed(kRocketBackwardMiddle)) {
482 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
483 } else if (data.IsPressed(kRocketForwardUpper)) {
484 elevator_wrist_pos_ = kPanelForwardUpperPos;
485 } else if (data.IsPressed(kRocketBackwardUpper)) {
486 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800487 } else if (data.IsPressed(kCargoForward)) {
488 elevator_wrist_pos_ = kPanelCargoForwardPos;
489 } else if (data.IsPressed(kCargoBackward)) {
490 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800491 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800492 }
493
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800494 if (switch_ball_) {
495 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700496 (kDoBallIntake &&
Austin Schuh20dc0502019-03-30 07:24:07 -0700497 monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700498 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(0.83);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800499 }
Austin Schuh23a51632019-02-19 16:50:36 -0800500
Alex Perrycb7da4b2019-08-28 19:35:56 -0700501 if (kDoBallIntake && !superstructure_status_fetcher_->has_piece()) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800502 elevator_wrist_pos_ = kBallIntakePos;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700503 mutable_superstructure_goal->mutate_roller_voltage(9.0);
Sabina Davisc6329342019-03-01 20:44:42 -0800504 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800505 } else {
506 if (kDoBallOutake) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700507 mutable_superstructure_goal->mutate_roller_voltage(-6.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800508 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700509 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800510 }
511 }
Austin Schuh23a51632019-02-19 16:50:36 -0800512 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800513
Austin Schuh457bde32019-03-17 18:16:41 -0700514 constexpr double kDeployStiltPosition = 0.5;
515
Austin Schuh457bde32019-03-17 18:16:41 -0700516 if (data.IsPressed(kFallOver)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700517 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.71);
518 mutable_superstructure_goal->mutable_stilts()
519 ->mutable_profile_params()
520 ->mutate_max_velocity(0.65);
521 mutable_superstructure_goal->mutable_stilts()
522 ->mutable_profile_params()
523 ->mutate_max_acceleration(1.25);
Austin Schuhe2f22482019-04-13 23:05:43 -0700524 } else if (data.IsPressed(kHalfStilt)) {
525 was_above_ = false;
James Kuszmaul7077d342021-06-09 20:23:58 -0700526 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.345);
527 mutable_superstructure_goal->mutable_stilts()
528 ->mutable_profile_params()
529 ->mutate_max_velocity(0.65);
Austin Schuhe2f22482019-04-13 23:05:43 -0700530 } else if (data.IsPressed(kDeployStilt) || was_above_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700531 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(
532 kDeployStiltPosition);
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 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700540 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.005);
541 mutable_superstructure_goal->mutable_stilts()
542 ->mutable_profile_params()
543 ->mutate_max_velocity(0.65);
544 mutable_superstructure_goal->mutable_stilts()
545 ->mutable_profile_params()
546 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700547 }
548
Alex Perrycb7da4b2019-08-28 19:35:56 -0700549 if (superstructure_status_fetcher_->stilts()->position() > 0.1) {
Austin Schuh02be8b92019-03-24 16:04:14 -0700550 elevator_wrist_pos_ = kClimbPos;
James Kuszmaul13738862019-04-14 10:48:00 -0700551 climbed_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700552 mutable_superstructure_goal->mutable_wrist()
553 ->mutable_profile_params()
554 ->mutate_max_acceleration(10);
555 mutable_superstructure_goal->mutable_elevator()
556 ->mutable_profile_params()
557 ->mutate_max_acceleration(6);
Austin Schuh02be8b92019-03-24 16:04:14 -0700558 }
559
Austin Schuhe2f22482019-04-13 23:05:43 -0700560 // If we've been asked to go above deploy and made it up that high, latch
561 // was_above.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700562 if (mutable_superstructure_goal->stilts()->unsafe_goal() >
563 kDeployStiltPosition &&
564 superstructure_status_fetcher_->stilts()->position() >=
Austin Schuh170f4952019-06-29 18:58:30 -0700565 kDeployStiltPosition) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700566 was_above_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700567 } else if ((superstructure_position_fetcher_->platform_left_detect() &&
568 superstructure_position_fetcher_->platform_right_detect()) &&
Austin Schuhe2f22482019-04-13 23:05:43 -0700569 !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700570 was_above_ = false;
571 }
572
Alex Perrycb7da4b2019-08-28 19:35:56 -0700573 if (superstructure_status_fetcher_->stilts()->position() >
Austin Schuh170f4952019-06-29 18:58:30 -0700574 kDeployStiltPosition &&
Alex Perrycb7da4b2019-08-28 19:35:56 -0700575 mutable_superstructure_goal->stilts()->unsafe_goal() ==
576 kDeployStiltPosition) {
577 mutable_superstructure_goal->mutable_stilts()
578 ->mutable_profile_params()
579 ->mutate_max_velocity(0.30);
580 mutable_superstructure_goal->mutable_stilts()
581 ->mutable_profile_params()
582 ->mutate_max_acceleration(0.75);
Austin Schuh457bde32019-03-17 18:16:41 -0700583 }
584
James Kuszmaul13738862019-04-14 10:48:00 -0700585 if ((release_mode_ == ReleaseButtonMode::kRelease &&
586 data.IsPressed(kRelease)) ||
587 data.IsPressed(kReleaseButtonBoard)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800588 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700589 AOS_LOG(INFO, "Releasing due to button\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800590 }
591
Sabina Davisc6329342019-03-01 20:44:42 -0800592 if (switch_ball_) {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800593 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
594 ->mutate_gamepiece_mode(0);
Sabina Davisc6329342019-03-01 20:44:42 -0800595 } else {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800596 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
597 ->mutate_gamepiece_mode(1);
Sabina Davisc6329342019-03-01 20:44:42 -0800598 }
599
Tyler Chatowe0241452019-03-08 21:07:50 -0800600 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
601
James Kuszmaul2457eb72019-12-15 15:37:18 -0800602 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
603 ->mutate_grab_piece(grab_piece_);
Sabina Davis91b23602019-01-21 00:06:01 -0800604
Alex Perrycb7da4b2019-08-28 19:35:56 -0700605 mutable_superstructure_goal->mutable_elevator()->mutate_unsafe_goal(
606 elevator_wrist_pos_.elevator);
607 mutable_superstructure_goal->mutable_wrist()->mutate_unsafe_goal(
608 elevator_wrist_pos_.wrist);
Sabina Davis91b23602019-01-21 00:06:01 -0800609
milind1f1dca32021-07-03 13:50:07 -0700610 if (main_superstructure_goal_builder.Send(superstructure_goal_offset) !=
611 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700612 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800613 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800614
Austin Schuhaab7e162019-03-13 22:44:58 -0700615 if (monotonic_now >
616 last_vision_control_ + ::std::chrono::milliseconds(50)) {
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700617 video_tx_->Send(vision_control_);
Austin Schuhaab7e162019-03-13 22:44:58 -0700618 last_vision_control_ = monotonic_now;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700619 }
Austin Schuh4e2629d2019-03-28 14:44:37 -0700620
621 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700622 auto builder = camera_log_sender_.MakeBuilder();
milind1f1dca32021-07-03 13:50:07 -0700623 (void)builder.Send(
624 CreateCameraLog(*builder.fbb(), data.IsPressed(kCameraLog)));
Austin Schuh4e2629d2019-03-28 14:44:37 -0700625 }
Sabina Davis91b23602019-01-21 00:06:01 -0800626 }
627
628 private:
Austin Schuhc087b102019-05-12 15:33:12 -0700629 ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
630 target_selector_hint_sender_;
631
Alex Perrycb7da4b2019-08-28 19:35:56 -0700632 ::aos::Sender<LocalizerControl> localizer_control_sender_;
Austin Schuheb99d072019-05-12 21:03:38 -0700633
Austin Schuh5671a8c2019-05-19 17:01:04 -0700634 ::aos::Sender<::y2019::CameraLog> camera_log_sender_;
635
Alex Perrycb7da4b2019-08-28 19:35:56 -0700636 ::aos::Fetcher<superstructure::Goal> superstructure_goal_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700637
Alex Perrycb7da4b2019-08-28 19:35:56 -0700638 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
Austin Schuh170f4952019-06-29 18:58:30 -0700639
Alex Perrycb7da4b2019-08-28 19:35:56 -0700640 ::aos::Fetcher<superstructure::Position> superstructure_position_fetcher_;
641 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700642
Austin Schuhe2f22482019-04-13 23:05:43 -0700643 // Bool to track if we've been above the deploy position. Once this bool is
644 // set, don't let the stilts retract until we see the platform.
645 bool was_above_ = false;
646
Sabina Davis91b23602019-01-21 00:06:01 -0800647 // Current goals here.
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800648 ElevatorWristPosition elevator_wrist_pos_ = kStowPos;
Sabina Davisc6329342019-03-01 20:44:42 -0800649 bool grab_piece_ = false;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800650
651 bool switch_ball_ = false;
Tyler Chatowe0241452019-03-08 21:07:50 -0800652
James Kuszmaul13738862019-04-14 10:48:00 -0700653 bool climbed_ = false;
654
655 enum class ReleaseButtonMode {
656 kBallIntake,
657 kRelease,
658 };
659
660 ReleaseButtonMode release_mode_ = ReleaseButtonMode::kRelease;
661 aos::monotonic_clock::time_point last_release_button_press_ =
662 aos::monotonic_clock::min_time;
663
Tyler Chatowe0241452019-03-08 21:07:50 -0800664 VisionControl vision_control_;
665 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700666 ::aos::monotonic_clock::time_point last_vision_control_ =
667 ::aos::monotonic_clock::time_point::min();
Austin Schuhaab7e162019-03-13 22:44:58 -0700668
669 // Time at which we last did not have a game piece.
670 ::aos::monotonic_clock::time_point last_not_has_piece_ =
671 ::aos::monotonic_clock::time_point::min();
Sabina Davis91b23602019-01-21 00:06:01 -0800672};
673
674} // namespace joysticks
675} // namespace input
676} // namespace y2019
677
Austin Schuh094d09b2020-11-20 23:26:52 -0800678int main(int argc, char **argv) {
679 ::aos::InitGoogle(&argc, &argv);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700680
Alex Perrycb7da4b2019-08-28 19:35:56 -0700681 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -0800682 aos::configuration::ReadConfig("aos_config.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700683
684 ::aos::ShmEventLoop event_loop(&config.message());
Sabina Davis91b23602019-01-21 00:06:01 -0800685 ::y2019::input::joysticks::Reader reader(&event_loop);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700686
687 event_loop.Run();
688
Austin Schuhae87e312020-08-01 16:15:01 -0700689 return 0;
Sabina Davis91b23602019-01-21 00:06:01 -0800690}