blob: fbde0bebe0a8480ff467d774ab5f16e6deb4ef60 [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>(
147 aos::Sender<frc971::control_loops::drivetrain::Goal>::Builder *builder)>
148BindIsLeft(Functor f, bool is_left) {
149 return
150 [is_left, f](aos::Sender<frc971::control_loops::drivetrain::Goal>::Builder
151 *builder) { return f(builder, is_left); };
152}
153
Austin Schuh13379ba2019-03-12 21:06:46 -0700154bool AutonomousActor::RunAction(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700155 const ::frc971::autonomous::AutonomousActionParams *params) {
Austin Schuh77ed5432019-07-07 20:41:36 -0700156 const monotonic_clock::time_point start_time = monotonic_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700157 const bool is_left = params->mode() == 0;
Austin Schuha9644062019-03-28 14:31:52 -0700158
159 {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700160 AOS_LOG(INFO, "Starting autonomous action with mode %" PRId32 " %s\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700161 params->mode(), is_left ? "left" : "right");
Austin Schuha9644062019-03-28 14:31:52 -0700162 }
Austin Schuhb5b79a52019-05-08 20:32:07 -0700163
Austin Schuha9644062019-03-28 14:31:52 -0700164 const double turn_scalar = is_left ? 1.0 : -1.0;
165
166 Reset(is_left);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700167 enum class Mode { kTesting, kRocket, kCargoship };
168 Mode mode = Mode::kCargoship;
169 if (mode == Mode::kRocket) {
170 SplineHandle spline1 =
Alex Perrycb7da4b2019-08-28 19:35:56 -0700171 PlanSpline(BindIsLeft(AutonomousSplines::HabToFarRocketTest, is_left),
Austin Schuhb5b79a52019-05-08 20:32:07 -0700172 SplineDirection::kBackward);
Austin Schuh13379ba2019-03-12 21:06:46 -0700173
Austin Schuhb5b79a52019-05-08 20:32:07 -0700174 // Grab the disk, jump, wait until we have vacuum, then raise the elevator
175 set_elevator_goal(0.010);
176 set_wrist_goal(-M_PI / 2.0);
177 set_intake_goal(-1.2);
178 set_suction_goal(true, 1);
179 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700180
Austin Schuhb5b79a52019-05-08 20:32:07 -0700181 // if planned start the spline and plan the next
182 if (!spline1.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700183 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700184 spline1.Start();
Austin Schuh13379ba2019-03-12 21:06:46 -0700185
Austin Schuhb5b79a52019-05-08 20:32:07 -0700186 // If suction, move the superstructure to score
187 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700188 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700189 if (!spline1.WaitForSplineDistanceRemaining(3.5)) return true;
190 set_elevator_wrist_goal(kPanelBackwardMiddlePos);
191 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700192
Austin Schuhb5b79a52019-05-08 20:32:07 -0700193 if (!spline1.WaitForSplineDistanceRemaining(2.0)) return true;
194 set_elevator_wrist_goal(kPanelForwardMiddlePos);
195 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700196
Austin Schuhb5b79a52019-05-08 20:32:07 -0700197 // END SPLINE 1
Austin Schuh13379ba2019-03-12 21:06:46 -0700198
Austin Schuhb5b79a52019-05-08 20:32:07 -0700199 if (!spline1.WaitForSplineDistanceRemaining(0.2)) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700200 LineFollowAtVelocity(1.3,
201 control_loops::drivetrain::SelectionHint_FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700202 if (!WaitForMilliseconds(::std::chrono::milliseconds(1200))) return true;
Austin Schuh13379ba2019-03-12 21:06:46 -0700203
Austin Schuhb5b79a52019-05-08 20:32:07 -0700204 set_suction_goal(false, 1);
205 SendSuperstructureGoal();
206 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700207 LineFollowAtVelocity(-1.0,
208 control_loops::drivetrain::SelectionHint_FAR_ROCKET);
209 SplineHandle spline2 =
210 PlanSpline(BindIsLeft(AutonomousSplines::FarRocketToHP, is_left),
211 SplineDirection::kBackward);
Austin Schuh13379ba2019-03-12 21:06:46 -0700212
Austin Schuhb5b79a52019-05-08 20:32:07 -0700213 if (!WaitForMilliseconds(::std::chrono::milliseconds(150))) return true;
214 if (!spline2.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700215 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700216 // Drive back to hp and set the superstructure accordingly
217 spline2.Start();
218 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
219 set_elevator_wrist_goal(kPanelHPIntakeBackwardPos);
220 SendSuperstructureGoal();
221 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
222 set_suction_goal(true, 1);
223 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700224
Austin Schuhb5b79a52019-05-08 20:32:07 -0700225 if (!spline2.WaitForSplineDistanceRemaining(1.6)) return true;
226 LineFollowAtVelocity(-1.6);
227
228 // As soon as we pick up Panel 2 go score on the back rocket
229 if (!WaitForGamePiece()) return true;
230 LineFollowAtVelocity(1.5);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700231 SplineHandle spline3 =
232 PlanSpline(BindIsLeft(AutonomousSplines::HPToFarRocket, is_left),
233 SplineDirection::kForward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700234 if (!WaitForDriveXGreater(0.50)) return true;
235 if (!spline3.WaitForPlan()) return true;
236 spline3.Start();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700237 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700238 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
239 set_elevator_wrist_goal(kPanelBackwardMiddlePos);
240 SendSuperstructureGoal();
241 if (!WaitForDriveXGreater(7.1)) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700242 LineFollowAtVelocity(-1.5,
243 control_loops::drivetrain::SelectionHint_FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700244 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
245 set_elevator_wrist_goal(kPanelBackwardUpperPos);
246 SendSuperstructureGoal();
247 if (!WaitForMilliseconds(::std::chrono::milliseconds(1500))) return true;
248 set_suction_goal(false, 1);
249 SendSuperstructureGoal();
250 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700251 LineFollowAtVelocity(1.0,
252 control_loops::drivetrain::SelectionHint_FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700253 SendSuperstructureGoal();
254 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
255 } else if (mode == Mode::kCargoship) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700256 SplineHandle spline1 = PlanSpline(
257 BindIsLeft(AutonomousSplines::HABToSecondCargoShipBay, is_left),
258 SplineDirection::kBackward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700259 set_elevator_goal(0.01);
260 set_wrist_goal(-M_PI / 2.0);
261 set_intake_goal(-1.2);
262 set_suction_goal(true, 1);
263 SendSuperstructureGoal();
264
265 // if planned start the spline and plan the next
266 if (!spline1.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700267 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700268 spline1.Start();
269
270 // If suction, move the superstructure to score
271 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700272 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700273 // unstick the hatch panel
274 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
275 set_elevator_goal(0.5);
276 set_wrist_goal(-M_PI / 2.0);
277 SendSuperstructureGoal();
278 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
279 set_elevator_wrist_goal(kPanelCargoBackwardPos);
280 SendSuperstructureGoal();
281
282 if (!spline1.WaitForSplineDistanceRemaining(0.8)) return true;
283 // Line follow in to the first disc.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700284 LineFollowAtVelocity(-0.9,
285 control_loops::drivetrain::SelectionHint_MID_SHIP);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700286 if (!WaitForDriveYCloseToZero(1.2)) return true;
287
288 set_suction_goal(false, 1);
289 SendSuperstructureGoal();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700290 AOS_LOG(INFO, "Dropping disc 1 %f\n",
291 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700292
293 if (!WaitForDriveYCloseToZero(1.13)) return true;
294 if (!WaitForMilliseconds(::std::chrono::milliseconds(300))) return true;
295
Alex Perrycb7da4b2019-08-28 19:35:56 -0700296 LineFollowAtVelocity(0.9,
297 control_loops::drivetrain::SelectionHint_MID_SHIP);
298 SplineHandle spline2 = PlanSpline(
299 BindIsLeft(AutonomousSplines::SecondCargoShipBayToHP, is_left),
300 SplineDirection::kForward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700301 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
302 if (!spline2.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700303 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700304 // Drive back to hp and set the superstructure accordingly
305 spline2.Start();
306 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
307 set_elevator_wrist_goal(kPanelHPIntakeForwrdPos);
308 SendSuperstructureGoal();
309 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
310 set_suction_goal(true, 1);
311 SendSuperstructureGoal();
312
313 if (!spline2.WaitForSplineDistanceRemaining(1.75)) return true;
314 LineFollowAtVelocity(1.5);
315 // As soon as we pick up Panel 2 go score on the rocket
316 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700317 AOS_LOG(INFO, "Got gamepiece %f\n",
318 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700319 LineFollowAtVelocity(-4.0);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700320 SplineHandle spline3 = PlanSpline(
321 BindIsLeft(AutonomousSplines::HPToThirdCargoShipBay, is_left),
322 SplineDirection::kBackward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700323 if (!WaitForDriveXGreater(0.55)) return true;
324 if (!spline3.WaitForPlan()) return true;
325 spline3.Start();
326 // Wait until we are a bit out to lift.
327 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
328 set_elevator_wrist_goal(kPanelCargoBackwardPos);
329 SendSuperstructureGoal();
330
331 if (!spline3.WaitForSplineDistanceRemaining(0.7)) return true;
332 // Line follow in to the second disc.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700333 LineFollowAtVelocity(-0.7,
334 control_loops::drivetrain::SelectionHint_FAR_SHIP);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700335 AOS_LOG(INFO, "Drawing in disc 2 %f\n",
336 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700337 if (!WaitForDriveYCloseToZero(1.2)) return true;
338
339 set_suction_goal(false, 1);
340 SendSuperstructureGoal();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700341 AOS_LOG(INFO, "Dropping disc 2 %f\n",
342 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700343
344 if (!WaitForDriveYCloseToZero(1.13)) return true;
345 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700346 AOS_LOG(INFO, "Backing up %f\n",
347 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700348 LineFollowAtVelocity(0.9,
349 control_loops::drivetrain::SelectionHint_FAR_SHIP);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700350 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
351 } else {
352 // Grab the disk, wait until we have vacuum, then jump
353 set_elevator_goal(0.01);
354 set_wrist_goal(-M_PI / 2.0);
355 set_intake_goal(-1.2);
356 set_suction_goal(true, 1);
357 SendSuperstructureGoal();
358
359 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700360 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700361
362 StartDrive(-4.0, 0.0, kJumpDrive, kTurn);
363 if (!WaitForDriveNear(3.3, 10.0)) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700364 AOS_LOG(INFO, "Lifting\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700365 set_elevator_goal(0.30);
366 SendSuperstructureGoal();
367
368 if (!WaitForDriveNear(2.8, 10.0)) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700369 AOS_LOG(INFO, "Off the platform\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700370
371 StartDrive(0.0, 1.00 * turn_scalar, kDrive, kTurn);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700372 AOS_LOG(INFO, "Turn started\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700373 if (!WaitForSuperstructureDone()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700374 AOS_LOG(INFO, "Superstructure done\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700375
376 if (!WaitForDriveNear(0.7, 10.0)) return true;
377 StartDrive(0.0, -0.35 * turn_scalar, kDrive, kTurn);
378
Austin Schuhf257f3c2019-10-27 21:00:43 -0700379 AOS_LOG(INFO, "Elevator up\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700380 set_elevator_goal(0.78);
381 SendSuperstructureGoal();
382
383 if (!WaitForDriveDone()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700384 AOS_LOG(INFO, "Done driving\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700385
386 if (!WaitForSuperstructureDone()) return true;
387 }
Austin Schuh13379ba2019-03-12 21:06:46 -0700388
Austin Schuhf257f3c2019-10-27 21:00:43 -0700389 AOS_LOG(INFO, "Done %f\n",
390 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuh13379ba2019-03-12 21:06:46 -0700391
Austin Schuh13379ba2019-03-12 21:06:46 -0700392 return true;
393}
394
395} // namespace actors
396} // namespace y2019