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