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 | |
| 54 | const ButtonLocation kHighCube(4, 1); |
| 55 | const ButtonLocation kMidCube(4, 2); |
| 56 | const ButtonLocation kLowCube(4, 3); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 57 | |
| 58 | const ButtonLocation kGroundPickupConeUp(4, 7); |
| 59 | const ButtonLocation kGroundPickupConeDown(4, 8); |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 60 | const ButtonLocation kGroundPickupCube(4, 10); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 61 | const ButtonLocation kHPConePickup(4, 6); |
| 62 | |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 63 | const ButtonLocation kSuck(4, 11); |
| 64 | const ButtonLocation kBack(4, 12); |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 65 | |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 66 | const ButtonLocation kWrist(4, 10); |
| 67 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 68 | namespace superstructure = y2023::control_loops::superstructure; |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 69 | namespace arm = superstructure::arm; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 70 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 71 | enum class GamePiece { |
| 72 | CONE_UP = 0, |
| 73 | CONE_DOWN = 1, |
| 74 | CUBE = 2, |
| 75 | }; |
| 76 | |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 77 | enum class Side { |
| 78 | FRONT = 0, |
| 79 | BACK = 1, |
| 80 | }; |
| 81 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 82 | struct ArmSetpoint { |
| 83 | uint32_t index; |
| 84 | double wrist_goal; |
| 85 | std::optional<double> score_wrist_goal = std::nullopt; |
| 86 | GamePiece game_piece; |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 87 | std::vector<ButtonLocation> buttons; |
| 88 | Side side; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 89 | std::optional<RowSelectionHint> row_hint = std::nullopt; |
| 90 | std::optional<SpotSelectionHint> spot_hint = std::nullopt; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | const std::vector<ArmSetpoint> setpoints = { |
| 94 | { |
| 95 | .index = arm::GroundPickupBackConeUpIndex(), |
| 96 | .wrist_goal = 0.0, |
| 97 | .game_piece = GamePiece::CONE_UP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 98 | .buttons = {kGroundPickupConeUp}, |
| 99 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 100 | }, |
| 101 | { |
| 102 | .index = arm::GroundPickupBackConeDownIndex(), |
| 103 | .wrist_goal = 0.0, |
| 104 | .game_piece = GamePiece::CONE_DOWN, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 105 | .buttons = {kGroundPickupConeDown}, |
| 106 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 107 | }, |
| 108 | { |
| 109 | .index = arm::ScoreBackMidConeUpPosIndex(), |
| 110 | .wrist_goal = 0.55, |
| 111 | .game_piece = GamePiece::CONE_UP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 112 | .buttons = {kMidConeScoreRight}, |
| 113 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 114 | .row_hint = RowSelectionHint::MIDDLE, |
| 115 | .spot_hint = SpotSelectionHint::RIGHT, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 116 | }, |
| 117 | { |
| 118 | .index = arm::ScoreBackMidConeDownPosIndex(), |
| 119 | .wrist_goal = 2.2, |
| 120 | .score_wrist_goal = 0.0, |
| 121 | .game_piece = GamePiece::CONE_DOWN, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 122 | .buttons = {kMidConeScoreRight}, |
| 123 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 124 | .row_hint = RowSelectionHint::MIDDLE, |
| 125 | .spot_hint = SpotSelectionHint::RIGHT, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 126 | }, |
| 127 | { |
| 128 | .index = arm::HPPickupBackConeUpIndex(), |
| 129 | .wrist_goal = 0.2, |
| 130 | .game_piece = GamePiece::CONE_UP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 131 | .buttons = {kHPConePickup}, |
| 132 | .side = Side::BACK, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 133 | }, |
| 134 | { |
| 135 | .index = arm::ScoreFrontHighConeUpPosIndex(), |
| 136 | .wrist_goal = 0.05, |
| 137 | .game_piece = GamePiece::CONE_UP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 138 | .buttons = {kHighConeScoreLeft, kHighConeScoreRight}, |
| 139 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 140 | .row_hint = RowSelectionHint::TOP, |
| 141 | .spot_hint = SpotSelectionHint::LEFT, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 142 | }, |
| 143 | { |
| 144 | .index = arm::ScoreFrontMidConeUpPosIndex(), |
| 145 | .wrist_goal = 0.05, |
| 146 | .game_piece = GamePiece::CONE_UP, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 147 | .buttons = {kMidConeScoreLeft, kMidConeScoreRight}, |
| 148 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 149 | .row_hint = RowSelectionHint::MIDDLE, |
| 150 | .spot_hint = SpotSelectionHint::LEFT, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 151 | }, |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 152 | { |
| 153 | .index = arm::GroundPickupBackCubeIndex(), |
| 154 | .wrist_goal = 0.6, |
| 155 | .game_piece = GamePiece::CUBE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 156 | .buttons = {kGroundPickupCube}, |
| 157 | .side = Side::BACK, |
| 158 | }, |
| 159 | { |
| 160 | .index = arm::ScoreFrontMidCubeIndex(), |
| 161 | .wrist_goal = 0.6, |
| 162 | .game_piece = GamePiece::CUBE, |
| 163 | .buttons = {kMidCube}, |
| 164 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 165 | .row_hint = RowSelectionHint::MIDDLE, |
| 166 | .spot_hint = SpotSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 167 | }, |
| 168 | { |
| 169 | .index = arm::ScoreBackMidCubeIndex(), |
| 170 | .wrist_goal = 0.6, |
| 171 | .score_wrist_goal = 0.0, |
| 172 | .game_piece = GamePiece::CUBE, |
| 173 | .buttons = {kMidCube}, |
| 174 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 175 | .row_hint = RowSelectionHint::MIDDLE, |
| 176 | .spot_hint = SpotSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 177 | }, |
| 178 | { |
| 179 | .index = arm::ScoreFrontLowCubeIndex(), |
| 180 | .wrist_goal = 0.6, |
| 181 | .game_piece = GamePiece::CUBE, |
| 182 | .buttons = {kLowCube}, |
| 183 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 184 | .row_hint = RowSelectionHint::BOTTOM, |
| 185 | .spot_hint = SpotSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 186 | }, |
| 187 | { |
| 188 | .index = arm::ScoreBackLowCubeIndex(), |
| 189 | .wrist_goal = 0.6, |
| 190 | .game_piece = GamePiece::CUBE, |
| 191 | .buttons = {kLowCube}, |
| 192 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 193 | .row_hint = RowSelectionHint::BOTTOM, |
| 194 | .spot_hint = SpotSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 195 | }, |
| 196 | { |
| 197 | .index = arm::ScoreFrontHighCubeIndex(), |
| 198 | .wrist_goal = 0.6, |
| 199 | .game_piece = GamePiece::CUBE, |
| 200 | .buttons = {kHighCube}, |
| 201 | .side = Side::FRONT, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 202 | .row_hint = RowSelectionHint::TOP, |
| 203 | .spot_hint = SpotSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 204 | }, |
| 205 | { |
| 206 | .index = arm::ScoreBackHighCubeIndex(), |
| 207 | .wrist_goal = 0.6, |
| 208 | .score_wrist_goal = 0.0, |
| 209 | .game_piece = GamePiece::CUBE, |
| 210 | .buttons = {kHighCube}, |
| 211 | .side = Side::BACK, |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 212 | .row_hint = RowSelectionHint::TOP, |
| 213 | .spot_hint = SpotSelectionHint::MIDDLE, |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 214 | }, |
| 215 | { |
| 216 | .index = arm::GroundPickupFrontCubeIndex(), |
| 217 | .wrist_goal = 0.6, |
| 218 | .game_piece = GamePiece::CUBE, |
| 219 | .buttons = {kGroundPickupCube}, |
| 220 | .side = Side::FRONT, |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 221 | }, |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 222 | }; |
| 223 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 224 | class Reader : public ::frc971::input::ActionJoystickInput { |
| 225 | public: |
| 226 | Reader(::aos::EventLoop *event_loop) |
| 227 | : ::frc971::input::ActionJoystickInput( |
| 228 | event_loop, |
| 229 | ::y2023::control_loops::drivetrain::GetDrivetrainConfig(), |
| 230 | ::frc971::input::DrivetrainInputReader::InputType::kPistol, {}), |
| 231 | superstructure_goal_sender_( |
| 232 | event_loop->MakeSender<superstructure::Goal>("/superstructure")), |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 233 | target_selector_hint_sender_( |
| 234 | event_loop->MakeSender<TargetSelectorHint>("/drivetrain")), |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 235 | superstructure_status_fetcher_( |
| 236 | event_loop->MakeFetcher<superstructure::Status>( |
| 237 | "/superstructure")) {} |
| 238 | |
| 239 | void AutoEnded() override { AOS_LOG(INFO, "Auto ended.\n"); } |
| 240 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 241 | GamePiece current_game_piece_ = GamePiece::CONE_UP; |
| 242 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 243 | void HandleTeleop( |
| 244 | const ::frc971::input::driver_station::Data &data) override { |
| 245 | superstructure_status_fetcher_.Fetch(); |
| 246 | if (!superstructure_status_fetcher_.get()) { |
| 247 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 248 | return; |
| 249 | } |
| 250 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 251 | if (!superstructure_status_fetcher_->has_wrist()) { |
| 252 | AOS_LOG(ERROR, "Got no superstructure status message.\n"); |
| 253 | return; |
| 254 | } |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 255 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 256 | double wrist_goal = 0.0; |
| 257 | RollerGoal roller_goal = RollerGoal::IDLE; |
Austin Schuh | 9a11ebd | 2023-02-26 14:16:31 -0800 | [diff] [blame] | 258 | arm_goal_position_ = arm::NeutralIndex(); |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 259 | std::optional<double> score_wrist_goal = std::nullopt; |
| 260 | |
| 261 | if (data.IsPressed(kGroundPickupConeUp) || data.IsPressed(kHPConePickup)) { |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 262 | roller_goal = RollerGoal::INTAKE_CONE; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 263 | current_game_piece_ = GamePiece::CONE_UP; |
| 264 | } else if (data.IsPressed(kGroundPickupConeDown)) { |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 265 | roller_goal = RollerGoal::INTAKE_CONE; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 266 | current_game_piece_ = GamePiece::CONE_DOWN; |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 267 | } else if (data.IsPressed(kGroundPickupCube)) { |
| 268 | roller_goal = RollerGoal::INTAKE_CUBE; |
| 269 | current_game_piece_ = GamePiece::CUBE; |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 270 | } |
| 271 | |
milind-u | 68842e1 | 2023-02-26 12:45:40 -0800 | [diff] [blame] | 272 | if (current_game_piece_ == GamePiece::CUBE) { |
| 273 | wrist_goal = 0.6; |
| 274 | } |
| 275 | |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 276 | const Side current_side = data.IsPressed(kBack) ? Side::BACK : Side::FRONT; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 277 | std::optional<RowSelectionHint> placing_row; |
| 278 | std::optional<SpotSelectionHint> placing_spot; |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 279 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 280 | // Search for the active setpoint. |
| 281 | for (const ArmSetpoint &setpoint : setpoints) { |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 282 | for (const ButtonLocation &button : setpoint.buttons) { |
| 283 | if (data.IsPressed(button)) { |
| 284 | if (setpoint.game_piece == current_game_piece_ && |
| 285 | setpoint.side == current_side) { |
| 286 | wrist_goal = setpoint.wrist_goal; |
| 287 | arm_goal_position_ = setpoint.index; |
| 288 | score_wrist_goal = setpoint.score_wrist_goal; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 289 | placing_row = setpoint.row_hint; |
| 290 | placing_spot = setpoint.spot_hint; |
Austin Schuh | 9b3e41c | 2023-02-26 22:29:53 -0800 | [diff] [blame] | 291 | break; |
| 292 | } |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 293 | } |
| 294 | } |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 295 | } |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 296 | CHECK_EQ(placing_row.has_value(), placing_spot.has_value()); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 297 | |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 298 | if (data.IsPressed(kSuck)) { |
milind-u | 71da539 | 2023-02-26 12:45:00 -0800 | [diff] [blame] | 299 | roller_goal = RollerGoal::INTAKE_LAST; |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 300 | } else if (data.IsPressed(kSpit)) { |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 301 | if (score_wrist_goal.has_value()) { |
| 302 | wrist_goal = score_wrist_goal.value(); |
Austin Schuh | 23a9002 | 2023-02-24 22:13:39 -0800 | [diff] [blame] | 303 | |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 304 | // If we are supposed to dunk it, wait until we are close enough to |
| 305 | // spit. |
| 306 | if (std::abs(score_wrist_goal.value() - |
| 307 | superstructure_status_fetcher_->wrist()->position()) < |
| 308 | 0.1) { |
| 309 | roller_goal = RollerGoal::SPIT; |
| 310 | } |
| 311 | } else { |
| 312 | roller_goal = RollerGoal::SPIT; |
| 313 | } |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 316 | { |
| 317 | auto builder = superstructure_goal_sender_.MakeBuilder(); |
| 318 | |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 319 | flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal> |
Maxwell Henderson | 1ac7aac | 2023-02-23 17:35:32 -0800 | [diff] [blame] | 320 | wrist_offset = CreateStaticZeroingSingleDOFProfiledSubsystemGoal( |
| 321 | *builder.fbb(), wrist_goal, |
| 322 | CreateProfileParameters(*builder.fbb(), 12.0, 90.0)); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 323 | |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 324 | superstructure::Goal::Builder superstructure_goal_builder = |
| 325 | builder.MakeBuilder<superstructure::Goal>(); |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 326 | superstructure_goal_builder.add_arm_goal_position(arm_goal_position_); |
Maxwell Henderson | 5938a83 | 2023-02-23 09:33:15 -0800 | [diff] [blame] | 327 | superstructure_goal_builder.add_roller_goal(roller_goal); |
Austin Schuh | 6dc925b | 2023-02-24 16:23:32 -0800 | [diff] [blame] | 328 | superstructure_goal_builder.add_wrist(wrist_offset); |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 329 | if (builder.Send(superstructure_goal_builder.Finish()) != |
| 330 | aos::RawSender::Error::kOk) { |
| 331 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 332 | } |
| 333 | } |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 334 | if (placing_row.has_value()) { |
| 335 | auto builder = target_selector_hint_sender_.MakeBuilder(); |
| 336 | auto hint_builder = builder.MakeBuilder<TargetSelectorHint>(); |
| 337 | hint_builder.add_row(placing_row.value()); |
| 338 | hint_builder.add_spot(placing_spot.value()); |
| 339 | // TODO: Add field to TargetSelector hint for forwards vs. backwards |
| 340 | // placement. |
| 341 | if (builder.Send(hint_builder.Finish()) != aos::RawSender::Error::kOk) { |
| 342 | AOS_LOG(ERROR, "Sending target selector hint failed.\n"); |
| 343 | } |
| 344 | } |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | private: |
| 348 | ::aos::Sender<superstructure::Goal> superstructure_goal_sender_; |
James Kuszmaul | 4e17143 | 2023-02-26 13:39:37 -0800 | [diff] [blame] | 349 | ::aos::Sender<TargetSelectorHint> target_selector_hint_sender_; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 350 | |
| 351 | ::aos::Fetcher<superstructure::Status> superstructure_status_fetcher_; |
milind-u | defab71 | 2023-02-20 22:22:02 -0800 | [diff] [blame] | 352 | |
| 353 | uint32_t arm_goal_position_; |
Maxwell Henderson | ad31234 | 2023-01-10 12:07:47 -0800 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | } // namespace joysticks |
| 357 | } // namespace input |
| 358 | } // namespace y2023 |
| 359 | |
| 360 | int main(int argc, char **argv) { |
| 361 | ::aos::InitGoogle(&argc, &argv); |
| 362 | |
| 363 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 364 | aos::configuration::ReadConfig("aos_config.json"); |
| 365 | |
| 366 | ::aos::ShmEventLoop event_loop(&config.message()); |
| 367 | ::y2023::input::joysticks::Reader reader(&event_loop); |
| 368 | |
| 369 | event_loop.Run(); |
| 370 | |
| 371 | return 0; |
| 372 | } |