Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 1 | #include "y2019/actors/autonomous_actor.h" |
| 2 | |
| 3 | #include <inttypes.h> |
| 4 | |
| 5 | #include <chrono> |
| 6 | #include <cmath> |
| 7 | |
| 8 | #include "aos/logging/logging.h" |
| 9 | #include "aos/util/phased_loop.h" |
| 10 | |
| 11 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 12 | #include "frc971/control_loops/drivetrain/localizer.q.h" |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 13 | #include "y2019/actors/auto_splines.h" |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 14 | #include "y2019/control_loops/drivetrain/drivetrain_base.h" |
| 15 | |
| 16 | namespace y2019 { |
| 17 | namespace actors { |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 18 | using ::aos::monotonic_clock; |
| 19 | namespace chrono = ::std::chrono; |
| 20 | |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 21 | AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop) |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 22 | : frc971::autonomous::BaseAutonomousActor( |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 23 | event_loop, control_loops::drivetrain::GetDrivetrainConfig()), |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 24 | localizer_control_sender_( |
| 25 | event_loop->MakeSender< |
| 26 | ::frc971::control_loops::drivetrain::LocalizerControl>( |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 27 | ".frc971.control_loops.drivetrain.localizer_control")), |
| 28 | superstructure_goal_sender_( |
| 29 | event_loop->MakeSender<::y2019::control_loops::superstructure:: |
| 30 | SuperstructureQueue::Goal>( |
| 31 | ".y2019.control_loops.superstructure.superstructure_queue.goal")), |
| 32 | superstructure_status_fetcher_(event_loop->MakeFetcher< |
| 33 | ::y2019::control_loops::superstructure:: |
| 34 | SuperstructureQueue::Status>( |
| 35 | ".y2019.control_loops.superstructure.superstructure_queue.status")) {} |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 36 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 37 | bool AutonomousActor::WaitForDriveXGreater(double x) { |
| 38 | LOG(INFO, "Waiting until x > %f\n", x); |
| 39 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 40 | event_loop()->monotonic_now(), |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 41 | ::std::chrono::milliseconds(5) / 2); |
| 42 | |
| 43 | while (true) { |
| 44 | if (ShouldCancel()) { |
| 45 | return false; |
| 46 | } |
| 47 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 48 | drivetrain_status_fetcher_.Fetch(); |
| 49 | if (drivetrain_status_fetcher_->x > x) { |
| 50 | LOG(INFO, "X at %f\n", drivetrain_status_fetcher_->x); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 51 | return true; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | bool AutonomousActor::WaitForDriveYCloseToZero(double y) { |
| 57 | LOG(INFO, "Waiting until |y| < %f\n", y); |
| 58 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 59 | event_loop()->monotonic_now(), |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 60 | ::std::chrono::milliseconds(5) / 2); |
| 61 | |
| 62 | while (true) { |
| 63 | if (ShouldCancel()) { |
| 64 | return false; |
| 65 | } |
| 66 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 67 | drivetrain_status_fetcher_.Fetch(); |
| 68 | if (::std::abs(drivetrain_status_fetcher_->y) < y) { |
| 69 | LOG(INFO, "Y at %f\n", drivetrain_status_fetcher_->y); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 70 | return true; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 75 | void AutonomousActor::Reset(bool is_left) { |
| 76 | const double turn_scalar = is_left ? 1.0 : -1.0; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 77 | elevator_goal_ = 0.01; |
| 78 | wrist_goal_ = -M_PI / 2.0; |
| 79 | intake_goal_ = -1.2; |
| 80 | |
| 81 | suction_on_ = false; |
| 82 | suction_gamepiece_ = 1; |
| 83 | |
| 84 | elevator_max_velocity_ = 0.0; |
| 85 | elevator_max_acceleration_ = 0.0; |
| 86 | wrist_max_velocity_ = 0.0; |
| 87 | wrist_max_acceleration_ = 0.0; |
| 88 | |
| 89 | InitializeEncoders(); |
| 90 | SendSuperstructureGoal(); |
| 91 | |
| 92 | { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 93 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 94 | // Start on the left l2. |
| 95 | localizer_resetter->x = 1.0; |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 96 | localizer_resetter->y = 1.35 * turn_scalar; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 97 | localizer_resetter->theta = M_PI; |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 98 | localizer_resetter->theta_uncertainty = 0.00001; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 99 | if (!localizer_resetter.Send()) { |
| 100 | LOG(ERROR, "Failed to reset localizer.\n"); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Wait for the drivetrain to run so it has time to reset the heading. |
| 105 | // Otherwise our drivetrain reset will do a 180 right at the start. |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 106 | WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); }); |
| 107 | LOG(INFO, "Heading is %f\n", drivetrain_status_fetcher_->estimated_heading); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 108 | InitializeEncoders(); |
| 109 | ResetDrivetrain(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame^] | 110 | WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); }); |
| 111 | LOG(INFO, "Heading is %f\n", drivetrain_status_fetcher_->estimated_heading); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 112 | |
| 113 | ResetDrivetrain(); |
| 114 | InitializeEncoders(); |
| 115 | } |
| 116 | |
| 117 | const ProfileParameters kJumpDrive = {2.0, 3.0}; |
| 118 | const ProfileParameters kDrive = {4.0, 3.0}; |
| 119 | const ProfileParameters kTurn = {5.0, 15.0}; |
| 120 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 121 | const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0}; |
| 122 | const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0}; |
| 123 | |
| 124 | const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0}; |
| 125 | const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0}; |
| 126 | |
| 127 | const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0}; |
| 128 | |
| 129 | const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0}; |
| 130 | |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 131 | bool AutonomousActor::RunAction( |
| 132 | const ::frc971::autonomous::AutonomousActionParams ¶ms) { |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 133 | const monotonic_clock::time_point start_time = monotonic_clock::now(); |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 134 | const bool is_left = params.mode == 0; |
| 135 | |
| 136 | { |
| 137 | LOG(INFO, "Starting autonomous action with mode %" PRId32 " %s\n", |
| 138 | params.mode, is_left ? "left" : "right"); |
| 139 | } |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 140 | |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 141 | const double turn_scalar = is_left ? 1.0 : -1.0; |
| 142 | |
| 143 | Reset(is_left); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 144 | enum class Mode { kTesting, kRocket, kCargoship }; |
| 145 | Mode mode = Mode::kCargoship; |
| 146 | if (mode == Mode::kRocket) { |
| 147 | SplineHandle spline1 = |
| 148 | PlanSpline(AutonomousSplines::HabToFarRocketTest(is_left), |
| 149 | SplineDirection::kBackward); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 150 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 151 | // Grab the disk, jump, wait until we have vacuum, then raise the elevator |
| 152 | set_elevator_goal(0.010); |
| 153 | set_wrist_goal(-M_PI / 2.0); |
| 154 | set_intake_goal(-1.2); |
| 155 | set_suction_goal(true, 1); |
| 156 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 157 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 158 | // if planned start the spline and plan the next |
| 159 | if (!spline1.WaitForPlan()) return true; |
| 160 | LOG(INFO, "Planned\n"); |
| 161 | spline1.Start(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 162 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 163 | // If suction, move the superstructure to score |
| 164 | if (!WaitForGamePiece()) return true; |
| 165 | LOG(INFO, "Has game piece\n"); |
| 166 | if (!spline1.WaitForSplineDistanceRemaining(3.5)) return true; |
| 167 | set_elevator_wrist_goal(kPanelBackwardMiddlePos); |
| 168 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 169 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 170 | if (!spline1.WaitForSplineDistanceRemaining(2.0)) return true; |
| 171 | set_elevator_wrist_goal(kPanelForwardMiddlePos); |
| 172 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 173 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 174 | // END SPLINE 1 |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 175 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 176 | if (!spline1.WaitForSplineDistanceRemaining(0.2)) return true; |
| 177 | LineFollowAtVelocity(1.3, 4); |
| 178 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1200))) return true; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 179 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 180 | set_suction_goal(false, 1); |
| 181 | SendSuperstructureGoal(); |
| 182 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
| 183 | LineFollowAtVelocity(-1.0, 4); |
| 184 | SplineHandle spline2 = PlanSpline(AutonomousSplines::FarRocketToHP(is_left), |
| 185 | SplineDirection::kBackward); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 186 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 187 | if (!WaitForMilliseconds(::std::chrono::milliseconds(150))) return true; |
| 188 | if (!spline2.WaitForPlan()) return true; |
| 189 | LOG(INFO, "Planned\n"); |
| 190 | // Drive back to hp and set the superstructure accordingly |
| 191 | spline2.Start(); |
| 192 | if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true; |
| 193 | set_elevator_wrist_goal(kPanelHPIntakeBackwardPos); |
| 194 | SendSuperstructureGoal(); |
| 195 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 196 | set_suction_goal(true, 1); |
| 197 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 198 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 199 | if (!spline2.WaitForSplineDistanceRemaining(1.6)) return true; |
| 200 | LineFollowAtVelocity(-1.6); |
| 201 | |
| 202 | // As soon as we pick up Panel 2 go score on the back rocket |
| 203 | if (!WaitForGamePiece()) return true; |
| 204 | LineFollowAtVelocity(1.5); |
| 205 | SplineHandle spline3 = PlanSpline(AutonomousSplines::HPToFarRocket(is_left), |
| 206 | SplineDirection::kForward); |
| 207 | if (!WaitForDriveXGreater(0.50)) return true; |
| 208 | if (!spline3.WaitForPlan()) return true; |
| 209 | spline3.Start(); |
| 210 | LOG(INFO, "Has game piece\n"); |
| 211 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 212 | set_elevator_wrist_goal(kPanelBackwardMiddlePos); |
| 213 | SendSuperstructureGoal(); |
| 214 | if (!WaitForDriveXGreater(7.1)) return true; |
| 215 | LineFollowAtVelocity(-1.5, 4); |
| 216 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 217 | set_elevator_wrist_goal(kPanelBackwardUpperPos); |
| 218 | SendSuperstructureGoal(); |
| 219 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1500))) return true; |
| 220 | set_suction_goal(false, 1); |
| 221 | SendSuperstructureGoal(); |
| 222 | if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true; |
| 223 | LineFollowAtVelocity(1.0, 4); |
| 224 | SendSuperstructureGoal(); |
| 225 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
| 226 | } else if (mode == Mode::kCargoship) { |
| 227 | SplineHandle spline1 = |
| 228 | PlanSpline(AutonomousSplines::HABToSecondCargoShipBay(is_left), |
| 229 | SplineDirection::kBackward); |
| 230 | set_elevator_goal(0.01); |
| 231 | set_wrist_goal(-M_PI / 2.0); |
| 232 | set_intake_goal(-1.2); |
| 233 | set_suction_goal(true, 1); |
| 234 | SendSuperstructureGoal(); |
| 235 | |
| 236 | // if planned start the spline and plan the next |
| 237 | if (!spline1.WaitForPlan()) return true; |
| 238 | LOG(INFO, "Planned\n"); |
| 239 | spline1.Start(); |
| 240 | |
| 241 | // If suction, move the superstructure to score |
| 242 | if (!WaitForGamePiece()) return true; |
| 243 | LOG(INFO, "Has game piece\n"); |
| 244 | // unstick the hatch panel |
| 245 | if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true; |
| 246 | set_elevator_goal(0.5); |
| 247 | set_wrist_goal(-M_PI / 2.0); |
| 248 | SendSuperstructureGoal(); |
| 249 | if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true; |
| 250 | set_elevator_wrist_goal(kPanelCargoBackwardPos); |
| 251 | SendSuperstructureGoal(); |
| 252 | |
| 253 | if (!spline1.WaitForSplineDistanceRemaining(0.8)) return true; |
| 254 | // Line follow in to the first disc. |
| 255 | LineFollowAtVelocity(-0.9, 2); |
| 256 | if (!WaitForDriveYCloseToZero(1.2)) return true; |
| 257 | |
| 258 | set_suction_goal(false, 1); |
| 259 | SendSuperstructureGoal(); |
| 260 | LOG(INFO, "Dropping disc 1 %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 261 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 262 | |
| 263 | if (!WaitForDriveYCloseToZero(1.13)) return true; |
| 264 | if (!WaitForMilliseconds(::std::chrono::milliseconds(300))) return true; |
| 265 | |
| 266 | LineFollowAtVelocity(0.9, 2); |
| 267 | SplineHandle spline2 = |
| 268 | PlanSpline(AutonomousSplines::SecondCargoShipBayToHP(is_left), |
| 269 | SplineDirection::kForward); |
| 270 | if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true; |
| 271 | if (!spline2.WaitForPlan()) return true; |
| 272 | LOG(INFO, "Planned\n"); |
| 273 | // Drive back to hp and set the superstructure accordingly |
| 274 | spline2.Start(); |
| 275 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
| 276 | set_elevator_wrist_goal(kPanelHPIntakeForwrdPos); |
| 277 | SendSuperstructureGoal(); |
| 278 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 279 | set_suction_goal(true, 1); |
| 280 | SendSuperstructureGoal(); |
| 281 | |
| 282 | if (!spline2.WaitForSplineDistanceRemaining(1.75)) return true; |
| 283 | LineFollowAtVelocity(1.5); |
| 284 | // As soon as we pick up Panel 2 go score on the rocket |
| 285 | if (!WaitForGamePiece()) return true; |
| 286 | LOG(INFO, "Got gamepiece %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 287 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 288 | LineFollowAtVelocity(-4.0); |
| 289 | SplineHandle spline3 = |
| 290 | PlanSpline(AutonomousSplines::HPToThirdCargoShipBay(is_left), |
| 291 | SplineDirection::kBackward); |
| 292 | if (!WaitForDriveXGreater(0.55)) return true; |
| 293 | if (!spline3.WaitForPlan()) return true; |
| 294 | spline3.Start(); |
| 295 | // Wait until we are a bit out to lift. |
| 296 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 297 | set_elevator_wrist_goal(kPanelCargoBackwardPos); |
| 298 | SendSuperstructureGoal(); |
| 299 | |
| 300 | if (!spline3.WaitForSplineDistanceRemaining(0.7)) return true; |
| 301 | // Line follow in to the second disc. |
| 302 | LineFollowAtVelocity(-0.7, 3); |
| 303 | LOG(INFO, "Drawing in disc 2 %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 304 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 305 | if (!WaitForDriveYCloseToZero(1.2)) return true; |
| 306 | |
| 307 | set_suction_goal(false, 1); |
| 308 | SendSuperstructureGoal(); |
| 309 | LOG(INFO, "Dropping disc 2 %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 310 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 311 | |
| 312 | if (!WaitForDriveYCloseToZero(1.13)) return true; |
| 313 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
| 314 | LOG(INFO, "Backing up %f\n", |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 315 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 316 | LineFollowAtVelocity(0.9, 3); |
| 317 | if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true; |
| 318 | } else { |
| 319 | // Grab the disk, wait until we have vacuum, then jump |
| 320 | set_elevator_goal(0.01); |
| 321 | set_wrist_goal(-M_PI / 2.0); |
| 322 | set_intake_goal(-1.2); |
| 323 | set_suction_goal(true, 1); |
| 324 | SendSuperstructureGoal(); |
| 325 | |
| 326 | if (!WaitForGamePiece()) return true; |
| 327 | LOG(INFO, "Has game piece\n"); |
| 328 | |
| 329 | StartDrive(-4.0, 0.0, kJumpDrive, kTurn); |
| 330 | if (!WaitForDriveNear(3.3, 10.0)) return true; |
| 331 | LOG(INFO, "Lifting\n"); |
| 332 | set_elevator_goal(0.30); |
| 333 | SendSuperstructureGoal(); |
| 334 | |
| 335 | if (!WaitForDriveNear(2.8, 10.0)) return true; |
| 336 | LOG(INFO, "Off the platform\n"); |
| 337 | |
| 338 | StartDrive(0.0, 1.00 * turn_scalar, kDrive, kTurn); |
| 339 | LOG(INFO, "Turn started\n"); |
| 340 | if (!WaitForSuperstructureDone()) return true; |
| 341 | LOG(INFO, "Superstructure done\n"); |
| 342 | |
| 343 | if (!WaitForDriveNear(0.7, 10.0)) return true; |
| 344 | StartDrive(0.0, -0.35 * turn_scalar, kDrive, kTurn); |
| 345 | |
| 346 | LOG(INFO, "Elevator up\n"); |
| 347 | set_elevator_goal(0.78); |
| 348 | SendSuperstructureGoal(); |
| 349 | |
| 350 | if (!WaitForDriveDone()) return true; |
| 351 | LOG(INFO, "Done driving\n"); |
| 352 | |
| 353 | if (!WaitForSuperstructureDone()) return true; |
| 354 | } |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 355 | |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 356 | LOG(INFO, "Done %f\n", |
| 357 | ::aos::time::DurationInSeconds(monotonic_clock::now() - start_time)); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 358 | |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 359 | return true; |
| 360 | } |
| 361 | |
| 362 | } // namespace actors |
| 363 | } // namespace y2019 |