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