blob: 2cf94363ee2ba352313e9d3037b687e362796d3b [file] [log] [blame]
Maxwell Hendersonad312342023-01-10 12:07:47 -08001#include <unistd.h>
2
3#include <cmath>
4#include <cstdio>
5#include <cstring>
6
7#include "aos/actions/actions.h"
8#include "aos/init.h"
9#include "aos/logging/logging.h"
10#include "aos/network/team_number.h"
11#include "aos/util/log_interval.h"
12#include "frc971/autonomous/base_autonomous_actor.h"
13#include "frc971/control_loops/drivetrain/localizer_generated.h"
14#include "frc971/control_loops/profiled_subsystem_generated.h"
15#include "frc971/input/action_joystick_input.h"
16#include "frc971/input/driver_station_data.h"
17#include "frc971/input/drivetrain_input.h"
18#include "frc971/input/joystick_input.h"
19#include "frc971/zeroing/wrap.h"
20#include "y2023/constants.h"
21#include "y2023/control_loops/drivetrain/drivetrain_base.h"
James Kuszmaul4e171432023-02-26 13:39:37 -080022#include "y2023/control_loops/drivetrain/target_selector_hint_generated.h"
milind-udefab712023-02-20 22:22:02 -080023#include "y2023/control_loops/superstructure/arm/generated_graph.h"
Maxwell Hendersonad312342023-01-10 12:07:47 -080024#include "y2023/control_loops/superstructure/superstructure_goal_generated.h"
25#include "y2023/control_loops/superstructure/superstructure_status_generated.h"
26
27using frc971::CreateProfileParameters;
28using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal;
29using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal;
30using frc971::input::driver_station::ButtonLocation;
31using frc971::input::driver_station::ControlBit;
32using frc971::input::driver_station::JoystickAxis;
33using frc971::input::driver_station::POVLocation;
Maxwell Henderson5938a832023-02-23 09:33:15 -080034using y2023::control_loops::superstructure::RollerGoal;
James Kuszmaul4e171432023-02-26 13:39:37 -080035using y2023::control_loops::drivetrain::RowSelectionHint;
36using y2023::control_loops::drivetrain::GridSelectionHint;
37using y2023::control_loops::drivetrain::SpotSelectionHint;
38using y2023::control_loops::drivetrain::TargetSelectorHint;
Maxwell Hendersonad312342023-01-10 12:07:47 -080039
40namespace y2023 {
41namespace input {
42namespace joysticks {
43
milind-udefab712023-02-20 22:22:02 -080044// TODO(milind): add correct locations
Austin Schuh6dc925b2023-02-24 16:23:32 -080045const ButtonLocation kScore(4, 4);
Austin Schuh23a90022023-02-24 22:13:39 -080046const ButtonLocation kSpit(4, 13);
47
Austin Schuh9b3e41c2023-02-26 22:29:53 -080048const ButtonLocation kHighConeScoreLeft(4, 14);
49const ButtonLocation kHighConeScoreRight(3, 1);
50
51const ButtonLocation kMidConeScoreLeft(4, 15);
52const ButtonLocation kMidConeScoreRight(3, 2);
53
Austin Schuhe062be02023-03-04 21:12:07 -080054const ButtonLocation kLowConeScoreLeft(4, 16);
55const ButtonLocation kLowConeScoreRight(3, 3);
56
Austin Schuh9b3e41c2023-02-26 22:29:53 -080057const ButtonLocation kHighCube(4, 1);
58const ButtonLocation kMidCube(4, 2);
59const ButtonLocation kLowCube(4, 3);
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -080060
61const ButtonLocation kGroundPickupConeUp(4, 7);
Austin Schuhe062be02023-03-04 21:12:07 -080062const ButtonLocation kGroundPickupConeDownBase(4, 8);
milind-u71da5392023-02-26 12:45:00 -080063const ButtonLocation kGroundPickupCube(4, 10);
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -080064const ButtonLocation kHPConePickup(4, 6);
65
Austin Schuh9b3e41c2023-02-26 22:29:53 -080066const ButtonLocation kSuck(4, 11);
67const ButtonLocation kBack(4, 12);
milind-udefab712023-02-20 22:22:02 -080068
Austin Schuh6dc925b2023-02-24 16:23:32 -080069const ButtonLocation kWrist(4, 10);
70
Maxwell Hendersonad312342023-01-10 12:07:47 -080071namespace superstructure = y2023::control_loops::superstructure;
milind-udefab712023-02-20 22:22:02 -080072namespace arm = superstructure::arm;
Maxwell Hendersonad312342023-01-10 12:07:47 -080073
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -080074enum class GamePiece {
75 CONE_UP = 0,
76 CONE_DOWN = 1,
77 CUBE = 2,
78};
79
Austin Schuh9b3e41c2023-02-26 22:29:53 -080080enum class Side {
81 FRONT = 0,
82 BACK = 1,
83};
84
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -080085struct ArmSetpoint {
86 uint32_t index;
87 double wrist_goal;
88 std::optional<double> score_wrist_goal = std::nullopt;
89 GamePiece game_piece;
Austin Schuh9b3e41c2023-02-26 22:29:53 -080090 std::vector<ButtonLocation> buttons;
91 Side side;
James Kuszmaul4e171432023-02-26 13:39:37 -080092 std::optional<RowSelectionHint> row_hint = std::nullopt;
93 std::optional<SpotSelectionHint> spot_hint = std::nullopt;
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -080094};
95
96const std::vector<ArmSetpoint> setpoints = {
97 {
98 .index = arm::GroundPickupBackConeUpIndex(),
99 .wrist_goal = 0.0,
100 .game_piece = GamePiece::CONE_UP,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800101 .buttons = {kGroundPickupConeUp},
102 .side = Side::BACK,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800103 },
104 {
Austin Schuhe062be02023-03-04 21:12:07 -0800105 .index = arm::GroundPickupFrontConeUpIndex(),
106 .wrist_goal = 0.2,
107 .game_piece = GamePiece::CONE_UP,
108 .buttons = {kGroundPickupConeUp},
109 .side = Side::FRONT,
110 },
111 {
112 .index = arm::GroundPickupBackConeDownBaseIndex(),
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800113 .wrist_goal = 0.0,
114 .game_piece = GamePiece::CONE_DOWN,
Austin Schuhe062be02023-03-04 21:12:07 -0800115 .buttons = {kGroundPickupConeDownBase},
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800116 .side = Side::BACK,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800117 },
118 {
Austin Schuhe062be02023-03-04 21:12:07 -0800119 .index = arm::GroundPickupFrontConeDownBaseIndex(),
120 .wrist_goal = 0.2,
121 .game_piece = GamePiece::CONE_DOWN,
122 .buttons = {kGroundPickupConeDownBase},
123 .side = Side::FRONT,
124 },
125 {
126 .index = arm::ScoreBackMidConeUpIndex(),
127 .wrist_goal = 0.0,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800128 .game_piece = GamePiece::CONE_UP,
Austin Schuhe062be02023-03-04 21:12:07 -0800129 .buttons = {kMidConeScoreRight, kMidConeScoreLeft},
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800130 .side = Side::BACK,
James Kuszmaul4e171432023-02-26 13:39:37 -0800131 .row_hint = RowSelectionHint::MIDDLE,
132 .spot_hint = SpotSelectionHint::RIGHT,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800133 },
134 {
Austin Schuhe062be02023-03-04 21:12:07 -0800135 .index = arm::ScoreBackLowConeUpIndex(),
136 .wrist_goal = 0.0,
137 .game_piece = GamePiece::CONE_UP,
138 .buttons = {kLowConeScoreLeft, kLowConeScoreRight},
139 .side = Side::BACK,
140 .row_hint = RowSelectionHint::BOTTOM,
141 .spot_hint = SpotSelectionHint::LEFT,
142 },
143 {
144 .index = arm::ScoreFrontLowConeUpIndex(),
145 .wrist_goal = 0.0,
146 .game_piece = GamePiece::CONE_UP,
147 .buttons = {kLowConeScoreLeft, kLowConeScoreRight},
148 .side = Side::FRONT,
149 .row_hint = RowSelectionHint::BOTTOM,
150 .spot_hint = SpotSelectionHint::LEFT,
151 },
152 {
153 .index = arm::ScoreBackMidConeDownBaseIndex(),
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800154 .wrist_goal = 2.2,
155 .score_wrist_goal = 0.0,
156 .game_piece = GamePiece::CONE_DOWN,
Austin Schuhe062be02023-03-04 21:12:07 -0800157 .buttons = {kMidConeScoreLeft, kMidConeScoreRight},
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800158 .side = Side::BACK,
James Kuszmaul4e171432023-02-26 13:39:37 -0800159 .row_hint = RowSelectionHint::MIDDLE,
160 .spot_hint = SpotSelectionHint::RIGHT,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800161 },
162 {
Austin Schuhe062be02023-03-04 21:12:07 -0800163 .index = arm::ScoreBackLowConeDownBaseIndex(),
164 .wrist_goal = 0.0,
165 .score_wrist_goal = 0.0,
166 .game_piece = GamePiece::CONE_DOWN,
167 .buttons = {kLowConeScoreLeft, kLowConeScoreRight},
168 .side = Side::BACK,
169 .row_hint = RowSelectionHint::BOTTOM,
170 .spot_hint = SpotSelectionHint::RIGHT,
171 },
172 {
173 .index = arm::ScoreFrontLowConeDownBaseIndex(),
174 .wrist_goal = 0.0,
175 .game_piece = GamePiece::CONE_DOWN,
176 .buttons = {kLowConeScoreLeft, kLowConeScoreRight},
177 .side = Side::FRONT,
178 .row_hint = RowSelectionHint::BOTTOM,
179 .spot_hint = SpotSelectionHint::LEFT,
180 },
181 {
182 .index = arm::ScoreFrontMidConeDownBaseIndex(),
183 .wrist_goal = 2.0,
184 .score_wrist_goal = 0.0,
185 .game_piece = GamePiece::CONE_DOWN,
186 .buttons = {kMidConeScoreLeft, kMidConeScoreRight},
187 .side = Side::FRONT,
188 .row_hint = RowSelectionHint::MIDDLE,
189 .spot_hint = SpotSelectionHint::LEFT,
190 },
191 {
192 .index = arm::ScoreFrontHighConeDownBaseIndex(),
193 .wrist_goal = 2.0,
194 .score_wrist_goal = 0.0,
195 .game_piece = GamePiece::CONE_DOWN,
196 .buttons = {kHighConeScoreLeft, kHighConeScoreRight},
197 .side = Side::FRONT,
198 .row_hint = RowSelectionHint::TOP,
199 .spot_hint = SpotSelectionHint::LEFT,
200 },
201 {
202 .index = arm::HPPickupFrontConeUpIndex(),
203 .wrist_goal = 0.0,
204 .game_piece = GamePiece::CONE_UP,
205 .buttons = {kHPConePickup},
206 .side = Side::FRONT,
207 },
208 {
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800209 .index = arm::HPPickupBackConeUpIndex(),
Austin Schuhe062be02023-03-04 21:12:07 -0800210 .wrist_goal = 0.4,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800211 .game_piece = GamePiece::CONE_UP,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800212 .buttons = {kHPConePickup},
213 .side = Side::BACK,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800214 },
215 {
Austin Schuhe062be02023-03-04 21:12:07 -0800216 .index = arm::ScoreFrontHighConeUpIndex(),
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800217 .wrist_goal = 0.05,
218 .game_piece = GamePiece::CONE_UP,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800219 .buttons = {kHighConeScoreLeft, kHighConeScoreRight},
220 .side = Side::FRONT,
James Kuszmaul4e171432023-02-26 13:39:37 -0800221 .row_hint = RowSelectionHint::TOP,
222 .spot_hint = SpotSelectionHint::LEFT,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800223 },
224 {
Austin Schuhe062be02023-03-04 21:12:07 -0800225 .index = arm::ScoreFrontMidConeUpIndex(),
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800226 .wrist_goal = 0.05,
227 .game_piece = GamePiece::CONE_UP,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800228 .buttons = {kMidConeScoreLeft, kMidConeScoreRight},
229 .side = Side::FRONT,
James Kuszmaul4e171432023-02-26 13:39:37 -0800230 .row_hint = RowSelectionHint::MIDDLE,
231 .spot_hint = SpotSelectionHint::LEFT,
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800232 },
milind-u68842e12023-02-26 12:45:40 -0800233 {
234 .index = arm::GroundPickupBackCubeIndex(),
235 .wrist_goal = 0.6,
236 .game_piece = GamePiece::CUBE,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800237 .buttons = {kGroundPickupCube},
238 .side = Side::BACK,
239 },
240 {
241 .index = arm::ScoreFrontMidCubeIndex(),
242 .wrist_goal = 0.6,
243 .game_piece = GamePiece::CUBE,
244 .buttons = {kMidCube},
245 .side = Side::FRONT,
James Kuszmaul4e171432023-02-26 13:39:37 -0800246 .row_hint = RowSelectionHint::MIDDLE,
247 .spot_hint = SpotSelectionHint::MIDDLE,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800248 },
249 {
250 .index = arm::ScoreBackMidCubeIndex(),
251 .wrist_goal = 0.6,
252 .score_wrist_goal = 0.0,
253 .game_piece = GamePiece::CUBE,
254 .buttons = {kMidCube},
255 .side = Side::BACK,
James Kuszmaul4e171432023-02-26 13:39:37 -0800256 .row_hint = RowSelectionHint::MIDDLE,
257 .spot_hint = SpotSelectionHint::MIDDLE,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800258 },
259 {
260 .index = arm::ScoreFrontLowCubeIndex(),
261 .wrist_goal = 0.6,
262 .game_piece = GamePiece::CUBE,
263 .buttons = {kLowCube},
264 .side = Side::FRONT,
James Kuszmaul4e171432023-02-26 13:39:37 -0800265 .row_hint = RowSelectionHint::BOTTOM,
266 .spot_hint = SpotSelectionHint::MIDDLE,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800267 },
268 {
269 .index = arm::ScoreBackLowCubeIndex(),
270 .wrist_goal = 0.6,
271 .game_piece = GamePiece::CUBE,
272 .buttons = {kLowCube},
273 .side = Side::BACK,
James Kuszmaul4e171432023-02-26 13:39:37 -0800274 .row_hint = RowSelectionHint::BOTTOM,
275 .spot_hint = SpotSelectionHint::MIDDLE,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800276 },
277 {
278 .index = arm::ScoreFrontHighCubeIndex(),
279 .wrist_goal = 0.6,
280 .game_piece = GamePiece::CUBE,
281 .buttons = {kHighCube},
282 .side = Side::FRONT,
James Kuszmaul4e171432023-02-26 13:39:37 -0800283 .row_hint = RowSelectionHint::TOP,
284 .spot_hint = SpotSelectionHint::MIDDLE,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800285 },
286 {
287 .index = arm::ScoreBackHighCubeIndex(),
288 .wrist_goal = 0.6,
289 .score_wrist_goal = 0.0,
290 .game_piece = GamePiece::CUBE,
291 .buttons = {kHighCube},
292 .side = Side::BACK,
James Kuszmaul4e171432023-02-26 13:39:37 -0800293 .row_hint = RowSelectionHint::TOP,
294 .spot_hint = SpotSelectionHint::MIDDLE,
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800295 },
296 {
297 .index = arm::GroundPickupFrontCubeIndex(),
298 .wrist_goal = 0.6,
299 .game_piece = GamePiece::CUBE,
300 .buttons = {kGroundPickupCube},
301 .side = Side::FRONT,
milind-u68842e12023-02-26 12:45:40 -0800302 },
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800303};
304
Maxwell Hendersonad312342023-01-10 12:07:47 -0800305class Reader : public ::frc971::input::ActionJoystickInput {
306 public:
307 Reader(::aos::EventLoop *event_loop)
308 : ::frc971::input::ActionJoystickInput(
309 event_loop,
310 ::y2023::control_loops::drivetrain::GetDrivetrainConfig(),
311 ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}),
312 superstructure_goal_sender_(
313 event_loop->MakeSender<superstructure::Goal>("/superstructure")),
James Kuszmaul4e171432023-02-26 13:39:37 -0800314 target_selector_hint_sender_(
315 event_loop->MakeSender<TargetSelectorHint>("/drivetrain")),
Maxwell Hendersonad312342023-01-10 12:07:47 -0800316 superstructure_status_fetcher_(
317 event_loop->MakeFetcher<superstructure::Status>(
318 "/superstructure")) {}
319
320 void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); }
321
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800322 GamePiece current_game_piece_ = GamePiece::CONE_UP;
323
Maxwell Hendersonad312342023-01-10 12:07:47 -0800324 void HandleTeleop(
325 const ::frc971::input::driver_station::Data &data) override {
326 superstructure_status_fetcher_.Fetch();
327 if (!superstructure_status_fetcher_.get()) {
328 AOS_LOG(ERROR, "Got no superstructure status message.\n");
329 return;
330 }
331
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800332 if (!superstructure_status_fetcher_->has_wrist()) {
333 AOS_LOG(ERROR, "Got no superstructure status message.\n");
334 return;
335 }
milind-udefab712023-02-20 22:22:02 -0800336
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800337 double wrist_goal = 0.0;
338 RollerGoal roller_goal = RollerGoal::IDLE;
Austin Schuh9a11ebd2023-02-26 14:16:31 -0800339 arm_goal_position_ = arm::NeutralIndex();
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800340 std::optional<double> score_wrist_goal = std::nullopt;
341
342 if (data.IsPressed(kGroundPickupConeUp) || data.IsPressed(kHPConePickup)) {
milind-u71da5392023-02-26 12:45:00 -0800343 roller_goal = RollerGoal::INTAKE_CONE;
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800344 current_game_piece_ = GamePiece::CONE_UP;
Austin Schuhe062be02023-03-04 21:12:07 -0800345 } else if (data.IsPressed(kGroundPickupConeDownBase)) {
milind-u71da5392023-02-26 12:45:00 -0800346 roller_goal = RollerGoal::INTAKE_CONE;
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800347 current_game_piece_ = GamePiece::CONE_DOWN;
milind-u71da5392023-02-26 12:45:00 -0800348 } else if (data.IsPressed(kGroundPickupCube)) {
349 roller_goal = RollerGoal::INTAKE_CUBE;
350 current_game_piece_ = GamePiece::CUBE;
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800351 }
352
milind-u68842e12023-02-26 12:45:40 -0800353 if (current_game_piece_ == GamePiece::CUBE) {
354 wrist_goal = 0.6;
355 }
356
James Kuszmaul4e171432023-02-26 13:39:37 -0800357 std::optional<RowSelectionHint> placing_row;
358 std::optional<SpotSelectionHint> placing_spot;
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800359
Austin Schuhe062be02023-03-04 21:12:07 -0800360 // Keep the setpoint if the button is still held. This lets us release the
361 // back button once a side has been selected.
362 if (current_setpoint_ != nullptr) {
363 bool found = false;
364 for (const ButtonLocation &button : current_setpoint_->buttons) {
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800365 if (data.IsPressed(button)) {
Austin Schuhe062be02023-03-04 21:12:07 -0800366 found = true;
367 }
368 }
369 if (!found) {
370 current_setpoint_ = nullptr;
371 }
372 }
373
374 // Ok, no active setpoint. Search for the right one.
375 if (current_setpoint_ == nullptr) {
376 const Side current_side =
377 data.IsPressed(kBack) ? Side::BACK : Side::FRONT;
378 // Search for the active setpoint.
379 for (const ArmSetpoint &setpoint : setpoints) {
380 for (const ButtonLocation &button : setpoint.buttons) {
381 if (data.IsPressed(button)) {
382 if (setpoint.game_piece == current_game_piece_ &&
383 setpoint.side == current_side) {
384 current_setpoint_ = &setpoint;
385 }
Austin Schuh9b3e41c2023-02-26 22:29:53 -0800386 }
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800387 }
388 }
Austin Schuh6dc925b2023-02-24 16:23:32 -0800389 }
Austin Schuhe062be02023-03-04 21:12:07 -0800390
391 // And, pull the bits out of it.
392 if (current_setpoint_ != nullptr) {
393 wrist_goal = current_setpoint_->wrist_goal;
394 arm_goal_position_ = current_setpoint_->index;
395 score_wrist_goal = current_setpoint_->score_wrist_goal;
396 placing_row = current_setpoint_->row_hint;
397 placing_spot = current_setpoint_->spot_hint;
398 }
399
James Kuszmaul4e171432023-02-26 13:39:37 -0800400 CHECK_EQ(placing_row.has_value(), placing_spot.has_value());
Austin Schuh6dc925b2023-02-24 16:23:32 -0800401
Austin Schuh23a90022023-02-24 22:13:39 -0800402 if (data.IsPressed(kSuck)) {
milind-u71da5392023-02-26 12:45:00 -0800403 roller_goal = RollerGoal::INTAKE_LAST;
Austin Schuh23a90022023-02-24 22:13:39 -0800404 } else if (data.IsPressed(kSpit)) {
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800405 if (score_wrist_goal.has_value()) {
406 wrist_goal = score_wrist_goal.value();
Austin Schuh23a90022023-02-24 22:13:39 -0800407
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800408 // If we are supposed to dunk it, wait until we are close enough to
409 // spit.
410 if (std::abs(score_wrist_goal.value() -
411 superstructure_status_fetcher_->wrist()->position()) <
412 0.1) {
413 roller_goal = RollerGoal::SPIT;
414 }
415 } else {
416 roller_goal = RollerGoal::SPIT;
417 }
milind-udefab712023-02-20 22:22:02 -0800418 }
419
Maxwell Hendersonad312342023-01-10 12:07:47 -0800420 {
421 auto builder = superstructure_goal_sender_.MakeBuilder();
422
Austin Schuh6dc925b2023-02-24 16:23:32 -0800423 flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal>
Maxwell Henderson1ac7aac2023-02-23 17:35:32 -0800424 wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal(
425 *builder.fbb(), wrist_goal,
426 CreateProfileParameters(*builder.fbb(), 12.0, 90.0));
Austin Schuh6dc925b2023-02-24 16:23:32 -0800427
Maxwell Hendersonad312342023-01-10 12:07:47 -0800428 superstructure::Goal::Builder superstructure_goal_builder =
429 builder.MakeBuilder<superstructure::Goal>();
milind-udefab712023-02-20 22:22:02 -0800430 superstructure_goal_builder.add_arm_goal_position(arm_goal_position_);
Maxwell Henderson5938a832023-02-23 09:33:15 -0800431 superstructure_goal_builder.add_roller_goal(roller_goal);
Austin Schuh6dc925b2023-02-24 16:23:32 -0800432 superstructure_goal_builder.add_wrist(wrist_offset);
Maxwell Hendersonad312342023-01-10 12:07:47 -0800433 if (builder.Send(superstructure_goal_builder.Finish()) !=
434 aos::RawSender::Error::kOk) {
435 AOS_LOG(ERROR, "Sending superstructure goal failed.\n");
436 }
437 }
James Kuszmaul4e171432023-02-26 13:39:37 -0800438 if (placing_row.has_value()) {
439 auto builder = target_selector_hint_sender_.MakeBuilder();
440 auto hint_builder = builder.MakeBuilder<TargetSelectorHint>();
441 hint_builder.add_row(placing_row.value());
442 hint_builder.add_spot(placing_spot.value());
443 // TODO: Add field to TargetSelector hint for forwards vs. backwards
444 // placement.
445 if (builder.Send(hint_builder.Finish()) != aos::RawSender::Error::kOk) {
446 AOS_LOG(ERROR, "Sending target selector hint failed.\n");
447 }
448 }
Maxwell Hendersonad312342023-01-10 12:07:47 -0800449 }
450
451 private:
452 ::aos::Sender<superstructure::Goal> superstructure_goal_sender_;
James Kuszmaul4e171432023-02-26 13:39:37 -0800453 ::aos::Sender<TargetSelectorHint> target_selector_hint_sender_;
Maxwell Hendersonad312342023-01-10 12:07:47 -0800454
455 ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_;
milind-udefab712023-02-20 22:22:02 -0800456
457 uint32_t arm_goal_position_;
Austin Schuhe062be02023-03-04 21:12:07 -0800458
459 const ArmSetpoint *current_setpoint_ = nullptr;
Maxwell Hendersonad312342023-01-10 12:07:47 -0800460};
461
462} // namespace joysticks
463} // namespace input
464} // namespace y2023
465
466int main(int argc, char **argv) {
467 ::aos::InitGoogle(&argc, &argv);
468
469 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
470 aos::configuration::ReadConfig("aos_config.json");
471
472 ::aos::ShmEventLoop event_loop(&config.message());
473 ::y2023::input::joysticks::Reader reader(&event_loop);
474
475 event_loop.Run();
476
477 return 0;
478}