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" |
| 19 | #include "frc971/zeroing/wrap.h" |
| 20 | #include "y2023/constants.h" |
| 21 | #include "y2023/control_loops/drivetrain/drivetrain_base.h" |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 22 | #include "y2023/control_loops/drivetrain/target_selector_hint_generated.h" |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 23 | #include "y2023/control_loops/superstructure/arm/generated_graph.h" |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 24 | #include "y2023/control_loops/superstructure/superstructure_goal_generated.h" |
| 25 | #include "y2023/control_loops/superstructure/superstructure_status_generated.h" |
| 26 | |
| 27 | using frc971::CreateProfileParameters; |
| 28 | using frc971::control_loops::CreateStaticZeroingSingleDOFProfiledSubsystemGoal; |
| 29 | using frc971::control_loops::StaticZeroingSingleDOFProfiledSubsystemGoal; |
| 30 | using frc971::input::driver_station::ButtonLocation; |
| 31 | using frc971::input::driver_station::ControlBit; |
| 32 | using frc971::input::driver_station::JoystickAxis; |
| 33 | using frc971::input::driver_station::POVLocation; |
Maxwell Henderson | 5938a83 | 2023-02-23 09:33:15 -0800 | [diff] [blame] | 34 | using y2023::control_loops::superstructure::RollerGoal; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 35 | using y2023::control_loops::drivetrain::RowSelectionHint; |
| 36 | using y2023::control_loops::drivetrain::GridSelectionHint; |
| 37 | using y2023::control_loops::drivetrain::SpotSelectionHint; |
| 38 | using y2023::control_loops::drivetrain::TargetSelectorHint; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 39 | |
| 40 | namespace y2023 { |
| 41 | namespace input { |
| 42 | namespace joysticks { |
| 43 | |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 44 | // TODO(milind): add correct locations |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 45 | const ButtonLocation kScore(4, 4); |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 46 | const ButtonLocation kSpit(4, 13); |
| 47 | |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 48 | const ButtonLocation kHighConeScoreLeft(4, 14); |
| 49 | const ButtonLocation kHighConeScoreRight(3, 1); |
| 50 | |
| 51 | const ButtonLocation kMidConeScoreLeft(4, 15); |
| 52 | const ButtonLocation kMidConeScoreRight(3, 2); |
| 53 | |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 54 | const ButtonLocation kLowConeScoreLeft(4, 16); |
| 55 | const ButtonLocation kLowConeScoreRight(3, 3); |
| 56 | |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 57 | const ButtonLocation kHighCube(4, 1); |
| 58 | const ButtonLocation kMidCube(4, 2); |
| 59 | const ButtonLocation kLowCube(4, 3); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 60 | |
| 61 | const ButtonLocation kGroundPickupConeUp(4, 7); |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 62 | const ButtonLocation kGroundPickupConeDownBase(4, 8); |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 63 | const ButtonLocation kGroundPickupCube(4, 10); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 64 | const ButtonLocation kHPConePickup(4, 6); |
| 65 | |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 66 | const ButtonLocation kSuck(4, 11); |
| 67 | const ButtonLocation kBack(4, 12); |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 68 | |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 69 | const ButtonLocation kWrist(4, 10); |
| 70 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 71 | namespace superstructure = y2023::control_loops::superstructure; |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 72 | namespace arm = superstructure::arm; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 73 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 74 | enum class GamePiece { |
| 75 | CONE_UP = 0, |
| 76 | CONE_DOWN = 1, |
| 77 | CUBE = 2, |
| 78 | }; |
| 79 | |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 80 | enum class Side { |
| 81 | FRONT = 0, |
| 82 | BACK = 1, |
| 83 | }; |
| 84 | |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 85 | struct ButtonData { |
| 86 | ButtonLocation button; |
| 87 | std::optional<SpotSelectionHint> spot = std::nullopt; |
| 88 | }; |
| 89 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 90 | struct ArmSetpoint { |
| 91 | uint32_t index; |
| 92 | double wrist_goal; |
| 93 | std::optional<double> score_wrist_goal = std::nullopt; |
| 94 | GamePiece game_piece; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 95 | std::vector<ButtonData> buttons; |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 96 | Side side; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 97 | std::optional<RowSelectionHint> row_hint = std::nullopt; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | const std::vector<ArmSetpoint> setpoints = { |
| 101 | { |
| 102 | .index = arm::GroundPickupBackConeUpIndex(), |
| 103 | .wrist_goal = 0.0, |
| 104 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 105 | .buttons = {{kGroundPickupConeUp}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 106 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 107 | }, |
| 108 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 109 | .index = arm::GroundPickupFrontConeUpIndex(), |
| 110 | .wrist_goal = 0.2, |
| 111 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 112 | .buttons = {{kGroundPickupConeUp}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 113 | .side = Side::FRONT, |
| 114 | }, |
| 115 | { |
| 116 | .index = arm::GroundPickupBackConeDownBaseIndex(), |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 117 | .wrist_goal = 0.0, |
| 118 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 119 | .buttons = {{kGroundPickupConeDownBase}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 120 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 121 | }, |
| 122 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 123 | .index = arm::GroundPickupFrontConeDownBaseIndex(), |
| 124 | .wrist_goal = 0.2, |
| 125 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 126 | .buttons = {{kGroundPickupConeDownBase}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 127 | .side = Side::FRONT, |
| 128 | }, |
| 129 | { |
| 130 | .index = arm::ScoreBackMidConeUpIndex(), |
| 131 | .wrist_goal = 0.0, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 132 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 133 | .buttons = {{kMidConeScoreRight, SpotSelectionHint::RIGHT}, |
| 134 | {kMidConeScoreLeft, SpotSelectionHint::LEFT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 135 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 136 | .row_hint = RowSelectionHint::MIDDLE, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 137 | }, |
| 138 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 139 | .index = arm::ScoreBackLowConeUpIndex(), |
| 140 | .wrist_goal = 0.0, |
| 141 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 142 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
| 143 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 144 | .side = Side::BACK, |
| 145 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 146 | }, |
| 147 | { |
| 148 | .index = arm::ScoreFrontLowConeUpIndex(), |
| 149 | .wrist_goal = 0.0, |
| 150 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 151 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
| 152 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 153 | .side = Side::FRONT, |
| 154 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 155 | }, |
| 156 | { |
| 157 | .index = arm::ScoreBackMidConeDownBaseIndex(), |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 158 | .wrist_goal = 2.2, |
| 159 | .score_wrist_goal = 0.0, |
| 160 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 161 | .buttons = {{kMidConeScoreLeft, SpotSelectionHint::LEFT}, |
| 162 | {kMidConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 163 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 164 | .row_hint = RowSelectionHint::MIDDLE, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 165 | }, |
| 166 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 167 | .index = arm::ScoreBackLowConeDownBaseIndex(), |
| 168 | .wrist_goal = 0.0, |
| 169 | .score_wrist_goal = 0.0, |
| 170 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 171 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
| 172 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 173 | .side = Side::BACK, |
| 174 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 175 | }, |
| 176 | { |
| 177 | .index = arm::ScoreFrontLowConeDownBaseIndex(), |
| 178 | .wrist_goal = 0.0, |
| 179 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 180 | .buttons = {{kLowConeScoreLeft, SpotSelectionHint::LEFT}, |
| 181 | {kLowConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 182 | .side = Side::FRONT, |
| 183 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 184 | }, |
| 185 | { |
| 186 | .index = arm::ScoreFrontMidConeDownBaseIndex(), |
| 187 | .wrist_goal = 2.0, |
| 188 | .score_wrist_goal = 0.0, |
| 189 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 190 | .buttons = {{kMidConeScoreLeft, SpotSelectionHint::LEFT}, |
| 191 | {kMidConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 192 | .side = Side::FRONT, |
| 193 | .row_hint = RowSelectionHint::MIDDLE, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 194 | }, |
| 195 | { |
| 196 | .index = arm::ScoreFrontHighConeDownBaseIndex(), |
| 197 | .wrist_goal = 2.0, |
| 198 | .score_wrist_goal = 0.0, |
| 199 | .game_piece = GamePiece::CONE_DOWN, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 200 | .buttons = {{kHighConeScoreLeft, SpotSelectionHint::LEFT}, |
| 201 | {kHighConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 202 | .side = Side::FRONT, |
| 203 | .row_hint = RowSelectionHint::TOP, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 204 | }, |
| 205 | { |
| 206 | .index = arm::HPPickupFrontConeUpIndex(), |
| 207 | .wrist_goal = 0.0, |
| 208 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 209 | .buttons = {{kHPConePickup}}, |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 210 | .side = Side::FRONT, |
| 211 | }, |
| 212 | { |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 213 | .index = arm::HPPickupBackConeUpIndex(), |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 214 | .wrist_goal = 0.4, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 215 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 216 | .buttons = {{kHPConePickup}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 217 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 218 | }, |
| 219 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 220 | .index = arm::ScoreFrontHighConeUpIndex(), |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 221 | .wrist_goal = 0.05, |
| 222 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 223 | .buttons = {{kHighConeScoreLeft, SpotSelectionHint::LEFT}, |
| 224 | {kHighConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 225 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 226 | .row_hint = RowSelectionHint::TOP, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 227 | }, |
| 228 | { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 229 | .index = arm::ScoreFrontMidConeUpIndex(), |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 230 | .wrist_goal = 0.05, |
| 231 | .game_piece = GamePiece::CONE_UP, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 232 | .buttons = {{kMidConeScoreLeft, SpotSelectionHint::LEFT}, |
| 233 | {kMidConeScoreRight, SpotSelectionHint::RIGHT}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 234 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 235 | .row_hint = RowSelectionHint::MIDDLE, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 236 | }, |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 237 | { |
| 238 | .index = arm::GroundPickupBackCubeIndex(), |
| 239 | .wrist_goal = 0.6, |
| 240 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 241 | .buttons = {{kGroundPickupCube}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 242 | .side = Side::BACK, |
| 243 | }, |
| 244 | { |
| 245 | .index = arm::ScoreFrontMidCubeIndex(), |
| 246 | .wrist_goal = 0.6, |
| 247 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 248 | .buttons = {{kMidCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 249 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 250 | .row_hint = RowSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 251 | }, |
| 252 | { |
| 253 | .index = arm::ScoreBackMidCubeIndex(), |
| 254 | .wrist_goal = 0.6, |
| 255 | .score_wrist_goal = 0.0, |
| 256 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 257 | .buttons = {{kMidCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 258 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 259 | .row_hint = RowSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 260 | }, |
| 261 | { |
| 262 | .index = arm::ScoreFrontLowCubeIndex(), |
| 263 | .wrist_goal = 0.6, |
| 264 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 265 | .buttons = {{kLowCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 266 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 267 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 268 | }, |
| 269 | { |
| 270 | .index = arm::ScoreBackLowCubeIndex(), |
| 271 | .wrist_goal = 0.6, |
| 272 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 273 | .buttons = {{kLowCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 274 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 275 | .row_hint = RowSelectionHint::BOTTOM, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 276 | }, |
| 277 | { |
| 278 | .index = arm::ScoreFrontHighCubeIndex(), |
| 279 | .wrist_goal = 0.6, |
| 280 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 281 | .buttons = {{kHighCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 282 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 283 | .row_hint = RowSelectionHint::TOP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 284 | }, |
| 285 | { |
| 286 | .index = arm::ScoreBackHighCubeIndex(), |
| 287 | .wrist_goal = 0.6, |
| 288 | .score_wrist_goal = 0.0, |
| 289 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 290 | .buttons = {{kHighCube, SpotSelectionHint::MIDDLE}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 291 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 292 | .row_hint = RowSelectionHint::TOP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 293 | }, |
| 294 | { |
| 295 | .index = arm::GroundPickupFrontCubeIndex(), |
| 296 | .wrist_goal = 0.6, |
| 297 | .game_piece = GamePiece::CUBE, |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 298 | .buttons = {{kGroundPickupCube}}, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 299 | .side = Side::FRONT, |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 300 | }, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 301 | }; |
| 302 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 303 | class Reader : public ::frc971::input::ActionJoystickInput { |
| 304 | public: |
| 305 | Reader(::aos::EventLoop *event_loop) |
| 306 | : ::frc971::input::ActionJoystickInput( |
| 307 | event_loop, |
| 308 | ::y2023::control_loops::drivetrain::GetDrivetrainConfig(), |
| 309 | ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}), |
| 310 | superstructure_goal_sender_( |
| 311 | event_loop->MakeSender<superstructure::Goal>("/superstructure")), |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 312 | target_selector_hint_sender_( |
| 313 | event_loop->MakeSender<TargetSelectorHint>("/drivetrain")), |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 314 | superstructure_status_fetcher_( |
| 315 | event_loop->MakeFetcher<superstructure::Status>( |
| 316 | "/superstructure")) {} |
| 317 | |
| 318 | void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); } |
| 319 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 320 | GamePiece current_game_piece_ = GamePiece::CONE_UP; |
| 321 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 322 | void HandleTeleop( |
| 323 | const ::frc971::input::driver_station::Data &data) override { |
| 324 | superstructure_status_fetcher_.Fetch(); |
| 325 | if (!superstructure_status_fetcher_.get()) { |
| 326 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 327 | return; |
| 328 | } |
| 329 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 330 | if (!superstructure_status_fetcher_->has_wrist()) { |
| 331 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 332 | return; |
| 333 | } |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 334 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 335 | double wrist_goal = 0.0; |
| 336 | RollerGoal roller_goal = RollerGoal::IDLE; |
Austin Schuh | 9a11ebd | 2023-02-26 14:16:31 -0800 | [diff] [blame] | 337 | arm_goal_position_ = arm::NeutralIndex(); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 338 | std::optional<double> score_wrist_goal = std::nullopt; |
| 339 | |
| 340 | if (data.IsPressed(kGroundPickupConeUp) || data.IsPressed(kHPConePickup)) { |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 341 | roller_goal = RollerGoal::INTAKE_CONE; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 342 | current_game_piece_ = GamePiece::CONE_UP; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 343 | } else if (data.IsPressed(kGroundPickupConeDownBase)) { |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 344 | roller_goal = RollerGoal::INTAKE_CONE; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 345 | current_game_piece_ = GamePiece::CONE_DOWN; |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 346 | } else if (data.IsPressed(kGroundPickupCube)) { |
| 347 | roller_goal = RollerGoal::INTAKE_CUBE; |
| 348 | current_game_piece_ = GamePiece::CUBE; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 349 | } |
| 350 | |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 351 | if (current_game_piece_ == GamePiece::CUBE) { |
| 352 | wrist_goal = 0.6; |
| 353 | } |
| 354 | |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 355 | std::optional<RowSelectionHint> placing_row; |
| 356 | std::optional<SpotSelectionHint> placing_spot; |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 357 | |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 358 | // Keep the setpoint if the button is still held. This lets us release the |
| 359 | // back button once a side has been selected. |
| 360 | if (current_setpoint_ != nullptr) { |
| 361 | bool found = false; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 362 | for (const auto &button : current_setpoint_->buttons) { |
| 363 | if (data.IsPressed(button.button)) { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 364 | found = true; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 365 | placing_spot = button.spot; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | if (!found) { |
| 369 | current_setpoint_ = nullptr; |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | // Ok, no active setpoint. Search for the right one. |
| 374 | if (current_setpoint_ == nullptr) { |
| 375 | const Side current_side = |
| 376 | data.IsPressed(kBack) ? Side::BACK : Side::FRONT; |
| 377 | // Search for the active setpoint. |
| 378 | for (const ArmSetpoint &setpoint : setpoints) { |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 379 | for (const auto &button : setpoint.buttons) { |
| 380 | if (data.IsPressed(button.button)) { |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 381 | if (setpoint.game_piece == current_game_piece_ && |
| 382 | setpoint.side == current_side) { |
| 383 | current_setpoint_ = &setpoint; |
James Kuszmaul | 4ac4576 | 2023-03-04 19:10:55 -0800 | [diff] [blame^] | 384 | placing_spot = button.spot; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 385 | } |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 386 | } |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 387 | } |
| 388 | } |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 389 | } |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 390 | |
| 391 | // And, pull the bits out of it. |
| 392 | if (current_setpoint_ != nullptr) { |
| 393 | wrist_goal = current_setpoint_->wrist_goal; |
| 394 | arm_goal_position_ = current_setpoint_->index; |
| 395 | score_wrist_goal = current_setpoint_->score_wrist_goal; |
| 396 | placing_row = current_setpoint_->row_hint; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 397 | } |
| 398 | |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 399 | CHECK_EQ(placing_row.has_value(), placing_spot.has_value()); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 400 | |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 401 | if (data.IsPressed(kSuck)) { |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 402 | roller_goal = RollerGoal::INTAKE_LAST; |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 403 | } else if (data.IsPressed(kSpit)) { |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 404 | if (score_wrist_goal.has_value()) { |
| 405 | wrist_goal = score_wrist_goal.value(); |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 406 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 407 | // If we are supposed to dunk it, wait until we are close enough to |
| 408 | // spit. |
| 409 | if (std::abs(score_wrist_goal.value() - |
| 410 | superstructure_status_fetcher_->wrist()->position()) < |
| 411 | 0.1) { |
| 412 | roller_goal = RollerGoal::SPIT; |
| 413 | } |
| 414 | } else { |
| 415 | roller_goal = RollerGoal::SPIT; |
| 416 | } |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 417 | } |
| 418 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 419 | { |
| 420 | auto builder = superstructure_goal_sender_.MakeBuilder(); |
| 421 | |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 422 | flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal> |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 423 | wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 424 | *builder.fbb(), wrist_goal, |
| 425 | CreateProfileParameters(*builder.fbb(), 12.0, 90.0)); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 426 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 427 | superstructure::Goal::Builder superstructure_goal_builder = |
| 428 | builder.MakeBuilder<superstructure::Goal>(); |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 429 | superstructure_goal_builder.add_arm_goal_position(arm_goal_position_); |
Maxwell Henderson | 5938a83 | 2023-02-23 09:33:15 -0800 | [diff] [blame] | 430 | superstructure_goal_builder.add_roller_goal(roller_goal); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 431 | superstructure_goal_builder.add_wrist(wrist_offset); |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 432 | if (builder.Send(superstructure_goal_builder.Finish()) != |
| 433 | aos::RawSender::Error::kOk) { |
| 434 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 435 | } |
| 436 | } |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 437 | if (placing_row.has_value()) { |
| 438 | auto builder = target_selector_hint_sender_.MakeBuilder(); |
| 439 | auto hint_builder = builder.MakeBuilder<TargetSelectorHint>(); |
| 440 | hint_builder.add_row(placing_row.value()); |
| 441 | hint_builder.add_spot(placing_spot.value()); |
| 442 | // TODO: Add field to TargetSelector hint for forwards vs. backwards |
| 443 | // placement. |
| 444 | if (builder.Send(hint_builder.Finish()) != aos::RawSender::Error::kOk) { |
| 445 | AOS_LOG(ERROR, "Sending target selector hint failed.\n"); |
| 446 | } |
| 447 | } |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | private: |
| 451 | ::aos::Sender<superstructure::Goal> superstructure_goal_sender_; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 452 | ::aos::Sender<TargetSelectorHint> target_selector_hint_sender_; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 453 | |
| 454 | ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_; |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 455 | |
| 456 | uint32_t arm_goal_position_; |
Austin Schuh | e062be0 | 2023-03-04 21:12:07 -0800 | [diff] [blame] | 457 | |
| 458 | const ArmSetpoint *current_setpoint_ = nullptr; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | } // namespace joysticks |
| 462 | } // namespace input |
| 463 | } // namespace y2023 |
| 464 | |
| 465 | int main(int argc, char **argv) { |
| 466 | ::aos::InitGoogle(&argc, &argv); |
| 467 | |
| 468 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 469 | aos::configuration::ReadConfig("aos_config.json"); |
| 470 | |
| 471 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 472 | ::y2023::input::joysticks::Reader reader(&event_loop); |
| 473 | |
| 474 | event_loop.Run(); |
| 475 | |
| 476 | return 0; |
| 477 | } |