Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 1 | #include <math.h> |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <unistd.h> |
Tyler Chatow | 4fedeea | 2019-03-10 15:33:36 -0700 | [diff] [blame] | 5 | #include <chrono> |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 6 | |
| 7 | #include "aos/actions/actions.h" |
| 8 | #include "aos/init.h" |
| 9 | #include "aos/input/action_joystick_input.h" |
| 10 | #include "aos/input/driver_station_data.h" |
| 11 | #include "aos/input/drivetrain_input.h" |
| 12 | #include "aos/input/joystick_input.h" |
| 13 | #include "aos/logging/logging.h" |
| 14 | #include "aos/logging/logging.h" |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 15 | #include "aos/network/team_number.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 16 | #include "aos/util/log_interval.h" |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 17 | #include "aos/vision/events/udp.h" |
| 18 | #include "external/com_google_protobuf/src/google/protobuf/stubs/stringprintf.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 19 | #include "frc971/autonomous/auto.q.h" |
| 20 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 21 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
James Kuszmaul | d8deb68 | 2019-03-10 10:38:42 -0700 | [diff] [blame] | 22 | #include "frc971/control_loops/drivetrain/localizer.q.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 23 | |
| 24 | #include "y2019/control_loops/drivetrain/drivetrain_base.h" |
James Kuszmaul | 7d1ef44 | 2019-03-23 20:20:50 -0700 | [diff] [blame] | 25 | #include "y2019/control_loops/drivetrain/target_selector.q.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 26 | #include "y2019/control_loops/superstructure/superstructure.q.h" |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 27 | #include "y2019/status_light.q.h" |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 28 | #include "y2019/vision.pb.h" |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 29 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 30 | using ::aos::input::driver_station::ButtonLocation; |
| 31 | using ::aos::input::driver_station::ControlBit; |
| 32 | using ::aos::input::driver_station::JoystickAxis; |
| 33 | using ::aos::input::driver_station::POVLocation; |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 34 | using ::aos::events::ProtoTXUdpSocket; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 35 | |
Austin Schuh | aab7e16 | 2019-03-13 22:44:58 -0700 | [diff] [blame] | 36 | namespace chrono = ::std::chrono; |
| 37 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 38 | namespace y2019 { |
| 39 | namespace input { |
| 40 | namespace joysticks { |
| 41 | |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 42 | using google::protobuf::StringPrintf; |
| 43 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 44 | struct ElevatorWristPosition { |
| 45 | double elevator; |
| 46 | double wrist; |
| 47 | }; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 48 | |
Tyler Chatow | 5eeee90 | 2019-04-12 20:47:48 -0700 | [diff] [blame] | 49 | const ButtonLocation kSuctionBall(4, 2); |
| 50 | const ButtonLocation kSuctionHatch(3, 15); |
| 51 | const ButtonLocation kDeployStilt(4, 1); |
| 52 | const ButtonLocation kHalfStilt(4, 3); |
| 53 | const ButtonLocation kFallOver(3, 16); |
| 54 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 55 | const ButtonLocation kRocketForwardLower(5, 1); |
| 56 | const ButtonLocation kRocketForwardMiddle(5, 2); |
| 57 | const ButtonLocation kRocketForwardUpper(5, 4); |
| 58 | const ButtonLocation kCargoForward(5, 3); |
| 59 | |
| 60 | const POVLocation kRocketBackwardUnpressed(5, -1); |
| 61 | const POVLocation kRocketBackwardLower(5, 180); |
| 62 | const POVLocation kRocketBackwardMiddle(5, 90); |
| 63 | const POVLocation kRocketBackwardUpper(5, 0); |
| 64 | const POVLocation kCargoBackward(5, 270); |
| 65 | |
| 66 | const ButtonLocation kPanelSwitch(5, 7); |
| 67 | const ButtonLocation kCargoSwitch(5, 8); |
| 68 | |
| 69 | const ButtonLocation kBallHPIntakeForward(5, 6); |
| 70 | const ButtonLocation kBallHPIntakeBackward(5, 5); |
| 71 | const JoystickAxis kBallOutake(5, 3); |
| 72 | const JoystickAxis kBallIntake(5, 4); |
| 73 | |
| 74 | const ButtonLocation kPanelHPIntakeForward(5, 6); |
| 75 | const ButtonLocation kPanelHPIntakeBackward(5, 5); |
| 76 | |
| 77 | const ButtonLocation kRelease(2, 4); |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 78 | // Reuse quickturn for the cancel button. |
| 79 | const ButtonLocation kCancelAutoMode(2, 3); |
Tyler Chatow | 5eeee90 | 2019-04-12 20:47:48 -0700 | [diff] [blame] | 80 | const ButtonLocation kReleaseButtonBoard(3, 4); |
| 81 | const ButtonLocation kResetLocalizerLeftForwards(3, 10); |
| 82 | const ButtonLocation kResetLocalizerLeftBackwards(3, 9); |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 83 | |
Tyler Chatow | 5eeee90 | 2019-04-12 20:47:48 -0700 | [diff] [blame] | 84 | const ButtonLocation kResetLocalizerRightForwards(3, 8); |
| 85 | const ButtonLocation kResetLocalizerRightBackwards(3, 7); |
Tyler Chatow | 07c906b | 2019-03-09 21:29:06 -0800 | [diff] [blame] | 86 | |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 87 | const ButtonLocation kResetLocalizerLeft(3, 11); |
| 88 | const ButtonLocation kResetLocalizerRight(3, 13); |
| 89 | |
Tyler Chatow | 5eeee90 | 2019-04-12 20:47:48 -0700 | [diff] [blame] | 90 | const ButtonLocation kNearCargoHint(3, 3); |
| 91 | const ButtonLocation kMidCargoHint(3, 5); |
| 92 | const ButtonLocation kFarCargoHint(3, 6); |
James Kuszmaul | 7d1ef44 | 2019-03-23 20:20:50 -0700 | [diff] [blame] | 93 | |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 94 | const JoystickAxis kCargoSelectorY(5, 6); |
| 95 | const JoystickAxis kCargoSelectorX(5, 5); |
| 96 | |
Tyler Chatow | 5eeee90 | 2019-04-12 20:47:48 -0700 | [diff] [blame] | 97 | const ButtonLocation kCameraLog(3, 14); |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 98 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 99 | const ElevatorWristPosition kStowPos{0.36, 0.0}; |
Austin Schuh | 02be8b9 | 2019-03-24 16:04:14 -0700 | [diff] [blame] | 100 | const ElevatorWristPosition kClimbPos{0.0, M_PI / 4.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 101 | |
Austin Schuh | 139f59d | 2019-03-17 18:16:13 -0700 | [diff] [blame] | 102 | const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0}; |
| 103 | const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 104 | |
| 105 | const ElevatorWristPosition kPanelForwardLowerPos{0.0, M_PI / 2.0}; |
| 106 | const ElevatorWristPosition kPanelBackwardLowerPos{0.0, -M_PI / 2.0}; |
| 107 | |
Sabina Davis | e48004f | 2019-03-02 23:15:24 -0800 | [diff] [blame] | 108 | const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0}; |
| 109 | const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 110 | |
Sabina Davis | e48004f | 2019-03-02 23:15:24 -0800 | [diff] [blame] | 111 | const ElevatorWristPosition kPanelForwardUpperPos{1.51, M_PI / 2.0}; |
| 112 | const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 113 | |
Sabina Davis | e6fe6c5 | 2019-03-03 15:48:51 -0800 | [diff] [blame] | 114 | const ElevatorWristPosition kPanelCargoForwardPos{0.0, M_PI / 2.0}; |
| 115 | const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0}; |
| 116 | |
Austin Schuh | 6c5deb1 | 2019-03-24 16:48:32 -0700 | [diff] [blame] | 117 | const ElevatorWristPosition kBallForwardLowerPos{0.21, 1.27}; |
Austin Schuh | 20dc050 | 2019-03-30 07:24:07 -0700 | [diff] [blame] | 118 | const ElevatorWristPosition kBallBackwardLowerPos{0.43, -1.99}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 119 | |
Austin Schuh | 20dc050 | 2019-03-30 07:24:07 -0700 | [diff] [blame] | 120 | const ElevatorWristPosition kBallForwardMiddlePos{0.925, 1.21}; |
| 121 | const ElevatorWristPosition kBallBackwardMiddlePos{1.19, -1.98}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 122 | |
Austin Schuh | 139f59d | 2019-03-17 18:16:13 -0700 | [diff] [blame] | 123 | const ElevatorWristPosition kBallForwardUpperPos{1.51, 0.961}; |
| 124 | const ElevatorWristPosition kBallBackwardUpperPos{1.44, -1.217}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 125 | |
Austin Schuh | 20dc050 | 2019-03-30 07:24:07 -0700 | [diff] [blame] | 126 | const ElevatorWristPosition kBallCargoForwardPos{0.59, 1.2}; |
| 127 | const ElevatorWristPosition kBallCargoBackwardPos{0.868265, -2.1}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 128 | |
Sabina Davis | e6fe6c5 | 2019-03-03 15:48:51 -0800 | [diff] [blame] | 129 | const ElevatorWristPosition kBallHPIntakeForwardPos{0.55, 1.097}; |
| 130 | const ElevatorWristPosition kBallHPIntakeBackwardPos{0.89, -2.018}; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 131 | |
Austin Schuh | 20dc050 | 2019-03-30 07:24:07 -0700 | [diff] [blame] | 132 | const ElevatorWristPosition kBallIntakePos{0.309, 2.13}; |
Austin Schuh | 2cf16b8 | 2019-02-15 23:23:22 -0800 | [diff] [blame] | 133 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 134 | class Reader : public ::aos::input::ActionJoystickInput { |
| 135 | public: |
| 136 | Reader(::aos::EventLoop *event_loop) |
| 137 | : ::aos::input::ActionJoystickInput( |
| 138 | event_loop, |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 139 | ::y2019::control_loops::drivetrain::GetDrivetrainConfig(), |
Austin Schuh | bfb0412 | 2019-05-22 21:16:51 -0700 | [diff] [blame] | 140 | ::aos::input::DrivetrainInputReader::InputType::kPistol, |
James Kuszmaul | ccc368b | 2019-04-11 20:00:07 -0700 | [diff] [blame] | 141 | {.run_teleop_in_auto = true, |
Austin Schuh | c087b10 | 2019-05-12 15:33:12 -0700 | [diff] [blame] | 142 | .cancel_auto_button = kCancelAutoMode}), |
| 143 | target_selector_hint_sender_( |
| 144 | event_loop->MakeSender< |
| 145 | ::y2019::control_loops::drivetrain::TargetSelectorHint>( |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 146 | ".y2019.control_loops.drivetrain.target_selector_hint")), |
| 147 | localizer_control_sender_( |
| 148 | event_loop->MakeSender< |
| 149 | ::frc971::control_loops::drivetrain::LocalizerControl>( |
Austin Schuh | 5671a8c | 2019-05-19 17:01:04 -0700 | [diff] [blame] | 150 | ".frc971.control_loops.drivetrain.localizer_control")), |
| 151 | camera_log_sender_( |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 152 | event_loop->MakeSender<::y2019::CameraLog>(".y2019.camera_log")), |
| 153 | superstructure_goal_fetcher_(event_loop->MakeFetcher< |
| 154 | ::y2019::control_loops::superstructure:: |
| 155 | SuperstructureQueue::Goal>( |
| 156 | ".y2019.control_loops.superstructure.superstructure_queue.goal")), |
| 157 | superstructure_goal_sender_(event_loop->MakeSender< |
| 158 | ::y2019::control_loops::superstructure:: |
| 159 | SuperstructureQueue::Goal>( |
| 160 | ".y2019.control_loops.superstructure.superstructure_queue.goal")), |
| 161 | superstructure_position_fetcher_( |
| 162 | event_loop->MakeFetcher<::y2019::control_loops::superstructure:: |
| 163 | SuperstructureQueue::Position>( |
| 164 | ".y2019.control_loops.superstructure.superstructure_queue." |
| 165 | "position")), |
| 166 | superstructure_status_fetcher_( |
| 167 | event_loop->MakeFetcher<::y2019::control_loops::superstructure:: |
| 168 | SuperstructureQueue::Status>( |
| 169 | ".y2019.control_loops.superstructure.superstructure_queue." |
| 170 | "status")) { |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 171 | const uint16_t team = ::aos::network::GetTeamNumber(); |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 172 | superstructure_goal_fetcher_.Fetch(); |
| 173 | if (superstructure_goal_fetcher_.get()) { |
| 174 | grab_piece_ = superstructure_goal_fetcher_->suction.grab_piece; |
| 175 | switch_ball_ = superstructure_goal_fetcher_->suction.gamepiece_mode == 0; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 176 | } |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 177 | video_tx_.reset(new ProtoTXUdpSocket<VisionControl>( |
| 178 | StringPrintf("10.%d.%d.179", team / 100, team % 100), 5000)); |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 179 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 180 | |
Austin Schuh | a78857f | 2019-03-13 22:43:41 -0700 | [diff] [blame] | 181 | void AutoEnded() override { |
| 182 | LOG(INFO, "Auto ended, assuming disc and have piece\n"); |
| 183 | grab_piece_ = true; |
| 184 | switch_ball_ = false; |
| 185 | } |
| 186 | |
| 187 | void HandleTeleop(const ::aos::input::driver_station::Data &data) override { |
Austin Schuh | aab7e16 | 2019-03-13 22:44:58 -0700 | [diff] [blame] | 188 | ::aos::monotonic_clock::time_point monotonic_now = |
| 189 | ::aos::monotonic_clock::now(); |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 190 | superstructure_position_fetcher_.Fetch(); |
| 191 | superstructure_status_fetcher_.Fetch(); |
| 192 | if (!superstructure_status_fetcher_.get() || |
| 193 | !superstructure_position_fetcher_.get()) { |
Austin Schuh | e2f2248 | 2019-04-13 23:05:43 -0700 | [diff] [blame] | 194 | LOG(ERROR, "Got no superstructure status or position packet.\n"); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 198 | if (!superstructure_status_fetcher_->has_piece) { |
Austin Schuh | aab7e16 | 2019-03-13 22:44:58 -0700 | [diff] [blame] | 199 | last_not_has_piece_ = monotonic_now; |
| 200 | } |
| 201 | |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 202 | auto new_superstructure_goal = superstructure_goal_sender_.MakeMessage(); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 203 | |
James Kuszmaul | 7d1ef44 | 2019-03-23 20:20:50 -0700 | [diff] [blame] | 204 | { |
Austin Schuh | c087b10 | 2019-05-12 15:33:12 -0700 | [diff] [blame] | 205 | auto target_hint = target_selector_hint_sender_.MakeMessage(); |
James Kuszmaul | 7d1ef44 | 2019-03-23 20:20:50 -0700 | [diff] [blame] | 206 | if (data.IsPressed(kNearCargoHint)) { |
| 207 | target_hint->suggested_target = 1; |
| 208 | } else if (data.IsPressed(kMidCargoHint)) { |
| 209 | target_hint->suggested_target = 2; |
| 210 | } else if (data.IsPressed(kFarCargoHint)) { |
| 211 | target_hint->suggested_target = 3; |
| 212 | } else { |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 213 | const double cargo_joy_y = data.GetAxis(kCargoSelectorY); |
| 214 | const double cargo_joy_x = data.GetAxis(kCargoSelectorX); |
| 215 | if (cargo_joy_y > 0.5) { |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 216 | target_hint->suggested_target = 1; |
James Kuszmaul | 1b822b4 | 2019-04-14 14:27:35 -0700 | [diff] [blame] | 217 | } else if (cargo_joy_y < -0.5) { |
| 218 | target_hint->suggested_target = 3; |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 219 | } else if (::std::abs(cargo_joy_x) > 0.5) { |
| 220 | target_hint->suggested_target = 2; |
| 221 | } else { |
| 222 | target_hint->suggested_target = 0; |
| 223 | } |
James Kuszmaul | 7d1ef44 | 2019-03-23 20:20:50 -0700 | [diff] [blame] | 224 | } |
| 225 | if (!target_hint.Send()) { |
| 226 | LOG(ERROR, "Failed to send target selector hint.\n"); |
| 227 | } |
| 228 | } |
| 229 | |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 230 | if (data.PosEdge(kResetLocalizerLeft)) { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 231 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 232 | // Start at the left feeder station. |
| 233 | localizer_resetter->x = 0.6; |
| 234 | localizer_resetter->y = 3.4; |
| 235 | localizer_resetter->keep_current_theta = true; |
| 236 | |
| 237 | if (!localizer_resetter.Send()) { |
| 238 | LOG(ERROR, "Failed to reset localizer.\n"); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if (data.PosEdge(kResetLocalizerRight)) { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 243 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
James Kuszmaul | 518640d | 2019-04-13 15:50:50 -0700 | [diff] [blame] | 244 | // Start at the left feeder station. |
| 245 | localizer_resetter->x = 0.6; |
| 246 | localizer_resetter->y = -3.4; |
| 247 | localizer_resetter->keep_current_theta = true; |
| 248 | |
| 249 | if (!localizer_resetter.Send()) { |
| 250 | LOG(ERROR, "Failed to reset localizer.\n"); |
| 251 | } |
| 252 | } |
| 253 | |
Austin Schuh | bb1df6f | 2019-03-17 18:15:43 -0700 | [diff] [blame] | 254 | if (data.PosEdge(kResetLocalizerLeftForwards)) { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 255 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
Austin Schuh | 3632f8d | 2019-03-22 21:14:14 -0700 | [diff] [blame] | 256 | // Start at the left feeder station. |
James Kuszmaul | d8deb68 | 2019-03-10 10:38:42 -0700 | [diff] [blame] | 257 | localizer_resetter->x = 0.4; |
| 258 | localizer_resetter->y = 3.4; |
| 259 | localizer_resetter->theta = 0.0; |
Austin Schuh | bb1df6f | 2019-03-17 18:15:43 -0700 | [diff] [blame] | 260 | |
| 261 | if (!localizer_resetter.Send()) { |
| 262 | LOG(ERROR, "Failed to reset localizer.\n"); |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | if (data.PosEdge(kResetLocalizerLeftBackwards)) { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 267 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
Austin Schuh | bb1df6f | 2019-03-17 18:15:43 -0700 | [diff] [blame] | 268 | // Start at the left feeder station. |
| 269 | localizer_resetter->x = 0.4; |
| 270 | localizer_resetter->y = 3.4; |
| 271 | localizer_resetter->theta = M_PI; |
| 272 | |
| 273 | if (!localizer_resetter.Send()) { |
| 274 | LOG(ERROR, "Failed to reset localizer.\n"); |
| 275 | } |
| 276 | } |
| 277 | |
Austin Schuh | bb1df6f | 2019-03-17 18:15:43 -0700 | [diff] [blame] | 278 | if (data.PosEdge(kResetLocalizerRightForwards)) { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 279 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
Austin Schuh | 3632f8d | 2019-03-22 21:14:14 -0700 | [diff] [blame] | 280 | // Start at the right feeder station. |
Austin Schuh | bb1df6f | 2019-03-17 18:15:43 -0700 | [diff] [blame] | 281 | localizer_resetter->x = 0.4; |
| 282 | localizer_resetter->y = -3.4; |
| 283 | localizer_resetter->theta = 0.0; |
| 284 | |
| 285 | if (!localizer_resetter.Send()) { |
| 286 | LOG(ERROR, "Failed to reset localizer.\n"); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | if (data.PosEdge(kResetLocalizerRightBackwards)) { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 291 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
Austin Schuh | 3632f8d | 2019-03-22 21:14:14 -0700 | [diff] [blame] | 292 | // Start at the right feeder station. |
Austin Schuh | bb1df6f | 2019-03-17 18:15:43 -0700 | [diff] [blame] | 293 | localizer_resetter->x = 0.4; |
| 294 | localizer_resetter->y = -3.4; |
| 295 | localizer_resetter->theta = M_PI; |
| 296 | |
James Kuszmaul | d8deb68 | 2019-03-10 10:38:42 -0700 | [diff] [blame] | 297 | if (!localizer_resetter.Send()) { |
| 298 | LOG(ERROR, "Failed to reset localizer.\n"); |
| 299 | } |
| 300 | } |
| 301 | |
James Kuszmaul | 1373886 | 2019-04-14 10:48:00 -0700 | [diff] [blame] | 302 | if (data.PosEdge(kRelease) && |
| 303 | monotonic_now > |
| 304 | last_release_button_press_ + ::std::chrono::milliseconds(500)) { |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 305 | if (superstructure_status_fetcher_->has_piece) { |
James Kuszmaul | 1373886 | 2019-04-14 10:48:00 -0700 | [diff] [blame] | 306 | release_mode_ = ReleaseButtonMode::kRelease; |
| 307 | } else { |
| 308 | release_mode_ = ReleaseButtonMode::kBallIntake; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | if (data.IsPressed(kRelease)) { |
| 313 | last_release_button_press_ = monotonic_now; |
| 314 | } |
| 315 | |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 316 | LOG(INFO, "has_piece: %d\n", superstructure_status_fetcher_->has_piece); |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 317 | if (data.IsPressed(kSuctionBall)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 318 | grab_piece_ = true; |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 319 | } else if (data.IsPressed(kSuctionHatch)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 320 | grab_piece_ = true; |
James Kuszmaul | 1373886 | 2019-04-14 10:48:00 -0700 | [diff] [blame] | 321 | } else if ((release_mode_ == ReleaseButtonMode::kRelease && |
| 322 | data.IsPressed(kRelease)) || |
Tyler Chatow | 5eeee90 | 2019-04-12 20:47:48 -0700 | [diff] [blame] | 323 | data.IsPressed(kReleaseButtonBoard) || |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 324 | !superstructure_status_fetcher_->has_piece) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 325 | grab_piece_ = false; |
Austin Schuh | 1a8fb57 | 2019-05-08 20:07:58 -0700 | [diff] [blame] | 326 | LOG(INFO, "releasing due to other thing\n"); |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 327 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 328 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 329 | if (data.IsPressed(kRocketBackwardUnpressed)) { |
| 330 | elevator_wrist_pos_ = kStowPos; |
| 331 | } |
| 332 | new_superstructure_goal->intake.unsafe_goal = -1.2; |
| 333 | new_superstructure_goal->roller_voltage = 0.0; |
| 334 | |
James Kuszmaul | 1373886 | 2019-04-14 10:48:00 -0700 | [diff] [blame] | 335 | const bool kDoBallIntake = |
| 336 | (!climbed_ && release_mode_ == ReleaseButtonMode::kBallIntake && |
| 337 | data.IsPressed(kRelease)) || |
| 338 | data.GetAxis(kBallIntake) > 0.9; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 339 | const bool kDoBallOutake = data.GetAxis(kBallOutake) > 0.9; |
| 340 | |
| 341 | if (data.IsPressed(kPanelSwitch)) { |
| 342 | switch_ball_ = false; |
| 343 | } else if (data.IsPressed(kCargoSwitch)) { |
| 344 | switch_ball_ = true; |
| 345 | } |
| 346 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 347 | if (switch_ball_) { |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 348 | if (superstructure_status_fetcher_->has_piece) { |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 349 | new_superstructure_goal->wrist.profile_params.max_acceleration = 20; |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 350 | } |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 351 | |
| 352 | // Go to intake position and apply vacuum |
| 353 | if (data.IsPressed(kBallHPIntakeForward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 354 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 355 | elevator_wrist_pos_ = kBallHPIntakeForwardPos; |
| 356 | } else if (data.IsPressed(kBallHPIntakeBackward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 357 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 358 | elevator_wrist_pos_ = kBallHPIntakeBackwardPos; |
| 359 | } |
| 360 | |
| 361 | // Go to elevator/wrist position. Overrides intake position if pressed so |
| 362 | // we can re-grab the ball. |
| 363 | if (data.IsPressed(kRocketForwardLower)) { |
| 364 | elevator_wrist_pos_ = kBallForwardLowerPos; |
| 365 | } else if (data.IsPressed(kRocketBackwardLower)) { |
| 366 | elevator_wrist_pos_ = kBallBackwardLowerPos; |
| 367 | } else if (data.IsPressed(kRocketForwardMiddle)) { |
| 368 | elevator_wrist_pos_ = kBallForwardMiddlePos; |
| 369 | } else if (data.IsPressed(kRocketBackwardMiddle)) { |
| 370 | elevator_wrist_pos_ = kBallBackwardMiddlePos; |
| 371 | } else if (data.IsPressed(kRocketForwardUpper)) { |
| 372 | elevator_wrist_pos_ = kBallForwardUpperPos; |
| 373 | } else if (data.IsPressed(kRocketBackwardUpper)) { |
| 374 | elevator_wrist_pos_ = kBallBackwardUpperPos; |
| 375 | } else if (data.IsPressed(kCargoForward)) { |
| 376 | elevator_wrist_pos_ = kBallCargoForwardPos; |
| 377 | } else if (data.IsPressed(kCargoBackward)) { |
| 378 | elevator_wrist_pos_ = kBallCargoBackwardPos; |
| 379 | } |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 380 | } else { |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 381 | if (data.IsPressed(kPanelHPIntakeForward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 382 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 383 | elevator_wrist_pos_ = kPanelHPIntakeForwrdPos; |
| 384 | } else if (data.IsPressed(kPanelHPIntakeBackward)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 385 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 386 | elevator_wrist_pos_ = kPanelHPIntakeBackwardPos; |
| 387 | } |
| 388 | |
| 389 | // Go to elevator/wrist position. Overrides intake position if pressed so |
| 390 | // we can re-grab the panel. |
| 391 | if (data.IsPressed(kRocketForwardLower)) { |
| 392 | elevator_wrist_pos_ = kPanelForwardLowerPos; |
| 393 | } else if (data.IsPressed(kRocketBackwardLower)) { |
| 394 | elevator_wrist_pos_ = kPanelBackwardLowerPos; |
| 395 | } else if (data.IsPressed(kRocketForwardMiddle)) { |
| 396 | elevator_wrist_pos_ = kPanelForwardMiddlePos; |
| 397 | } else if (data.IsPressed(kRocketBackwardMiddle)) { |
| 398 | elevator_wrist_pos_ = kPanelBackwardMiddlePos; |
| 399 | } else if (data.IsPressed(kRocketForwardUpper)) { |
| 400 | elevator_wrist_pos_ = kPanelForwardUpperPos; |
| 401 | } else if (data.IsPressed(kRocketBackwardUpper)) { |
| 402 | elevator_wrist_pos_ = kPanelBackwardUpperPos; |
Sabina Davis | e6fe6c5 | 2019-03-03 15:48:51 -0800 | [diff] [blame] | 403 | } else if (data.IsPressed(kCargoForward)) { |
| 404 | elevator_wrist_pos_ = kPanelCargoForwardPos; |
| 405 | } else if (data.IsPressed(kCargoBackward)) { |
| 406 | elevator_wrist_pos_ = kPanelCargoBackwardPos; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 407 | } |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 410 | if (switch_ball_) { |
| 411 | if (kDoBallOutake || |
Austin Schuh | aab7e16 | 2019-03-13 22:44:58 -0700 | [diff] [blame] | 412 | (kDoBallIntake && |
Austin Schuh | 20dc050 | 2019-03-30 07:24:07 -0700 | [diff] [blame] | 413 | monotonic_now < last_not_has_piece_ + chrono::milliseconds(200))) { |
Austin Schuh | d8098b4 | 2019-05-08 20:48:17 -0700 | [diff] [blame] | 414 | new_superstructure_goal->intake.unsafe_goal = 0.83; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 415 | } |
Austin Schuh | 23a5163 | 2019-02-19 16:50:36 -0800 | [diff] [blame] | 416 | |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 417 | if (kDoBallIntake && !superstructure_status_fetcher_->has_piece) { |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 418 | elevator_wrist_pos_ = kBallIntakePos; |
| 419 | new_superstructure_goal->roller_voltage = 9.0; |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 420 | grab_piece_ = true; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 421 | } else { |
| 422 | if (kDoBallOutake) { |
| 423 | new_superstructure_goal->roller_voltage = -6.0; |
| 424 | } else { |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 425 | new_superstructure_goal->roller_voltage = 0.0; |
| 426 | } |
| 427 | } |
Austin Schuh | 23a5163 | 2019-02-19 16:50:36 -0800 | [diff] [blame] | 428 | } |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 429 | |
Austin Schuh | 457bde3 | 2019-03-17 18:16:41 -0700 | [diff] [blame] | 430 | constexpr double kDeployStiltPosition = 0.5; |
| 431 | |
Austin Schuh | 457bde3 | 2019-03-17 18:16:41 -0700 | [diff] [blame] | 432 | if (data.IsPressed(kFallOver)) { |
| 433 | new_superstructure_goal->stilts.unsafe_goal = 0.71; |
| 434 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.65; |
| 435 | new_superstructure_goal->stilts.profile_params.max_acceleration = 1.25; |
Austin Schuh | e2f2248 | 2019-04-13 23:05:43 -0700 | [diff] [blame] | 436 | } else if (data.IsPressed(kHalfStilt)) { |
| 437 | was_above_ = false; |
| 438 | new_superstructure_goal->stilts.unsafe_goal = 0.345; |
| 439 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.65; |
| 440 | } else if (data.IsPressed(kDeployStilt) || was_above_) { |
Austin Schuh | 457bde3 | 2019-03-17 18:16:41 -0700 | [diff] [blame] | 441 | new_superstructure_goal->stilts.unsafe_goal = kDeployStiltPosition; |
| 442 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.65; |
| 443 | new_superstructure_goal->stilts.profile_params.max_acceleration = 2.0; |
Austin Schuh | 457bde3 | 2019-03-17 18:16:41 -0700 | [diff] [blame] | 444 | } else { |
| 445 | new_superstructure_goal->stilts.unsafe_goal = 0.005; |
| 446 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.65; |
| 447 | new_superstructure_goal->stilts.profile_params.max_acceleration = 2.0; |
| 448 | } |
| 449 | |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 450 | if (superstructure_status_fetcher_->stilts.position > 0.1) { |
Austin Schuh | 02be8b9 | 2019-03-24 16:04:14 -0700 | [diff] [blame] | 451 | elevator_wrist_pos_ = kClimbPos; |
James Kuszmaul | 1373886 | 2019-04-14 10:48:00 -0700 | [diff] [blame] | 452 | climbed_ = true; |
Austin Schuh | d8a18bb | 2019-03-24 19:21:38 -0700 | [diff] [blame] | 453 | new_superstructure_goal->wrist.profile_params.max_acceleration = 10; |
| 454 | new_superstructure_goal->elevator.profile_params.max_acceleration = 6; |
Austin Schuh | 02be8b9 | 2019-03-24 16:04:14 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Austin Schuh | e2f2248 | 2019-04-13 23:05:43 -0700 | [diff] [blame] | 457 | // If we've been asked to go above deploy and made it up that high, latch |
| 458 | // was_above. |
| 459 | if (new_superstructure_goal->stilts.unsafe_goal > kDeployStiltPosition && |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 460 | superstructure_status_fetcher_->stilts.position >= |
| 461 | kDeployStiltPosition) { |
Austin Schuh | e2f2248 | 2019-04-13 23:05:43 -0700 | [diff] [blame] | 462 | was_above_ = true; |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 463 | } else if ((superstructure_position_fetcher_->platform_left_detect && |
| 464 | superstructure_position_fetcher_->platform_right_detect) && |
Austin Schuh | e2f2248 | 2019-04-13 23:05:43 -0700 | [diff] [blame] | 465 | !data.IsPressed(kDeployStilt) && !data.IsPressed(kFallOver)) { |
Austin Schuh | e2f2248 | 2019-04-13 23:05:43 -0700 | [diff] [blame] | 466 | was_above_ = false; |
| 467 | } |
| 468 | |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 469 | if (superstructure_status_fetcher_->stilts.position > |
| 470 | kDeployStiltPosition && |
Austin Schuh | 457bde3 | 2019-03-17 18:16:41 -0700 | [diff] [blame] | 471 | new_superstructure_goal->stilts.unsafe_goal == kDeployStiltPosition) { |
| 472 | new_superstructure_goal->stilts.profile_params.max_velocity = 0.30; |
| 473 | new_superstructure_goal->stilts.profile_params.max_acceleration = 0.75; |
| 474 | } |
| 475 | |
James Kuszmaul | 1373886 | 2019-04-14 10:48:00 -0700 | [diff] [blame] | 476 | if ((release_mode_ == ReleaseButtonMode::kRelease && |
| 477 | data.IsPressed(kRelease)) || |
| 478 | data.IsPressed(kReleaseButtonBoard)) { |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 479 | grab_piece_ = false; |
Austin Schuh | 1a8fb57 | 2019-05-08 20:07:58 -0700 | [diff] [blame] | 480 | LOG(INFO, "Releasing due to button\n"); |
Austin Schuh | 1a17e13 | 2019-02-17 15:05:06 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 483 | if (switch_ball_) { |
| 484 | new_superstructure_goal->suction.gamepiece_mode = 0; |
| 485 | } else { |
| 486 | new_superstructure_goal->suction.gamepiece_mode = 1; |
| 487 | } |
| 488 | |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 489 | vision_control_.set_flip_image(elevator_wrist_pos_.wrist < 0); |
| 490 | |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 491 | new_superstructure_goal->suction.grab_piece = grab_piece_; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 492 | |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 493 | new_superstructure_goal->elevator.unsafe_goal = |
| 494 | elevator_wrist_pos_.elevator; |
| 495 | new_superstructure_goal->wrist.unsafe_goal = elevator_wrist_pos_.wrist; |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 496 | |
| 497 | LOG_STRUCT(DEBUG, "sending goal", *new_superstructure_goal); |
| 498 | if (!new_superstructure_goal.Send()) { |
| 499 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 500 | } |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 501 | |
Austin Schuh | aab7e16 | 2019-03-13 22:44:58 -0700 | [diff] [blame] | 502 | if (monotonic_now > |
| 503 | last_vision_control_ + ::std::chrono::milliseconds(50)) { |
Tyler Chatow | 4fedeea | 2019-03-10 15:33:36 -0700 | [diff] [blame] | 504 | video_tx_->Send(vision_control_); |
Austin Schuh | aab7e16 | 2019-03-13 22:44:58 -0700 | [diff] [blame] | 505 | last_vision_control_ = monotonic_now; |
Tyler Chatow | 4fedeea | 2019-03-10 15:33:36 -0700 | [diff] [blame] | 506 | } |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 507 | |
| 508 | { |
Austin Schuh | 5671a8c | 2019-05-19 17:01:04 -0700 | [diff] [blame] | 509 | auto camera_log_message = camera_log_sender_.MakeMessage(); |
Austin Schuh | 4e2629d | 2019-03-28 14:44:37 -0700 | [diff] [blame] | 510 | camera_log_message->log = data.IsPressed(kCameraLog); |
| 511 | LOG_STRUCT(DEBUG, "camera_log", *camera_log_message); |
| 512 | camera_log_message.Send(); |
| 513 | } |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | private: |
Austin Schuh | c087b10 | 2019-05-12 15:33:12 -0700 | [diff] [blame] | 517 | ::aos::Sender<::y2019::control_loops::drivetrain::TargetSelectorHint> |
| 518 | target_selector_hint_sender_; |
| 519 | |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 520 | ::aos::Sender<::frc971::control_loops::drivetrain::LocalizerControl> |
| 521 | localizer_control_sender_; |
| 522 | |
Austin Schuh | 5671a8c | 2019-05-19 17:01:04 -0700 | [diff] [blame] | 523 | ::aos::Sender<::y2019::CameraLog> camera_log_sender_; |
| 524 | |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 525 | ::aos::Fetcher< |
| 526 | ::y2019::control_loops::superstructure::SuperstructureQueue::Goal> |
| 527 | superstructure_goal_fetcher_; |
| 528 | |
| 529 | ::aos::Sender< |
| 530 | ::y2019::control_loops::superstructure::SuperstructureQueue::Goal> |
| 531 | superstructure_goal_sender_; |
| 532 | |
| 533 | ::aos::Fetcher< |
| 534 | ::y2019::control_loops::superstructure::SuperstructureQueue::Position> |
| 535 | superstructure_position_fetcher_; |
| 536 | ::aos::Fetcher< |
| 537 | ::y2019::control_loops::superstructure::SuperstructureQueue::Status> |
| 538 | superstructure_status_fetcher_; |
| 539 | |
| 540 | |
Austin Schuh | e2f2248 | 2019-04-13 23:05:43 -0700 | [diff] [blame] | 541 | // Bool to track if we've been above the deploy position. Once this bool is |
| 542 | // set, don't let the stilts retract until we see the platform. |
| 543 | bool was_above_ = false; |
| 544 | |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 545 | // Current goals here. |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 546 | ElevatorWristPosition elevator_wrist_pos_ = kStowPos; |
Sabina Davis | c632934 | 2019-03-01 20:44:42 -0800 | [diff] [blame] | 547 | bool grab_piece_ = false; |
Tyler Chatow | 7bcb52f | 2019-02-24 00:16:54 -0800 | [diff] [blame] | 548 | |
| 549 | bool switch_ball_ = false; |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 550 | |
James Kuszmaul | 1373886 | 2019-04-14 10:48:00 -0700 | [diff] [blame] | 551 | bool climbed_ = false; |
| 552 | |
| 553 | enum class ReleaseButtonMode { |
| 554 | kBallIntake, |
| 555 | kRelease, |
| 556 | }; |
| 557 | |
| 558 | ReleaseButtonMode release_mode_ = ReleaseButtonMode::kRelease; |
| 559 | aos::monotonic_clock::time_point last_release_button_press_ = |
| 560 | aos::monotonic_clock::min_time; |
| 561 | |
Tyler Chatow | e024145 | 2019-03-08 21:07:50 -0800 | [diff] [blame] | 562 | VisionControl vision_control_; |
| 563 | ::std::unique_ptr<ProtoTXUdpSocket<VisionControl>> video_tx_; |
Tyler Chatow | 4fedeea | 2019-03-10 15:33:36 -0700 | [diff] [blame] | 564 | ::aos::monotonic_clock::time_point last_vision_control_ = |
| 565 | ::aos::monotonic_clock::time_point::min(); |
Austin Schuh | aab7e16 | 2019-03-13 22:44:58 -0700 | [diff] [blame] | 566 | |
| 567 | // Time at which we last did not have a game piece. |
| 568 | ::aos::monotonic_clock::time_point last_not_has_piece_ = |
| 569 | ::aos::monotonic_clock::time_point::min(); |
Sabina Davis | 91b2360 | 2019-01-21 00:06:01 -0800 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | } // namespace joysticks |
| 573 | } // namespace input |
| 574 | } // namespace y2019 |
| 575 | |
| 576 | int main() { |
| 577 | ::aos::Init(-1); |
| 578 | ::aos::ShmEventLoop event_loop; |
| 579 | ::y2019::input::joysticks::Reader reader(&event_loop); |
| 580 | reader.Run(); |
| 581 | ::aos::Cleanup(); |
| 582 | } |