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