Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 1 | #include "frc971/autonomous/base_autonomous_actor.h" |
| 2 | |
| 3 | #include <inttypes.h> |
| 4 | |
| 5 | #include <chrono> |
| 6 | #include <cmath> |
| 7 | |
John Park | 33858a3 | 2018-09-28 23:05:48 -0700 | [diff] [blame] | 8 | #include "aos/util/phased_loop.h" |
| 9 | #include "aos/logging/logging.h" |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 10 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 11 | #include "frc971/control_loops/control_loops_generated.h" |
| 12 | #include "frc971/control_loops/drivetrain/drivetrain_goal_generated.h" |
| 13 | #include "frc971/control_loops/drivetrain/drivetrain_status_generated.h" |
| 14 | #include "y2019/control_loops/drivetrain/target_selector_generated.h" |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 15 | |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 16 | using ::aos::monotonic_clock; |
| 17 | namespace chrono = ::std::chrono; |
| 18 | namespace this_thread = ::std::this_thread; |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 19 | namespace drivetrain = frc971::control_loops::drivetrain; |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 20 | |
Brian Silverman | f83678c | 2017-03-11 14:02:26 -0800 | [diff] [blame] | 21 | namespace frc971 { |
| 22 | namespace autonomous { |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 23 | |
| 24 | BaseAutonomousActor::BaseAutonomousActor( |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 25 | ::aos::EventLoop *event_loop, |
Austin Schuh | bcce26a | 2018-03-26 23:41:24 -0700 | [diff] [blame] | 26 | const control_loops::drivetrain::DrivetrainConfig<double> &dt_config) |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 27 | : aos::common::actions::ActorBase<Goal>(event_loop, "/autonomous"), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 28 | dt_config_(dt_config), |
Austin Schuh | c087b10 | 2019-05-12 15:33:12 -0700 | [diff] [blame] | 29 | initial_drivetrain_({0.0, 0.0}), |
| 30 | target_selector_hint_sender_( |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 31 | event_loop->MakeSender< |
Austin Schuh | c087b10 | 2019-05-12 15:33:12 -0700 | [diff] [blame] | 32 | ::y2019::control_loops::drivetrain::TargetSelectorHint>( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 33 | "/drivetrain")), |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 34 | drivetrain_goal_sender_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 35 | event_loop->MakeSender<drivetrain::Goal>("/drivetrain")), |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 36 | drivetrain_status_fetcher_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 37 | event_loop->MakeFetcher<drivetrain::Status>("/drivetrain")), |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 38 | drivetrain_goal_fetcher_( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 39 | event_loop->MakeFetcher<drivetrain::Goal>("/drivetrain")) {} |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 40 | |
| 41 | void BaseAutonomousActor::ResetDrivetrain() { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 42 | AOS_LOG(INFO, "resetting the drivetrain\n"); |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 43 | max_drivetrain_voltage_ = 12.0; |
James Kuszmaul | c73bb22 | 2019-04-07 12:15:35 -0700 | [diff] [blame] | 44 | goal_spline_handle_ = 0; |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 45 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 46 | auto builder = drivetrain_goal_sender_.MakeBuilder(); |
| 47 | |
| 48 | drivetrain::Goal::Builder goal_builder = |
| 49 | builder.MakeBuilder<drivetrain::Goal>(); |
| 50 | goal_builder.add_controller_type(drivetrain::ControllerType_POLYDRIVE); |
| 51 | goal_builder.add_highgear(true); |
| 52 | goal_builder.add_wheel(0.0); |
| 53 | goal_builder.add_throttle(0.0); |
| 54 | goal_builder.add_left_goal(initial_drivetrain_.left); |
| 55 | goal_builder.add_right_goal(initial_drivetrain_.right); |
| 56 | goal_builder.add_max_ss_voltage(max_drivetrain_voltage_); |
| 57 | builder.Send(goal_builder.Finish()); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void BaseAutonomousActor::InitializeEncoders() { |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 61 | // Spin until we get a message. |
| 62 | WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); }); |
| 63 | |
| 64 | initial_drivetrain_.left = |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 65 | drivetrain_status_fetcher_->estimated_left_position(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 66 | initial_drivetrain_.right = |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 67 | drivetrain_status_fetcher_->estimated_right_position(); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void BaseAutonomousActor::StartDrive(double distance, double angle, |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 71 | ProfileParametersT linear, |
| 72 | ProfileParametersT angular) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 73 | AOS_LOG(INFO, "Driving distance %f, angle %f\n", distance, angle); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 74 | { |
| 75 | const double dangle = angle * dt_config_.robot_radius; |
| 76 | initial_drivetrain_.left += distance - dangle; |
| 77 | initial_drivetrain_.right += distance + dangle; |
| 78 | } |
| 79 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 80 | auto builder = drivetrain_goal_sender_.MakeBuilder(); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 81 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 82 | auto linear_offset = ProfileParameters::Pack(*builder.fbb(), &linear); |
| 83 | auto angular_offset = ProfileParameters::Pack(*builder.fbb(), &angular); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 84 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 85 | drivetrain::Goal::Builder goal_builder = |
| 86 | builder.MakeBuilder<drivetrain::Goal>(); |
| 87 | |
| 88 | goal_builder.add_controller_type(drivetrain::ControllerType_MOTION_PROFILE); |
| 89 | goal_builder.add_highgear(true); |
| 90 | goal_builder.add_wheel(0.0); |
| 91 | goal_builder.add_throttle(0.0); |
| 92 | goal_builder.add_left_goal(initial_drivetrain_.left); |
| 93 | goal_builder.add_right_goal(initial_drivetrain_.right); |
| 94 | goal_builder.add_max_ss_voltage(max_drivetrain_voltage_); |
| 95 | goal_builder.add_linear(linear_offset); |
| 96 | goal_builder.add_angular(angular_offset); |
| 97 | |
| 98 | builder.Send(goal_builder.Finish()); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void BaseAutonomousActor::WaitUntilDoneOrCanceled( |
| 102 | ::std::unique_ptr<aos::common::actions::Action> action) { |
| 103 | if (!action) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 104 | AOS_LOG(ERROR, "No action, not waiting\n"); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 105 | return; |
| 106 | } |
| 107 | |
| 108 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 109 | event_loop()->monotonic_now(), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 110 | ::std::chrono::milliseconds(5) / 2); |
| 111 | while (true) { |
| 112 | // Poll the running bit and see if we should cancel. |
| 113 | phased_loop.SleepUntilNext(); |
| 114 | if (!action->Running() || ShouldCancel()) { |
| 115 | return; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | bool BaseAutonomousActor::WaitForDriveDone() { |
| 121 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 122 | event_loop()->monotonic_now(), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 123 | ::std::chrono::milliseconds(5) / 2); |
| 124 | |
| 125 | while (true) { |
| 126 | if (ShouldCancel()) { |
| 127 | return false; |
| 128 | } |
| 129 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 130 | drivetrain_status_fetcher_.Fetch(); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 131 | if (IsDriveDone()) { |
| 132 | return true; |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | bool BaseAutonomousActor::IsDriveDone() { |
Brian Silverman | f83678c | 2017-03-11 14:02:26 -0800 | [diff] [blame] | 138 | static constexpr double kPositionTolerance = 0.02; |
| 139 | static constexpr double kVelocityTolerance = 0.10; |
| 140 | static constexpr double kProfileTolerance = 0.001; |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 141 | |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 142 | if (drivetrain_status_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 143 | if (::std::abs(drivetrain_status_fetcher_->profiled_left_position_goal() - |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 144 | initial_drivetrain_.left) < kProfileTolerance && |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 145 | ::std::abs(drivetrain_status_fetcher_->profiled_right_position_goal() - |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 146 | initial_drivetrain_.right) < kProfileTolerance && |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 147 | ::std::abs(drivetrain_status_fetcher_->estimated_left_position() - |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 148 | initial_drivetrain_.left) < kPositionTolerance && |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 149 | ::std::abs(drivetrain_status_fetcher_->estimated_right_position() - |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 150 | initial_drivetrain_.right) < kPositionTolerance && |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 151 | ::std::abs(drivetrain_status_fetcher_->estimated_left_velocity()) < |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 152 | kVelocityTolerance && |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 153 | ::std::abs(drivetrain_status_fetcher_->estimated_right_velocity()) < |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 154 | kVelocityTolerance) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 155 | AOS_LOG(INFO, "Finished drive\n"); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 156 | return true; |
| 157 | } |
| 158 | } |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | bool BaseAutonomousActor::WaitForAboveAngle(double angle) { |
| 163 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 164 | event_loop()->monotonic_now(), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 165 | ::std::chrono::milliseconds(5) / 2); |
| 166 | while (true) { |
| 167 | if (ShouldCancel()) { |
| 168 | return false; |
| 169 | } |
| 170 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 171 | drivetrain_status_fetcher_.Fetch(); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 172 | if (IsDriveDone()) { |
| 173 | return true; |
| 174 | } |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 175 | if (drivetrain_status_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 176 | if (drivetrain_status_fetcher_->ground_angle() > angle) { |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 177 | return true; |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | bool BaseAutonomousActor::WaitForBelowAngle(double angle) { |
| 184 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 185 | event_loop()->monotonic_now(), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 186 | ::std::chrono::milliseconds(5) / 2); |
| 187 | while (true) { |
| 188 | if (ShouldCancel()) { |
| 189 | return false; |
| 190 | } |
| 191 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 192 | drivetrain_status_fetcher_.Fetch(); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 193 | if (IsDriveDone()) { |
| 194 | return true; |
| 195 | } |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 196 | if (drivetrain_status_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 197 | if (drivetrain_status_fetcher_->ground_angle() < angle) { |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 198 | return true; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | bool BaseAutonomousActor::WaitForMaxBy(double angle) { |
| 205 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 206 | event_loop()->monotonic_now(), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 207 | ::std::chrono::milliseconds(5) / 2); |
| 208 | double max_angle = -M_PI; |
| 209 | while (true) { |
| 210 | if (ShouldCancel()) { |
| 211 | return false; |
| 212 | } |
| 213 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 214 | drivetrain_status_fetcher_.Fetch(); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 215 | if (IsDriveDone()) { |
| 216 | return true; |
| 217 | } |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 218 | if (drivetrain_status_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 219 | if (drivetrain_status_fetcher_->ground_angle() > max_angle) { |
| 220 | max_angle = drivetrain_status_fetcher_->ground_angle(); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 221 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 222 | if (drivetrain_status_fetcher_->ground_angle() < max_angle - angle) { |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 223 | return true; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | bool BaseAutonomousActor::WaitForDriveNear(double distance, double angle) { |
| 230 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 231 | event_loop()->monotonic_now(), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 232 | ::std::chrono::milliseconds(5) / 2); |
| 233 | constexpr double kPositionTolerance = 0.02; |
| 234 | constexpr double kProfileTolerance = 0.001; |
| 235 | |
Austin Schuh | e6af999 | 2018-07-08 15:59:14 -0700 | [diff] [blame] | 236 | bool drive_has_been_close = false; |
| 237 | bool turn_has_been_close = false; |
| 238 | bool printed_first = false; |
| 239 | |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 240 | while (true) { |
| 241 | if (ShouldCancel()) { |
| 242 | return false; |
| 243 | } |
| 244 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 245 | drivetrain_status_fetcher_.Fetch(); |
| 246 | if (drivetrain_status_fetcher_.get()) { |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 247 | const double left_profile_error = |
| 248 | (initial_drivetrain_.left - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 249 | drivetrain_status_fetcher_->profiled_left_position_goal()); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 250 | const double right_profile_error = |
| 251 | (initial_drivetrain_.right - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 252 | drivetrain_status_fetcher_->profiled_right_position_goal()); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 253 | |
| 254 | const double left_error = |
| 255 | (initial_drivetrain_.left - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 256 | drivetrain_status_fetcher_->estimated_left_position()); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 257 | const double right_error = |
| 258 | (initial_drivetrain_.right - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 259 | drivetrain_status_fetcher_->estimated_right_position()); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 260 | |
| 261 | const double profile_distance_to_go = |
| 262 | (left_profile_error + right_profile_error) / 2.0; |
| 263 | const double profile_angle_to_go = |
| 264 | (right_profile_error - left_profile_error) / |
| 265 | (dt_config_.robot_radius * 2.0); |
| 266 | |
| 267 | const double distance_to_go = (left_error + right_error) / 2.0; |
| 268 | const double angle_to_go = |
| 269 | (right_error - left_error) / (dt_config_.robot_radius * 2.0); |
| 270 | |
Austin Schuh | e6af999 | 2018-07-08 15:59:14 -0700 | [diff] [blame] | 271 | const bool drive_close = |
| 272 | ::std::abs(profile_distance_to_go) < distance + kProfileTolerance && |
| 273 | ::std::abs(distance_to_go) < distance + kPositionTolerance; |
| 274 | const bool turn_close = |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 275 | ::std::abs(profile_angle_to_go) < angle + kProfileTolerance && |
Austin Schuh | e6af999 | 2018-07-08 15:59:14 -0700 | [diff] [blame] | 276 | ::std::abs(angle_to_go) < angle + kPositionTolerance; |
| 277 | |
| 278 | drive_has_been_close |= drive_close; |
| 279 | turn_has_been_close |= turn_close; |
| 280 | if (drive_has_been_close && !turn_has_been_close && !printed_first) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 281 | AOS_LOG(INFO, "Drive finished first\n"); |
Austin Schuh | e6af999 | 2018-07-08 15:59:14 -0700 | [diff] [blame] | 282 | printed_first = true; |
| 283 | } else if (!drive_has_been_close && turn_has_been_close && |
| 284 | !printed_first) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 285 | AOS_LOG(INFO, "Turn finished first\n"); |
Austin Schuh | e6af999 | 2018-07-08 15:59:14 -0700 | [diff] [blame] | 286 | printed_first = true; |
| 287 | } |
| 288 | |
| 289 | if (drive_close && turn_close) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 290 | AOS_LOG(INFO, "Closer than %f < %f distance, %f < %f angle\n", |
| 291 | distance_to_go, distance, angle_to_go, angle); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 292 | return true; |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 298 | bool BaseAutonomousActor::WaitForDriveProfileNear(double tolerance) { |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 299 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 300 | event_loop()->monotonic_now(), |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 301 | ::std::chrono::milliseconds(5) / 2); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 302 | while (true) { |
| 303 | if (ShouldCancel()) { |
| 304 | return false; |
| 305 | } |
| 306 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 307 | drivetrain_status_fetcher_.Fetch(); |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 308 | |
| 309 | const Eigen::Matrix<double, 7, 1> current_error = |
| 310 | (Eigen::Matrix<double, 7, 1>() |
| 311 | << initial_drivetrain_.left - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 312 | drivetrain_status_fetcher_->profiled_left_position_goal(), |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 313 | 0.0, initial_drivetrain_.right - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 314 | drivetrain_status_fetcher_->profiled_right_position_goal(), |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 315 | 0.0, 0.0, 0.0, 0.0) |
| 316 | .finished(); |
| 317 | const Eigen::Matrix<double, 2, 1> linear_error = |
| 318 | dt_config_.LeftRightToLinear(current_error); |
| 319 | |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 320 | if (drivetrain_status_fetcher_.get()) { |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 321 | if (::std::abs(linear_error(0)) < tolerance) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 322 | AOS_LOG(INFO, "Finished drive\n"); |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 323 | return true; |
| 324 | } |
| 325 | } |
| 326 | } |
| 327 | } |
| 328 | |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 329 | bool BaseAutonomousActor::WaitForDriveProfileDone() { |
| 330 | constexpr double kProfileTolerance = 0.001; |
| 331 | return WaitForDriveProfileNear(kProfileTolerance); |
| 332 | } |
| 333 | |
| 334 | bool BaseAutonomousActor::WaitForTurnProfileNear(double tolerance) { |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 335 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 336 | event_loop()->monotonic_now(), |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 337 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 338 | while (true) { |
| 339 | if (ShouldCancel()) { |
| 340 | return false; |
| 341 | } |
| 342 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 343 | drivetrain_status_fetcher_.Fetch(); |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 344 | |
| 345 | const Eigen::Matrix<double, 7, 1> current_error = |
| 346 | (Eigen::Matrix<double, 7, 1>() |
| 347 | << initial_drivetrain_.left - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 348 | drivetrain_status_fetcher_->profiled_left_position_goal(), |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 349 | 0.0, initial_drivetrain_.right - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 350 | drivetrain_status_fetcher_->profiled_right_position_goal(), |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 351 | 0.0, 0.0, 0.0, 0.0) |
| 352 | .finished(); |
| 353 | const Eigen::Matrix<double, 2, 1> angular_error = |
| 354 | dt_config_.LeftRightToAngular(current_error); |
| 355 | |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 356 | if (drivetrain_status_fetcher_.get()) { |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 357 | if (::std::abs(angular_error(0)) < tolerance) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 358 | AOS_LOG(INFO, "Finished turn\n"); |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 359 | return true; |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
Austin Schuh | 0aae924 | 2018-03-14 19:49:44 -0700 | [diff] [blame] | 365 | bool BaseAutonomousActor::WaitForTurnProfileDone() { |
| 366 | constexpr double kProfileTolerance = 0.001; |
| 367 | return WaitForTurnProfileNear(kProfileTolerance); |
| 368 | } |
| 369 | |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 370 | double BaseAutonomousActor::DriveDistanceLeft() { |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 371 | drivetrain_status_fetcher_.Fetch(); |
| 372 | if (drivetrain_status_fetcher_.get()) { |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 373 | const double left_error = |
| 374 | (initial_drivetrain_.left - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 375 | drivetrain_status_fetcher_->estimated_left_position()); |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 376 | const double right_error = |
| 377 | (initial_drivetrain_.right - |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 378 | drivetrain_status_fetcher_->estimated_right_position()); |
Austin Schuh | 546a038 | 2017-04-16 19:10:18 -0700 | [diff] [blame] | 379 | |
| 380 | return (left_error + right_error) / 2.0; |
| 381 | } else { |
| 382 | return 0; |
| 383 | } |
| 384 | } |
| 385 | |
James Kuszmaul | 838040b | 2019-04-13 15:51:02 -0700 | [diff] [blame] | 386 | bool BaseAutonomousActor::SplineHandle::SplineDistanceRemaining( |
| 387 | double distance) { |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 388 | base_autonomous_actor_->drivetrain_status_fetcher_.Fetch(); |
| 389 | if (base_autonomous_actor_->drivetrain_status_fetcher_.get()) { |
| 390 | return base_autonomous_actor_->drivetrain_status_fetcher_ |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 391 | ->trajectory_logging() |
| 392 | ->is_executing() && |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 393 | base_autonomous_actor_->drivetrain_status_fetcher_ |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 394 | ->trajectory_logging() |
| 395 | ->distance_remaining() < distance; |
James Kuszmaul | 838040b | 2019-04-13 15:51:02 -0700 | [diff] [blame] | 396 | } |
| 397 | return false; |
| 398 | } |
| 399 | bool BaseAutonomousActor::SplineHandle::WaitForSplineDistanceRemaining( |
| 400 | double distance) { |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 401 | ::aos::time::PhasedLoop phased_loop( |
| 402 | ::std::chrono::milliseconds(5), |
| 403 | base_autonomous_actor_->event_loop()->monotonic_now(), |
| 404 | ::std::chrono::milliseconds(5) / 2); |
James Kuszmaul | 838040b | 2019-04-13 15:51:02 -0700 | [diff] [blame] | 405 | while (true) { |
| 406 | if (base_autonomous_actor_->ShouldCancel()) { |
| 407 | return false; |
| 408 | } |
| 409 | phased_loop.SleepUntilNext(); |
| 410 | if (SplineDistanceRemaining(distance)) { |
| 411 | return true; |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 416 | void BaseAutonomousActor::LineFollowAtVelocity( |
| 417 | double velocity, y2019::control_loops::drivetrain::SelectionHint hint) { |
| 418 | { |
| 419 | auto builder = drivetrain_goal_sender_.MakeBuilder(); |
| 420 | drivetrain::Goal::Builder goal_builder = |
| 421 | builder.MakeBuilder<drivetrain::Goal>(); |
| 422 | goal_builder.add_controller_type( |
| 423 | drivetrain::ControllerType_SPLINE_FOLLOWER); |
| 424 | // TODO(james): Currently the 4.0 is copied from the |
| 425 | // line_follow_drivetrain.cc, but it is somewhat year-specific, so we should |
| 426 | // factor it out in some way. |
| 427 | goal_builder.add_throttle(velocity / 4.0); |
| 428 | builder.Send(goal_builder.Finish()); |
| 429 | } |
| 430 | |
| 431 | { |
| 432 | auto builder = target_selector_hint_sender_.MakeBuilder(); |
| 433 | ::y2019::control_loops::drivetrain::TargetSelectorHint::Builder |
| 434 | target_hint_builder = builder.MakeBuilder< |
| 435 | ::y2019::control_loops::drivetrain::TargetSelectorHint>(); |
| 436 | |
| 437 | target_hint_builder.add_suggested_target(hint); |
| 438 | builder.Send(target_hint_builder.Finish()); |
| 439 | } |
James Kuszmaul | 838040b | 2019-04-13 15:51:02 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 442 | BaseAutonomousActor::SplineHandle BaseAutonomousActor::PlanSpline( |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 443 | std::function<flatbuffers::Offset<frc971::MultiSpline>( |
| 444 | aos::Sender<frc971::control_loops::drivetrain::Goal>::Builder *builder)> |
| 445 | &&multispline_builder, |
| 446 | SplineDirection direction) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 447 | AOS_LOG(INFO, "Planning spline\n"); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 448 | |
| 449 | int32_t spline_handle = (++spline_handle_) | ((getpid() & 0xFFFF) << 15); |
| 450 | |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 451 | drivetrain_goal_fetcher_.Fetch(); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 452 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 453 | auto builder = drivetrain_goal_sender_.MakeBuilder(); |
James Kuszmaul | c864bcf | 2019-05-01 20:17:34 -0700 | [diff] [blame] | 454 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 455 | flatbuffers::Offset<frc971::MultiSpline> multispline_offset = |
| 456 | multispline_builder(&builder); |
| 457 | |
| 458 | drivetrain::SplineGoal::Builder spline_builder = |
| 459 | builder.MakeBuilder<drivetrain::SplineGoal>(); |
| 460 | spline_builder.add_spline_idx(spline_handle); |
| 461 | spline_builder.add_drive_spline_backwards(direction == |
| 462 | SplineDirection::kBackward); |
| 463 | spline_builder.add_spline(multispline_offset); |
| 464 | |
| 465 | flatbuffers::Offset<drivetrain::SplineGoal> spline_offset = |
| 466 | spline_builder.Finish(); |
| 467 | |
| 468 | drivetrain::Goal::Builder goal_builder = |
| 469 | builder.MakeBuilder<drivetrain::Goal>(); |
| 470 | |
| 471 | drivetrain::ControllerType controller_type = |
| 472 | drivetrain::ControllerType_SPLINE_FOLLOWER; |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 473 | if (drivetrain_goal_fetcher_.get()) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 474 | controller_type = drivetrain_goal_fetcher_->controller_type(); |
| 475 | goal_builder.add_throttle(drivetrain_goal_fetcher_->throttle()); |
James Kuszmaul | c864bcf | 2019-05-01 20:17:34 -0700 | [diff] [blame] | 476 | } |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 477 | goal_builder.add_controller_type(controller_type); |
| 478 | goal_builder.add_spline_handle(goal_spline_handle_); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 479 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 480 | goal_builder.add_spline(spline_offset); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 481 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 482 | builder.Send(goal_builder.Finish()); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 483 | |
| 484 | return BaseAutonomousActor::SplineHandle(spline_handle, this); |
| 485 | } |
| 486 | |
| 487 | bool BaseAutonomousActor::SplineHandle::IsPlanned() { |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 488 | base_autonomous_actor_->drivetrain_status_fetcher_.Fetch(); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 489 | VLOG(1) << aos::FlatbufferToJson( |
| 490 | base_autonomous_actor_->drivetrain_status_fetcher_.get()); |
| 491 | |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 492 | if (base_autonomous_actor_->drivetrain_status_fetcher_.get() && |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 493 | ((base_autonomous_actor_->drivetrain_status_fetcher_->trajectory_logging() |
| 494 | ->planning_spline_idx() == spline_handle_ && |
| 495 | base_autonomous_actor_->drivetrain_status_fetcher_->trajectory_logging() |
| 496 | ->planning_state() == 3) || |
| 497 | base_autonomous_actor_->drivetrain_status_fetcher_->trajectory_logging() |
| 498 | ->current_spline_idx() == spline_handle_)) { |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 499 | return true; |
| 500 | } |
| 501 | return false; |
| 502 | } |
| 503 | |
| 504 | bool BaseAutonomousActor::SplineHandle::WaitForPlan() { |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 505 | ::aos::time::PhasedLoop phased_loop( |
| 506 | ::std::chrono::milliseconds(5), |
| 507 | base_autonomous_actor_->event_loop()->monotonic_now(), |
| 508 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 509 | while (true) { |
| 510 | if (base_autonomous_actor_->ShouldCancel()) { |
| 511 | return false; |
| 512 | } |
| 513 | phased_loop.SleepUntilNext(); |
| 514 | if (IsPlanned()) { |
| 515 | return true; |
| 516 | } |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | void BaseAutonomousActor::SplineHandle::Start() { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 521 | auto builder = base_autonomous_actor_->drivetrain_goal_sender_.MakeBuilder(); |
| 522 | drivetrain::Goal::Builder goal_builder = |
| 523 | builder.MakeBuilder<drivetrain::Goal>(); |
| 524 | goal_builder.add_controller_type(drivetrain::ControllerType_SPLINE_FOLLOWER); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 525 | |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame] | 526 | AOS_LOG(INFO, "Starting spline\n"); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 527 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 528 | goal_builder.add_spline_handle(spline_handle_); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 529 | base_autonomous_actor_->goal_spline_handle_ = spline_handle_; |
| 530 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 531 | builder.Send(goal_builder.Finish()); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | bool BaseAutonomousActor::SplineHandle::IsDone() { |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 535 | base_autonomous_actor_->drivetrain_status_fetcher_.Fetch(); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 536 | |
James Kuszmaul | c73bb22 | 2019-04-07 12:15:35 -0700 | [diff] [blame] | 537 | // We check that the spline we are waiting on is neither currently planning |
James Kuszmaul | 29e417d | 2019-04-13 10:03:35 -0700 | [diff] [blame] | 538 | // nor executing (we check is_executed because it is possible to receive |
| 539 | // status messages with is_executing false before the execution has started). |
| 540 | // We check for planning so that the user can go straight from starting the |
| 541 | // planner to executing without a WaitForPlan in between. |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 542 | if (base_autonomous_actor_->drivetrain_status_fetcher_.get() && |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame^] | 543 | ((!base_autonomous_actor_->drivetrain_status_fetcher_ |
| 544 | ->trajectory_logging() |
| 545 | ->is_executed() && |
| 546 | base_autonomous_actor_->drivetrain_status_fetcher_->trajectory_logging() |
| 547 | ->current_spline_idx() == spline_handle_) || |
| 548 | base_autonomous_actor_->drivetrain_status_fetcher_->trajectory_logging() |
| 549 | ->planning_spline_idx() == spline_handle_)) { |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 550 | return false; |
| 551 | } |
| 552 | return true; |
| 553 | } |
| 554 | |
| 555 | bool BaseAutonomousActor::SplineHandle::WaitForDone() { |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 556 | ::aos::time::PhasedLoop phased_loop( |
| 557 | ::std::chrono::milliseconds(5), |
| 558 | base_autonomous_actor_->event_loop()->monotonic_now(), |
| 559 | ::std::chrono::milliseconds(5) / 2); |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 560 | while (true) { |
| 561 | if (base_autonomous_actor_->ShouldCancel()) { |
| 562 | return false; |
| 563 | } |
| 564 | phased_loop.SleepUntilNext(); |
| 565 | if (IsDone()) { |
| 566 | return true; |
| 567 | } |
| 568 | } |
| 569 | } |
| 570 | |
Philipp Schrader | 4bd29b1 | 2017-02-22 04:42:27 +0000 | [diff] [blame] | 571 | } // namespace autonomous |
| 572 | } // namespace frc971 |