blob: b8024ec0608bf4ec47e237abd1d81fc9d0209b26 [file] [log] [blame]
Austin Schuh13379ba2019-03-12 21:06:46 -07001#include "y2019/actors/autonomous_actor.h"
2
Austin Schuh13379ba2019-03-12 21:06:46 -07003#include <chrono>
Tyler Chatowbf0609c2021-07-31 16:13:27 -07004#include <cinttypes>
Austin Schuh13379ba2019-03-12 21:06:46 -07005#include <cmath>
6
7#include "aos/logging/logging.h"
8#include "aos/util/phased_loop.h"
Alex Perrycb7da4b2019-08-28 19:35:56 -07009#include "frc971/control_loops/drivetrain/localizer_generated.h"
Austin Schuh6bcc2302019-03-23 22:28:06 -070010#include "y2019/actors/auto_splines.h"
Austin Schuh13379ba2019-03-12 21:06:46 -070011#include "y2019/control_loops/drivetrain/drivetrain_base.h"
12
13namespace y2019 {
14namespace actors {
Alex Perrycb7da4b2019-08-28 19:35:56 -070015
Austin Schuh13379ba2019-03-12 21:06:46 -070016using ::aos::monotonic_clock;
Tyler Chatowbf0609c2021-07-31 16:13:27 -070017using ::frc971::ProfileParametersT;
Alex Perrycb7da4b2019-08-28 19:35:56 -070018using frc971::control_loops::drivetrain::LocalizerControl;
Austin Schuh13379ba2019-03-12 21:06:46 -070019namespace chrono = ::std::chrono;
20
Austin Schuh1bf8a212019-05-26 22:13:14 -070021AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop)
Austin Schuh13379ba2019-03-12 21:06:46 -070022 : frc971::autonomous::BaseAutonomousActor(
Austin Schuh1bf8a212019-05-26 22:13:14 -070023 event_loop, control_loops::drivetrain::GetDrivetrainConfig()),
Austin Schuheb99d072019-05-12 21:03:38 -070024 localizer_control_sender_(
25 event_loop->MakeSender<
26 ::frc971::control_loops::drivetrain::LocalizerControl>(
Alex Perrycb7da4b2019-08-28 19:35:56 -070027 "/drivetrain")),
Austin Schuh170f4952019-06-29 18:58:30 -070028 superstructure_goal_sender_(
Alex Perrycb7da4b2019-08-28 19:35:56 -070029 event_loop->MakeSender<::y2019::control_loops::superstructure::Goal>(
30 "/superstructure")),
31 superstructure_status_fetcher_(
32 event_loop
33 ->MakeFetcher<::y2019::control_loops::superstructure::Status>(
34 "/superstructure")) {}
Austin Schuh13379ba2019-03-12 21:06:46 -070035
Austin Schuhb5b79a52019-05-08 20:32:07 -070036bool AutonomousActor::WaitForDriveXGreater(double x) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070037 AOS_LOG(INFO, "Waiting until x > %f\n", x);
Yash Chainania6fe97b2021-12-15 21:01:11 -080038 ::aos::time::PhasedLoop phased_loop(frc971::controls::kLoopFrequency,
Austin Schuhd32b3622019-06-23 18:49:06 -070039 event_loop()->monotonic_now(),
Yash Chainania6fe97b2021-12-15 21:01:11 -080040 ActorBase::kLoopOffset);
Austin Schuhb5b79a52019-05-08 20:32:07 -070041
42 while (true) {
43 if (ShouldCancel()) {
44 return false;
45 }
46 phased_loop.SleepUntilNext();
Austin Schuhbd0a40f2019-06-30 14:56:31 -070047 drivetrain_status_fetcher_.Fetch();
Alex Perrycb7da4b2019-08-28 19:35:56 -070048 if (drivetrain_status_fetcher_->x() > x) {
49 AOS_LOG(INFO, "X at %f\n", drivetrain_status_fetcher_->x());
Austin Schuhb5b79a52019-05-08 20:32:07 -070050 return true;
51 }
52 }
53}
54
55bool AutonomousActor::WaitForDriveYCloseToZero(double y) {
Austin Schuhf257f3c2019-10-27 21:00:43 -070056 AOS_LOG(INFO, "Waiting until |y| < %f\n", y);
Yash Chainania6fe97b2021-12-15 21:01:11 -080057 ::aos::time::PhasedLoop phased_loop(frc971::controls::kLoopFrequency,
Austin Schuhd32b3622019-06-23 18:49:06 -070058 event_loop()->monotonic_now(),
Yash Chainania6fe97b2021-12-15 21:01:11 -080059 ActorBase::kLoopOffset);
Austin Schuhb5b79a52019-05-08 20:32:07 -070060
61 while (true) {
62 if (ShouldCancel()) {
63 return false;
64 }
65 phased_loop.SleepUntilNext();
Austin Schuhbd0a40f2019-06-30 14:56:31 -070066 drivetrain_status_fetcher_.Fetch();
Alex Perrycb7da4b2019-08-28 19:35:56 -070067 if (::std::abs(drivetrain_status_fetcher_->y()) < y) {
68 AOS_LOG(INFO, "Y at %f\n", drivetrain_status_fetcher_->y());
Austin Schuhb5b79a52019-05-08 20:32:07 -070069 return true;
70 }
71 }
72}
73
Austin Schuha9644062019-03-28 14:31:52 -070074void AutonomousActor::Reset(bool is_left) {
75 const double turn_scalar = is_left ? 1.0 : -1.0;
Austin Schuh13379ba2019-03-12 21:06:46 -070076 elevator_goal_ = 0.01;
77 wrist_goal_ = -M_PI / 2.0;
78 intake_goal_ = -1.2;
79
80 suction_on_ = false;
81 suction_gamepiece_ = 1;
82
83 elevator_max_velocity_ = 0.0;
84 elevator_max_acceleration_ = 0.0;
85 wrist_max_velocity_ = 0.0;
86 wrist_max_acceleration_ = 0.0;
87
88 InitializeEncoders();
89 SendSuperstructureGoal();
90
91 {
Alex Perrycb7da4b2019-08-28 19:35:56 -070092 auto builder = localizer_control_sender_.MakeBuilder();
93
94 LocalizerControl::Builder localizer_control_builder =
95 builder.MakeBuilder<LocalizerControl>();
Austin Schuh13379ba2019-03-12 21:06:46 -070096 // Start on the left l2.
Alex Perrycb7da4b2019-08-28 19:35:56 -070097 localizer_control_builder.add_x(1.0);
98 localizer_control_builder.add_y(1.35 * turn_scalar);
99 localizer_control_builder.add_theta(M_PI);
100 localizer_control_builder.add_theta_uncertainty(0.00001);
milind1f1dca32021-07-03 13:50:07 -0700101 if (builder.Send(localizer_control_builder.Finish()) !=
102 aos::RawSender::Error::kOk) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700103 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuh13379ba2019-03-12 21:06:46 -0700104 }
105 }
106
107 // Wait for the drivetrain to run so it has time to reset the heading.
108 // Otherwise our drivetrain reset will do a 180 right at the start.
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700109 WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
Austin Schuhf257f3c2019-10-27 21:00:43 -0700110 AOS_LOG(INFO, "Heading is %f\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700111 drivetrain_status_fetcher_->estimated_heading());
Austin Schuh13379ba2019-03-12 21:06:46 -0700112 InitializeEncoders();
113 ResetDrivetrain();
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700114 WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
Austin Schuhf257f3c2019-10-27 21:00:43 -0700115 AOS_LOG(INFO, "Heading is %f\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700116 drivetrain_status_fetcher_->estimated_heading());
Austin Schuh13379ba2019-03-12 21:06:46 -0700117
118 ResetDrivetrain();
119 InitializeEncoders();
120}
121
Alex Perrycb7da4b2019-08-28 19:35:56 -0700122ProfileParametersT MakeProfileParameters(float max_velocity,
123 float max_acceleration) {
124 ProfileParametersT result;
125 result.max_velocity = max_velocity;
126 result.max_acceleration = max_acceleration;
127 return result;
128}
129
130const ProfileParametersT kJumpDrive = MakeProfileParameters(2.0, 3.0);
131const ProfileParametersT kDrive = MakeProfileParameters(4.0, 3.0);
132const ProfileParametersT kTurn = MakeProfileParameters(5.0, 15.0);
Austin Schuh13379ba2019-03-12 21:06:46 -0700133
Austin Schuhb5b79a52019-05-08 20:32:07 -0700134const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
135const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
136
137const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
138const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
139
140const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
141
142const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
143
Alex Perrycb7da4b2019-08-28 19:35:56 -0700144template <typename Functor>
145std::function<flatbuffers::Offset<frc971::MultiSpline>(
James Kuszmaul75a18c52021-03-10 22:02:07 -0800146 aos::Sender<frc971::control_loops::drivetrain::SplineGoal>::Builder
147 *builder)>
Alex Perrycb7da4b2019-08-28 19:35:56 -0700148BindIsLeft(Functor f, bool is_left) {
James Kuszmaul75a18c52021-03-10 22:02:07 -0800149 return [is_left,
150 f](aos::Sender<frc971::control_loops::drivetrain::SplineGoal>::Builder
151 *builder) { return f(builder, is_left); };
Alex Perrycb7da4b2019-08-28 19:35:56 -0700152}
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,
Austin Schuh872723c2019-12-25 14:38:09 -0800201 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,
Austin Schuh872723c2019-12-25 14:38:09 -0800208 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700209 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,
Austin Schuh872723c2019-12-25 14:38:09 -0800243 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,
Austin Schuh872723c2019-12-25 14:38:09 -0800252 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,
Austin Schuh872723c2019-12-25 14:38:09 -0800285 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,
Austin Schuh872723c2019-12-25 14:38:09 -0800297 control_loops::drivetrain::SelectionHint::MID_SHIP);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700298 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,
Austin Schuh872723c2019-12-25 14:38:09 -0800334 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,
Austin Schuh872723c2019-12-25 14:38:09 -0800349 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