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