Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 1 | #include "y2016/actors/autonomous_actor.h" |
| 2 | |
| 3 | #include <inttypes.h> |
| 4 | |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 5 | #include <chrono> |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 6 | #include <cmath> |
| 7 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 8 | #include "aos/logging/logging.h" |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 9 | #include "aos/util/phased_loop.h" |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 10 | |
| 11 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 12 | #include "y2016/control_loops/drivetrain/drivetrain_base.h" |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 13 | #include "y2016/control_loops/shooter/shooter.q.h" |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 14 | #include "y2016/control_loops/superstructure/superstructure.q.h" |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 15 | #include "y2016/queues/ball_detector.q.h" |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 16 | #include "y2016/vision/vision.q.h" |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 17 | |
| 18 | namespace y2016 { |
| 19 | namespace actors { |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 20 | using ::aos::monotonic_clock; |
| 21 | namespace chrono = ::std::chrono; |
| 22 | namespace this_thread = ::std::this_thread; |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 23 | |
| 24 | namespace { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 25 | const ProfileParameters kSlowDrive = {0.8, 2.5}; |
| 26 | const ProfileParameters kLowBarDrive = {1.3, 2.5}; |
| 27 | const ProfileParameters kMoatDrive = {1.2, 3.5}; |
| 28 | const ProfileParameters kRealignDrive = {2.0, 2.5}; |
| 29 | const ProfileParameters kRockWallDrive = {0.8, 2.5}; |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 30 | const ProfileParameters kFastDrive = {3.0, 2.5}; |
| 31 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 32 | const ProfileParameters kSlowTurn = {0.8, 3.0}; |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 33 | const ProfileParameters kFastTurn = {3.0, 10.0}; |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 34 | const ProfileParameters kStealTurn = {4.0, 15.0}; |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 35 | const ProfileParameters kSwerveTurn = {2.0, 7.0}; |
| 36 | const ProfileParameters kFinishTurn = {2.0, 5.0}; |
| 37 | |
| 38 | const ProfileParameters kTwoBallLowDrive = {1.7, 3.5}; |
| 39 | const ProfileParameters kTwoBallFastDrive = {3.0, 1.5}; |
| 40 | const ProfileParameters kTwoBallReturnDrive = {3.0, 1.9}; |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 41 | const ProfileParameters kTwoBallReturnSlow = {3.0, 2.5}; |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 42 | const ProfileParameters kTwoBallBallPickup = {2.0, 1.75}; |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 43 | const ProfileParameters kTwoBallBallPickupAccel = {2.0, 2.5}; |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 44 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 45 | } // namespace |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 46 | |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 47 | AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop) |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 48 | : frc971::autonomous::BaseAutonomousActor( |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 49 | event_loop, control_loops::drivetrain::GetDrivetrainConfig()), |
| 50 | vision_align_actor_factory_( |
Austin Schuh | 28bde30 | 2019-05-26 22:24:33 -0700 | [diff] [blame] | 51 | actors::VisionAlignActor::MakeFactory(event_loop)), |
| 52 | vision_status_fetcher_( |
| 53 | event_loop->MakeFetcher<::y2016::vision::VisionStatus>( |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 54 | ".y2016.vision.vision_status")), |
| 55 | ball_detector_fetcher_( |
| 56 | event_loop->MakeFetcher<::y2016::sensors::BallDetector>( |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 57 | ".y2016.sensors.ball_detector")), |
| 58 | shooter_goal_sender_( |
| 59 | event_loop |
| 60 | ->MakeSender<::y2016::control_loops::shooter::ShooterQueue::Goal>( |
| 61 | ".y2016.control_loops.shooter.shooter_queue.goal")), |
| 62 | shooter_status_fetcher_( |
| 63 | event_loop->MakeFetcher< |
| 64 | ::y2016::control_loops::shooter::ShooterQueue::Status>( |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 65 | ".y2016.control_loops.shooter.shooter_queue.status")), |
| 66 | superstructure_status_fetcher_( |
| 67 | event_loop->MakeFetcher< |
| 68 | ::y2016::control_loops::SuperstructureQueue::Status>( |
| 69 | ".y2016.control_loops.superstructure_queue.status")), |
| 70 | superstructure_goal_sender_( |
| 71 | event_loop |
| 72 | ->MakeSender<::y2016::control_loops::SuperstructureQueue::Goal>( |
| 73 | ".y2016.control_loops.superstructure_queue.goal")) {} |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 74 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 75 | constexpr double kDoNotTurnCare = 2.0; |
| 76 | |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 77 | void AutonomousActor::MoveSuperstructure( |
| 78 | double intake, double shoulder, double wrist, |
| 79 | const ProfileParameters intake_params, |
| 80 | const ProfileParameters shoulder_params, |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 81 | const ProfileParameters wrist_params, bool traverse_up, |
| 82 | double roller_power) { |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 83 | superstructure_goal_ = {intake, shoulder, wrist}; |
| 84 | |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 85 | auto new_superstructure_goal = superstructure_goal_sender_.MakeMessage(); |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 86 | |
| 87 | new_superstructure_goal->angle_intake = intake; |
| 88 | new_superstructure_goal->angle_shoulder = shoulder; |
| 89 | new_superstructure_goal->angle_wrist = wrist; |
| 90 | |
| 91 | new_superstructure_goal->max_angular_velocity_intake = |
| 92 | intake_params.max_velocity; |
| 93 | new_superstructure_goal->max_angular_velocity_shoulder = |
| 94 | shoulder_params.max_velocity; |
| 95 | new_superstructure_goal->max_angular_velocity_wrist = |
| 96 | wrist_params.max_velocity; |
| 97 | |
| 98 | new_superstructure_goal->max_angular_acceleration_intake = |
| 99 | intake_params.max_acceleration; |
| 100 | new_superstructure_goal->max_angular_acceleration_shoulder = |
| 101 | shoulder_params.max_acceleration; |
| 102 | new_superstructure_goal->max_angular_acceleration_wrist = |
| 103 | wrist_params.max_acceleration; |
| 104 | |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 105 | new_superstructure_goal->voltage_top_rollers = roller_power; |
| 106 | new_superstructure_goal->voltage_bottom_rollers = roller_power; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 107 | |
| 108 | new_superstructure_goal->traverse_unlatched = true; |
| 109 | new_superstructure_goal->traverse_down = !traverse_up; |
Diana Vandenberg | 9cc9ab6 | 2016-04-20 21:27:47 -0700 | [diff] [blame] | 110 | new_superstructure_goal->voltage_climber = 0.0; |
| 111 | new_superstructure_goal->unfold_climber = false; |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 112 | |
| 113 | if (!new_superstructure_goal.Send()) { |
| 114 | LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 115 | } |
| 116 | } |
| 117 | |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 118 | void AutonomousActor::OpenShooter() { |
| 119 | shooter_speed_ = 0.0; |
| 120 | |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 121 | auto shooter_goal = shooter_goal_sender_.MakeMessage(); |
| 122 | shooter_goal->angular_velocity = shooter_speed_; |
| 123 | shooter_goal->clamp_open = true; |
| 124 | shooter_goal->push_to_shooter = false; |
| 125 | shooter_goal->force_lights_on = false; |
| 126 | if (!shooter_goal.Send()) { |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 127 | LOG(ERROR, "Sending shooter goal failed.\n"); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | void AutonomousActor::CloseShooter() { |
| 132 | shooter_speed_ = 0.0; |
| 133 | |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 134 | auto shooter_goal = shooter_goal_sender_.MakeMessage(); |
| 135 | shooter_goal->angular_velocity = shooter_speed_; |
| 136 | shooter_goal->clamp_open = false; |
| 137 | shooter_goal->push_to_shooter = false; |
| 138 | shooter_goal->force_lights_on = false; |
| 139 | |
| 140 | if (!shooter_goal.Send()) { |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 141 | LOG(ERROR, "Sending shooter goal failed.\n"); |
| 142 | } |
| 143 | } |
| 144 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 145 | void AutonomousActor::SetShooterSpeed(double speed) { |
| 146 | shooter_speed_ = speed; |
| 147 | |
| 148 | // In auto, we want to have the lights on whenever possible since we have no |
| 149 | // hope of a human aligning the robot. |
| 150 | bool force_lights_on = shooter_speed_ > 1.0; |
| 151 | |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 152 | auto shooter_goal = shooter_goal_sender_.MakeMessage(); |
| 153 | shooter_goal->angular_velocity = shooter_speed_; |
| 154 | shooter_goal->clamp_open = false; |
| 155 | shooter_goal->push_to_shooter = false; |
| 156 | shooter_goal->force_lights_on = force_lights_on; |
| 157 | |
| 158 | if (!shooter_goal.Send()) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 159 | LOG(ERROR, "Sending shooter goal failed.\n"); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | void AutonomousActor::Shoot() { |
| 164 | uint32_t initial_shots = 0; |
| 165 | |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 166 | shooter_status_fetcher_.Fetch(); |
| 167 | if (shooter_status_fetcher_.get()) { |
| 168 | initial_shots = shooter_status_fetcher_->shots; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | // In auto, we want to have the lights on whenever possible since we have no |
| 172 | // hope of a human aligning the robot. |
| 173 | bool force_lights_on = shooter_speed_ > 1.0; |
| 174 | |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 175 | auto shooter_goal = shooter_goal_sender_.MakeMessage(); |
| 176 | shooter_goal->angular_velocity = shooter_speed_; |
| 177 | shooter_goal->clamp_open = false; |
| 178 | shooter_goal->push_to_shooter = true; |
| 179 | shooter_goal->force_lights_on = force_lights_on; |
| 180 | |
| 181 | if (!shooter_goal.Send()) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 182 | LOG(ERROR, "Sending shooter goal failed.\n"); |
| 183 | } |
| 184 | |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 185 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 186 | event_loop()->monotonic_now(), |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 187 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 188 | while (true) { |
| 189 | if (ShouldCancel()) return; |
| 190 | |
| 191 | // Wait for the shot count to change so we know when the shot is complete. |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 192 | shooter_status_fetcher_.Fetch(); |
| 193 | if (shooter_status_fetcher_.get()) { |
| 194 | if (initial_shots < shooter_status_fetcher_->shots) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 195 | return; |
| 196 | } |
| 197 | } |
| 198 | phased_loop.SleepUntilNext(); |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | void AutonomousActor::WaitForShooterSpeed() { |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 203 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 204 | event_loop()->monotonic_now(), |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 205 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 206 | while (true) { |
| 207 | if (ShouldCancel()) return; |
| 208 | |
Austin Schuh | ae023fb | 2019-06-29 17:11:45 -0700 | [diff] [blame] | 209 | shooter_status_fetcher_.Fetch(); |
| 210 | if (shooter_status_fetcher_.get()) { |
| 211 | if (shooter_status_fetcher_->left.ready && |
| 212 | shooter_status_fetcher_->right.ready) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 213 | return; |
| 214 | } |
| 215 | } |
| 216 | phased_loop.SleepUntilNext(); |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | void AutonomousActor::AlignWithVisionGoal() { |
| 221 | actors::VisionAlignActionParams params; |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 222 | vision_action_ = vision_align_actor_factory_.Make(params); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 223 | vision_action_->Start(); |
| 224 | } |
| 225 | |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 226 | void AutonomousActor::WaitForAlignedWithVision( |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 227 | chrono::nanoseconds align_duration) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 228 | bool vision_valid = false; |
| 229 | double last_angle = 0.0; |
| 230 | int ready_to_fire = 0; |
| 231 | |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 232 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 233 | event_loop()->monotonic_now(), |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 234 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 235 | monotonic_clock::time_point end_time = |
| 236 | monotonic_clock::now() + align_duration; |
| 237 | while (end_time > monotonic_clock::now()) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 238 | if (ShouldCancel()) break; |
| 239 | |
Austin Schuh | 28bde30 | 2019-05-26 22:24:33 -0700 | [diff] [blame] | 240 | vision_status_fetcher_.Fetch(); |
| 241 | if (vision_status_fetcher_.get()) { |
| 242 | vision_valid = (vision_status_fetcher_->left_image_valid && |
| 243 | vision_status_fetcher_->right_image_valid); |
| 244 | last_angle = vision_status_fetcher_->horizontal_angle; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 247 | drivetrain_status_fetcher_.Fetch(); |
| 248 | drivetrain_goal_fetcher_.Fetch(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 249 | |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 250 | if (drivetrain_status_fetcher_.get() && drivetrain_goal_fetcher_.get()) { |
| 251 | const double left_goal = drivetrain_goal_fetcher_->left_goal; |
| 252 | const double right_goal = drivetrain_goal_fetcher_->right_goal; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 253 | const double left_current = |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 254 | drivetrain_status_fetcher_->estimated_left_position; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 255 | const double right_current = |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 256 | drivetrain_status_fetcher_->estimated_right_position; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 257 | const double left_velocity = |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 258 | drivetrain_status_fetcher_->estimated_left_velocity; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 259 | const double right_velocity = |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 260 | drivetrain_status_fetcher_->estimated_right_velocity; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 261 | |
| 262 | if (vision_valid && ::std::abs(last_angle) < 0.02 && |
| 263 | ::std::abs((left_goal - right_goal) - |
| 264 | (left_current - right_current)) / |
| 265 | dt_config_.robot_radius / 2.0 < |
| 266 | 0.02 && |
| 267 | ::std::abs(left_velocity - right_velocity) < 0.01) { |
| 268 | ++ready_to_fire; |
| 269 | } else { |
| 270 | ready_to_fire = 0; |
| 271 | } |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 272 | if (ready_to_fire > 15) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 273 | break; |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 274 | LOG(INFO, "Vision align success!\n"); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | phased_loop.SleepUntilNext(); |
| 278 | } |
| 279 | |
| 280 | vision_action_->Cancel(); |
| 281 | WaitUntilDoneOrCanceled(::std::move(vision_action_)); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 282 | LOG(INFO, "Done waiting for vision\n"); |
| 283 | } |
| 284 | |
| 285 | bool AutonomousActor::IntakeDone() { |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 286 | superstructure_status_fetcher_.Fetch(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 287 | |
| 288 | constexpr double kProfileError = 1e-5; |
| 289 | constexpr double kEpsilon = 0.15; |
| 290 | |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 291 | if (superstructure_status_fetcher_->state < 12 || |
| 292 | superstructure_status_fetcher_->state == 16) { |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 293 | LOG(ERROR, "Superstructure no longer running, aborting action\n"); |
| 294 | return true; |
| 295 | } |
| 296 | |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 297 | if (::std::abs(superstructure_status_fetcher_->intake.goal_angle - |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 298 | superstructure_goal_.intake) < kProfileError && |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 299 | ::std::abs(superstructure_status_fetcher_->intake |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 300 | .goal_angular_velocity) < kProfileError) { |
| 301 | LOG(DEBUG, "Profile done.\n"); |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 302 | if (::std::abs(superstructure_status_fetcher_->intake.angle - |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 303 | superstructure_goal_.intake) < kEpsilon && |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 304 | ::std::abs(superstructure_status_fetcher_->intake |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 305 | .angular_velocity) < kEpsilon) { |
| 306 | LOG(INFO, "Near goal, done.\n"); |
| 307 | return true; |
| 308 | } |
| 309 | } |
| 310 | return false; |
| 311 | } |
| 312 | |
| 313 | bool AutonomousActor::SuperstructureProfileDone() { |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 314 | if (superstructure_status_fetcher_->state < 12 || |
| 315 | superstructure_status_fetcher_->state == 16) { |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 316 | LOG(ERROR, "Superstructure no longer running, aborting action\n"); |
| 317 | return true; |
| 318 | } |
| 319 | |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 320 | constexpr double kProfileError = 1e-5; |
| 321 | return ::std::abs( |
| 322 | superstructure_status_fetcher_->intake.goal_angle - |
| 323 | superstructure_goal_.intake) < kProfileError && |
| 324 | ::std::abs( |
| 325 | superstructure_status_fetcher_->shoulder.goal_angle - |
| 326 | superstructure_goal_.shoulder) < kProfileError && |
| 327 | ::std::abs( |
| 328 | superstructure_status_fetcher_->wrist.goal_angle - |
| 329 | superstructure_goal_.wrist) < kProfileError && |
| 330 | ::std::abs(superstructure_status_fetcher_->intake |
| 331 | .goal_angular_velocity) < kProfileError && |
| 332 | ::std::abs(superstructure_status_fetcher_->shoulder |
| 333 | .goal_angular_velocity) < kProfileError && |
| 334 | ::std::abs(superstructure_status_fetcher_->wrist |
| 335 | .goal_angular_velocity) < kProfileError; |
| 336 | } |
| 337 | |
| 338 | bool AutonomousActor::SuperstructureDone() { |
| 339 | superstructure_status_fetcher_.Fetch(); |
| 340 | |
| 341 | constexpr double kEpsilon = 0.03; |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 342 | if (SuperstructureProfileDone()) { |
| 343 | LOG(DEBUG, "Profile done.\n"); |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 344 | if (::std::abs(superstructure_status_fetcher_->intake.angle - |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 345 | superstructure_goal_.intake) < (kEpsilon + 0.1) && |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 346 | ::std::abs(superstructure_status_fetcher_->shoulder.angle - |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 347 | superstructure_goal_.shoulder) < (kEpsilon + 0.05) && |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 348 | ::std::abs(superstructure_status_fetcher_->wrist.angle - |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 349 | superstructure_goal_.wrist) < (kEpsilon + 0.01) && |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 350 | ::std::abs(superstructure_status_fetcher_->intake |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 351 | .angular_velocity) < (kEpsilon + 0.1) && |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 352 | ::std::abs(superstructure_status_fetcher_->shoulder |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 353 | .angular_velocity) < (kEpsilon + 0.10) && |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 354 | ::std::abs(superstructure_status_fetcher_->wrist |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 355 | .angular_velocity) < (kEpsilon + 0.05)) { |
| 356 | LOG(INFO, "Near goal, done.\n"); |
| 357 | return true; |
| 358 | } |
| 359 | } |
| 360 | return false; |
| 361 | } |
| 362 | |
| 363 | void AutonomousActor::WaitForIntake() { |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 364 | WaitUntil(::std::bind(&AutonomousActor::IntakeDone, this)); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 365 | } |
| 366 | |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 367 | void AutonomousActor::WaitForSuperstructure() { |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 368 | WaitUntil(::std::bind(&AutonomousActor::SuperstructureDone, this)); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 369 | } |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 370 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 371 | void AutonomousActor::WaitForSuperstructureProfile() { |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 372 | WaitUntil([this]() { |
| 373 | superstructure_status_fetcher_.Fetch(); |
| 374 | return SuperstructureProfileDone(); |
| 375 | }); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 378 | void AutonomousActor::WaitForSuperstructureLow() { |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 379 | WaitUntil([this]() { |
| 380 | superstructure_status_fetcher_.Fetch(); |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 381 | |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 382 | return SuperstructureProfileDone() || |
| 383 | superstructure_status_fetcher_->shoulder.angle < 0.1; |
| 384 | }); |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 385 | } |
Austin Schuh | 9481d0d | 2019-06-29 21:56:17 -0700 | [diff] [blame] | 386 | |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 387 | void AutonomousActor::BackLongShotLowBarTwoBall() { |
| 388 | LOG(INFO, "Expanding for back long shot\n"); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 389 | MoveSuperstructure(0.00, M_PI / 2.0 - 0.2, -0.55, {7.0, 40.0}, {4.0, 6.0}, |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 390 | {10.0, 25.0}, false, 0.0); |
| 391 | } |
| 392 | |
| 393 | void AutonomousActor::BackLongShotTwoBall() { |
| 394 | LOG(INFO, "Expanding for back long shot\n"); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 395 | MoveSuperstructure(0.00, M_PI / 2.0 - 0.2, -0.55, {7.0, 40.0}, {4.0, 6.0}, |
| 396 | {10.0, 25.0}, false, 0.0); |
| 397 | } |
| 398 | |
| 399 | void AutonomousActor::BackLongShotTwoBallFinish() { |
| 400 | LOG(INFO, "Expanding for back long shot\n"); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 401 | MoveSuperstructure(0.00, M_PI / 2.0 - 0.2, -0.625 + 0.03, {7.0, 40.0}, |
| 402 | {4.0, 6.0}, {10.0, 25.0}, false, 0.0); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 405 | void AutonomousActor::BackLongShot() { |
| 406 | LOG(INFO, "Expanding for back long shot\n"); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 407 | MoveSuperstructure(0.80, M_PI / 2.0 - 0.2, -0.62, {7.0, 40.0}, {4.0, 6.0}, |
| 408 | {10.0, 25.0}, false, 0.0); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | void AutonomousActor::BackMiddleShot() { |
| 412 | LOG(INFO, "Expanding for back middle shot\n"); |
| 413 | MoveSuperstructure(-0.05, M_PI / 2.0 - 0.2, -0.665, {7.0, 40.0}, {4.0, 10.0}, |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 414 | {10.0, 25.0}, false, 0.0); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 417 | void AutonomousActor::FrontLongShot() { |
| 418 | LOG(INFO, "Expanding for front long shot\n"); |
| 419 | MoveSuperstructure(0.80, M_PI / 2.0 + 0.1, M_PI + 0.41 + 0.02, {7.0, 40.0}, |
| 420 | {4.0, 6.0}, {10.0, 25.0}, false, 0.0); |
| 421 | } |
| 422 | |
| 423 | void AutonomousActor::FrontMiddleShot() { |
| 424 | LOG(INFO, "Expanding for front middle shot\n"); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 425 | MoveSuperstructure(-0.05, M_PI / 2.0 + 0.1, M_PI + 0.44, {7.0, 40.0}, |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 426 | {4.0, 10.0}, {10.0, 25.0}, true, 0.0); |
| 427 | } |
| 428 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 429 | void AutonomousActor::TuckArm(bool low_bar, bool traverse_down) { |
| 430 | MoveSuperstructure(low_bar ? -0.05 : 2.0, -0.010, 0.0, {7.0, 40.0}, |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 431 | {4.0, 10.0}, {10.0, 25.0}, !traverse_down, 0.0); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 434 | void AutonomousActor::DoFullShot() { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 435 | if (ShouldCancel()) return; |
| 436 | // Make sure that the base is aligned with the base. |
| 437 | LOG(INFO, "Waiting for the superstructure\n"); |
| 438 | WaitForSuperstructure(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 439 | |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 440 | this_thread::sleep_for(chrono::milliseconds(500)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 441 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 442 | if (ShouldCancel()) return; |
| 443 | LOG(INFO, "Triggering the vision actor\n"); |
| 444 | AlignWithVisionGoal(); |
| 445 | |
| 446 | // Wait for the drive base to be aligned with the target and make sure that |
| 447 | // the shooter is up to speed. |
| 448 | LOG(INFO, "Waiting for vision to be aligned\n"); |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 449 | WaitForAlignedWithVision(chrono::milliseconds(2000)); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 450 | if (ShouldCancel()) return; |
| 451 | LOG(INFO, "Waiting for shooter to be up to speed\n"); |
| 452 | WaitForShooterSpeed(); |
| 453 | if (ShouldCancel()) return; |
| 454 | |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 455 | this_thread::sleep_for(chrono::milliseconds(300)); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 456 | LOG(INFO, "Shoot!\n"); |
| 457 | Shoot(); |
| 458 | |
| 459 | // Turn off the shooter and fold up the superstructure. |
| 460 | if (ShouldCancel()) return; |
| 461 | LOG(INFO, "Stopping shooter\n"); |
| 462 | SetShooterSpeed(0.0); |
| 463 | LOG(INFO, "Folding superstructure back down\n"); |
| 464 | TuckArm(false, false); |
| 465 | |
| 466 | // Wait for everything to be folded up. |
| 467 | LOG(INFO, "Waiting for superstructure to be folded back down\n"); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 468 | WaitForSuperstructureLow(); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | void AutonomousActor::LowBarDrive() { |
| 472 | TuckArm(false, true); |
| 473 | StartDrive(-5.5, 0.0, kLowBarDrive, kSlowTurn); |
| 474 | |
| 475 | if (!WaitForDriveNear(5.3, 0.0)) return; |
| 476 | TuckArm(true, true); |
| 477 | |
| 478 | if (!WaitForDriveNear(5.0, 0.0)) return; |
| 479 | |
| 480 | StartDrive(0.0, 0.0, kLowBarDrive, kSlowTurn); |
| 481 | |
| 482 | if (!WaitForDriveNear(3.0, 0.0)) return; |
| 483 | |
| 484 | StartDrive(0.0, 0.0, kLowBarDrive, kSlowTurn); |
| 485 | |
| 486 | if (!WaitForDriveNear(1.0, 0.0)) return; |
| 487 | |
Austin Schuh | 15b5f6a | 2016-03-26 19:43:56 -0700 | [diff] [blame] | 488 | StartDrive(0, -M_PI / 4.0 - 0.2, kLowBarDrive, kSlowTurn); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 491 | void AutonomousActor::TippyDrive(double goal_distance, double tip_distance, |
| 492 | double below, double above) { |
| 493 | StartDrive(goal_distance, 0.0, kMoatDrive, kSlowTurn); |
| 494 | if (!WaitForBelowAngle(below)) return; |
| 495 | if (!WaitForAboveAngle(above)) return; |
| 496 | // Ok, we are good now. Compensate by moving the goal by the error. |
| 497 | // Should be here at 2.7 |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 498 | drivetrain_status_fetcher_.Fetch(); |
| 499 | if (drivetrain_status_fetcher_.get()) { |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 500 | const double left_error = |
| 501 | (initial_drivetrain_.left - |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 502 | drivetrain_status_fetcher_->estimated_left_position); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 503 | const double right_error = |
| 504 | (initial_drivetrain_.right - |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 505 | drivetrain_status_fetcher_->estimated_right_position); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 506 | const double distance_to_go = (left_error + right_error) / 2.0; |
| 507 | const double distance_compensation = |
| 508 | goal_distance - tip_distance - distance_to_go; |
| 509 | LOG(INFO, "Going %f further at the bump\n", distance_compensation); |
| 510 | StartDrive(distance_compensation, 0.0, kMoatDrive, kSlowTurn); |
| 511 | } |
| 512 | } |
| 513 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 514 | void AutonomousActor::MiddleDrive() { |
| 515 | TuckArm(false, false); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 516 | TippyDrive(3.65, 2.7, -0.2, 0.0); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 517 | if (!WaitForDriveDone()) return; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | void AutonomousActor::OneFromMiddleDrive(bool left) { |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 521 | const double kTurnAngle = left ? -0.41 : 0.41; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 522 | TuckArm(false, false); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 523 | TippyDrive(4.05, 2.7, -0.2, 0.0); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 524 | |
| 525 | if (!WaitForDriveDone()) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 526 | StartDrive(0.0, kTurnAngle, kRealignDrive, kFastTurn); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | void AutonomousActor::TwoFromMiddleDrive() { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 530 | TuckArm(false, false); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 531 | constexpr double kDriveDistance = 5.10; |
| 532 | TippyDrive(kDriveDistance, 2.7, -0.2, 0.0); |
| 533 | |
| 534 | if (!WaitForDriveNear(kDriveDistance - 3.0, 2.0)) return; |
| 535 | StartDrive(0, -M_PI / 2 - 0.10, kMoatDrive, kFastTurn); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 536 | |
| 537 | if (!WaitForDriveDone()) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 538 | StartDrive(0, M_PI / 3 + 0.35, kMoatDrive, kFastTurn); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 539 | } |
Comran Morshed | b134e77 | 2016-03-16 21:05:05 +0000 | [diff] [blame] | 540 | |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 541 | void AutonomousActor::CloseIfBall() { |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 542 | ball_detector_fetcher_.Fetch(); |
| 543 | if (ball_detector_fetcher_.get()) { |
| 544 | const bool ball_detected = ball_detector_fetcher_->voltage > 2.5; |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 545 | if (ball_detected) { |
| 546 | CloseShooter(); |
| 547 | } |
| 548 | } |
| 549 | } |
| 550 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 551 | void AutonomousActor::WaitForBallOrDriveDone() { |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 552 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 553 | event_loop()->monotonic_now(), |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 554 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 555 | while (true) { |
| 556 | if (ShouldCancel()) { |
| 557 | return; |
| 558 | } |
| 559 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 560 | drivetrain_status_fetcher_.Fetch(); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 561 | if (IsDriveDone()) { |
| 562 | return; |
| 563 | } |
| 564 | |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 565 | ball_detector_fetcher_.Fetch(); |
| 566 | if (ball_detector_fetcher_.get()) { |
| 567 | const bool ball_detected = ball_detector_fetcher_->voltage > 2.5; |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 568 | if (ball_detected) { |
| 569 | return; |
| 570 | } |
| 571 | } |
| 572 | } |
| 573 | } |
| 574 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 575 | void AutonomousActor::TwoBallAuto() { |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 576 | monotonic_clock::time_point start_time = monotonic_clock::now(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 577 | OpenShooter(); |
| 578 | MoveSuperstructure(0.10, -0.010, 0.0, {8.0, 60.0}, {4.0, 10.0}, {10.0, 25.0}, |
| 579 | false, 12.0); |
| 580 | if (ShouldCancel()) return; |
| 581 | LOG(INFO, "Waiting for the intake to come down.\n"); |
| 582 | |
| 583 | WaitForIntake(); |
| 584 | LOG(INFO, "Intake done at %f seconds, starting to drive\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 585 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 586 | if (ShouldCancel()) return; |
| 587 | const double kDriveDistance = 5.05; |
| 588 | StartDrive(-kDriveDistance, 0.0, kTwoBallLowDrive, kSlowTurn); |
| 589 | |
| 590 | StartDrive(0.0, 0.4, kTwoBallLowDrive, kSwerveTurn); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 591 | if (!WaitForDriveNear(kDriveDistance - 0.5, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 592 | |
Austin Schuh | 295c2d9 | 2016-05-01 12:28:04 -0700 | [diff] [blame] | 593 | // Check if the ball is there. |
| 594 | bool first_ball_there = true; |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 595 | ball_detector_fetcher_.Fetch(); |
| 596 | if (ball_detector_fetcher_.get()) { |
| 597 | const bool ball_detected = ball_detector_fetcher_->voltage > 2.5; |
Austin Schuh | 295c2d9 | 2016-05-01 12:28:04 -0700 | [diff] [blame] | 598 | first_ball_there = ball_detected; |
| 599 | LOG(INFO, "Saw the ball: %d at %f\n", first_ball_there, |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 600 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 295c2d9 | 2016-05-01 12:28:04 -0700 | [diff] [blame] | 601 | } |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 602 | MoveSuperstructure(0.10, -0.010, 0.0, {8.0, 40.0}, {4.0, 10.0}, {10.0, 25.0}, |
| 603 | false, 0.0); |
| 604 | LOG(INFO, "Shutting off rollers at %f seconds, starting to straighten out\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 605 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 606 | StartDrive(0.0, -0.4, kTwoBallLowDrive, kSwerveTurn); |
| 607 | MoveSuperstructure(-0.05, -0.010, 0.0, {8.0, 40.0}, {4.0, 10.0}, {10.0, 25.0}, |
| 608 | false, 0.0); |
| 609 | CloseShooter(); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 610 | if (!WaitForDriveNear(kDriveDistance - 2.4, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 611 | |
| 612 | // We are now under the low bar. Start lifting. |
| 613 | BackLongShotLowBarTwoBall(); |
| 614 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 615 | SetShooterSpeed(640.0); |
| 616 | StartDrive(0.0, 0.0, kTwoBallFastDrive, kSwerveTurn); |
| 617 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 618 | if (!WaitForDriveNear(1.50, kDoNotTurnCare)) return; |
| 619 | constexpr double kShootTurnAngle = -M_PI / 4.0 - 0.05; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 620 | StartDrive(0, kShootTurnAngle, kTwoBallFastDrive, kFinishTurn); |
| 621 | BackLongShotTwoBall(); |
| 622 | |
| 623 | if (!WaitForDriveDone()) return; |
| 624 | LOG(INFO, "First shot done driving at %f seconds\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 625 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 626 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 627 | WaitForSuperstructureProfile(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 628 | |
| 629 | if (ShouldCancel()) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 630 | AlignWithVisionGoal(); |
| 631 | |
| 632 | WaitForShooterSpeed(); |
| 633 | if (ShouldCancel()) return; |
| 634 | |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 635 | constexpr chrono::milliseconds kVisionExtra{0}; |
| 636 | WaitForAlignedWithVision(chrono::milliseconds(500) + kVisionExtra); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 637 | BackLongShotTwoBallFinish(); |
| 638 | WaitForSuperstructureProfile(); |
| 639 | if (ShouldCancel()) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 640 | LOG(INFO, "Shoot!\n"); |
Austin Schuh | 295c2d9 | 2016-05-01 12:28:04 -0700 | [diff] [blame] | 641 | if (first_ball_there) { |
| 642 | Shoot(); |
| 643 | } else { |
| 644 | LOG(INFO, "Nah, not shooting\n"); |
| 645 | } |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 646 | |
| 647 | LOG(INFO, "First shot at %f seconds\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 648 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 649 | if (ShouldCancel()) return; |
| 650 | |
| 651 | SetShooterSpeed(0.0); |
| 652 | LOG(INFO, "Folding superstructure back down\n"); |
| 653 | TuckArm(true, true); |
| 654 | |
| 655 | // Undo vision move. |
| 656 | StartDrive(0.0, 0.0, kTwoBallFastDrive, kFinishTurn); |
| 657 | if (!WaitForDriveDone()) return; |
| 658 | |
| 659 | constexpr double kBackDrive = 3.09 - 0.4; |
| 660 | StartDrive(kBackDrive, 0.0, kTwoBallReturnDrive, kSlowTurn); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 661 | if (!WaitForDriveNear(kBackDrive - 0.19, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 662 | StartDrive(0, -kShootTurnAngle, kTwoBallReturnDrive, kSwerveTurn); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 663 | if (!WaitForDriveNear(1.0, kDoNotTurnCare)) return; |
| 664 | StartDrive(0, 0, kTwoBallReturnSlow, kSwerveTurn); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 665 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 666 | if (!WaitForDriveNear(0.06, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 667 | LOG(INFO, "At Low Bar %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 668 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 669 | |
| 670 | OpenShooter(); |
| 671 | constexpr double kSecondBallAfterBarDrive = 2.10; |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 672 | StartDrive(kSecondBallAfterBarDrive, 0.0, kTwoBallBallPickupAccel, kSlowTurn); |
| 673 | if (!WaitForDriveNear(kSecondBallAfterBarDrive - 0.5, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 674 | constexpr double kBallSmallWallTurn = -0.11; |
| 675 | StartDrive(0, kBallSmallWallTurn, kTwoBallBallPickup, kFinishTurn); |
| 676 | |
| 677 | MoveSuperstructure(0.03, -0.010, 0.0, {8.0, 60.0}, {4.0, 10.0}, {10.0, 25.0}, |
| 678 | false, 12.0); |
| 679 | |
| 680 | if (!WaitForDriveProfileDone()) return; |
| 681 | |
| 682 | MoveSuperstructure(0.10, -0.010, 0.0, {8.0, 60.0}, {4.0, 10.0}, {10.0, 25.0}, |
| 683 | false, 12.0); |
| 684 | |
| 685 | LOG(INFO, "Done backing up %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 686 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 687 | |
| 688 | constexpr double kDriveBackDistance = 5.15 - 0.4; |
| 689 | StartDrive(-kDriveBackDistance, 0.0, kTwoBallLowDrive, kFinishTurn); |
| 690 | CloseIfBall(); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 691 | if (!WaitForDriveNear(kDriveBackDistance - 0.75, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 692 | |
| 693 | StartDrive(0.0, -kBallSmallWallTurn, kTwoBallLowDrive, kFinishTurn); |
| 694 | LOG(INFO, "Straightening up at %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 695 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 696 | |
| 697 | CloseIfBall(); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 698 | if (!WaitForDriveNear(kDriveBackDistance - 2.3, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 699 | |
Austin Schuh | 4b652c9 | 2019-05-27 13:22:27 -0700 | [diff] [blame] | 700 | ball_detector_fetcher_.Fetch(); |
| 701 | if (ball_detector_fetcher_.get()) { |
| 702 | const bool ball_detected = ball_detector_fetcher_->voltage > 2.5; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 703 | if (!ball_detected) { |
| 704 | if (!WaitForDriveDone()) return; |
| 705 | LOG(INFO, "Aborting, no ball %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 706 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 707 | return; |
| 708 | } |
| 709 | } |
| 710 | CloseShooter(); |
| 711 | |
| 712 | BackLongShotLowBarTwoBall(); |
| 713 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 714 | SetShooterSpeed(640.0); |
| 715 | StartDrive(0.0, 0.0, kTwoBallFastDrive, kSwerveTurn); |
| 716 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 717 | if (!WaitForDriveNear(1.80, kDoNotTurnCare)) return; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 718 | StartDrive(0, kShootTurnAngle, kTwoBallFastDrive, kFinishTurn); |
| 719 | BackLongShotTwoBall(); |
| 720 | |
| 721 | if (!WaitForDriveDone()) return; |
| 722 | LOG(INFO, "Second shot done driving at %f seconds\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 723 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 724 | WaitForSuperstructure(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 725 | AlignWithVisionGoal(); |
| 726 | if (ShouldCancel()) return; |
| 727 | |
| 728 | WaitForShooterSpeed(); |
| 729 | if (ShouldCancel()) return; |
| 730 | |
| 731 | // 2.2 with 0.4 of vision. |
| 732 | // 1.8 without any vision. |
| 733 | LOG(INFO, "Going to vision align at %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 734 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 735 | WaitForAlignedWithVision( |
| 736 | (start_time + chrono::milliseconds(13500) + kVisionExtra * 2) - |
| 737 | monotonic_clock::now()); |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 738 | BackLongShotTwoBallFinish(); |
| 739 | WaitForSuperstructureProfile(); |
| 740 | if (ShouldCancel()) return; |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 741 | LOG(INFO, "Shoot at %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 742 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 743 | Shoot(); |
| 744 | |
| 745 | LOG(INFO, "Second shot at %f seconds\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 746 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 747 | if (ShouldCancel()) return; |
| 748 | |
| 749 | SetShooterSpeed(0.0); |
| 750 | LOG(INFO, "Folding superstructure back down\n"); |
| 751 | TuckArm(true, false); |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 752 | LOG(INFO, "Shot %f\n", |
| 753 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 754 | |
| 755 | WaitForSuperstructureLow(); |
| 756 | |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 757 | LOG(INFO, "Done %f\n", |
| 758 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 761 | void AutonomousActor::StealAndMoveOverBy(double distance) { |
| 762 | OpenShooter(); |
| 763 | MoveSuperstructure(0.10, -0.010, 0.0, {8.0, 60.0}, {4.0, 10.0}, {10.0, 25.0}, |
| 764 | true, 12.0); |
| 765 | if (ShouldCancel()) return; |
| 766 | LOG(INFO, "Waiting for the intake to come down.\n"); |
| 767 | |
| 768 | WaitForIntake(); |
| 769 | if (ShouldCancel()) return; |
| 770 | StartDrive(-distance, M_PI / 2.0, kFastDrive, kStealTurn); |
| 771 | WaitForBallOrDriveDone(); |
| 772 | if (ShouldCancel()) return; |
| 773 | MoveSuperstructure(1.0, -0.010, 0.0, {8.0, 60.0}, {4.0, 10.0}, {10.0, 25.0}, |
| 774 | true, 12.0); |
| 775 | |
| 776 | if (!WaitForDriveDone()) return; |
| 777 | StartDrive(0.0, M_PI / 2.0, kFastDrive, kStealTurn); |
| 778 | if (!WaitForDriveDone()) return; |
| 779 | } |
| 780 | |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 781 | bool AutonomousActor::RunAction( |
| 782 | const ::frc971::autonomous::AutonomousActionParams ¶ms) { |
Austin Schuh | f2a50ba | 2016-12-24 16:16:26 -0800 | [diff] [blame] | 783 | monotonic_clock::time_point start_time = monotonic_clock::now(); |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 784 | LOG(INFO, "Starting autonomous action with mode %" PRId32 "\n", params.mode); |
| 785 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 786 | InitializeEncoders(); |
| 787 | ResetDrivetrain(); |
| 788 | |
Austin Schuh | 295c2d9 | 2016-05-01 12:28:04 -0700 | [diff] [blame] | 789 | switch (params.mode) { |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 790 | case 0: |
| 791 | LowBarDrive(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 792 | if (!WaitForDriveDone()) return true; |
| 793 | // Get the superstructure to unfold and get ready for shooting. |
| 794 | LOG(INFO, "Unfolding superstructure\n"); |
| 795 | FrontLongShot(); |
| 796 | |
| 797 | // Spin up the shooter wheels. |
| 798 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 799 | SetShooterSpeed(640.0); |
| 800 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 801 | break; |
| 802 | case 1: |
| 803 | TwoFromMiddleDrive(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 804 | if (!WaitForDriveDone()) return true; |
| 805 | // Get the superstructure to unfold and get ready for shooting. |
| 806 | LOG(INFO, "Unfolding superstructure\n"); |
| 807 | FrontMiddleShot(); |
| 808 | |
| 809 | // Spin up the shooter wheels. |
| 810 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 811 | SetShooterSpeed(600.0); |
| 812 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 813 | break; |
| 814 | case 2: |
| 815 | OneFromMiddleDrive(true); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 816 | if (!WaitForDriveDone()) return true; |
| 817 | // Get the superstructure to unfold and get ready for shooting. |
| 818 | LOG(INFO, "Unfolding superstructure\n"); |
| 819 | FrontMiddleShot(); |
| 820 | |
| 821 | // Spin up the shooter wheels. |
| 822 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 823 | SetShooterSpeed(600.0); |
| 824 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 825 | break; |
| 826 | case 3: |
| 827 | MiddleDrive(); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 828 | if (!WaitForDriveDone()) return true; |
| 829 | // Get the superstructure to unfold and get ready for shooting. |
| 830 | LOG(INFO, "Unfolding superstructure\n"); |
| 831 | FrontMiddleShot(); |
| 832 | |
| 833 | // Spin up the shooter wheels. |
| 834 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 835 | SetShooterSpeed(600.0); |
| 836 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 837 | break; |
| 838 | case 4: |
| 839 | OneFromMiddleDrive(false); |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 840 | if (!WaitForDriveDone()) return true; |
| 841 | // Get the superstructure to unfold and get ready for shooting. |
| 842 | LOG(INFO, "Unfolding superstructure\n"); |
| 843 | FrontMiddleShot(); |
| 844 | |
| 845 | // Spin up the shooter wheels. |
| 846 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 847 | SetShooterSpeed(600.0); |
| 848 | |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 849 | break; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 850 | case 5: |
Campbell Crowley | 9ed61a5 | 2016-11-05 17:13:07 -0700 | [diff] [blame] | 851 | case 15: |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 852 | TwoBallAuto(); |
Austin Schuh | 23b2180 | 2016-04-03 21:18:56 -0700 | [diff] [blame] | 853 | return true; |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 854 | break; |
Austin Schuh | e4ec49c | 2016-04-24 19:07:15 -0700 | [diff] [blame] | 855 | case 6: |
| 856 | StealAndMoveOverBy(3.10 + 2 * 52 * 2.54 / 100.0); |
| 857 | if (ShouldCancel()) return true; |
| 858 | |
| 859 | TwoFromMiddleDrive(); |
| 860 | if (!WaitForDriveDone()) return true; |
| 861 | // Get the superstructure to unfold and get ready for shooting. |
| 862 | LOG(INFO, "Unfolding superstructure\n"); |
| 863 | FrontMiddleShot(); |
| 864 | |
| 865 | // Spin up the shooter wheels. |
| 866 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 867 | SetShooterSpeed(600.0); |
| 868 | |
| 869 | break; |
| 870 | case 7: |
| 871 | StealAndMoveOverBy(2.95 + 52 * 2.54 / 100.0); |
| 872 | if (ShouldCancel()) return true; |
| 873 | |
| 874 | OneFromMiddleDrive(true); |
| 875 | if (!WaitForDriveDone()) return true; |
| 876 | // Get the superstructure to unfold and get ready for shooting. |
| 877 | LOG(INFO, "Unfolding superstructure\n"); |
| 878 | FrontMiddleShot(); |
| 879 | |
| 880 | // Spin up the shooter wheels. |
| 881 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 882 | SetShooterSpeed(600.0); |
| 883 | |
| 884 | break; |
| 885 | case 8: { |
| 886 | StealAndMoveOverBy(2.95); |
| 887 | if (ShouldCancel()) return true; |
| 888 | |
| 889 | MiddleDrive(); |
| 890 | if (!WaitForDriveDone()) return true; |
| 891 | // Get the superstructure to unfold and get ready for shooting. |
| 892 | LOG(INFO, "Unfolding superstructure\n"); |
| 893 | FrontMiddleShot(); |
| 894 | |
| 895 | // Spin up the shooter wheels. |
| 896 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 897 | SetShooterSpeed(600.0); |
| 898 | |
| 899 | } break; |
| 900 | case 9: { |
| 901 | StealAndMoveOverBy(1.70); |
| 902 | if (ShouldCancel()) return true; |
| 903 | |
| 904 | OneFromMiddleDrive(false); |
| 905 | if (!WaitForDriveDone()) return true; |
| 906 | // Get the superstructure to unfold and get ready for shooting. |
| 907 | LOG(INFO, "Unfolding superstructure\n"); |
| 908 | FrontMiddleShot(); |
| 909 | |
| 910 | // Spin up the shooter wheels. |
| 911 | LOG(INFO, "Spinning up the shooter wheels\n"); |
| 912 | SetShooterSpeed(600.0); |
| 913 | |
| 914 | } break; |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 915 | default: |
Austin Schuh | 6c9bc62 | 2016-03-26 19:44:12 -0700 | [diff] [blame] | 916 | LOG(ERROR, "Invalid auto mode %d\n", params.mode); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 917 | return true; |
| 918 | } |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 919 | |
Austin Schuh | 3e4a527 | 2016-04-20 20:11:00 -0700 | [diff] [blame] | 920 | DoFullShot(); |
| 921 | |
| 922 | StartDrive(0.5, 0.0, kMoatDrive, kFastTurn); |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 923 | if (!WaitForDriveDone()) return true; |
| 924 | |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 925 | LOG(INFO, "Done %f\n", |
| 926 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 927 | |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 928 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 929 | event_loop()->monotonic_now(), |
Austin Schuh | 8aec1ed | 2016-05-01 13:29:20 -0700 | [diff] [blame] | 930 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | f59b8ee | 2016-03-19 21:31:36 -0700 | [diff] [blame] | 931 | |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 932 | while (!ShouldCancel()) { |
| 933 | phased_loop.SleepUntilNext(); |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 934 | } |
Comran Morshed | 435f111 | 2016-03-12 14:20:45 +0000 | [diff] [blame] | 935 | LOG(DEBUG, "Done running\n"); |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 936 | |
| 937 | return true; |
| 938 | } |
| 939 | |
Comran Morshed | e68e373 | 2016-03-12 14:12:11 +0000 | [diff] [blame] | 940 | } // namespace actors |
| 941 | } // namespace y2016 |