blob: 12f590ff59c1edc121e0a8ffa230e73854dff441 [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
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 Chatow7bcb52f2019-02-24 00:16:54 -080050struct ElevatorWristPosition {
51 double elevator;
52 double wrist;
53};
Sabina Davis91b23602019-01-21 00:06:01 -080054
Tyler Chatow5eeee902019-04-12 20:47:48 -070055const ButtonLocation kSuctionBall(4, 2);
56const ButtonLocation kSuctionHatch(3, 15);
57const ButtonLocation kDeployStilt(4, 1);
58const ButtonLocation kHalfStilt(4, 3);
59const ButtonLocation kFallOver(3, 16);
60
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080061const ButtonLocation kRocketForwardLower(5, 1);
62const ButtonLocation kRocketForwardMiddle(5, 2);
63const ButtonLocation kRocketForwardUpper(5, 4);
64const ButtonLocation kCargoForward(5, 3);
65
66const POVLocation kRocketBackwardUnpressed(5, -1);
67const POVLocation kRocketBackwardLower(5, 180);
68const POVLocation kRocketBackwardMiddle(5, 90);
69const POVLocation kRocketBackwardUpper(5, 0);
70const POVLocation kCargoBackward(5, 270);
71
72const ButtonLocation kPanelSwitch(5, 7);
73const ButtonLocation kCargoSwitch(5, 8);
74
75const ButtonLocation kBallHPIntakeForward(5, 6);
76const ButtonLocation kBallHPIntakeBackward(5, 5);
77const JoystickAxis kBallOutake(5, 3);
78const JoystickAxis kBallIntake(5, 4);
79
80const ButtonLocation kPanelHPIntakeForward(5, 6);
81const ButtonLocation kPanelHPIntakeBackward(5, 5);
82
83const ButtonLocation kRelease(2, 4);
James Kuszmaulccc368b2019-04-11 20:00:07 -070084// Reuse quickturn for the cancel button.
85const ButtonLocation kCancelAutoMode(2, 3);
Tyler Chatow5eeee902019-04-12 20:47:48 -070086const ButtonLocation kReleaseButtonBoard(3, 4);
87const ButtonLocation kResetLocalizerLeftForwards(3, 10);
88const ButtonLocation kResetLocalizerLeftBackwards(3, 9);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080089
Tyler Chatow5eeee902019-04-12 20:47:48 -070090const ButtonLocation kResetLocalizerRightForwards(3, 8);
91const ButtonLocation kResetLocalizerRightBackwards(3, 7);
Tyler Chatow07c906b2019-03-09 21:29:06 -080092
James Kuszmaul518640d2019-04-13 15:50:50 -070093const ButtonLocation kResetLocalizerLeft(3, 11);
94const ButtonLocation kResetLocalizerRight(3, 13);
95
Tyler Chatow5eeee902019-04-12 20:47:48 -070096const ButtonLocation kNearCargoHint(3, 3);
97const ButtonLocation kMidCargoHint(3, 5);
98const ButtonLocation kFarCargoHint(3, 6);
James Kuszmaul7d1ef442019-03-23 20:20:50 -070099
James Kuszmaul518640d2019-04-13 15:50:50 -0700100const JoystickAxis kCargoSelectorY(5, 6);
101const JoystickAxis kCargoSelectorX(5, 5);
102
Tyler Chatow5eeee902019-04-12 20:47:48 -0700103const ButtonLocation kCameraLog(3, 14);
Austin Schuh4e2629d2019-03-28 14:44:37 -0700104
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800105const ElevatorWristPosition kStowPos{0.36, 0.0};
Austin Schuh02be8b92019-03-24 16:04:14 -0700106const ElevatorWristPosition kClimbPos{0.0, M_PI / 4.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800107
Austin Schuh139f59d2019-03-17 18:16:13 -0700108const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
109const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800110
111const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0};
112const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0};
113
Sabina Davise48004f2019-03-02 23:15:24 -0800114const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
115const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800116
Sabina Davise48004f2019-03-02 23:15:24 -0800117const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0};
118const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800119
Sabina Davise6fe6c52019-03-03 15:48:51 -0800120const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0};
121const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
122
Austin Schuh6c5deb12019-03-24 16:48:32 -0700123const ElevatorWristPosition kBallForwardLowerPos{0.21, 1.27};
Austin Schuh20dc0502019-03-30 07:24:07 -0700124const ElevatorWristPosition kBallBackwardLowerPos{0.43, -1.99};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800125
Austin Schuh20dc0502019-03-30 07:24:07 -0700126const ElevatorWristPosition kBallForwardMiddlePos{0.925, 1.21};
127const ElevatorWristPosition kBallBackwardMiddlePos{1.19, -1.98};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800128
Austin Schuh139f59d2019-03-17 18:16:13 -0700129const ElevatorWristPosition kBallForwardUpperPos{1.51, 0.961};
130const ElevatorWristPosition kBallBackwardUpperPos{1.44, -1.217};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800131
Austin Schuh20dc0502019-03-30 07:24:07 -0700132const ElevatorWristPosition kBallCargoForwardPos{0.59, 1.2};
133const ElevatorWristPosition kBallCargoBackwardPos{0.868265, -2.1};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800134
Sabina Davise6fe6c52019-03-03 15:48:51 -0800135const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097};
136const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800137
Austin Schuh20dc0502019-03-30 07:24:07 -0700138const ElevatorWristPosition kBallIntakePos{0.309, 2.13};
Austin Schuh2cf16b82019-02-15 23:23:22 -0800139
James Kuszmaul7077d342021-06-09 20:23:58 -0700140class Reader : public ::frc971::input::ActionJoystickInput {
Sabina Davis91b23602019-01-21 00:06:01 -0800141 public:
142 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -0700143 : ::frc971::input::ActionJoystickInput(
Sabina Davis91b23602019-01-21 00:06:01 -0800144 event_loop,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700145 ::y2019::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -0700146 ::frc971::input::DrivetrainInputReader::InputType::kPistol,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700147 {.run_teleop_in_auto = true,
Austin Schuhc087b102019-05-12 15:33:12 -0700148 .cancel_auto_button = kCancelAutoMode}),
149 target_selector_hint_sender_(
150 event_loop->MakeSender<
151 ::y2019::control_loops::drivetrain::TargetSelectorHint>(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700152 "/drivetrain")),
Austin Schuheb99d072019-05-12 21:03:38 -0700153 localizer_control_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700154 event_loop->MakeSender<LocalizerControl>("/drivetrain")),
Austin Schuh5671a8c2019-05-19 17:01:04 -0700155 camera_log_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700156 event_loop->MakeSender<::y2019::CameraLog>("/camera")),
157 superstructure_goal_fetcher_(
158 event_loop->MakeFetcher<superstructure::Goal>("/superstructure")),
159 superstructure_goal_sender_(
160 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700161 superstructure_position_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700162 event_loop->MakeFetcher<superstructure::Position>(
163 "/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700164 superstructure_status_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700165 event_loop->MakeFetcher<superstructure::Status>(
166 "/superstructure")) {
Tyler Chatowe0241452019-03-08 21:07:50 -0800167 const uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuh170f4952019-06-29 18:58:30 -0700168 superstructure_goal_fetcher_.Fetch();
169 if (superstructure_goal_fetcher_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700170 grab_piece_ = superstructure_goal_fetcher_->has_suction()
171 ? superstructure_goal_fetcher_->suction()->grab_piece()
172 : false;
173 switch_ball_ =
174 superstructure_goal_fetcher_->has_suction()
175 ? (superstructure_goal_fetcher_->suction()->gamepiece_mode() == 0)
176 : true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800177 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800178 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
Adam Snaider13d48d92023-08-03 12:20:15 -0700179 absl::StrFormat("10.%d.%d.179", team / 100, team % 100), 5000));
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800180 }
Sabina Davis91b23602019-01-21 00:06:01 -0800181
Austin Schuha78857f2019-03-13 22:43:41 -0700182 void AutoEnded() override {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700183 AOS_LOG(INFO, "Auto ended, assuming disc and have piece\n");
Austin Schuha78857f2019-03-13 22:43:41 -0700184 grab_piece_ = true;
185 switch_ball_ = false;
186 }
187
James Kuszmaul7077d342021-06-09 20:23:58 -0700188 void HandleTeleop(
189 const ::frc971::input::driver_station::Data &data) override {
Austin Schuhaab7e162019-03-13 22:44:58 -0700190 ::aos::monotonic_clock::time_point monotonic_now =
191 ::aos::monotonic_clock::now();
Austin Schuh170f4952019-06-29 18:58:30 -0700192 superstructure_position_fetcher_.Fetch();
193 superstructure_status_fetcher_.Fetch();
194 if (!superstructure_status_fetcher_.get() ||
195 !superstructure_position_fetcher_.get()) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700196 AOS_LOG(ERROR, "Got no superstructure status or position packet.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800197 return;
198 }
199
Alex Perrycb7da4b2019-08-28 19:35:56 -0700200 CHECK(superstructure_status_fetcher_->has_stilts());
201
202 if (!superstructure_status_fetcher_->has_piece()) {
Austin Schuhaab7e162019-03-13 22:44:58 -0700203 last_not_has_piece_ = monotonic_now;
204 }
205
Alex Perrycb7da4b2019-08-28 19:35:56 -0700206 auto main_superstructure_goal_builder =
207 superstructure_goal_sender_.MakeBuilder();
208
209 flatbuffers::Offset<superstructure::Goal> superstructure_goal_offset;
Sabina Davis91b23602019-01-21 00:06:01 -0800210
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700211 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700212 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
213 elevator_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
214 *main_superstructure_goal_builder.fbb(), 0.0,
215 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
216 0.0, 0.0));
217
218 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
219 intake_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
220 *main_superstructure_goal_builder.fbb(), -1.2);
221
222 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
223 wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
224 *main_superstructure_goal_builder.fbb(), 0.0,
225 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
226 0.0, 0.0));
227
228 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
229 stilts_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
230 *main_superstructure_goal_builder.fbb(), 0.0,
231 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
232 0.0, 0.0));
233
James Kuszmaul2457eb72019-12-15 15:37:18 -0800234 flatbuffers::Offset<SuctionGoal> suction_offset =
235 CreateSuctionGoal(*main_superstructure_goal_builder.fbb(), false, 0);
236
Alex Perrycb7da4b2019-08-28 19:35:56 -0700237 superstructure::Goal::Builder superstructure_goal_builder =
238 main_superstructure_goal_builder.MakeBuilder<superstructure::Goal>();
239
240 superstructure_goal_builder.add_elevator(elevator_offset);
241 superstructure_goal_builder.add_intake(intake_offset);
242 superstructure_goal_builder.add_wrist(wrist_offset);
243 superstructure_goal_builder.add_stilts(stilts_offset);
James Kuszmaul2457eb72019-12-15 15:37:18 -0800244 superstructure_goal_builder.add_suction(suction_offset);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700245 superstructure_goal_builder.add_roller_voltage(0.0);
246
247 superstructure_goal_offset = superstructure_goal_builder.Finish();
248 }
James Kuszmaul2457eb72019-12-15 15:37:18 -0800249 superstructure::Goal *mutable_superstructure_goal = CHECK_NOTNULL(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700250 GetMutableTemporaryPointer(*main_superstructure_goal_builder.fbb(),
James Kuszmaul2457eb72019-12-15 15:37:18 -0800251 superstructure_goal_offset));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700252
253 {
254 auto builder = target_selector_hint_sender_.MakeBuilder();
255 control_loops::drivetrain::TargetSelectorHint::Builder
256 target_selector_hint_builder =
257 builder
258 .MakeBuilder<control_loops::drivetrain::TargetSelectorHint>();
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700259 if (data.IsPressed(kNearCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700260 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800261 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700262 } else if (data.IsPressed(kMidCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700263 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800264 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700265 } else if (data.IsPressed(kFarCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700266 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800267 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700268 } else {
James Kuszmaul518640d2019-04-13 15:50:50 -0700269 const double cargo_joy_y = data.GetAxis(kCargoSelectorY);
270 const double cargo_joy_x = data.GetAxis(kCargoSelectorX);
271 if (cargo_joy_y > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700272 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700273 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul1b822b42019-04-14 14:27:35 -0700274 } else if (cargo_joy_y < -0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700275 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800276 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700277 } else if (::std::abs(cargo_joy_x) > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700278 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700279 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700280 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700281 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700282 control_loops::drivetrain::SelectionHint::NONE);
James Kuszmaul518640d2019-04-13 15:50:50 -0700283 }
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700284 }
milind1f1dca32021-07-03 13:50:07 -0700285 if (builder.Send(target_selector_hint_builder.Finish()) !=
286 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700287 AOS_LOG(ERROR, "Failed to send target selector hint.\n");
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700288 }
289 }
290
James Kuszmaul518640d2019-04-13 15:50:50 -0700291 if (data.PosEdge(kResetLocalizerLeft)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700292 auto builder = localizer_control_sender_.MakeBuilder();
James Kuszmaul518640d2019-04-13 15:50:50 -0700293 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700294 LocalizerControl::Builder localizer_control_builder =
295 builder.MakeBuilder<LocalizerControl>();
296 localizer_control_builder.add_x(0.6);
297 localizer_control_builder.add_y(3.4);
298 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700299
milind1f1dca32021-07-03 13:50:07 -0700300 if (builder.Send(localizer_control_builder.Finish()) !=
301 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700302 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700303 }
304 }
305
306 if (data.PosEdge(kResetLocalizerRight)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700307 auto builder = localizer_control_sender_.MakeBuilder();
308 // Start at the right feeder station.
309 LocalizerControl::Builder localizer_control_builder =
310 builder.MakeBuilder<LocalizerControl>();
311 localizer_control_builder.add_x(0.6);
312 localizer_control_builder.add_y(-3.4);
313 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700314
milind1f1dca32021-07-03 13:50:07 -0700315 if (builder.Send(localizer_control_builder.Finish()) !=
316 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700317 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700318 }
319 }
320
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700321 if (data.PosEdge(kResetLocalizerLeftForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700322 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700323 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700324 LocalizerControl::Builder localizer_control_builder =
325 builder.MakeBuilder<LocalizerControl>();
326 localizer_control_builder.add_x(0.4);
327 localizer_control_builder.add_y(3.4);
328 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700329
milind1f1dca32021-07-03 13:50:07 -0700330 if (builder.Send(localizer_control_builder.Finish()) !=
331 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700332 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700333 }
334 }
335
336 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700337 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700338 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700339 LocalizerControl::Builder localizer_control_builder =
340 builder.MakeBuilder<LocalizerControl>();
341 localizer_control_builder.add_x(0.4);
342 localizer_control_builder.add_y(3.4);
343 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700344
milind1f1dca32021-07-03 13:50:07 -0700345 if (builder.Send(localizer_control_builder.Finish()) !=
346 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700347 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700348 }
349 }
350
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700351 if (data.PosEdge(kResetLocalizerRightForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700352 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700353 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700354 LocalizerControl::Builder localizer_control_builder =
355 builder.MakeBuilder<LocalizerControl>();
356 localizer_control_builder.add_x(0.4);
357 localizer_control_builder.add_y(-3.4);
358 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700359
milind1f1dca32021-07-03 13:50:07 -0700360 if (builder.Send(localizer_control_builder.Finish()) !=
361 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700362 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700363 }
364 }
365
366 if (data.PosEdge(kResetLocalizerRightBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700367 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700368 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700369 LocalizerControl::Builder localizer_control_builder =
370 builder.MakeBuilder<LocalizerControl>();
371 localizer_control_builder.add_x(0.4);
372 localizer_control_builder.add_y(-3.4);
373 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700374
milind1f1dca32021-07-03 13:50:07 -0700375 if (builder.Send(localizer_control_builder.Finish()) !=
376 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700377 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmauld8deb682019-03-10 10:38:42 -0700378 }
379 }
380
James Kuszmaul13738862019-04-14 10:48:00 -0700381 if (data.PosEdge(kRelease) &&
382 monotonic_now >
383 last_release_button_press_ + ::std::chrono::milliseconds(500)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700384 if (superstructure_status_fetcher_->has_piece()) {
James Kuszmaul13738862019-04-14 10:48:00 -0700385 release_mode_ = ReleaseButtonMode::kRelease;
386 } else {
387 release_mode_ = ReleaseButtonMode::kBallIntake;
388 }
389 }
390
391 if (data.IsPressed(kRelease)) {
392 last_release_button_press_ = monotonic_now;
393 }
394
Alex Perrycb7da4b2019-08-28 19:35:56 -0700395 AOS_LOG(INFO, "has_piece: %d\n",
396 superstructure_status_fetcher_->has_piece());
Austin Schuh1a17e132019-02-17 15:05:06 -0800397 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800398 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800399 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800400 grab_piece_ = true;
James Kuszmaul13738862019-04-14 10:48:00 -0700401 } else if ((release_mode_ == ReleaseButtonMode::kRelease &&
402 data.IsPressed(kRelease)) ||
Tyler Chatow5eeee902019-04-12 20:47:48 -0700403 data.IsPressed(kReleaseButtonBoard) ||
Alex Perrycb7da4b2019-08-28 19:35:56 -0700404 !superstructure_status_fetcher_->has_piece()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800405 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700406 AOS_LOG(INFO, "releasing due to other thing\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800407 }
Sabina Davis91b23602019-01-21 00:06:01 -0800408
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800409 if (data.IsPressed(kRocketBackwardUnpressed)) {
410 elevator_wrist_pos_ = kStowPos;
411 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700412 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(-1.2);
413 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800414
James Kuszmaul13738862019-04-14 10:48:00 -0700415 const bool kDoBallIntake =
416 (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake &&
417 data.IsPressed(kRelease)) ||
418 data.GetAxis(kBallIntake) > 0.9;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800419 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
420
421 if (data.IsPressed(kPanelSwitch)) {
422 switch_ball_ = false;
423 } else if (data.IsPressed(kCargoSwitch)) {
424 switch_ball_ = true;
425 }
426
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800427 if (switch_ball_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700428 if (superstructure_status_fetcher_->has_piece()) {
429 mutable_superstructure_goal->mutable_wrist()
430 ->mutable_profile_params()
431 ->mutate_max_acceleration(20);
Austin Schuh1a17e132019-02-17 15:05:06 -0800432 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800433
434 // Go to intake position and apply vacuum
435 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800436 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800437 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
438 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800439 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800440 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
441 }
442
443 // Go to elevator/wrist position. Overrides intake position if pressed so
444 // we can re-grab the ball.
445 if (data.IsPressed(kRocketForwardLower)) {
446 elevator_wrist_pos_ = kBallForwardLowerPos;
447 } else if (data.IsPressed(kRocketBackwardLower)) {
448 elevator_wrist_pos_ = kBallBackwardLowerPos;
449 } else if (data.IsPressed(kRocketForwardMiddle)) {
450 elevator_wrist_pos_ = kBallForwardMiddlePos;
451 } else if (data.IsPressed(kRocketBackwardMiddle)) {
452 elevator_wrist_pos_ = kBallBackwardMiddlePos;
453 } else if (data.IsPressed(kRocketForwardUpper)) {
454 elevator_wrist_pos_ = kBallForwardUpperPos;
455 } else if (data.IsPressed(kRocketBackwardUpper)) {
456 elevator_wrist_pos_ = kBallBackwardUpperPos;
457 } else if (data.IsPressed(kCargoForward)) {
458 elevator_wrist_pos_ = kBallCargoForwardPos;
459 } else if (data.IsPressed(kCargoBackward)) {
460 elevator_wrist_pos_ = kBallCargoBackwardPos;
461 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800462 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800463 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800464 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800465 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
466 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800467 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800468 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
469 }
470
471 // Go to elevator/wrist position. Overrides intake position if pressed so
472 // we can re-grab the panel.
473 if (data.IsPressed(kRocketForwardLower)) {
474 elevator_wrist_pos_ = kPanelForwardLowerPos;
475 } else if (data.IsPressed(kRocketBackwardLower)) {
476 elevator_wrist_pos_ = kPanelBackwardLowerPos;
477 } else if (data.IsPressed(kRocketForwardMiddle)) {
478 elevator_wrist_pos_ = kPanelForwardMiddlePos;
479 } else if (data.IsPressed(kRocketBackwardMiddle)) {
480 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
481 } else if (data.IsPressed(kRocketForwardUpper)) {
482 elevator_wrist_pos_ = kPanelForwardUpperPos;
483 } else if (data.IsPressed(kRocketBackwardUpper)) {
484 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800485 } else if (data.IsPressed(kCargoForward)) {
486 elevator_wrist_pos_ = kPanelCargoForwardPos;
487 } else if (data.IsPressed(kCargoBackward)) {
488 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800489 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800490 }
491
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800492 if (switch_ball_) {
493 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700494 (kDoBallIntake &&
Austin Schuh20dc0502019-03-30 07:24:07 -0700495 monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700496 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(0.83);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800497 }
Austin Schuh23a51632019-02-19 16:50:36 -0800498
Alex Perrycb7da4b2019-08-28 19:35:56 -0700499 if (kDoBallIntake && !superstructure_status_fetcher_->has_piece()) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800500 elevator_wrist_pos_ = kBallIntakePos;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700501 mutable_superstructure_goal->mutate_roller_voltage(9.0);
Sabina Davisc6329342019-03-01 20:44:42 -0800502 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800503 } else {
504 if (kDoBallOutake) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700505 mutable_superstructure_goal->mutate_roller_voltage(-6.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800506 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700507 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800508 }
509 }
Austin Schuh23a51632019-02-19 16:50:36 -0800510 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800511
Austin Schuh457bde32019-03-17 18:16:41 -0700512 constexpr double kDeployStiltPosition = 0.5;
513
Austin Schuh457bde32019-03-17 18:16:41 -0700514 if (data.IsPressed(kFallOver)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700515 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.71);
516 mutable_superstructure_goal->mutable_stilts()
517 ->mutable_profile_params()
518 ->mutate_max_velocity(0.65);
519 mutable_superstructure_goal->mutable_stilts()
520 ->mutable_profile_params()
521 ->mutate_max_acceleration(1.25);
Austin Schuhe2f22482019-04-13 23:05:43 -0700522 } else if (data.IsPressed(kHalfStilt)) {
523 was_above_ = false;
James Kuszmaul7077d342021-06-09 20:23:58 -0700524 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.345);
525 mutable_superstructure_goal->mutable_stilts()
526 ->mutable_profile_params()
527 ->mutate_max_velocity(0.65);
Austin Schuhe2f22482019-04-13 23:05:43 -0700528 } else if (data.IsPressed(kDeployStilt) || was_above_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700529 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(
530 kDeployStiltPosition);
531 mutable_superstructure_goal->mutable_stilts()
532 ->mutable_profile_params()
533 ->mutate_max_velocity(0.65);
534 mutable_superstructure_goal->mutable_stilts()
535 ->mutable_profile_params()
536 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700537 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700538 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.005);
539 mutable_superstructure_goal->mutable_stilts()
540 ->mutable_profile_params()
541 ->mutate_max_velocity(0.65);
542 mutable_superstructure_goal->mutable_stilts()
543 ->mutable_profile_params()
544 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700545 }
546
Alex Perrycb7da4b2019-08-28 19:35:56 -0700547 if (superstructure_status_fetcher_->stilts()->position() > 0.1) {
Austin Schuh02be8b92019-03-24 16:04:14 -0700548 elevator_wrist_pos_ = kClimbPos;
James Kuszmaul13738862019-04-14 10:48:00 -0700549 climbed_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700550 mutable_superstructure_goal->mutable_wrist()
551 ->mutable_profile_params()
552 ->mutate_max_acceleration(10);
553 mutable_superstructure_goal->mutable_elevator()
554 ->mutable_profile_params()
555 ->mutate_max_acceleration(6);
Austin Schuh02be8b92019-03-24 16:04:14 -0700556 }
557
Austin Schuhe2f22482019-04-13 23:05:43 -0700558 // If we've been asked to go above deploy and made it up that high, latch
559 // was_above.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700560 if (mutable_superstructure_goal->stilts()->unsafe_goal() >
561 kDeployStiltPosition &&
562 superstructure_status_fetcher_->stilts()->position() >=
Austin Schuh170f4952019-06-29 18:58:30 -0700563 kDeployStiltPosition) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700564 was_above_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700565 } else if ((superstructure_position_fetcher_->platform_left_detect() &&
566 superstructure_position_fetcher_->platform_right_detect()) &&
Austin Schuhe2f22482019-04-13 23:05:43 -0700567 !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700568 was_above_ = false;
569 }
570
Alex Perrycb7da4b2019-08-28 19:35:56 -0700571 if (superstructure_status_fetcher_->stilts()->position() >
Austin Schuh170f4952019-06-29 18:58:30 -0700572 kDeployStiltPosition &&
Alex Perrycb7da4b2019-08-28 19:35:56 -0700573 mutable_superstructure_goal->stilts()->unsafe_goal() ==
574 kDeployStiltPosition) {
575 mutable_superstructure_goal->mutable_stilts()
576 ->mutable_profile_params()
577 ->mutate_max_velocity(0.30);
578 mutable_superstructure_goal->mutable_stilts()
579 ->mutable_profile_params()
580 ->mutate_max_acceleration(0.75);
Austin Schuh457bde32019-03-17 18:16:41 -0700581 }
582
James Kuszmaul13738862019-04-14 10:48:00 -0700583 if ((release_mode_ == ReleaseButtonMode::kRelease &&
584 data.IsPressed(kRelease)) ||
585 data.IsPressed(kReleaseButtonBoard)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800586 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700587 AOS_LOG(INFO, "Releasing due to button\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800588 }
589
Sabina Davisc6329342019-03-01 20:44:42 -0800590 if (switch_ball_) {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800591 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
592 ->mutate_gamepiece_mode(0);
Sabina Davisc6329342019-03-01 20:44:42 -0800593 } else {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800594 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
595 ->mutate_gamepiece_mode(1);
Sabina Davisc6329342019-03-01 20:44:42 -0800596 }
597
Tyler Chatowe0241452019-03-08 21:07:50 -0800598 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
599
James Kuszmaul2457eb72019-12-15 15:37:18 -0800600 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
601 ->mutate_grab_piece(grab_piece_);
Sabina Davis91b23602019-01-21 00:06:01 -0800602
Alex Perrycb7da4b2019-08-28 19:35:56 -0700603 mutable_superstructure_goal->mutable_elevator()->mutate_unsafe_goal(
604 elevator_wrist_pos_.elevator);
605 mutable_superstructure_goal->mutable_wrist()->mutate_unsafe_goal(
606 elevator_wrist_pos_.wrist);
Sabina Davis91b23602019-01-21 00:06:01 -0800607
milind1f1dca32021-07-03 13:50:07 -0700608 if (main_superstructure_goal_builder.Send(superstructure_goal_offset) !=
609 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700610 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800611 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800612
Austin Schuhaab7e162019-03-13 22:44:58 -0700613 if (monotonic_now >
614 last_vision_control_ + ::std::chrono::milliseconds(50)) {
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700615 video_tx_->Send(vision_control_);
Austin Schuhaab7e162019-03-13 22:44:58 -0700616 last_vision_control_ = monotonic_now;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700617 }
Austin Schuh4e2629d2019-03-28 14:44:37 -0700618
619 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700620 auto builder = camera_log_sender_.MakeBuilder();
milind1f1dca32021-07-03 13:50:07 -0700621 (void)builder.Send(
622 CreateCameraLog(*builder.fbb(), data.IsPressed(kCameraLog)));
Austin Schuh4e2629d2019-03-28 14:44:37 -0700623 }
Sabina Davis91b23602019-01-21 00:06:01 -0800624 }
625
626 private:
Austin Schuhc087b102019-05-12 15:33:12 -0700627 ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
628 target_selector_hint_sender_;
629
Alex Perrycb7da4b2019-08-28 19:35:56 -0700630 ::aos::Sender<LocalizerControl> localizer_control_sender_;
Austin Schuheb99d072019-05-12 21:03:38 -0700631
Austin Schuh5671a8c2019-05-19 17:01:04 -0700632 ::aos::Sender<::y2019::CameraLog> camera_log_sender_;
633
Alex Perrycb7da4b2019-08-28 19:35:56 -0700634 ::aos::Fetcher<superstructure::Goal> superstructure_goal_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700635
Alex Perrycb7da4b2019-08-28 19:35:56 -0700636 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
Austin Schuh170f4952019-06-29 18:58:30 -0700637
Alex Perrycb7da4b2019-08-28 19:35:56 -0700638 ::aos::Fetcher<superstructure::Position> superstructure_position_fetcher_;
639 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700640
Austin Schuhe2f22482019-04-13 23:05:43 -0700641 // Bool to track if we've been above the deploy position. Once this bool is
642 // set, don't let the stilts retract until we see the platform.
643 bool was_above_ = false;
644
Sabina Davis91b23602019-01-21 00:06:01 -0800645 // Current goals here.
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800646 ElevatorWristPosition elevator_wrist_pos_ = kStowPos;
Sabina Davisc6329342019-03-01 20:44:42 -0800647 bool grab_piece_ = false;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800648
649 bool switch_ball_ = false;
Tyler Chatowe0241452019-03-08 21:07:50 -0800650
James Kuszmaul13738862019-04-14 10:48:00 -0700651 bool climbed_ = false;
652
653 enum class ReleaseButtonMode {
654 kBallIntake,
655 kRelease,
656 };
657
658 ReleaseButtonMode release_mode_ = ReleaseButtonMode::kRelease;
659 aos::monotonic_clock::time_point last_release_button_press_ =
660 aos::monotonic_clock::min_time;
661
Tyler Chatowe0241452019-03-08 21:07:50 -0800662 VisionControl vision_control_;
663 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700664 ::aos::monotonic_clock::time_point last_vision_control_ =
665 ::aos::monotonic_clock::time_point::min();
Austin Schuhaab7e162019-03-13 22:44:58 -0700666
667 // Time at which we last did not have a game piece.
668 ::aos::monotonic_clock::time_point last_not_has_piece_ =
669 ::aos::monotonic_clock::time_point::min();
Sabina Davis91b23602019-01-21 00:06:01 -0800670};
671
672} // namespace joysticks
673} // namespace input
674} // namespace y2019
675
Austin Schuh094d09b2020-11-20 23:26:52 -0800676int main(int argc, char **argv) {
677 ::aos::InitGoogle(&argc, &argv);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700678
Alex Perrycb7da4b2019-08-28 19:35:56 -0700679 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -0800680 aos::configuration::ReadConfig("aos_config.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700681
682 ::aos::ShmEventLoop event_loop(&config.message());
Sabina Davis91b23602019-01-21 00:06:01 -0800683 ::y2019::input::joysticks::Reader reader(&event_loop);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700684
685 event_loop.Run();
686
Austin Schuhae87e312020-08-01 16:15:01 -0700687 return 0;
Sabina Davis91b23602019-01-21 00:06:01 -0800688}