blob: ed55dfc780ff8c956fd2738cb58cf9126549eb4c [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
8#include "aos/actions/actions.h"
9#include "aos/init.h"
Sabina Davis91b23602019-01-21 00:06:01 -080010#include "aos/logging/logging.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080011#include "aos/network/team_number.h"
Sabina Davis91b23602019-01-21 00:06:01 -080012#include "aos/util/log_interval.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080013#include "aos/vision/events/udp.h"
14#include "external/com_google_protobuf/src/google/protobuf/stubs/stringprintf.h"
Sabina Davis91b23602019-01-21 00:06:01 -080015#include "frc971/autonomous/base_autonomous_actor.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070016#include "frc971/control_loops/drivetrain/localizer_generated.h"
James Kuszmaul7077d342021-06-09 20:23:58 -070017#include "frc971/input/action_joystick_input.h"
18#include "frc971/input/driver_station_data.h"
19#include "frc971/input/drivetrain_input.h"
20#include "frc971/input/joystick_input.h"
Austin Schuhed5b26d2019-12-05 20:51:59 -080021#include "y2019/camera_log_generated.h"
Sabina Davis91b23602019-01-21 00:06:01 -080022#include "y2019/control_loops/drivetrain/drivetrain_base.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -070023#include "y2019/control_loops/drivetrain/target_selector_generated.h"
24#include "y2019/control_loops/superstructure/superstructure_goal_generated.h"
25#include "y2019/control_loops/superstructure/superstructure_position_generated.h"
26#include "y2019/control_loops/superstructure/superstructure_status_generated.h"
Tyler Chatowe0241452019-03-08 21:07:50 -080027#include "y2019/vision.pb.h"
Sabina Davis91b23602019-01-21 00:06:01 -080028
Alex Perrycb7da4b2019-08-28 19:35:56 -070029using aos::events::ProtoTXUdpSocket;
Alex Perrycb7da4b2019-08-28 19:35:56 -070030using frc971::CreateProfileParameters;
31using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal;
32using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
33using frc971::control_loops::drivetrain::LocalizerControl;
James Kuszmaul7077d342021-06-09 20:23:58 -070034using frc971::input::driver_station::ButtonLocation;
35using frc971::input::driver_station::ControlBit;
36using frc971::input::driver_station::JoystickAxis;
37using frc971::input::driver_station::POVLocation;
James Kuszmaul2457eb72019-12-15 15:37:18 -080038using y2019::control_loops::superstructure::CreateSuctionGoal;
James Kuszmaul7077d342021-06-09 20:23:58 -070039using y2019::control_loops::superstructure::SuctionGoal;
Sabina Davis91b23602019-01-21 00:06:01 -080040
Austin Schuhaab7e162019-03-13 22:44:58 -070041namespace chrono = ::std::chrono;
42
Sabina Davis91b23602019-01-21 00:06:01 -080043namespace y2019 {
44namespace input {
45namespace joysticks {
46
Alex Perrycb7da4b2019-08-28 19:35:56 -070047namespace superstructure = y2019::control_loops::superstructure;
48
Tyler Chatowe0241452019-03-08 21:07:50 -080049using google::protobuf::StringPrintf;
50
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080051struct ElevatorWristPosition {
52 double elevator;
53 double wrist;
54};
Sabina Davis91b23602019-01-21 00:06:01 -080055
Tyler Chatow5eeee902019-04-12 20:47:48 -070056const ButtonLocation kSuctionBall(4, 2);
57const ButtonLocation kSuctionHatch(3, 15);
58const ButtonLocation kDeployStilt(4, 1);
59const ButtonLocation kHalfStilt(4, 3);
60const ButtonLocation kFallOver(3, 16);
61
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080062const ButtonLocation kRocketForwardLower(5, 1);
63const ButtonLocation kRocketForwardMiddle(5, 2);
64const ButtonLocation kRocketForwardUpper(5, 4);
65const ButtonLocation kCargoForward(5, 3);
66
67const POVLocation kRocketBackwardUnpressed(5, -1);
68const POVLocation kRocketBackwardLower(5, 180);
69const POVLocation kRocketBackwardMiddle(5, 90);
70const POVLocation kRocketBackwardUpper(5, 0);
71const POVLocation kCargoBackward(5, 270);
72
73const ButtonLocation kPanelSwitch(5, 7);
74const ButtonLocation kCargoSwitch(5, 8);
75
76const ButtonLocation kBallHPIntakeForward(5, 6);
77const ButtonLocation kBallHPIntakeBackward(5, 5);
78const JoystickAxis kBallOutake(5, 3);
79const JoystickAxis kBallIntake(5, 4);
80
81const ButtonLocation kPanelHPIntakeForward(5, 6);
82const ButtonLocation kPanelHPIntakeBackward(5, 5);
83
84const ButtonLocation kRelease(2, 4);
James Kuszmaulccc368b2019-04-11 20:00:07 -070085// Reuse quickturn for the cancel button.
86const ButtonLocation kCancelAutoMode(2, 3);
Tyler Chatow5eeee902019-04-12 20:47:48 -070087const ButtonLocation kReleaseButtonBoard(3, 4);
88const ButtonLocation kResetLocalizerLeftForwards(3, 10);
89const ButtonLocation kResetLocalizerLeftBackwards(3, 9);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -080090
Tyler Chatow5eeee902019-04-12 20:47:48 -070091const ButtonLocation kResetLocalizerRightForwards(3, 8);
92const ButtonLocation kResetLocalizerRightBackwards(3, 7);
Tyler Chatow07c906b2019-03-09 21:29:06 -080093
James Kuszmaul518640d2019-04-13 15:50:50 -070094const ButtonLocation kResetLocalizerLeft(3, 11);
95const ButtonLocation kResetLocalizerRight(3, 13);
96
Tyler Chatow5eeee902019-04-12 20:47:48 -070097const ButtonLocation kNearCargoHint(3, 3);
98const ButtonLocation kMidCargoHint(3, 5);
99const ButtonLocation kFarCargoHint(3, 6);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700100
James Kuszmaul518640d2019-04-13 15:50:50 -0700101const JoystickAxis kCargoSelectorY(5, 6);
102const JoystickAxis kCargoSelectorX(5, 5);
103
Tyler Chatow5eeee902019-04-12 20:47:48 -0700104const ButtonLocation kCameraLog(3, 14);
Austin Schuh4e2629d2019-03-28 14:44:37 -0700105
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800106const ElevatorWristPosition kStowPos{0.36, 0.0};
Austin Schuh02be8b92019-03-24 16:04:14 -0700107const ElevatorWristPosition kClimbPos{0.0, M_PI / 4.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800108
Austin Schuh139f59d2019-03-17 18:16:13 -0700109const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
110const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800111
112const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0};
113const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0};
114
Sabina Davise48004f2019-03-02 23:15:24 -0800115const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
116const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800117
Sabina Davise48004f2019-03-02 23:15:24 -0800118const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0};
119const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800120
Sabina Davise6fe6c52019-03-03 15:48:51 -0800121const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0};
122const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
123
Austin Schuh6c5deb12019-03-24 16:48:32 -0700124const ElevatorWristPosition kBallForwardLowerPos{0.21, 1.27};
Austin Schuh20dc0502019-03-30 07:24:07 -0700125const ElevatorWristPosition kBallBackwardLowerPos{0.43, -1.99};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800126
Austin Schuh20dc0502019-03-30 07:24:07 -0700127const ElevatorWristPosition kBallForwardMiddlePos{0.925, 1.21};
128const ElevatorWristPosition kBallBackwardMiddlePos{1.19, -1.98};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800129
Austin Schuh139f59d2019-03-17 18:16:13 -0700130const ElevatorWristPosition kBallForwardUpperPos{1.51, 0.961};
131const ElevatorWristPosition kBallBackwardUpperPos{1.44, -1.217};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800132
Austin Schuh20dc0502019-03-30 07:24:07 -0700133const ElevatorWristPosition kBallCargoForwardPos{0.59, 1.2};
134const ElevatorWristPosition kBallCargoBackwardPos{0.868265, -2.1};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800135
Sabina Davise6fe6c52019-03-03 15:48:51 -0800136const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097};
137const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018};
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800138
Austin Schuh20dc0502019-03-30 07:24:07 -0700139const ElevatorWristPosition kBallIntakePos{0.309, 2.13};
Austin Schuh2cf16b82019-02-15 23:23:22 -0800140
James Kuszmaul7077d342021-06-09 20:23:58 -0700141class Reader : public ::frc971::input::ActionJoystickInput {
Sabina Davis91b23602019-01-21 00:06:01 -0800142 public:
143 Reader(::aos::EventLoop *event_loop)
James Kuszmaul7077d342021-06-09 20:23:58 -0700144 : ::frc971::input::ActionJoystickInput(
Sabina Davis91b23602019-01-21 00:06:01 -0800145 event_loop,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700146 ::y2019::control_loops::drivetrain::GetDrivetrainConfig(),
James Kuszmaul7077d342021-06-09 20:23:58 -0700147 ::frc971::input::DrivetrainInputReader::InputType::kPistol,
James Kuszmaulccc368b2019-04-11 20:00:07 -0700148 {.run_teleop_in_auto = true,
Austin Schuhc087b102019-05-12 15:33:12 -0700149 .cancel_auto_button = kCancelAutoMode}),
150 target_selector_hint_sender_(
151 event_loop->MakeSender<
152 ::y2019::control_loops::drivetrain::TargetSelectorHint>(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700153 "/drivetrain")),
Austin Schuheb99d072019-05-12 21:03:38 -0700154 localizer_control_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700155 event_loop->MakeSender<LocalizerControl>("/drivetrain")),
Austin Schuh5671a8c2019-05-19 17:01:04 -0700156 camera_log_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700157 event_loop->MakeSender<::y2019::CameraLog>("/camera")),
158 superstructure_goal_fetcher_(
159 event_loop->MakeFetcher<superstructure::Goal>("/superstructure")),
160 superstructure_goal_sender_(
161 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700162 superstructure_position_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700163 event_loop->MakeFetcher<superstructure::Position>(
164 "/superstructure")),
Austin Schuh170f4952019-06-29 18:58:30 -0700165 superstructure_status_fetcher_(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700166 event_loop->MakeFetcher<superstructure::Status>(
167 "/superstructure")) {
Tyler Chatowe0241452019-03-08 21:07:50 -0800168 const uint16_t team = ::aos::network::GetTeamNumber();
Austin Schuh170f4952019-06-29 18:58:30 -0700169 superstructure_goal_fetcher_.Fetch();
170 if (superstructure_goal_fetcher_.get()) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700171 grab_piece_ = superstructure_goal_fetcher_->has_suction()
172 ? superstructure_goal_fetcher_->suction()->grab_piece()
173 : false;
174 switch_ball_ =
175 superstructure_goal_fetcher_->has_suction()
176 ? (superstructure_goal_fetcher_->suction()->gamepiece_mode() == 0)
177 : true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800178 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800179 video_tx_.reset(new ProtoTXUdpSocket<VisionControl>(
180 StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000));
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800181 }
Sabina Davis91b23602019-01-21 00:06:01 -0800182
Austin Schuha78857f2019-03-13 22:43:41 -0700183 void AutoEnded() override {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700184 AOS_LOG(INFO, "Auto ended, assuming disc and have piece\n");
Austin Schuha78857f2019-03-13 22:43:41 -0700185 grab_piece_ = true;
186 switch_ball_ = false;
187 }
188
James Kuszmaul7077d342021-06-09 20:23:58 -0700189 void HandleTeleop(
190 const ::frc971::input::driver_station::Data &data) override {
Austin Schuhaab7e162019-03-13 22:44:58 -0700191 ::aos::monotonic_clock::time_point monotonic_now =
192 ::aos::monotonic_clock::now();
Austin Schuh170f4952019-06-29 18:58:30 -0700193 superstructure_position_fetcher_.Fetch();
194 superstructure_status_fetcher_.Fetch();
195 if (!superstructure_status_fetcher_.get() ||
196 !superstructure_position_fetcher_.get()) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700197 AOS_LOG(ERROR, "Got no superstructure status or position packet.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800198 return;
199 }
200
Alex Perrycb7da4b2019-08-28 19:35:56 -0700201 CHECK(superstructure_status_fetcher_->has_stilts());
202
203 if (!superstructure_status_fetcher_->has_piece()) {
Austin Schuhaab7e162019-03-13 22:44:58 -0700204 last_not_has_piece_ = monotonic_now;
205 }
206
Alex Perrycb7da4b2019-08-28 19:35:56 -0700207 auto main_superstructure_goal_builder =
208 superstructure_goal_sender_.MakeBuilder();
209
210 flatbuffers::Offset<superstructure::Goal> superstructure_goal_offset;
Sabina Davis91b23602019-01-21 00:06:01 -0800211
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700212 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700213 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
214 elevator_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
215 *main_superstructure_goal_builder.fbb(), 0.0,
216 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
217 0.0, 0.0));
218
219 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
220 intake_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
221 *main_superstructure_goal_builder.fbb(), -1.2);
222
223 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
224 wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
225 *main_superstructure_goal_builder.fbb(), 0.0,
226 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
227 0.0, 0.0));
228
229 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
230 stilts_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
231 *main_superstructure_goal_builder.fbb(), 0.0,
232 CreateProfileParameters(*main_superstructure_goal_builder.fbb(),
233 0.0, 0.0));
234
James Kuszmaul2457eb72019-12-15 15:37:18 -0800235 flatbuffers::Offset<SuctionGoal> suction_offset =
236 CreateSuctionGoal(*main_superstructure_goal_builder.fbb(), false, 0);
237
Alex Perrycb7da4b2019-08-28 19:35:56 -0700238 superstructure::Goal::Builder superstructure_goal_builder =
239 main_superstructure_goal_builder.MakeBuilder<superstructure::Goal>();
240
241 superstructure_goal_builder.add_elevator(elevator_offset);
242 superstructure_goal_builder.add_intake(intake_offset);
243 superstructure_goal_builder.add_wrist(wrist_offset);
244 superstructure_goal_builder.add_stilts(stilts_offset);
James Kuszmaul2457eb72019-12-15 15:37:18 -0800245 superstructure_goal_builder.add_suction(suction_offset);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700246 superstructure_goal_builder.add_roller_voltage(0.0);
247
248 superstructure_goal_offset = superstructure_goal_builder.Finish();
249 }
James Kuszmaul2457eb72019-12-15 15:37:18 -0800250 superstructure::Goal *mutable_superstructure_goal = CHECK_NOTNULL(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700251 GetMutableTemporaryPointer(*main_superstructure_goal_builder.fbb(),
James Kuszmaul2457eb72019-12-15 15:37:18 -0800252 superstructure_goal_offset));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700253
254 {
255 auto builder = target_selector_hint_sender_.MakeBuilder();
256 control_loops::drivetrain::TargetSelectorHint::Builder
257 target_selector_hint_builder =
258 builder
259 .MakeBuilder<control_loops::drivetrain::TargetSelectorHint>();
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700260 if (data.IsPressed(kNearCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700261 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800262 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700263 } else if (data.IsPressed(kMidCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700264 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800265 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700266 } else if (data.IsPressed(kFarCargoHint)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700267 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800268 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700269 } else {
James Kuszmaul518640d2019-04-13 15:50:50 -0700270 const double cargo_joy_y = data.GetAxis(kCargoSelectorY);
271 const double cargo_joy_x = data.GetAxis(kCargoSelectorX);
272 if (cargo_joy_y > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700273 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700274 control_loops::drivetrain::SelectionHint::NEAR_SHIP);
James Kuszmaul1b822b42019-04-14 14:27:35 -0700275 } else if (cargo_joy_y < -0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700276 target_selector_hint_builder.add_suggested_target(
Austin Schuh872723c2019-12-25 14:38:09 -0800277 control_loops::drivetrain::SelectionHint::FAR_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700278 } else if (::std::abs(cargo_joy_x) > 0.5) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700279 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700280 control_loops::drivetrain::SelectionHint::MID_SHIP);
James Kuszmaul518640d2019-04-13 15:50:50 -0700281 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700282 target_selector_hint_builder.add_suggested_target(
James Kuszmaul7077d342021-06-09 20:23:58 -0700283 control_loops::drivetrain::SelectionHint::NONE);
James Kuszmaul518640d2019-04-13 15:50:50 -0700284 }
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700285 }
milind1f1dca32021-07-03 13:50:07 -0700286 if (builder.Send(target_selector_hint_builder.Finish()) !=
287 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700288 AOS_LOG(ERROR, "Failed to send target selector hint.\n");
James Kuszmaul7d1ef442019-03-23 20:20:50 -0700289 }
290 }
291
James Kuszmaul518640d2019-04-13 15:50:50 -0700292 if (data.PosEdge(kResetLocalizerLeft)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700293 auto builder = localizer_control_sender_.MakeBuilder();
James Kuszmaul518640d2019-04-13 15:50:50 -0700294 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700295 LocalizerControl::Builder localizer_control_builder =
296 builder.MakeBuilder<LocalizerControl>();
297 localizer_control_builder.add_x(0.6);
298 localizer_control_builder.add_y(3.4);
299 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700300
milind1f1dca32021-07-03 13:50:07 -0700301 if (builder.Send(localizer_control_builder.Finish()) !=
302 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700303 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700304 }
305 }
306
307 if (data.PosEdge(kResetLocalizerRight)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700308 auto builder = localizer_control_sender_.MakeBuilder();
309 // Start at the right feeder station.
310 LocalizerControl::Builder localizer_control_builder =
311 builder.MakeBuilder<LocalizerControl>();
312 localizer_control_builder.add_x(0.6);
313 localizer_control_builder.add_y(-3.4);
314 localizer_control_builder.add_keep_current_theta(true);
James Kuszmaul518640d2019-04-13 15:50:50 -0700315
milind1f1dca32021-07-03 13:50:07 -0700316 if (builder.Send(localizer_control_builder.Finish()) !=
317 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700318 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmaul518640d2019-04-13 15:50:50 -0700319 }
320 }
321
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700322 if (data.PosEdge(kResetLocalizerLeftForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700323 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700324 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700325 LocalizerControl::Builder localizer_control_builder =
326 builder.MakeBuilder<LocalizerControl>();
327 localizer_control_builder.add_x(0.4);
328 localizer_control_builder.add_y(3.4);
329 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700330
milind1f1dca32021-07-03 13:50:07 -0700331 if (builder.Send(localizer_control_builder.Finish()) !=
332 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700333 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700334 }
335 }
336
337 if (data.PosEdge(kResetLocalizerLeftBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700338 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700339 // Start at the left feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700340 LocalizerControl::Builder localizer_control_builder =
341 builder.MakeBuilder<LocalizerControl>();
342 localizer_control_builder.add_x(0.4);
343 localizer_control_builder.add_y(3.4);
344 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700345
milind1f1dca32021-07-03 13:50:07 -0700346 if (builder.Send(localizer_control_builder.Finish()) !=
347 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700348 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700349 }
350 }
351
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700352 if (data.PosEdge(kResetLocalizerRightForwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700353 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700354 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700355 LocalizerControl::Builder localizer_control_builder =
356 builder.MakeBuilder<LocalizerControl>();
357 localizer_control_builder.add_x(0.4);
358 localizer_control_builder.add_y(-3.4);
359 localizer_control_builder.add_theta(0.0);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700360
milind1f1dca32021-07-03 13:50:07 -0700361 if (builder.Send(localizer_control_builder.Finish()) !=
362 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700363 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700364 }
365 }
366
367 if (data.PosEdge(kResetLocalizerRightBackwards)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700368 auto builder = localizer_control_sender_.MakeBuilder();
Austin Schuh3632f8d2019-03-22 21:14:14 -0700369 // Start at the right feeder station.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700370 LocalizerControl::Builder localizer_control_builder =
371 builder.MakeBuilder<LocalizerControl>();
372 localizer_control_builder.add_x(0.4);
373 localizer_control_builder.add_y(-3.4);
374 localizer_control_builder.add_theta(M_PI);
Austin Schuhbb1df6f2019-03-17 18:15:43 -0700375
milind1f1dca32021-07-03 13:50:07 -0700376 if (builder.Send(localizer_control_builder.Finish()) !=
377 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700378 AOS_LOG(ERROR, "Failed to reset localizer.\n");
James Kuszmauld8deb682019-03-10 10:38:42 -0700379 }
380 }
381
James Kuszmaul13738862019-04-14 10:48:00 -0700382 if (data.PosEdge(kRelease) &&
383 monotonic_now >
384 last_release_button_press_ + ::std::chrono::milliseconds(500)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700385 if (superstructure_status_fetcher_->has_piece()) {
James Kuszmaul13738862019-04-14 10:48:00 -0700386 release_mode_ = ReleaseButtonMode::kRelease;
387 } else {
388 release_mode_ = ReleaseButtonMode::kBallIntake;
389 }
390 }
391
392 if (data.IsPressed(kRelease)) {
393 last_release_button_press_ = monotonic_now;
394 }
395
Alex Perrycb7da4b2019-08-28 19:35:56 -0700396 AOS_LOG(INFO, "has_piece: %d\n",
397 superstructure_status_fetcher_->has_piece());
Austin Schuh1a17e132019-02-17 15:05:06 -0800398 if (data.IsPressed(kSuctionBall)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800399 grab_piece_ = true;
Austin Schuh1a17e132019-02-17 15:05:06 -0800400 } else if (data.IsPressed(kSuctionHatch)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800401 grab_piece_ = true;
James Kuszmaul13738862019-04-14 10:48:00 -0700402 } else if ((release_mode_ == ReleaseButtonMode::kRelease &&
403 data.IsPressed(kRelease)) ||
Tyler Chatow5eeee902019-04-12 20:47:48 -0700404 data.IsPressed(kReleaseButtonBoard) ||
Alex Perrycb7da4b2019-08-28 19:35:56 -0700405 !superstructure_status_fetcher_->has_piece()) {
Sabina Davisc6329342019-03-01 20:44:42 -0800406 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700407 AOS_LOG(INFO, "releasing due to other thing\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800408 }
Sabina Davis91b23602019-01-21 00:06:01 -0800409
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800410 if (data.IsPressed(kRocketBackwardUnpressed)) {
411 elevator_wrist_pos_ = kStowPos;
412 }
Alex Perrycb7da4b2019-08-28 19:35:56 -0700413 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(-1.2);
414 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800415
James Kuszmaul13738862019-04-14 10:48:00 -0700416 const bool kDoBallIntake =
417 (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake &&
418 data.IsPressed(kRelease)) ||
419 data.GetAxis(kBallIntake) > 0.9;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800420 const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9;
421
422 if (data.IsPressed(kPanelSwitch)) {
423 switch_ball_ = false;
424 } else if (data.IsPressed(kCargoSwitch)) {
425 switch_ball_ = true;
426 }
427
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800428 if (switch_ball_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700429 if (superstructure_status_fetcher_->has_piece()) {
430 mutable_superstructure_goal->mutable_wrist()
431 ->mutable_profile_params()
432 ->mutate_max_acceleration(20);
Austin Schuh1a17e132019-02-17 15:05:06 -0800433 }
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800434
435 // Go to intake position and apply vacuum
436 if (data.IsPressed(kBallHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800437 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800438 elevator_wrist_pos_ = kBallHPIntakeForwardPos;
439 } else if (data.IsPressed(kBallHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800440 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800441 elevator_wrist_pos_ = kBallHPIntakeBackwardPos;
442 }
443
444 // Go to elevator/wrist position. Overrides intake position if pressed so
445 // we can re-grab the ball.
446 if (data.IsPressed(kRocketForwardLower)) {
447 elevator_wrist_pos_ = kBallForwardLowerPos;
448 } else if (data.IsPressed(kRocketBackwardLower)) {
449 elevator_wrist_pos_ = kBallBackwardLowerPos;
450 } else if (data.IsPressed(kRocketForwardMiddle)) {
451 elevator_wrist_pos_ = kBallForwardMiddlePos;
452 } else if (data.IsPressed(kRocketBackwardMiddle)) {
453 elevator_wrist_pos_ = kBallBackwardMiddlePos;
454 } else if (data.IsPressed(kRocketForwardUpper)) {
455 elevator_wrist_pos_ = kBallForwardUpperPos;
456 } else if (data.IsPressed(kRocketBackwardUpper)) {
457 elevator_wrist_pos_ = kBallBackwardUpperPos;
458 } else if (data.IsPressed(kCargoForward)) {
459 elevator_wrist_pos_ = kBallCargoForwardPos;
460 } else if (data.IsPressed(kCargoBackward)) {
461 elevator_wrist_pos_ = kBallCargoBackwardPos;
462 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800463 } else {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800464 if (data.IsPressed(kPanelHPIntakeForward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800465 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800466 elevator_wrist_pos_ = kPanelHPIntakeForwrdPos;
467 } else if (data.IsPressed(kPanelHPIntakeBackward)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800468 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800469 elevator_wrist_pos_ = kPanelHPIntakeBackwardPos;
470 }
471
472 // Go to elevator/wrist position. Overrides intake position if pressed so
473 // we can re-grab the panel.
474 if (data.IsPressed(kRocketForwardLower)) {
475 elevator_wrist_pos_ = kPanelForwardLowerPos;
476 } else if (data.IsPressed(kRocketBackwardLower)) {
477 elevator_wrist_pos_ = kPanelBackwardLowerPos;
478 } else if (data.IsPressed(kRocketForwardMiddle)) {
479 elevator_wrist_pos_ = kPanelForwardMiddlePos;
480 } else if (data.IsPressed(kRocketBackwardMiddle)) {
481 elevator_wrist_pos_ = kPanelBackwardMiddlePos;
482 } else if (data.IsPressed(kRocketForwardUpper)) {
483 elevator_wrist_pos_ = kPanelForwardUpperPos;
484 } else if (data.IsPressed(kRocketBackwardUpper)) {
485 elevator_wrist_pos_ = kPanelBackwardUpperPos;
Sabina Davise6fe6c52019-03-03 15:48:51 -0800486 } else if (data.IsPressed(kCargoForward)) {
487 elevator_wrist_pos_ = kPanelCargoForwardPos;
488 } else if (data.IsPressed(kCargoBackward)) {
489 elevator_wrist_pos_ = kPanelCargoBackwardPos;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800490 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800491 }
492
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800493 if (switch_ball_) {
494 if (kDoBallOutake ||
Austin Schuhaab7e162019-03-13 22:44:58 -0700495 (kDoBallIntake &&
Austin Schuh20dc0502019-03-30 07:24:07 -0700496 monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700497 mutable_superstructure_goal->mutable_intake()->mutate_unsafe_goal(0.83);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800498 }
Austin Schuh23a51632019-02-19 16:50:36 -0800499
Alex Perrycb7da4b2019-08-28 19:35:56 -0700500 if (kDoBallIntake && !superstructure_status_fetcher_->has_piece()) {
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800501 elevator_wrist_pos_ = kBallIntakePos;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700502 mutable_superstructure_goal->mutate_roller_voltage(9.0);
Sabina Davisc6329342019-03-01 20:44:42 -0800503 grab_piece_ = true;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800504 } else {
505 if (kDoBallOutake) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700506 mutable_superstructure_goal->mutate_roller_voltage(-6.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800507 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700508 mutable_superstructure_goal->mutate_roller_voltage(0.0);
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800509 }
510 }
Austin Schuh23a51632019-02-19 16:50:36 -0800511 }
Austin Schuh1a17e132019-02-17 15:05:06 -0800512
Austin Schuh457bde32019-03-17 18:16:41 -0700513 constexpr double kDeployStiltPosition = 0.5;
514
Austin Schuh457bde32019-03-17 18:16:41 -0700515 if (data.IsPressed(kFallOver)) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700516 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.71);
517 mutable_superstructure_goal->mutable_stilts()
518 ->mutable_profile_params()
519 ->mutate_max_velocity(0.65);
520 mutable_superstructure_goal->mutable_stilts()
521 ->mutable_profile_params()
522 ->mutate_max_acceleration(1.25);
Austin Schuhe2f22482019-04-13 23:05:43 -0700523 } else if (data.IsPressed(kHalfStilt)) {
524 was_above_ = false;
James Kuszmaul7077d342021-06-09 20:23:58 -0700525 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.345);
526 mutable_superstructure_goal->mutable_stilts()
527 ->mutable_profile_params()
528 ->mutate_max_velocity(0.65);
Austin Schuhe2f22482019-04-13 23:05:43 -0700529 } else if (data.IsPressed(kDeployStilt) || was_above_) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700530 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(
531 kDeployStiltPosition);
532 mutable_superstructure_goal->mutable_stilts()
533 ->mutable_profile_params()
534 ->mutate_max_velocity(0.65);
535 mutable_superstructure_goal->mutable_stilts()
536 ->mutable_profile_params()
537 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700538 } else {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700539 mutable_superstructure_goal->mutable_stilts()->mutate_unsafe_goal(0.005);
540 mutable_superstructure_goal->mutable_stilts()
541 ->mutable_profile_params()
542 ->mutate_max_velocity(0.65);
543 mutable_superstructure_goal->mutable_stilts()
544 ->mutable_profile_params()
545 ->mutate_max_acceleration(2.0);
Austin Schuh457bde32019-03-17 18:16:41 -0700546 }
547
Alex Perrycb7da4b2019-08-28 19:35:56 -0700548 if (superstructure_status_fetcher_->stilts()->position() > 0.1) {
Austin Schuh02be8b92019-03-24 16:04:14 -0700549 elevator_wrist_pos_ = kClimbPos;
James Kuszmaul13738862019-04-14 10:48:00 -0700550 climbed_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700551 mutable_superstructure_goal->mutable_wrist()
552 ->mutable_profile_params()
553 ->mutate_max_acceleration(10);
554 mutable_superstructure_goal->mutable_elevator()
555 ->mutable_profile_params()
556 ->mutate_max_acceleration(6);
Austin Schuh02be8b92019-03-24 16:04:14 -0700557 }
558
Austin Schuhe2f22482019-04-13 23:05:43 -0700559 // If we've been asked to go above deploy and made it up that high, latch
560 // was_above.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700561 if (mutable_superstructure_goal->stilts()->unsafe_goal() >
562 kDeployStiltPosition &&
563 superstructure_status_fetcher_->stilts()->position() >=
Austin Schuh170f4952019-06-29 18:58:30 -0700564 kDeployStiltPosition) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700565 was_above_ = true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700566 } else if ((superstructure_position_fetcher_->platform_left_detect() &&
567 superstructure_position_fetcher_->platform_right_detect()) &&
Austin Schuhe2f22482019-04-13 23:05:43 -0700568 !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) {
Austin Schuhe2f22482019-04-13 23:05:43 -0700569 was_above_ = false;
570 }
571
Alex Perrycb7da4b2019-08-28 19:35:56 -0700572 if (superstructure_status_fetcher_->stilts()->position() >
Austin Schuh170f4952019-06-29 18:58:30 -0700573 kDeployStiltPosition &&
Alex Perrycb7da4b2019-08-28 19:35:56 -0700574 mutable_superstructure_goal->stilts()->unsafe_goal() ==
575 kDeployStiltPosition) {
576 mutable_superstructure_goal->mutable_stilts()
577 ->mutable_profile_params()
578 ->mutate_max_velocity(0.30);
579 mutable_superstructure_goal->mutable_stilts()
580 ->mutable_profile_params()
581 ->mutate_max_acceleration(0.75);
Austin Schuh457bde32019-03-17 18:16:41 -0700582 }
583
James Kuszmaul13738862019-04-14 10:48:00 -0700584 if ((release_mode_ == ReleaseButtonMode::kRelease &&
585 data.IsPressed(kRelease)) ||
586 data.IsPressed(kReleaseButtonBoard)) {
Sabina Davisc6329342019-03-01 20:44:42 -0800587 grab_piece_ = false;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700588 AOS_LOG(INFO, "Releasing due to button\n");
Austin Schuh1a17e132019-02-17 15:05:06 -0800589 }
590
Sabina Davisc6329342019-03-01 20:44:42 -0800591 if (switch_ball_) {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800592 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
593 ->mutate_gamepiece_mode(0);
Sabina Davisc6329342019-03-01 20:44:42 -0800594 } else {
James Kuszmaul2457eb72019-12-15 15:37:18 -0800595 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
596 ->mutate_gamepiece_mode(1);
Sabina Davisc6329342019-03-01 20:44:42 -0800597 }
598
Tyler Chatowe0241452019-03-08 21:07:50 -0800599 vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0);
600
James Kuszmaul2457eb72019-12-15 15:37:18 -0800601 CHECK_NOTNULL(mutable_superstructure_goal->mutable_suction())
602 ->mutate_grab_piece(grab_piece_);
Sabina Davis91b23602019-01-21 00:06:01 -0800603
Alex Perrycb7da4b2019-08-28 19:35:56 -0700604 mutable_superstructure_goal->mutable_elevator()->mutate_unsafe_goal(
605 elevator_wrist_pos_.elevator);
606 mutable_superstructure_goal->mutable_wrist()->mutate_unsafe_goal(
607 elevator_wrist_pos_.wrist);
Sabina Davis91b23602019-01-21 00:06:01 -0800608
milind1f1dca32021-07-03 13:50:07 -0700609 if (main_superstructure_goal_builder.Send(superstructure_goal_offset) !=
610 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700611 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
Sabina Davis91b23602019-01-21 00:06:01 -0800612 }
Tyler Chatowe0241452019-03-08 21:07:50 -0800613
Austin Schuhaab7e162019-03-13 22:44:58 -0700614 if (monotonic_now >
615 last_vision_control_ + ::std::chrono::milliseconds(50)) {
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700616 video_tx_->Send(vision_control_);
Austin Schuhaab7e162019-03-13 22:44:58 -0700617 last_vision_control_ = monotonic_now;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700618 }
Austin Schuh4e2629d2019-03-28 14:44:37 -0700619
620 {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700621 auto builder = camera_log_sender_.MakeBuilder();
milind1f1dca32021-07-03 13:50:07 -0700622 (void)builder.Send(
623 CreateCameraLog(*builder.fbb(), data.IsPressed(kCameraLog)));
Austin Schuh4e2629d2019-03-28 14:44:37 -0700624 }
Sabina Davis91b23602019-01-21 00:06:01 -0800625 }
626
627 private:
Austin Schuhc087b102019-05-12 15:33:12 -0700628 ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint>
629 target_selector_hint_sender_;
630
Alex Perrycb7da4b2019-08-28 19:35:56 -0700631 ::aos::Sender<LocalizerControl> localizer_control_sender_;
Austin Schuheb99d072019-05-12 21:03:38 -0700632
Austin Schuh5671a8c2019-05-19 17:01:04 -0700633 ::aos::Sender<::y2019::CameraLog> camera_log_sender_;
634
Alex Perrycb7da4b2019-08-28 19:35:56 -0700635 ::aos::Fetcher<superstructure::Goal> superstructure_goal_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700636
Alex Perrycb7da4b2019-08-28 19:35:56 -0700637 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
Austin Schuh170f4952019-06-29 18:58:30 -0700638
Alex Perrycb7da4b2019-08-28 19:35:56 -0700639 ::aos::Fetcher<superstructure::Position> superstructure_position_fetcher_;
640 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
Austin Schuh170f4952019-06-29 18:58:30 -0700641
Austin Schuhe2f22482019-04-13 23:05:43 -0700642 // Bool to track if we've been above the deploy position. Once this bool is
643 // set, don't let the stilts retract until we see the platform.
644 bool was_above_ = false;
645
Sabina Davis91b23602019-01-21 00:06:01 -0800646 // Current goals here.
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800647 ElevatorWristPosition elevator_wrist_pos_ = kStowPos;
Sabina Davisc6329342019-03-01 20:44:42 -0800648 bool grab_piece_ = false;
Tyler Chatow7bcb52f2019-02-24 00:16:54 -0800649
650 bool switch_ball_ = false;
Tyler Chatowe0241452019-03-08 21:07:50 -0800651
James Kuszmaul13738862019-04-14 10:48:00 -0700652 bool climbed_ = false;
653
654 enum class ReleaseButtonMode {
655 kBallIntake,
656 kRelease,
657 };
658
659 ReleaseButtonMode release_mode_ = ReleaseButtonMode::kRelease;
660 aos::monotonic_clock::time_point last_release_button_press_ =
661 aos::monotonic_clock::min_time;
662
Tyler Chatowe0241452019-03-08 21:07:50 -0800663 VisionControl vision_control_;
664 ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_;
Tyler Chatow4fedeea2019-03-10 15:33:36 -0700665 ::aos::monotonic_clock::time_point last_vision_control_ =
666 ::aos::monotonic_clock::time_point::min();
Austin Schuhaab7e162019-03-13 22:44:58 -0700667
668 // Time at which we last did not have a game piece.
669 ::aos::monotonic_clock::time_point last_not_has_piece_ =
670 ::aos::monotonic_clock::time_point::min();
Sabina Davis91b23602019-01-21 00:06:01 -0800671};
672
673} // namespace joysticks
674} // namespace input
675} // namespace y2019
676
Austin Schuh094d09b2020-11-20 23:26:52 -0800677int main(int argc, char **argv) {
678 ::aos::InitGoogle(&argc, &argv);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700679
Alex Perrycb7da4b2019-08-28 19:35:56 -0700680 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
Austin Schuhc5fa6d92022-02-25 14:36:28 -0800681 aos::configuration::ReadConfig("aos_config.json");
Alex Perrycb7da4b2019-08-28 19:35:56 -0700682
683 ::aos::ShmEventLoop event_loop(&config.message());
Sabina Davis91b23602019-01-21 00:06:01 -0800684 ::y2019::input::joysticks::Reader reader(&event_loop);
Austin Schuh9fe68f72019-08-10 19:32:03 -0700685
686 event_loop.Run();
687
Austin Schuhae87e312020-08-01 16:15:01 -0700688 return 0;
Sabina Davis91b23602019-01-21 00:06:01 -0800689}