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