blob: 7622a64d7106c0246ba0ae090bbed30b3e62f02e [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);
Austin Schuhb5b79a52019-05-08 20:32:07 -070038 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
Austin Schuhd32b3622019-06-23 18:49:06 -070039 event_loop()->monotonic_now(),
Austin Schuhb5b79a52019-05-08 20:32:07 -070040 ::std::chrono::milliseconds(5) / 2);
41
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);
Austin Schuhb5b79a52019-05-08 20:32:07 -070057 ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5),
Austin Schuhd32b3622019-06-23 18:49:06 -070058 event_loop()->monotonic_now(),
Austin Schuhb5b79a52019-05-08 20:32:07 -070059 ::std::chrono::milliseconds(5) / 2);
60
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);
101 if (!builder.Send(localizer_control_builder.Finish())) {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700102 AOS_LOG(ERROR, "Failed to reset localizer.\n");
Austin Schuh13379ba2019-03-12 21:06:46 -0700103 }
104 }
105
106 // Wait for the drivetrain to run so it has time to reset the heading.
107 // Otherwise our drivetrain reset will do a 180 right at the start.
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700108 WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
Austin Schuhf257f3c2019-10-27 21:00:43 -0700109 AOS_LOG(INFO, "Heading is %f\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700110 drivetrain_status_fetcher_->estimated_heading());
Austin Schuh13379ba2019-03-12 21:06:46 -0700111 InitializeEncoders();
112 ResetDrivetrain();
Austin Schuhbd0a40f2019-06-30 14:56:31 -0700113 WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); });
Austin Schuhf257f3c2019-10-27 21:00:43 -0700114 AOS_LOG(INFO, "Heading is %f\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700115 drivetrain_status_fetcher_->estimated_heading());
Austin Schuh13379ba2019-03-12 21:06:46 -0700116
117 ResetDrivetrain();
118 InitializeEncoders();
119}
120
Alex Perrycb7da4b2019-08-28 19:35:56 -0700121ProfileParametersT MakeProfileParameters(float max_velocity,
122 float max_acceleration) {
123 ProfileParametersT result;
124 result.max_velocity = max_velocity;
125 result.max_acceleration = max_acceleration;
126 return result;
127}
128
129const ProfileParametersT kJumpDrive = MakeProfileParameters(2.0, 3.0);
130const ProfileParametersT kDrive = MakeProfileParameters(4.0, 3.0);
131const ProfileParametersT kTurn = MakeProfileParameters(5.0, 15.0);
Austin Schuh13379ba2019-03-12 21:06:46 -0700132
Austin Schuhb5b79a52019-05-08 20:32:07 -0700133const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0};
134const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0};
135
136const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0};
137const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0};
138
139const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0};
140
141const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0};
142
Alex Perrycb7da4b2019-08-28 19:35:56 -0700143template <typename Functor>
144std::function<flatbuffers::Offset<frc971::MultiSpline>(
James Kuszmaul75a18c52021-03-10 22:02:07 -0800145 aos::Sender<frc971::control_loops::drivetrain::SplineGoal>::Builder
146 *builder)>
Alex Perrycb7da4b2019-08-28 19:35:56 -0700147BindIsLeft(Functor f, bool is_left) {
James Kuszmaul75a18c52021-03-10 22:02:07 -0800148 return [is_left,
149 f](aos::Sender<frc971::control_loops::drivetrain::SplineGoal>::Builder
150 *builder) { return f(builder, is_left); };
Alex Perrycb7da4b2019-08-28 19:35:56 -0700151}
152
Austin Schuh13379ba2019-03-12 21:06:46 -0700153bool AutonomousActor::RunAction(
Alex Perrycb7da4b2019-08-28 19:35:56 -0700154 const ::frc971::autonomous::AutonomousActionParams *params) {
Austin Schuh77ed5432019-07-07 20:41:36 -0700155 const monotonic_clock::time_point start_time = monotonic_now();
Alex Perrycb7da4b2019-08-28 19:35:56 -0700156 const bool is_left = params->mode() == 0;
Austin Schuha9644062019-03-28 14:31:52 -0700157
158 {
Austin Schuhf257f3c2019-10-27 21:00:43 -0700159 AOS_LOG(INFO, "Starting autonomous action with mode %" PRId32 " %s\n",
Alex Perrycb7da4b2019-08-28 19:35:56 -0700160 params->mode(), is_left ? "left" : "right");
Austin Schuha9644062019-03-28 14:31:52 -0700161 }
Austin Schuhb5b79a52019-05-08 20:32:07 -0700162
Austin Schuha9644062019-03-28 14:31:52 -0700163 const double turn_scalar = is_left ? 1.0 : -1.0;
164
165 Reset(is_left);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700166 enum class Mode { kTesting, kRocket, kCargoship };
167 Mode mode = Mode::kCargoship;
168 if (mode == Mode::kRocket) {
169 SplineHandle spline1 =
Alex Perrycb7da4b2019-08-28 19:35:56 -0700170 PlanSpline(BindIsLeft(AutonomousSplines::HabToFarRocketTest, is_left),
Austin Schuhb5b79a52019-05-08 20:32:07 -0700171 SplineDirection::kBackward);
Austin Schuh13379ba2019-03-12 21:06:46 -0700172
Austin Schuhb5b79a52019-05-08 20:32:07 -0700173 // Grab the disk, jump, wait until we have vacuum, then raise the elevator
174 set_elevator_goal(0.010);
175 set_wrist_goal(-M_PI / 2.0);
176 set_intake_goal(-1.2);
177 set_suction_goal(true, 1);
178 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700179
Austin Schuhb5b79a52019-05-08 20:32:07 -0700180 // if planned start the spline and plan the next
181 if (!spline1.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700182 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700183 spline1.Start();
Austin Schuh13379ba2019-03-12 21:06:46 -0700184
Austin Schuhb5b79a52019-05-08 20:32:07 -0700185 // If suction, move the superstructure to score
186 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700187 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700188 if (!spline1.WaitForSplineDistanceRemaining(3.5)) return true;
189 set_elevator_wrist_goal(kPanelBackwardMiddlePos);
190 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700191
Austin Schuhb5b79a52019-05-08 20:32:07 -0700192 if (!spline1.WaitForSplineDistanceRemaining(2.0)) return true;
193 set_elevator_wrist_goal(kPanelForwardMiddlePos);
194 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700195
Austin Schuhb5b79a52019-05-08 20:32:07 -0700196 // END SPLINE 1
Austin Schuh13379ba2019-03-12 21:06:46 -0700197
Austin Schuhb5b79a52019-05-08 20:32:07 -0700198 if (!spline1.WaitForSplineDistanceRemaining(0.2)) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700199 LineFollowAtVelocity(1.3,
Austin Schuh872723c2019-12-25 14:38:09 -0800200 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700201 if (!WaitForMilliseconds(::std::chrono::milliseconds(1200))) return true;
Austin Schuh13379ba2019-03-12 21:06:46 -0700202
Austin Schuhb5b79a52019-05-08 20:32:07 -0700203 set_suction_goal(false, 1);
204 SendSuperstructureGoal();
205 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700206 LineFollowAtVelocity(-1.0,
Austin Schuh872723c2019-12-25 14:38:09 -0800207 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700208 SplineHandle spline2 =
209 PlanSpline(BindIsLeft(AutonomousSplines::FarRocketToHP, is_left),
210 SplineDirection::kBackward);
Austin Schuh13379ba2019-03-12 21:06:46 -0700211
Austin Schuhb5b79a52019-05-08 20:32:07 -0700212 if (!WaitForMilliseconds(::std::chrono::milliseconds(150))) return true;
213 if (!spline2.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700214 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700215 // Drive back to hp and set the superstructure accordingly
216 spline2.Start();
217 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
218 set_elevator_wrist_goal(kPanelHPIntakeBackwardPos);
219 SendSuperstructureGoal();
220 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
221 set_suction_goal(true, 1);
222 SendSuperstructureGoal();
Austin Schuh13379ba2019-03-12 21:06:46 -0700223
Austin Schuhb5b79a52019-05-08 20:32:07 -0700224 if (!spline2.WaitForSplineDistanceRemaining(1.6)) return true;
225 LineFollowAtVelocity(-1.6);
226
227 // As soon as we pick up Panel 2 go score on the back rocket
228 if (!WaitForGamePiece()) return true;
229 LineFollowAtVelocity(1.5);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700230 SplineHandle spline3 =
231 PlanSpline(BindIsLeft(AutonomousSplines::HPToFarRocket, is_left),
232 SplineDirection::kForward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700233 if (!WaitForDriveXGreater(0.50)) return true;
234 if (!spline3.WaitForPlan()) return true;
235 spline3.Start();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700236 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700237 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
238 set_elevator_wrist_goal(kPanelBackwardMiddlePos);
239 SendSuperstructureGoal();
240 if (!WaitForDriveXGreater(7.1)) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700241 LineFollowAtVelocity(-1.5,
Austin Schuh872723c2019-12-25 14:38:09 -0800242 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700243 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
244 set_elevator_wrist_goal(kPanelBackwardUpperPos);
245 SendSuperstructureGoal();
246 if (!WaitForMilliseconds(::std::chrono::milliseconds(1500))) return true;
247 set_suction_goal(false, 1);
248 SendSuperstructureGoal();
249 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
Alex Perrycb7da4b2019-08-28 19:35:56 -0700250 LineFollowAtVelocity(1.0,
Austin Schuh872723c2019-12-25 14:38:09 -0800251 control_loops::drivetrain::SelectionHint::FAR_ROCKET);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700252 SendSuperstructureGoal();
253 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
254 } else if (mode == Mode::kCargoship) {
Alex Perrycb7da4b2019-08-28 19:35:56 -0700255 SplineHandle spline1 = PlanSpline(
256 BindIsLeft(AutonomousSplines::HABToSecondCargoShipBay, is_left),
257 SplineDirection::kBackward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700258 set_elevator_goal(0.01);
259 set_wrist_goal(-M_PI / 2.0);
260 set_intake_goal(-1.2);
261 set_suction_goal(true, 1);
262 SendSuperstructureGoal();
263
264 // if planned start the spline and plan the next
265 if (!spline1.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700266 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700267 spline1.Start();
268
269 // If suction, move the superstructure to score
270 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700271 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700272 // unstick the hatch panel
273 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
274 set_elevator_goal(0.5);
275 set_wrist_goal(-M_PI / 2.0);
276 SendSuperstructureGoal();
277 if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true;
278 set_elevator_wrist_goal(kPanelCargoBackwardPos);
279 SendSuperstructureGoal();
280
281 if (!spline1.WaitForSplineDistanceRemaining(0.8)) return true;
282 // Line follow in to the first disc.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700283 LineFollowAtVelocity(-0.9,
Austin Schuh872723c2019-12-25 14:38:09 -0800284 control_loops::drivetrain::SelectionHint::MID_SHIP);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700285 if (!WaitForDriveYCloseToZero(1.2)) return true;
286
287 set_suction_goal(false, 1);
288 SendSuperstructureGoal();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700289 AOS_LOG(INFO, "Dropping disc 1 %f\n",
290 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700291
292 if (!WaitForDriveYCloseToZero(1.13)) return true;
293 if (!WaitForMilliseconds(::std::chrono::milliseconds(300))) return true;
294
Alex Perrycb7da4b2019-08-28 19:35:56 -0700295 LineFollowAtVelocity(0.9,
Austin Schuh872723c2019-12-25 14:38:09 -0800296 control_loops::drivetrain::SelectionHint::MID_SHIP);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700297 SplineHandle spline2 = PlanSpline(
298 BindIsLeft(AutonomousSplines::SecondCargoShipBayToHP, is_left),
299 SplineDirection::kForward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700300 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
301 if (!spline2.WaitForPlan()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700302 AOS_LOG(INFO, "Planned\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700303 // Drive back to hp and set the superstructure accordingly
304 spline2.Start();
305 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
306 set_elevator_wrist_goal(kPanelHPIntakeForwrdPos);
307 SendSuperstructureGoal();
308 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
309 set_suction_goal(true, 1);
310 SendSuperstructureGoal();
311
312 if (!spline2.WaitForSplineDistanceRemaining(1.75)) return true;
313 LineFollowAtVelocity(1.5);
314 // As soon as we pick up Panel 2 go score on the rocket
315 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700316 AOS_LOG(INFO, "Got gamepiece %f\n",
317 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700318 LineFollowAtVelocity(-4.0);
Alex Perrycb7da4b2019-08-28 19:35:56 -0700319 SplineHandle spline3 = PlanSpline(
320 BindIsLeft(AutonomousSplines::HPToThirdCargoShipBay, is_left),
321 SplineDirection::kBackward);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700322 if (!WaitForDriveXGreater(0.55)) return true;
323 if (!spline3.WaitForPlan()) return true;
324 spline3.Start();
325 // Wait until we are a bit out to lift.
326 if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true;
327 set_elevator_wrist_goal(kPanelCargoBackwardPos);
328 SendSuperstructureGoal();
329
330 if (!spline3.WaitForSplineDistanceRemaining(0.7)) return true;
331 // Line follow in to the second disc.
Alex Perrycb7da4b2019-08-28 19:35:56 -0700332 LineFollowAtVelocity(-0.7,
Austin Schuh872723c2019-12-25 14:38:09 -0800333 control_loops::drivetrain::SelectionHint::FAR_SHIP);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700334 AOS_LOG(INFO, "Drawing in disc 2 %f\n",
335 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700336 if (!WaitForDriveYCloseToZero(1.2)) return true;
337
338 set_suction_goal(false, 1);
339 SendSuperstructureGoal();
Austin Schuhf257f3c2019-10-27 21:00:43 -0700340 AOS_LOG(INFO, "Dropping disc 2 %f\n",
341 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuhb5b79a52019-05-08 20:32:07 -0700342
343 if (!WaitForDriveYCloseToZero(1.13)) return true;
344 if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700345 AOS_LOG(INFO, "Backing up %f\n",
346 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Alex Perrycb7da4b2019-08-28 19:35:56 -0700347 LineFollowAtVelocity(0.9,
Austin Schuh872723c2019-12-25 14:38:09 -0800348 control_loops::drivetrain::SelectionHint::FAR_SHIP);
Austin Schuhb5b79a52019-05-08 20:32:07 -0700349 if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true;
350 } else {
351 // Grab the disk, wait until we have vacuum, then jump
352 set_elevator_goal(0.01);
353 set_wrist_goal(-M_PI / 2.0);
354 set_intake_goal(-1.2);
355 set_suction_goal(true, 1);
356 SendSuperstructureGoal();
357
358 if (!WaitForGamePiece()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700359 AOS_LOG(INFO, "Has game piece\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700360
361 StartDrive(-4.0, 0.0, kJumpDrive, kTurn);
362 if (!WaitForDriveNear(3.3, 10.0)) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700363 AOS_LOG(INFO, "Lifting\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700364 set_elevator_goal(0.30);
365 SendSuperstructureGoal();
366
367 if (!WaitForDriveNear(2.8, 10.0)) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700368 AOS_LOG(INFO, "Off the platform\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700369
370 StartDrive(0.0, 1.00 * turn_scalar, kDrive, kTurn);
Austin Schuhf257f3c2019-10-27 21:00:43 -0700371 AOS_LOG(INFO, "Turn started\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700372 if (!WaitForSuperstructureDone()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700373 AOS_LOG(INFO, "Superstructure done\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700374
375 if (!WaitForDriveNear(0.7, 10.0)) return true;
376 StartDrive(0.0, -0.35 * turn_scalar, kDrive, kTurn);
377
Austin Schuhf257f3c2019-10-27 21:00:43 -0700378 AOS_LOG(INFO, "Elevator up\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700379 set_elevator_goal(0.78);
380 SendSuperstructureGoal();
381
382 if (!WaitForDriveDone()) return true;
Austin Schuhf257f3c2019-10-27 21:00:43 -0700383 AOS_LOG(INFO, "Done driving\n");
Austin Schuhb5b79a52019-05-08 20:32:07 -0700384
385 if (!WaitForSuperstructureDone()) return true;
386 }
Austin Schuh13379ba2019-03-12 21:06:46 -0700387
Austin Schuhf257f3c2019-10-27 21:00:43 -0700388 AOS_LOG(INFO, "Done %f\n",
389 ::aos::time::DurationInSeconds(monotonic_now() - start_time));
Austin Schuh13379ba2019-03-12 21:06:46 -0700390
Austin Schuh13379ba2019-03-12 21:06:46 -0700391 return true;
392}
393
394} // namespace actors
395} // namespace y2019