Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 1 | #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" |
Ravago Jones | 8c65c43 | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 19 | #include "frc971/input/redundant_joystick_data.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 20 | #include "frc971/zeroing/wrap.h" |
| 21 | #include "y2023/constants.h" |
| 22 | #include "y2023/control_loops/drivetrain/drivetrain_base.h" |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 23 | #include "y2023/control_loops/drivetrain/target_selector_hint_generated.h" |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 24 | #include "y2023/control_loops/superstructure/arm/generated_graph.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 25 | #include "y2023/control_loops/superstructure/superstructure_goal_generated.h" |
| 26 | #include "y2023/control_loops/superstructure/superstructure_status_generated.h" |
| 27 | |
| 28 | using frc971::CreateProfileParameters; |
| 29 | using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal; |
| 30 | using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal; |
| 31 | using frc971::input::driver_station::ButtonLocation; |
| 32 | using frc971::input::driver_station::ControlBit; |
| 33 | using frc971::input::driver_station::JoystickAxis; |
| 34 | using frc971::input::driver_station::POVLocation; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 35 | using y2023::control_loops::drivetrain::GridSelectionHint; |
James Kuszmaul | 055fe76 | 2023-03-03 21:14:01 -0800 | [diff] [blame] | 36 | using y2023::control_loops::drivetrain::RowSelectionHint; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 37 | using y2023::control_loops::drivetrain::SpotSelectionHint; |
| 38 | using y2023::control_loops::drivetrain::TargetSelectorHint; |
James Kuszmaul | 055fe76 | 2023-03-03 21:14:01 -0800 | [diff] [blame] | 39 | using y2023::control_loops::superstructure::RollerGoal; |
| 40 | using Side = frc971::control_loops::drivetrain::RobotSide; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 41 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 42 | namespace y2023::input::joysticks { |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 43 | |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 44 | constexpr double kConeWrist = 0.4; |
| 45 | constexpr double kCubeWrist = 1.0; |
| 46 | |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 47 | // TODO(milind): add correct locations |
Ravago Jones | 8c65c43 | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 48 | const ButtonLocation kDriverSpit(1, 1); |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 49 | const ButtonLocation kSpit(2, 5); |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 50 | |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 51 | const ButtonLocation kHighConeScoreLeft(2, 6); |
| 52 | const ButtonLocation kHighConeScoreRight(2, 9); |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 53 | |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 54 | const ButtonLocation kMidConeScoreLeft(2, 7); |
| 55 | const ButtonLocation kMidConeScoreRight(2, 10); |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 56 | |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 57 | const ButtonLocation kLowConeScoreLeft(2, 8); |
| 58 | const ButtonLocation kLowConeScoreRight(2, 11); |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 59 | |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 60 | const ButtonLocation kHighCube(1, 6); |
| 61 | const ButtonLocation kMidCube(1, 7); |
| 62 | const ButtonLocation kLowCube(1, 8); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 63 | |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 64 | const ButtonLocation kGroundPickupConeUp(1, 12); |
| 65 | const ButtonLocation kGroundPickupConeDown(1, 13); |
| 66 | const ButtonLocation kGroundPickupCube(2, 2); |
| 67 | const ButtonLocation kHPConePickup(1, 11); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 68 | |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 69 | const ButtonLocation kSuck(2, 3); |
| 70 | const ButtonLocation kBack(2, 4); |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 71 | |
milind-u | 50c9a58 | 2023-05-03 20:05:22 -0700 | [diff] [blame] | 72 | const ButtonLocation kStayIn(3, 2); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 73 | |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 74 | const ButtonLocation kConeDownTip(1, 9); |
| 75 | const ButtonLocation kConeDownBase(1, 10); |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 76 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 77 | namespace superstructure = y2023::control_loops::superstructure; |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 78 | namespace arm = superstructure::arm; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 79 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 80 | enum class GamePiece { |
| 81 | CONE_UP = 0, |
| 82 | CONE_DOWN = 1, |
| 83 | CUBE = 2, |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 84 | CONE_TIP = 4, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 87 | struct ButtonData { |
| 88 | ButtonLocation button; |
| 89 | std::optional<SpotSelectionHint> spot = std::nullopt; |
| 90 | }; |
| 91 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 92 | struct ArmSetpoint { |
| 93 | uint32_t index; |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 94 | std::optional<uint32_t> place_index = std::nullopt; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 95 | double wrist_goal; |
| 96 | std::optional<double> score_wrist_goal = std::nullopt; |
| 97 | GamePiece game_piece; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 98 | std::vector<ButtonData> buttons; |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 99 | Side side; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 100 | std::optional<RowSelectionHint> row_hint = std::nullopt; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 101 | }; |
| 102 | |
| 103 | const std::vector<ArmSetpoint> setpoints = { |
| 104 | { |
| 105 | .index = arm::GroundPickupBackConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 106 | .wrist_goal = 0.7, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 107 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 108 | .buttons = {{kGroundPickupConeUp}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 109 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 110 | }, |
| 111 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 112 | .index = arm::GroundPickupFrontConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 113 | .wrist_goal = 0.6, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 114 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 115 | .buttons = {{kGroundPickupConeUp}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 116 | .side = Side::FRONT, |
| 117 | }, |
| 118 | { |
| 119 | .index = arm::GroundPickupBackConeDownBaseIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 120 | .wrist_goal = kConeWrist, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 121 | .game_piece = GamePiece::CONE_DOWN, |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 122 | .buttons = {{kGroundPickupConeDown}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 123 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 124 | }, |
| 125 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 126 | .index = arm::GroundPickupFrontConeDownBaseIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 127 | .wrist_goal = 0.6, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 128 | .game_piece = GamePiece::CONE_DOWN, |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 129 | .buttons = {{kGroundPickupConeDown}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 130 | .side = Side::FRONT, |
| 131 | }, |
| 132 | { |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 133 | .index = arm::ScoreBackLowConeDownTipIndex(), |
| 134 | .wrist_goal = 0.7, |
| 135 | .game_piece = GamePiece::CONE_TIP, |
| 136 | .buttons = {{kLowConeScoreRight, SpotSelectionHint::RIGHT}, |
| 137 | {kLowCube, SpotSelectionHint::MIDDLE}, |
| 138 | {kLowConeScoreLeft, SpotSelectionHint::LEFT}}, |
| 139 | .side = Side::BACK, |
| 140 | .row_hint = RowSelectionHint::BOTTOM, |
| 141 | }, |
| 142 | { |
| 143 | .index = arm::ScoreBackMidConeDownTipIndex(), |
| 144 | .place_index = arm::ScoreBackMidConeDownTipPlacedIndex(), |
| 145 | .wrist_goal = 0.8, |
| 146 | .score_wrist_goal = 2.0, |
| 147 | .game_piece = GamePiece::CONE_TIP, |
| 148 | .buttons = {{kMidConeScoreRight, SpotSelectionHint::RIGHT}, |
| 149 | {kMidConeScoreLeft, SpotSelectionHint::LEFT}}, |
| 150 | .side = Side::BACK, |
| 151 | .row_hint = RowSelectionHint::MIDDLE, |
| 152 | }, |
| 153 | { |
| 154 | .index = arm::ScoreFrontMidConeDownTipIndex(), |
| 155 | .place_index = arm::ScoreFrontMidConeDownTipPlacedIndex(), |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 156 | .wrist_goal = 0.0, |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 157 | .score_wrist_goal = 1.4, |
| 158 | .game_piece = GamePiece::CONE_TIP, |
| 159 | .buttons = {{kMidConeScoreRight, SpotSelectionHint::RIGHT}, |
| 160 | {kMidConeScoreLeft, SpotSelectionHint::LEFT}}, |
| 161 | .side = Side::FRONT, |
| 162 | .row_hint = RowSelectionHint::MIDDLE, |
| 163 | }, |
| 164 | { |
| 165 | .index = arm::ScoreFrontHighConeDownTipIndex(), |
| 166 | .place_index = arm::ScoreFrontHighConeDownTipPlacedIndex(), |
| 167 | .wrist_goal = 0.4, |
| 168 | .score_wrist_goal = 1.4, |
| 169 | .game_piece = GamePiece::CONE_TIP, |
| 170 | .buttons = {{kHighConeScoreRight, SpotSelectionHint::RIGHT}, |
| 171 | {kHighConeScoreLeft, SpotSelectionHint::LEFT}}, |
| 172 | .side = Side::FRONT, |
| 173 | .row_hint = RowSelectionHint::TOP, |
| 174 | }, |
| 175 | { |
| 176 | .index = arm::ScoreFrontLowConeDownTipIndex(), |
| 177 | .wrist_goal = 2.8, |
| 178 | .game_piece = GamePiece::CONE_TIP, |
| 179 | .buttons = {{kLowConeScoreRight, SpotSelectionHint::RIGHT}, |
| 180 | {kLowCube, SpotSelectionHint::MIDDLE}, |
| 181 | {kLowConeScoreLeft, SpotSelectionHint::LEFT}}, |
| 182 | .side = Side::FRONT, |
| 183 | .row_hint = RowSelectionHint::TOP, |
| 184 | }, |
| 185 | { |
| 186 | .index = arm::ScoreBackMidConeUpIndex(), |
Maxwell Henderson | 0cd91fb | 2023-09-22 22:25:21 -0700 | [diff] [blame] | 187 | .wrist_goal = kConeWrist + 0.05, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 188 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 189 | .buttons = {{kMidConeScoreRight, SpotSelectionHint::RIGHT}, |
| 190 | {kMidConeScoreLeft, SpotSelectionHint::LEFT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 191 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 192 | .row_hint = RowSelectionHint::MIDDLE, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 193 | }, |
| 194 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 195 | .index = arm::ScoreBackLowConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 196 | .wrist_goal = kConeWrist, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 197 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 198 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
Austin Schuh | 6be7577 | 2023-03-11 15:12:33 -0800 | [diff] [blame] | 199 | {kLowCube, SpotSelectionHint::MIDDLE}, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 200 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 201 | .side = Side::BACK, |
| 202 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 203 | }, |
| 204 | { |
| 205 | .index = arm::ScoreFrontLowConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 206 | .wrist_goal = kConeWrist, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 207 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 208 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
Austin Schuh | 6be7577 | 2023-03-11 15:12:33 -0800 | [diff] [blame] | 209 | {kLowCube, SpotSelectionHint::MIDDLE}, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 210 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 211 | .side = Side::FRONT, |
| 212 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 213 | }, |
| 214 | { |
| 215 | .index = arm::ScoreBackMidConeDownBaseIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 216 | .wrist_goal = 2.5, |
| 217 | .score_wrist_goal = kConeWrist, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 218 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 219 | .buttons = {{kMidConeScoreLeft, SpotSelectionHint::LEFT}, |
| 220 | {kMidConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 221 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 222 | .row_hint = RowSelectionHint::MIDDLE, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 223 | }, |
| 224 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 225 | .index = arm::ScoreBackLowConeDownBaseIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 226 | .wrist_goal = kConeWrist, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 227 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 228 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
Austin Schuh | 6be7577 | 2023-03-11 15:12:33 -0800 | [diff] [blame] | 229 | {kLowCube, SpotSelectionHint::MIDDLE}, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 230 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 231 | .side = Side::BACK, |
| 232 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 233 | }, |
| 234 | { |
| 235 | .index = arm::ScoreFrontLowConeDownBaseIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 236 | .wrist_goal = kConeWrist, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 237 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 238 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
Austin Schuh | 6be7577 | 2023-03-11 15:12:33 -0800 | [diff] [blame] | 239 | {kLowCube, SpotSelectionHint::MIDDLE}, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 240 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 241 | .side = Side::FRONT, |
| 242 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 243 | }, |
| 244 | { |
| 245 | .index = arm::ScoreFrontMidConeDownBaseIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 246 | .wrist_goal = 2.6, |
| 247 | .score_wrist_goal = 0.2, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 248 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 249 | .buttons = {{kMidConeScoreLeft, SpotSelectionHint::LEFT}, |
| 250 | {kMidConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 251 | .side = Side::FRONT, |
| 252 | .row_hint = RowSelectionHint::MIDDLE, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 253 | }, |
| 254 | { |
| 255 | .index = arm::ScoreFrontHighConeDownBaseIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 256 | .wrist_goal = 2.6, |
| 257 | .score_wrist_goal = 0.2, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 258 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 259 | .buttons = {{kHighConeScoreLeft, SpotSelectionHint::LEFT}, |
| 260 | {kHighConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 261 | .side = Side::FRONT, |
| 262 | .row_hint = RowSelectionHint::TOP, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 263 | }, |
| 264 | { |
| 265 | .index = arm::HPPickupFrontConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 266 | .wrist_goal = kConeWrist, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 267 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 268 | .buttons = {{kHPConePickup}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 269 | .side = Side::FRONT, |
| 270 | }, |
| 271 | { |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 272 | .index = arm::HPPickupBackConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 273 | .wrist_goal = 0.5, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 274 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 275 | .buttons = {{kHPConePickup}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 276 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 277 | }, |
| 278 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 279 | .index = arm::ScoreFrontHighConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 280 | .wrist_goal = kConeWrist + 0.05, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 281 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 282 | .buttons = {{kHighConeScoreLeft, SpotSelectionHint::LEFT}, |
| 283 | {kHighConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 284 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 285 | .row_hint = RowSelectionHint::TOP, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 286 | }, |
| 287 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 288 | .index = arm::ScoreFrontMidConeUpIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 289 | .wrist_goal = kConeWrist + 0.05, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 290 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 291 | .buttons = {{kMidConeScoreLeft, SpotSelectionHint::LEFT}, |
| 292 | {kMidConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 293 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 294 | .row_hint = RowSelectionHint::MIDDLE, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 295 | }, |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 296 | { |
| 297 | .index = arm::GroundPickupBackCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 298 | .wrist_goal = kCubeWrist, |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 299 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 300 | .buttons = {{kGroundPickupCube}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 301 | .side = Side::BACK, |
| 302 | }, |
| 303 | { |
| 304 | .index = arm::ScoreFrontMidCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 305 | .wrist_goal = kCubeWrist, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 306 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 307 | .buttons = {{kMidCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 308 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 309 | .row_hint = RowSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 310 | }, |
| 311 | { |
| 312 | .index = arm::ScoreBackMidCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 313 | .wrist_goal = kCubeWrist, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 314 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 315 | .buttons = {{kMidCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 316 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 317 | .row_hint = RowSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 318 | }, |
| 319 | { |
| 320 | .index = arm::ScoreFrontLowCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 321 | .wrist_goal = kCubeWrist, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 322 | .game_piece = GamePiece::CUBE, |
Austin Schuh | 6be7577 | 2023-03-11 15:12:33 -0800 | [diff] [blame] | 323 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
| 324 | {kLowCube, SpotSelectionHint::MIDDLE}, |
| 325 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 326 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 327 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 328 | }, |
| 329 | { |
| 330 | .index = arm::ScoreBackLowCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 331 | .wrist_goal = kCubeWrist, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 332 | .game_piece = GamePiece::CUBE, |
Austin Schuh | 6be7577 | 2023-03-11 15:12:33 -0800 | [diff] [blame] | 333 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
| 334 | {kLowCube, SpotSelectionHint::MIDDLE}, |
| 335 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 336 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 337 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 338 | }, |
| 339 | { |
| 340 | .index = arm::ScoreFrontHighCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 341 | .wrist_goal = kCubeWrist, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 342 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 343 | .buttons = {{kHighCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 344 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 345 | .row_hint = RowSelectionHint::TOP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 346 | }, |
| 347 | { |
| 348 | .index = arm::ScoreBackHighCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 349 | .wrist_goal = kCubeWrist, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 350 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 351 | .buttons = {{kHighCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 352 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 353 | .row_hint = RowSelectionHint::TOP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 354 | }, |
| 355 | { |
| 356 | .index = arm::GroundPickupFrontCubeIndex(), |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 357 | .wrist_goal = kCubeWrist, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 358 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 359 | .buttons = {{kGroundPickupCube}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 360 | .side = Side::FRONT, |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 361 | }, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 362 | }; |
| 363 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 364 | class Reader : public ::frc971::input::ActionJoystickInput { |
| 365 | public: |
| 366 | Reader(::aos::EventLoop *event_loop) |
| 367 | : ::frc971::input::ActionJoystickInput( |
| 368 | event_loop, |
| 369 | ::y2023::control_loops::drivetrain::GetDrivetrainConfig(), |
Ravago Jones | 8c65c43 | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 370 | ::frc971::input::DrivetrainInputReader::InputType::kPistol, |
| 371 | {.use_redundant_joysticks = true}), |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 372 | superstructure_goal_sender_( |
| 373 | event_loop->MakeSender<superstructure::Goal>("/superstructure")), |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 374 | target_selector_hint_sender_( |
| 375 | event_loop->MakeSender<TargetSelectorHint>("/drivetrain")), |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 376 | superstructure_status_fetcher_( |
| 377 | event_loop->MakeFetcher<superstructure::Status>( |
| 378 | "/superstructure")) {} |
| 379 | |
| 380 | void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); } |
| 381 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 382 | GamePiece current_game_piece_ = GamePiece::CONE_UP; |
| 383 | |
Austin Schuh | f194af3 | 2023-03-22 20:31:18 -0700 | [diff] [blame] | 384 | bool has_scored_ = false; |
| 385 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 386 | void HandleTeleop( |
| 387 | const ::frc971::input::driver_station::Data &data) override { |
| 388 | superstructure_status_fetcher_.Fetch(); |
| 389 | if (!superstructure_status_fetcher_.get()) { |
| 390 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 391 | return; |
| 392 | } |
| 393 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 394 | if (!superstructure_status_fetcher_->has_wrist()) { |
| 395 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 396 | return; |
| 397 | } |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 398 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 399 | double wrist_goal = 0.0; |
| 400 | RollerGoal roller_goal = RollerGoal::IDLE; |
Austin Schuh | 9a11ebd | 2023-02-26 14:16:31 -0800 | [diff] [blame] | 401 | arm_goal_position_ = arm::NeutralIndex(); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 402 | std::optional<double> score_wrist_goal = std::nullopt; |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 403 | std::optional<double> place_index = std::nullopt; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 404 | |
| 405 | if (data.IsPressed(kGroundPickupConeUp) || data.IsPressed(kHPConePickup)) { |
Maxwell Henderson | bf1bcec | 2023-03-05 18:00:20 -0800 | [diff] [blame] | 406 | roller_goal = RollerGoal::INTAKE_CONE_UP; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 407 | current_game_piece_ = GamePiece::CONE_UP; |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 408 | } else if (data.IsPressed(kGroundPickupConeDown)) { |
Maxwell Henderson | bf1bcec | 2023-03-05 18:00:20 -0800 | [diff] [blame] | 409 | roller_goal = RollerGoal::INTAKE_CONE_DOWN; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 410 | current_game_piece_ = GamePiece::CONE_DOWN; |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 411 | } else if (data.IsPressed(kGroundPickupCube)) { |
| 412 | roller_goal = RollerGoal::INTAKE_CUBE; |
| 413 | current_game_piece_ = GamePiece::CUBE; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 414 | } |
| 415 | |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 416 | if (current_game_piece_ == GamePiece::CONE_DOWN || |
| 417 | current_game_piece_ == GamePiece::CONE_TIP) { |
| 418 | if (data.IsPressed(kConeDownTip)) { |
| 419 | current_game_piece_ = GamePiece::CONE_TIP; |
| 420 | } else if (data.IsPressed(kConeDownBase)) { |
| 421 | current_game_piece_ = GamePiece::CONE_DOWN; |
| 422 | } |
| 423 | } |
| 424 | |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 425 | if (current_game_piece_ == GamePiece::CUBE) { |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 426 | wrist_goal = kCubeWrist; |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 427 | } |
| 428 | |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 429 | std::optional<RowSelectionHint> placing_row; |
| 430 | std::optional<SpotSelectionHint> placing_spot; |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 431 | |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 432 | // Keep the setpoint if the button is still held. This lets us release the |
| 433 | // back button once a side has been selected. |
| 434 | if (current_setpoint_ != nullptr) { |
| 435 | bool found = false; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 436 | for (const auto &button : current_setpoint_->buttons) { |
| 437 | if (data.IsPressed(button.button)) { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 438 | found = true; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 439 | placing_spot = button.spot; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | if (!found) { |
| 443 | current_setpoint_ = nullptr; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | // Ok, no active setpoint. Search for the right one. |
| 448 | if (current_setpoint_ == nullptr) { |
Austin Schuh | f194af3 | 2023-03-22 20:31:18 -0700 | [diff] [blame] | 449 | has_scored_ = false; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 450 | const Side current_side = |
| 451 | data.IsPressed(kBack) ? Side::BACK : Side::FRONT; |
| 452 | // Search for the active setpoint. |
| 453 | for (const ArmSetpoint &setpoint : setpoints) { |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 454 | for (const auto &button : setpoint.buttons) { |
| 455 | if (data.IsPressed(button.button)) { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 456 | if (setpoint.game_piece == current_game_piece_ && |
| 457 | setpoint.side == current_side) { |
| 458 | current_setpoint_ = &setpoint; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame] | 459 | placing_spot = button.spot; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 460 | } |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 461 | } |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 462 | } |
| 463 | } |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 464 | } |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 465 | |
| 466 | // And, pull the bits out of it. |
| 467 | if (current_setpoint_ != nullptr) { |
Austin Schuh | 038b545 | 2023-03-08 20:55:45 -0800 | [diff] [blame] | 468 | if (!data.IsPressed(kStayIn)) { |
| 469 | wrist_goal = current_setpoint_->wrist_goal; |
| 470 | arm_goal_position_ = current_setpoint_->index; |
| 471 | score_wrist_goal = current_setpoint_->score_wrist_goal; |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 472 | place_index = current_setpoint_->place_index; |
Austin Schuh | 038b545 | 2023-03-08 20:55:45 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 475 | placing_row = current_setpoint_->row_hint; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 476 | } |
| 477 | |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 478 | CHECK_EQ(placing_row.has_value(), placing_spot.has_value()); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 479 | |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 480 | if (data.IsPressed(kSuck)) { |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 481 | roller_goal = RollerGoal::INTAKE_LAST; |
Austin Schuh | 8e6f287 | 2023-03-08 20:55:27 -0800 | [diff] [blame] | 482 | } else if (data.IsPressed(kSpit) || data.IsPressed(kDriverSpit)) { |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 483 | if (score_wrist_goal.has_value()) { |
| 484 | wrist_goal = score_wrist_goal.value(); |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 485 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 486 | // If we are supposed to dunk it, wait until we are close enough to |
| 487 | // spit. |
| 488 | if (std::abs(score_wrist_goal.value() - |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 489 | superstructure_status_fetcher_->wrist()->goal_position()) < |
Austin Schuh | f194af3 | 2023-03-22 20:31:18 -0700 | [diff] [blame] | 490 | 0.1 || |
| 491 | has_scored_) { |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 492 | if (place_index.has_value()) { |
| 493 | arm_goal_position_ = place_index.value(); |
Austin Schuh | f194af3 | 2023-03-22 20:31:18 -0700 | [diff] [blame] | 494 | if ((arm_goal_position_ == |
| 495 | superstructure_status_fetcher_->arm()->current_node() && |
| 496 | superstructure_status_fetcher_->arm()->path_distance_to_go() < |
| 497 | 0.01) || |
| 498 | has_scored_) { |
| 499 | has_scored_ = true; |
Austin Schuh | 99dda68 | 2023-03-11 00:18:37 -0800 | [diff] [blame] | 500 | roller_goal = RollerGoal::SPIT; |
| 501 | } |
| 502 | } else { |
| 503 | roller_goal = RollerGoal::SPIT; |
| 504 | } |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 505 | } |
| 506 | } else { |
| 507 | roller_goal = RollerGoal::SPIT; |
| 508 | } |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 509 | } |
| 510 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 511 | { |
| 512 | auto builder = superstructure_goal_sender_.MakeBuilder(); |
| 513 | |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 514 | flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal> |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 515 | wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 516 | *builder.fbb(), wrist_goal, |
| 517 | CreateProfileParameters(*builder.fbb(), 12.0, 90.0)); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 518 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 519 | superstructure::Goal::Builder superstructure_goal_builder = |
| 520 | builder.MakeBuilder<superstructure::Goal>(); |
Ravago Jones | eb70f6b | 2023-03-25 17:35:39 -0700 | [diff] [blame] | 521 | superstructure_goal_builder.add_arm_goal_position(arm_goal_position_); |
Maxwell Henderson | 5938a83 | 2023-02-23 09:33:15 -0800 | [diff] [blame] | 522 | superstructure_goal_builder.add_roller_goal(roller_goal); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 523 | superstructure_goal_builder.add_wrist(wrist_offset); |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 524 | if (builder.Send(superstructure_goal_builder.Finish()) != |
| 525 | aos::RawSender::Error::kOk) { |
| 526 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 527 | } |
| 528 | } |
James Kuszmaul | 5a66f8a | 2023-03-11 14:28:30 -0800 | [diff] [blame] | 529 | // TODO(james): Is there a more principled way to detect Human Player |
| 530 | // pickup? Probably don't bother fixing it until/unless we add more buttons |
| 531 | // that can select human player pickup. |
| 532 | if (data.IsPressed(kHPConePickup)) { |
| 533 | auto builder = target_selector_hint_sender_.MakeBuilder(); |
| 534 | auto hint_builder = builder.MakeBuilder<TargetSelectorHint>(); |
| 535 | hint_builder.add_substation_pickup(true); |
James Kuszmaul | 7e16765 | 2023-03-11 17:52:46 -0800 | [diff] [blame] | 536 | hint_builder.add_robot_side(CHECK_NOTNULL(current_setpoint_)->side); |
James Kuszmaul | 5a66f8a | 2023-03-11 14:28:30 -0800 | [diff] [blame] | 537 | if (builder.Send(hint_builder.Finish()) != aos::RawSender::Error::kOk) { |
| 538 | AOS_LOG(ERROR, "Sending target selector hint failed.\n"); |
| 539 | } |
| 540 | } else if (placing_row.has_value()) { |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 541 | auto builder = target_selector_hint_sender_.MakeBuilder(); |
| 542 | auto hint_builder = builder.MakeBuilder<TargetSelectorHint>(); |
| 543 | hint_builder.add_row(placing_row.value()); |
| 544 | hint_builder.add_spot(placing_spot.value()); |
James Kuszmaul | 055fe76 | 2023-03-03 21:14:01 -0800 | [diff] [blame] | 545 | hint_builder.add_robot_side(CHECK_NOTNULL(current_setpoint_)->side); |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 546 | if (builder.Send(hint_builder.Finish()) != aos::RawSender::Error::kOk) { |
| 547 | AOS_LOG(ERROR, "Sending target selector hint failed.\n"); |
| 548 | } |
| 549 | } |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | private: |
| 553 | ::aos::Sender<superstructure::Goal> superstructure_goal_sender_; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 554 | ::aos::Sender<TargetSelectorHint> target_selector_hint_sender_; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 555 | |
| 556 | ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_; |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 557 | |
| 558 | uint32_t arm_goal_position_; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 559 | |
| 560 | const ArmSetpoint *current_setpoint_ = nullptr; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 561 | }; |
| 562 | |
Stephan Pleines | f63bde8 | 2024-01-13 15:59:33 -0800 | [diff] [blame] | 563 | } // namespace y2023::input::joysticks |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 564 | |
| 565 | int main(int argc, char **argv) { |
| 566 | ::aos::InitGoogle(&argc, &argv); |
| 567 | |
| 568 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 569 | aos::configuration::ReadConfig("aos_config.json"); |
| 570 | |
| 571 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 572 | ::y2023::input::joysticks::Reader reader(&event_loop); |
| 573 | |
| 574 | event_loop.Run(); |
| 575 | |
| 576 | return 0; |
| 577 | } |