blob: 078ad64eb5292877cc9cd9f482ba07fa7535d2dd [file] [log] [blame]
Austin Schuh13379ba2019-03-12 21:06:46 -07001#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
Alex Perrycb7da4b2019-08-28 19:35:56 -070011#include "frc971/control_loops/drivetrain/localizer_generated.h"
Austin Schuh6bcc2302019-03-23 22:28:06 -070012#include "y2019/actors/auto_splines.h"
Austin Schuh13379ba2019-03-12 21:06:46 -070013#include "y2019/control_loops/drivetrain/drivetrain_base.h"
14
15namespace y2019 {
16namespace actors {
Alex Perrycb7da4b2019-08-28 19:35:56 -070017
18using ::frc971::ProfileParametersT;
Austin Schuh13379ba2019-03-12 21:06:46 -070019using ::aos::monotonic_clock;
Alex Perrycb7da4b2019-08-28 19:35:56 -070020using frc971::control_loops::drivetrain::LocalizerControl;
Austin Schuh13379ba2019-03-12 21:06:46 -070021namespace chrono = ::std::chrono;
22
Austin Schuh1bf8a212019-05-26 22:13:14 -070023AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop)
Austin Schuh13379ba2019-03-12 21:06:46 -070024 : frc971::autonomous::BaseAutonomousActor(
Austin Schuh1bf8a212019-05-26 22:13:14 -070025 event_loop, control_loops::drivetrain::GetDrivetrainConfig()),
Austin Schuheb99d072019-05-12 21:03:38 -070026 localizer_control_sender_(
27 event_loop->MakeSender<
28 ::frc971::control_loops::drivetrain::LocalizerControl>(
Alex Perrycb7da4b2019-08-28 19:35:56 -070029 "/drivetrain")),
Austin Schuh170f4952019-06-29 18:58:30 -070030 superstructure_goal_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -070031 event_loop->MakeSender<::y2019::control_loops::superstructure::Goal>(
32 "/superstructure")),
33 superstructure_status_fetcher_(
34 event_loop
35 ->MakeFetcher<::y2019::control_loops::superstructure::Status>(
36 "/superstructure")) {}
Austin Schuh13379ba2019-03-12 21:06:46 -070037
Austin Schuhb5b79a52019-05-08 20:32:07 -070038bool AutonomousActor::WaitForDriveXGreater(double x) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070039 AOS_LOG(INFO, "Waiting until x > %f\n", x);
Austin Schuhb5b79a52019-05-08 20:32:07 -070040 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
Austin Schuhd32b3622019-06-23 18:49:06 -070041 event_loop()->monotonic_now(),
Austin Schuhb5b79a52019-05-08 20:32:07 -070042 ::std::chrono::milliseconds(5) / 2);
43
44 while (true) {
45 if (ShouldCancel()) {
46 return false;
47 }
48 phased_loop.SleepUntilNext();
Austin Schuhbd0a40f2019-06-30 14:56:31 -070049 drivetrain_status_fetcher_.Fetch();
Alex Perrycb7da4b2019-08-28 19:35:56 -070050 if (drivetrain_status_fetcher_->x() > x) {
51 AOS_LOG(INFO, "X at %f\n", drivetrain_status_fetcher_->x());
Austin Schuhb5b79a52019-05-08 20:32:07 -070052 return true;
53 }
54 }
55}
56
57bool AutonomousActor::WaitForDriveYCloseToZero(double y) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070058 AOS_LOG(INFO, "Waiting until |y| < %f\n", y);
Austin Schuhb5b79a52019-05-08 20:32:07 -070059 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
Austin Schuhd32b3622019-06-23 18:49:06 -070060 event_loop()->monotonic_now(),
Austin Schuhb5b79a52019-05-08 20:32:07 -070061 ::std::chrono::milliseconds(5) / 2);
62
63 while (true) {
64 if (ShouldCancel()) {
65 return false;
66 }
67 phased_loop.SleepUntilNext();
Austin Schuhbd0a40f2019-06-30 14:56:31 -070068 drivetrain_status_fetcher_.Fetch();
Alex Perrycb7da4b2019-08-28 19:35:56 -070069 if (::std::abs(drivetrain_status_fetcher_->y()) < y) {
70 AOS_LOG(INFO, "Y at %f\n", drivetrain_status_fetcher_->y());
Austin Schuhb5b79a52019-05-08 20:32:07 -070071 return true;
72 }
73 }
74}
75
Austin Schuha9644062019-03-28 14:31:52 -070076void AutonomousActor::Reset(bool is_left) {
77 const double turn_scalar = is_left ? 1.0 : -1.0;
Austin Schuh13379ba2019-03-12 21:06:46 -070078 elevator_goal_ = 0.01;
79 wrist_goal_ = -M_PI / 2.0;
80 intake_goal_ = -1.2;
81
82 suction_on_ = false;
83 suction_gamepiece_ = 1;
84
85 elevator_max_velocity_ = 0.0;
86 elevator_max_acceleration_ = 0.0;
87 wrist_max_velocity_ = 0.0;
88 wrist_max_acceleration_ = 0.0;
89
90 InitializeEncoders();
91 SendSuperstructureGoal();
92
93 {
Alex Perrycb7da4b2019-08-28 19:35:56 -070094 auto builder = localizer_control_sender_.MakeBuilder();
95
96 LocalizerControl::Builder localizer_control_builder =
97 builder.MakeBuilder<LocalizerControl>();
Austin Schuh13379ba2019-03-12 21:06:46 -070098 // Start on the left l2.
Alex Perrycb7da4b2019-08-28 19:35:56 -070099 localizer_control_builder.add_x(1.0);
100 localizer_control_builder.add_y(1.35 * turn_scalar);
101 localizer_control_builder.add_theta(M_PI);
102 localizer_control_builder.add_theta_uncertainty(0.00001);
103 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700104 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuh13379ba2019-03-12 21:06:46 -0700105 }
106 }
107
108 // Wait for the drivetrain to run so it has time to reset the heading.
109 // Otherwise our drivetrain reset will do a 180 right at the start.
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700110 WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
Austin Schuhf257f3c2019-10-27 21:00:43 -0700111 AOS_LOG(INFO, "Heading is %f\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700112 drivetrain_status_fetcher_->estimated_heading());
Austin Schuh13379ba2019-03-12 21:06:46 -0700113 InitializeEncoders();
114 ResetDrivetrain();
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700115 WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
Austin Schuhf257f3c2019-10-27 21:00:43 -0700116 AOS_LOG(INFO, "Heading is %f\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700117 drivetrain_status_fetcher_->estimated_heading());
Austin Schuh13379ba2019-03-12 21:06:46 -0700118
119 ResetDrivetrain();
120 InitializeEncoders();
121}
122
Alex Perrycb7da4b2019-08-28 19:35:56 -0700123ProfileParametersT MakeProfileParameters(float max_velocity,
124 float max_acceleration) {
125 ProfileParametersT result;
126 result.max_velocity = max_velocity;
127 result.max_acceleration = max_acceleration;
128 return result;
129}
130
131const ProfileParametersT kJumpDrive = MakeProfileParameters(2.0, 3.0);
132const ProfileParametersT kDrive = MakeProfileParameters(4.0, 3.0);
133const ProfileParametersT kTurn = MakeProfileParameters(5.0, 15.0);
Austin Schuh13379ba2019-03-12 21:06:46 -0700134
Austin Schuhb5b79a52019-05-08 20:32:07 -0700135const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
136const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
137
138const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
139const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
140
141const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
142
143const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
144
Alex Perrycb7da4b2019-08-28 19:35:56 -0700145template <typename Functor>
146std::function<flatbuffers::Offset<frc971::MultiSpline>(
James Kuszmaul75a18c52021-03-10 22:02:07 -0800147 aos::Sender<frc971::control_loops::drivetrain::SplineGoal>::Builder
148 *builder)>
Alex Perrycb7da4b2019-08-28 19:35:56 -0700149BindIsLeft(Functor f, bool is_left) {
James Kuszmaul75a18c52021-03-10 22:02:07 -0800150 return [is_left,
151 f](aos::Sender<frc971::control_loops::drivetrain::SplineGoal>::Builder
152 *builder) { return f(builder, is_left); };
Alex Perrycb7da4b2019-08-28 19:35:56 -0700153}
154
Austin Schuh13379ba2019-03-12 21:06:46 -0700155bool AutonomousActor::RunAction(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700156 const ::frc971::autonomous::AutonomousActionParams *params) {
Austin Schuh77ed5432019-07-07 20:41:36 -0700157 const monotonic_clock::time_point start_time = monotonic_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700158 const bool is_left = params->mode() == 0;
Austin Schuha9644062019-03-28 14:31:52 -0700159
160 {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700161 AOS_LOG(INFO, "Starting autonomous action with mode %" PRId32 " %s\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700162 params->mode(), is_left ? "left" : "right");
Austin Schuha9644062019-03-28 14:31:52 -0700163 }
Austin Schuhb5b79a52019-05-08 20:32:07 -0700164
Austin Schuha9644062019-03-28 14:31:52 -0700165 const double turn_scalar = is_left ? 1.0 : -1.0;
166
167 Reset(is_left);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700168 enum class Mode { kTesting, kRocket, kCargoship };
169 Mode mode = Mode::kCargoship;
170 if (mode == Mode::kRocket) {
171 SplineHandle spline1 =
Alex Perrycb7da4b2019-08-28 19:35:56 -0700172 PlanSpline(BindIsLeft(AutonomousSplines::HabToFarRocketTest, is_left),
Austin Schuhb5b79a52019-05-08 20:32:07 -0700173 SplineDirection::kBackward);
Austin Schuh13379ba2019-03-12 21:06:46 -0700174
Austin Schuhb5b79a52019-05-08 20:32:07 -0700175 // Grab the disk, jump, wait until we have vacuum, then raise the elevator
176 set_elevator_goal(0.010);
177 set_wrist_goal(-M_PI / 2.0);
178 set_intake_goal(-1.2);
179 set_suction_goal(true, 1);
180 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700181
Austin Schuhb5b79a52019-05-08 20:32:07 -0700182 // if planned start the spline and plan the next
183 if (!spline1.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700184 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700185 spline1.Start();
Austin Schuh13379ba2019-03-12 21:06:46 -0700186
Austin Schuhb5b79a52019-05-08 20:32:07 -0700187 // If suction, move the superstructure to score
188 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700189 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700190 if (!spline1.WaitForSplineDistanceRemaining(3.5)) return true;
191 set_elevator_wrist_goal(kPanelBackwardMiddlePos);
192 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700193
Austin Schuhb5b79a52019-05-08 20:32:07 -0700194 if (!spline1.WaitForSplineDistanceRemaining(2.0)) return true;
195 set_elevator_wrist_goal(kPanelForwardMiddlePos);
196 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700197
Austin Schuhb5b79a52019-05-08 20:32:07 -0700198 // END SPLINE 1
Austin Schuh13379ba2019-03-12 21:06:46 -0700199
Austin Schuhb5b79a52019-05-08 20:32:07 -0700200 if (!spline1.WaitForSplineDistanceRemaining(0.2)) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700201 LineFollowAtVelocity(1.3,
Austin Schuh872723c2019-12-25 14:38:09 -0800202 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700203 if (!WaitForMilliseconds(::std::chrono::milliseconds(1200))) return true;
Austin Schuh13379ba2019-03-12 21:06:46 -0700204
Austin Schuhb5b79a52019-05-08 20:32:07 -0700205 set_suction_goal(false, 1);
206 SendSuperstructureGoal();
207 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700208 LineFollowAtVelocity(-1.0,
Austin Schuh872723c2019-12-25 14:38:09 -0800209 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700210 SplineHandle spline2 =
211 PlanSpline(BindIsLeft(AutonomousSplines::FarRocketToHP, is_left),
212 SplineDirection::kBackward);
Austin Schuh13379ba2019-03-12 21:06:46 -0700213
Austin Schuhb5b79a52019-05-08 20:32:07 -0700214 if (!WaitForMilliseconds(::std::chrono::milliseconds(150))) return true;
215 if (!spline2.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700216 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700217 // Drive back to hp and set the superstructure accordingly
218 spline2.Start();
219 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
220 set_elevator_wrist_goal(kPanelHPIntakeBackwardPos);
221 SendSuperstructureGoal();
222 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
223 set_suction_goal(true, 1);
224 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700225
Austin Schuhb5b79a52019-05-08 20:32:07 -0700226 if (!spline2.WaitForSplineDistanceRemaining(1.6)) return true;
227 LineFollowAtVelocity(-1.6);
228
229 // As soon as we pick up Panel 2 go score on the back rocket
230 if (!WaitForGamePiece()) return true;
231 LineFollowAtVelocity(1.5);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700232 SplineHandle spline3 =
233 PlanSpline(BindIsLeft(AutonomousSplines::HPToFarRocket, is_left),
234 SplineDirection::kForward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700235 if (!WaitForDriveXGreater(0.50)) return true;
236 if (!spline3.WaitForPlan()) return true;
237 spline3.Start();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700238 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700239 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
240 set_elevator_wrist_goal(kPanelBackwardMiddlePos);
241 SendSuperstructureGoal();
242 if (!WaitForDriveXGreater(7.1)) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700243 LineFollowAtVelocity(-1.5,
Austin Schuh872723c2019-12-25 14:38:09 -0800244 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700245 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
246 set_elevator_wrist_goal(kPanelBackwardUpperPos);
247 SendSuperstructureGoal();
248 if (!WaitForMilliseconds(::std::chrono::milliseconds(1500))) return true;
249 set_suction_goal(false, 1);
250 SendSuperstructureGoal();
251 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700252 LineFollowAtVelocity(1.0,
Austin Schuh872723c2019-12-25 14:38:09 -0800253 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700254 SendSuperstructureGoal();
255 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
256 } else if (mode == Mode::kCargoship) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700257 SplineHandle spline1 = PlanSpline(
258 BindIsLeft(AutonomousSplines::HABToSecondCargoShipBay, is_left),
259 SplineDirection::kBackward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700260 set_elevator_goal(0.01);
261 set_wrist_goal(-M_PI / 2.0);
262 set_intake_goal(-1.2);
263 set_suction_goal(true, 1);
264 SendSuperstructureGoal();
265
266 // if planned start the spline and plan the next
267 if (!spline1.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700268 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700269 spline1.Start();
270
271 // If suction, move the superstructure to score
272 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700273 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700274 // unstick the hatch panel
275 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
276 set_elevator_goal(0.5);
277 set_wrist_goal(-M_PI / 2.0);
278 SendSuperstructureGoal();
279 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
280 set_elevator_wrist_goal(kPanelCargoBackwardPos);
281 SendSuperstructureGoal();
282
283 if (!spline1.WaitForSplineDistanceRemaining(0.8)) return true;
284 // Line follow in to the first disc.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700285 LineFollowAtVelocity(-0.9,
Austin Schuh872723c2019-12-25 14:38:09 -0800286 control_loops::drivetrain::SelectionHint::MID_SHIP);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700287 if (!WaitForDriveYCloseToZero(1.2)) return true;
288
289 set_suction_goal(false, 1);
290 SendSuperstructureGoal();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700291 AOS_LOG(INFO, "Dropping disc 1 %f\n",
292 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700293
294 if (!WaitForDriveYCloseToZero(1.13)) return true;
295 if (!WaitForMilliseconds(::std::chrono::milliseconds(300))) return true;
296
Alex Perrycb7da4b2019-08-28 19:35:56 -0700297 LineFollowAtVelocity(0.9,
Austin Schuh872723c2019-12-25 14:38:09 -0800298 control_loops::drivetrain::SelectionHint::MID_SHIP);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700299 SplineHandle spline2 = PlanSpline(
300 BindIsLeft(AutonomousSplines::SecondCargoShipBayToHP, is_left),
301 SplineDirection::kForward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700302 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
303 if (!spline2.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700304 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700305 // Drive back to hp and set the superstructure accordingly
306 spline2.Start();
307 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
308 set_elevator_wrist_goal(kPanelHPIntakeForwrdPos);
309 SendSuperstructureGoal();
310 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
311 set_suction_goal(true, 1);
312 SendSuperstructureGoal();
313
314 if (!spline2.WaitForSplineDistanceRemaining(1.75)) return true;
315 LineFollowAtVelocity(1.5);
316 // As soon as we pick up Panel 2 go score on the rocket
317 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700318 AOS_LOG(INFO, "Got gamepiece %f\n",
319 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700320 LineFollowAtVelocity(-4.0);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700321 SplineHandle spline3 = PlanSpline(
322 BindIsLeft(AutonomousSplines::HPToThirdCargoShipBay, is_left),
323 SplineDirection::kBackward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700324 if (!WaitForDriveXGreater(0.55)) return true;
325 if (!spline3.WaitForPlan()) return true;
326 spline3.Start();
327 // Wait until we are a bit out to lift.
328 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
329 set_elevator_wrist_goal(kPanelCargoBackwardPos);
330 SendSuperstructureGoal();
331
332 if (!spline3.WaitForSplineDistanceRemaining(0.7)) return true;
333 // Line follow in to the second disc.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700334 LineFollowAtVelocity(-0.7,
Austin Schuh872723c2019-12-25 14:38:09 -0800335 control_loops::drivetrain::SelectionHint::FAR_SHIP);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700336 AOS_LOG(INFO, "Drawing in disc 2 %f\n",
337 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700338 if (!WaitForDriveYCloseToZero(1.2)) return true;
339
340 set_suction_goal(false, 1);
341 SendSuperstructureGoal();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700342 AOS_LOG(INFO, "Dropping disc 2 %f\n",
343 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700344
345 if (!WaitForDriveYCloseToZero(1.13)) return true;
346 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700347 AOS_LOG(INFO, "Backing up %f\n",
348 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700349 LineFollowAtVelocity(0.9,
Austin Schuh872723c2019-12-25 14:38:09 -0800350 control_loops::drivetrain::SelectionHint::FAR_SHIP);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700351 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
352 } else {
353 // Grab the disk, wait until we have vacuum, then jump
354 set_elevator_goal(0.01);
355 set_wrist_goal(-M_PI / 2.0);
356 set_intake_goal(-1.2);
357 set_suction_goal(true, 1);
358 SendSuperstructureGoal();
359
360 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700361 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700362
363 StartDrive(-4.0, 0.0, kJumpDrive, kTurn);
364 if (!WaitForDriveNear(3.3, 10.0)) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700365 AOS_LOG(INFO, "Lifting\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700366 set_elevator_goal(0.30);
367 SendSuperstructureGoal();
368
369 if (!WaitForDriveNear(2.8, 10.0)) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700370 AOS_LOG(INFO, "Off the platform\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700371
372 StartDrive(0.0, 1.00 * turn_scalar, kDrive, kTurn);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700373 AOS_LOG(INFO, "Turn started\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700374 if (!WaitForSuperstructureDone()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700375 AOS_LOG(INFO, "Superstructure done\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700376
377 if (!WaitForDriveNear(0.7, 10.0)) return true;
378 StartDrive(0.0, -0.35 * turn_scalar, kDrive, kTurn);
379
Austin Schuhf257f3c2019-10-27 21:00:43 -0700380 AOS_LOG(INFO, "Elevator up\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700381 set_elevator_goal(0.78);
382 SendSuperstructureGoal();
383
384 if (!WaitForDriveDone()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700385 AOS_LOG(INFO, "Done driving\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700386
387 if (!WaitForSuperstructureDone()) return true;
388 }
Austin Schuh13379ba2019-03-12 21:06:46 -0700389
Austin Schuhf257f3c2019-10-27 21:00:43 -0700390 AOS_LOG(INFO, "Done %f\n",
391 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuh13379ba2019-03-12 21:06:46 -0700392
Austin Schuh13379ba2019-03-12 21:06:46 -0700393 return true;
394}
395
396} // namespace actors
397} // namespace y2019