blob: d0407560d168c6ade3e2d597585ca9f1192205de [file] [log] [blame]
Austin Schuh80ff2e12014-03-08 12:06:19 -08001#include <stdio.h>
2
3#include <memory>
Austin Schuh47017412013-03-10 11:50:46 -07004
Brian3afd6fc2014-04-02 20:41:49 -07005#include "aos/common/util/phased_loop.h"
Austin Schuh47017412013-03-10 11:50:46 -07006#include "aos/common/time.h"
Austin Schuh6be011a2013-03-19 10:07:02 +00007#include "aos/common/util/trapezoid_profile.h"
Brian Silverman598800f2013-05-09 17:08:42 -07008#include "aos/common/logging/logging.h"
Brian Silverman6f621542014-04-06 16:00:41 -07009#include "aos/common/logging/queue_logging.h"
Brian Silverman598800f2013-05-09 17:08:42 -070010
11#include "frc971/autonomous/auto.q.h"
Austin Schuh6be011a2013-03-19 10:07:02 +000012#include "frc971/constants.h"
13#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Daniel Petti3b1e48f2015-02-15 15:57:53 -080014#include "frc971/actors/drivetrain_actor.h"
Ben Fredrickson0a6ad252015-03-15 18:51:42 -070015#include "frc971/control_loops/claw/claw.q.h"
Brian Silverman5bfda6c2015-03-21 23:40:13 -070016#include "frc971/control_loops/fridge/fridge.q.h"
Ben Fredrickson0a6ad252015-03-15 18:51:42 -070017#include "frc971/actors/pickup_actor.h"
18#include "frc971/actors/stack_actor.h"
Austin Schuh1f3764e2015-04-18 23:00:09 -070019#include "frc971/actors/held_to_lift_actor.h"
Austin Schuh47017412013-03-10 11:50:46 -070020
21using ::aos::time::Time;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -070022using ::frc971::control_loops::claw_queue;
Brian Silverman5bfda6c2015-03-21 23:40:13 -070023using ::frc971::control_loops::fridge_queue;
Brian Silverman93936f72015-03-19 23:38:30 -070024using ::frc971::control_loops::drivetrain_queue;
Austin Schuh47017412013-03-10 11:50:46 -070025
26namespace frc971 {
27namespace autonomous {
28
Ben Fredrickson0a6ad252015-03-15 18:51:42 -070029constexpr double kClawAutoVelocity = 3.00;
30constexpr double kClawAutoAcceleration = 6.0;
31constexpr double kAngleEpsilon = 0.10;
Austin Schuh1f3764e2015-04-18 23:00:09 -070032const double kClawTotePackAngle = 0.90;
33const double kArmRaiseLowerClearance = -0.08;
34const double kClawStackClearance = 0.55;
35const double kStackUpHeight = 0.60;
36const double kStackUpArm = 0.0;
37
38struct ProfileParams {
39 double velocity;
40 double acceleration;
41};
Ben Fredrickson0a6ad252015-03-15 18:51:42 -070042
Austin Schuh80ff2e12014-03-08 12:06:19 -080043namespace time = ::aos::time;
44
Brian Silverman3b89ed82013-03-22 18:59:16 -070045static double left_initial_position, right_initial_position;
46
Austin Schuh6be011a2013-03-19 10:07:02 +000047bool ShouldExitAuto() {
48 ::frc971::autonomous::autonomous.FetchLatest();
49 bool ans = !::frc971::autonomous::autonomous->run_auto;
50 if (ans) {
51 LOG(INFO, "Time to exit auto mode\n");
52 }
53 return ans;
54}
55
Austin Schuh6be011a2013-03-19 10:07:02 +000056void StopDrivetrain() {
57 LOG(INFO, "Stopping the drivetrain\n");
Brian Silvermanada5f2c2015-02-01 02:41:14 -050058 control_loops::drivetrain_queue.goal.MakeWithBuilder()
Brian Silverman3b89ed82013-03-22 18:59:16 -070059 .control_loop_driving(true)
Brian Silvermance86bac2013-03-31 19:07:24 -070060 .left_goal(left_initial_position)
61 .left_velocity_goal(0)
62 .right_goal(right_initial_position)
63 .right_velocity_goal(0)
64 .quickturn(false)
65 .Send();
66}
67
68void ResetDrivetrain() {
69 LOG(INFO, "resetting the drivetrain\n");
Brian Silvermanada5f2c2015-02-01 02:41:14 -050070 control_loops::drivetrain_queue.goal.MakeWithBuilder()
Brian Silvermance86bac2013-03-31 19:07:24 -070071 .control_loop_driving(false)
Brian Silverman93335ae2015-01-26 20:43:39 -050072 //.highgear(false)
Austin Schuh6be011a2013-03-19 10:07:02 +000073 .steering(0.0)
74 .throttle(0.0)
Brian Silverman38ea9bf2014-04-19 22:57:54 -070075 .left_goal(left_initial_position)
76 .left_velocity_goal(0)
77 .right_goal(right_initial_position)
78 .right_velocity_goal(0)
Austin Schuh6be011a2013-03-19 10:07:02 +000079 .Send();
80}
81
Austin Schuh1f3764e2015-04-18 23:00:09 -070082void WaitUntilDoneOrCanceled(
83 ::std::unique_ptr<aos::common::actions::Action> action) {
84 if (!action) {
85 LOG(ERROR, "No action, not waiting\n");
86 return;
Brian Silverman3b89ed82013-03-22 18:59:16 -070087 }
Austin Schuh80ff2e12014-03-08 12:06:19 -080088 while (true) {
89 // Poll the running bit and auto done bits.
Brian Silverman547abb32015-02-16 00:37:48 -050090 ::aos::time::PhasedLoopXMS(5, 2500);
Austin Schuh80ff2e12014-03-08 12:06:19 -080091 if (!action->Running() || ShouldExitAuto()) {
92 return;
93 }
94 }
95}
96
Austin Schuh1f3764e2015-04-18 23:00:09 -070097void StepDrive(double distance, double theta) {
98 double left_goal = (left_initial_position + distance -
99 theta * constants::GetValues().turn_width / 2.0);
100 double right_goal = (right_initial_position + distance +
101 theta * constants::GetValues().turn_width / 2.0);
102 control_loops::drivetrain_queue.goal.MakeWithBuilder()
103 .control_loop_driving(true)
104 .left_goal(left_goal)
105 .right_goal(right_goal)
106 .left_velocity_goal(0.0)
107 .right_velocity_goal(0.0)
108 .Send();
109 left_initial_position = left_goal;
110 right_initial_position = right_goal;
111}
112
113void WaitUntilNear(double distance) {
114 while (true) {
115 if (ShouldExitAuto()) return;
116 control_loops::drivetrain_queue.status.FetchAnother();
117 double left_error = ::std::abs(
118 left_initial_position -
119 control_loops::drivetrain_queue.status->filtered_left_position);
120 double right_error = ::std::abs(
121 right_initial_position -
122 control_loops::drivetrain_queue.status->filtered_right_position);
123 const double kPositionThreshold = 0.05 + distance;
124 if (right_error < kPositionThreshold && left_error < kPositionThreshold) {
125 LOG(INFO, "At the goal\n");
126 return;
127 }
128 }
129}
130
131const ProfileParams kFastDrive = {2.0, 3.5};
132const ProfileParams kFastKnockDrive = {2.0, 3.0};
Austin Schuh9c414f42015-04-19 20:01:56 -0700133const ProfileParams kStackingSecondDrive = {2.0, 1.5};
Austin Schuh1f3764e2015-04-18 23:00:09 -0700134const ProfileParams kFastTurn = {3.0, 10.0};
Austin Schuh9c414f42015-04-19 20:01:56 -0700135const ProfileParams kStackingFirstTurn = {1.0, 1.0};
136const ProfileParams kStackingSecondTurn = {2.0, 6.0};
Austin Schuh1f3764e2015-04-18 23:00:09 -0700137const ProfileParams kComboTurn = {1.2, 8.0};
138const ProfileParams kRaceTurn = {4.0, 10.0};
139const ProfileParams kRaceDrive = {2.0, 2.0};
140const ProfileParams kRaceBackupDrive = {2.0, 5.0};
141
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -0800142::std::unique_ptr<::frc971::actors::DrivetrainAction> SetDriveGoal(
Austin Schuh1f3764e2015-04-18 23:00:09 -0700143 double distance, const ProfileParams drive_params, double theta = 0, const ProfileParams &turn_params = kFastTurn) {
Austin Schuha4faacc2014-03-09 00:50:50 -0800144 LOG(INFO, "Driving to %f\n", distance);
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -0800145
146 ::frc971::actors::DrivetrainActionParams params;
147 params.left_initial_position = left_initial_position;
148 params.right_initial_position = right_initial_position;
149 params.y_offset = distance;
150 params.theta_offset = theta;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700151 params.maximum_turn_acceleration = turn_params.acceleration;
152 params.maximum_turn_velocity = turn_params.velocity;
153 params.maximum_velocity = drive_params.velocity;
154 params.maximum_acceleration = drive_params.acceleration;
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -0800155 auto drivetrain_action = actors::MakeDrivetrainAction(params);
156
Austin Schuh80ff2e12014-03-08 12:06:19 -0800157 drivetrain_action->Start();
Brian Silvermanad9e0002014-04-13 14:55:57 -0700158 left_initial_position +=
159 distance - theta * constants::GetValues().turn_width / 2.0;
160 right_initial_position +=
Daniel Pettib0733be2014-11-14 22:44:03 -0800161 distance + theta * constants::GetValues().turn_width / 2.0;
Austin Schuh80ff2e12014-03-08 12:06:19 -0800162 return ::std::move(drivetrain_action);
163}
164
Austin Schuh1f3764e2015-04-18 23:00:09 -0700165const ProfileParams kFridgeYProfile{1.0, 4.0};
166const ProfileParams kFridgeXProfile{1.0, 2.0};
167const ProfileParams kFridgeFastXProfile{1.2, 5.0};
168
169static double fridge_goal_x = 0.0;
170static double fridge_goal_y = 0.0;
171
172void MoveFridge(double x, double y, bool grabbers, const ProfileParams x_params,
173 const ProfileParams y_params) {
174 auto new_fridge_goal = fridge_queue.goal.MakeMessage();
175 new_fridge_goal->profiling_type = 1;
176
177 new_fridge_goal->max_y_velocity = y_params.velocity;
178 new_fridge_goal->max_y_acceleration = y_params.acceleration;
179 new_fridge_goal->y = y;
180 fridge_goal_y = y;
181 new_fridge_goal->y_velocity = 0.0;
182
183 new_fridge_goal->max_x_velocity = x_params.velocity;
184 new_fridge_goal->max_x_acceleration = x_params.acceleration;
185 new_fridge_goal->x = x;
186 fridge_goal_x = x;
187 new_fridge_goal->x_velocity = 0.0;
188
189 new_fridge_goal->grabbers.top_front = grabbers;
190 new_fridge_goal->grabbers.top_back = grabbers;
191 new_fridge_goal->grabbers.bottom_front = grabbers;
192 new_fridge_goal->grabbers.bottom_back = grabbers;
193
194 if (!new_fridge_goal.Send()) {
195 LOG(ERROR, "Sending fridge goal failed.\n");
196 return;
Brian Silverman3b89ed82013-03-22 18:59:16 -0700197 }
Austin Schuh1f3764e2015-04-18 23:00:09 -0700198}
199
200void WaitForFridge() {
201 while (true) {
202 if (ShouldExitAuto()) return;
203 control_loops::fridge_queue.status.FetchAnother();
204
205 constexpr double kProfileError = 1e-5;
206 constexpr double kXEpsilon = 0.03, kYEpsilon = 0.03;
207
208 if (control_loops::fridge_queue.status->state != 4) {
209 LOG(ERROR, "Fridge no longer running, aborting action\n");
210 return;
211 }
212
213 if (::std::abs(control_loops::fridge_queue.status->goal_x - fridge_goal_x) <
214 kProfileError &&
215 ::std::abs(control_loops::fridge_queue.status->goal_y - fridge_goal_y) <
216 kProfileError &&
217 ::std::abs(control_loops::fridge_queue.status->goal_x_velocity) <
218 kProfileError &&
219 ::std::abs(control_loops::fridge_queue.status->goal_y_velocity) <
220 kProfileError) {
221 LOG(INFO, "Profile done.\n");
222 if (::std::abs(control_loops::fridge_queue.status->x - fridge_goal_x) <
223 kXEpsilon &&
224 ::std::abs(control_loops::fridge_queue.status->y - fridge_goal_y) <
225 kYEpsilon) {
226 LOG(INFO, "Near goal, done.\n");
227 return;
228 }
229 }
230 }
231}
232
233void InitializeEncoders() {
234 control_loops::drivetrain_queue.status.FetchAnother();
Brian Silverman3b89ed82013-03-22 18:59:16 -0700235 left_initial_position =
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500236 control_loops::drivetrain_queue.status->filtered_left_position;
Brian Silverman3b89ed82013-03-22 18:59:16 -0700237 right_initial_position =
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500238 control_loops::drivetrain_queue.status->filtered_right_position;
Austin Schuh80ff2e12014-03-08 12:06:19 -0800239}
240
Austin Schuh1f3764e2015-04-18 23:00:09 -0700241void WaitForClawZero() {
242 LOG(INFO, "Waiting for claw to zero.\n");
243 while (true) {
244 control_loops::claw_queue.status.FetchAnother();
245 LOG_STRUCT(DEBUG, "Got claw status", *control_loops::claw_queue.status);
246 if (control_loops::claw_queue.status->zeroed) {
247 LOG(INFO, "Claw zeroed\n");
248 return;
249 }
250
251 if (ShouldExitAuto()) return;
252 }
253}
254
255void WaitForFridgeZero() {
256 LOG(INFO, "Waiting for claw to zero.\n");
257 while (true) {
258 control_loops::fridge_queue.status.FetchAnother();
259 LOG_STRUCT(DEBUG, "Got fridge status", *control_loops::fridge_queue.status);
260 if (control_loops::fridge_queue.status->zeroed) {
261 LOG(INFO, "Fridge zeroed\n");
262 return;
263 }
264
265 if (ShouldExitAuto()) return;
266 }
267}
268
269constexpr ProfileParams kDefaultClawParams = {kClawAutoVelocity,
270 kClawAutoAcceleration};
271
272// Move the claw in a very small number of cycles.
273constexpr ProfileParams kInstantaneousClaw = {100.0, 100.0};
274constexpr ProfileParams kFastClaw = {8.0, 20.0};
275
276void SetClawStateNoWait(double angle, double intake_voltage,
277 double rollers_closed,
278 const ProfileParams &claw_params = kDefaultClawParams) {
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700279 auto message = control_loops::claw_queue.goal.MakeMessage();
280 message->angle = angle;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700281 message->max_velocity = claw_params.velocity;
282 message->max_acceleration = claw_params.acceleration;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700283 message->angular_velocity = 0.0;
284 message->intake = intake_voltage;
285 message->rollers_closed = rollers_closed;
286
287 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
288 message.Send();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700289}
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700290
Austin Schuh1f3764e2015-04-18 23:00:09 -0700291void SetClawState(double angle, double intake_voltage, double rollers_closed,
292 const ProfileParams &claw_params = kDefaultClawParams) {
293 SetClawStateNoWait(angle, intake_voltage, rollers_closed, claw_params);
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700294 while (true) {
295 control_loops::claw_queue.status.FetchAnother();
296 const double current_angle = control_loops::claw_queue.status->angle;
297 LOG_STRUCT(DEBUG, "Got claw status", *control_loops::claw_queue.status);
298
299 // I believe all we can care about here is the angle. Other values will
300 // either be set or not, but there is nothing we can do about it. If it
301 // never gets there we do not care, auto is over for us.
302 if (::std::abs(current_angle - angle) < kAngleEpsilon) {
303 break;
304 }
Austin Schuh1f3764e2015-04-18 23:00:09 -0700305 if (ShouldExitAuto()) return;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700306 }
307}
308
Austin Schuh80ff2e12014-03-08 12:06:19 -0800309void HandleAuto() {
Austin Schuh577edf62014-04-13 10:33:05 -0700310 ::aos::time::Time start_time = ::aos::time::Time::Now();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700311 LOG(INFO, "Starting auto mode at %f\n", start_time.ToSeconds());
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700312 ::std::unique_ptr<::frc971::actors::DrivetrainAction> drive;
313 ::std::unique_ptr<::frc971::actors::PickupAction> pickup;
314 ::std::unique_ptr<::frc971::actors::StackAction> stack;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700315 ::std::unique_ptr<::frc971::actors::HeldToLiftAction> lift;
Austin Schuh80ff2e12014-03-08 12:06:19 -0800316
Austin Schuh9c414f42015-04-19 20:01:56 -0700317 actors::PickupParams pickup_params;
318 // Lift to here initially.
319 pickup_params.pickup_angle = 0.9;
320 // Start sucking here
321 pickup_params.suck_angle = 0.8;
322 // Go back down to here to finish sucking.
323 pickup_params.suck_angle_finish = 0.4;
324 // Pack the box back in here.
325 pickup_params.pickup_finish_angle = kClawTotePackAngle;
326 pickup_params.intake_time = 0.70;
327 pickup_params.intake_voltage = 7.0;
328
Austin Schuh80ff2e12014-03-08 12:06:19 -0800329 if (ShouldExitAuto()) return;
330 InitializeEncoders();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700331 ResetDrivetrain();
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700332
Austin Schuh1f3764e2015-04-18 23:00:09 -0700333 WaitForClawZero();
334 WaitForFridgeZero();
Brian Silverman93936f72015-03-19 23:38:30 -0700335
Austin Schuh1f3764e2015-04-18 23:00:09 -0700336 // Initialize the fridge.
337 MoveFridge(0.0, 0.3, true, kFridgeXProfile, kFridgeYProfile);
Brian Silverman93936f72015-03-19 23:38:30 -0700338
Austin Schuh1f3764e2015-04-18 23:00:09 -0700339 LOG(INFO, "Lowering claw into position.\n");
340 SetClawState(0.0, 2.0, false, kInstantaneousClaw);
Austin Schuh9c414f42015-04-19 20:01:56 -0700341
Austin Schuh1f3764e2015-04-18 23:00:09 -0700342 LOG(INFO, "Sucking in tote.\n");
Austin Schuh9c414f42015-04-19 20:01:56 -0700343 SetClawState(0.0, 6.0, true, kInstantaneousClaw);
Brian Silverman93936f72015-03-19 23:38:30 -0700344
Austin Schuh1f3764e2015-04-18 23:00:09 -0700345 time::SleepFor(time::Time::InSeconds(0.7));
346 LOG(INFO, "Done sucking in tote\n");
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700347
Austin Schuh1f3764e2015-04-18 23:00:09 -0700348 // Now pick it up
Austin Schuh9c414f42015-04-19 20:01:56 -0700349 pickup = actors::MakePickupAction(pickup_params);
350 pickup->Start();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700351
352 time::SleepFor(time::Time::InSeconds(0.9));
353 // Start turning.
354 LOG(INFO, "Turning in place\n");
Austin Schuh9c414f42015-04-19 20:01:56 -0700355 drive = SetDriveGoal(0.0, kFastDrive, -0.23, kStackingFirstTurn);
Austin Schuh1f3764e2015-04-18 23:00:09 -0700356
357 WaitUntilDoneOrCanceled(::std::move(drive));
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700358 if (ShouldExitAuto()) return;
359
Austin Schuh1f3764e2015-04-18 23:00:09 -0700360 LOG(INFO, "Now driving next to the can\n");
361 drive = SetDriveGoal(0.60, kFastDrive);
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700362
Austin Schuh1f3764e2015-04-18 23:00:09 -0700363 WaitUntilDoneOrCanceled(::std::move(pickup));
364 if (ShouldExitAuto()) return;
365
366 // Now grab it in the fridge.
367 {
368 actors::StackParams params;
369
370 params.claw_out_angle = kClawTotePackAngle;
371 params.bottom = 0.020;
372 params.only_place = false;
373 params.arm_clearance = kArmRaiseLowerClearance;
374 params.over_box_before_place_height = 0.39;
375
376 stack = actors::MakeStackAction(params);
377 stack->Start();
378 }
379 WaitUntilDoneOrCanceled(::std::move(stack));
380 if (ShouldExitAuto()) return;
381
382 // Lower the claw to knock the tote.
383 LOG(INFO, "Lowering the claw to knock the tote\n");
384 SetClawStateNoWait(0.0, 0.0, true, kFastClaw);
385
386 time::SleepFor(time::Time::InSeconds(0.1));
387 if (ShouldExitAuto()) return;
388
389 WaitUntilDoneOrCanceled(::std::move(drive));
390 if (ShouldExitAuto()) return;
391
392 LOG(INFO, "Knocking the can over\n");
Austin Schuh9c414f42015-04-19 20:01:56 -0700393 drive = SetDriveGoal(0.40, kFastKnockDrive, 1.05, kComboTurn);
Austin Schuh1f3764e2015-04-18 23:00:09 -0700394 WaitUntilDoneOrCanceled(::std::move(drive));
395 if (ShouldExitAuto()) return;
396 {
397 actors::HeldToLiftParams params;
398 params.arm_clearance = kArmRaiseLowerClearance;
399 params.clamp_pause_time = 0.1;
400 params.before_lift_settle_time = 0.1;
401 params.bottom_height = 0.020;
402 params.claw_out_angle = kClawStackClearance;
403 params.lift_params.lift_height = kStackUpHeight;
404 params.lift_params.lift_arm = kStackUpArm;
Austin Schuh3cba3792015-04-19 20:01:22 -0700405 params.lift_params.second_lift = false;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700406
407 lift = actors::MakeHeldToLiftAction(params);
408 lift->Start();
409 }
410
411 LOG(INFO, "Turning back to aim\n");
412 drive = SetDriveGoal(0.0, kFastDrive, -0.70);
413 WaitUntilDoneOrCanceled(::std::move(drive));
414 if (ShouldExitAuto()) return;
415
416 SetClawStateNoWait(0.0, 4.0, false, kFastClaw);
417 LOG(INFO, "Now driving the second tote\n");
418 drive = SetDriveGoal(1.05, kFastDrive);
419
420 // Wait until we are almost at the tote, and then start intaking.
Austin Schuh9c414f42015-04-19 20:01:56 -0700421 WaitUntilNear(0.35);
Austin Schuh1f3764e2015-04-18 23:00:09 -0700422
423 SetClawState(0.0, 6.0, true, kFastClaw);
424 WaitUntilDoneOrCanceled(::std::move(drive));
425 if (ShouldExitAuto()) return;
426
427 if (ShouldExitAuto()) return;
Austin Schuh9c414f42015-04-19 20:01:56 -0700428 time::SleepFor(time::Time::InSeconds(0.30));
429 if (ShouldExitAuto()) return;
430
431 SetClawStateNoWait(0.0, 4.0, true, kFastClaw);
432 if (ShouldExitAuto()) return;
433 time::SleepFor(time::Time::InSeconds(0.10));
Austin Schuh1f3764e2015-04-18 23:00:09 -0700434
435 WaitUntilDoneOrCanceled(::std::move(lift));
436 if (ShouldExitAuto()) return;
437
438 LOG(INFO, "Done sucking in tote\n");
439 SetClawState(0.0, 0.0, true, kFastClaw);
440 if (ShouldExitAuto()) return;
441
442 // Now pick it up
Austin Schuh9c414f42015-04-19 20:01:56 -0700443 pickup = actors::MakePickupAction(pickup_params);
444 pickup->Start();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700445
Austin Schuh9c414f42015-04-19 20:01:56 -0700446 time::SleepFor(time::Time::InSeconds(1.0));
Austin Schuh1f3764e2015-04-18 23:00:09 -0700447 if (ShouldExitAuto()) return;
448
449 // Start turning.
450 LOG(INFO, "Turning in place\n");
Austin Schuh9c414f42015-04-19 20:01:56 -0700451 drive = SetDriveGoal(0.0, kStackingSecondDrive, -0.40, kStackingSecondTurn);
Austin Schuh1f3764e2015-04-18 23:00:09 -0700452
453 WaitUntilDoneOrCanceled(::std::move(pickup));
454 if (ShouldExitAuto()) return;
455
456 // Now grab it in the fridge.
457 {
458 actors::StackParams params;
459
460 params.claw_out_angle = kClawTotePackAngle;
461 params.bottom = 0.020;
462 params.only_place = false;
463 params.arm_clearance = kArmRaiseLowerClearance;
464 params.over_box_before_place_height = 0.39;
465
466 stack = actors::MakeStackAction(params);
467 stack->Start();
468 }
469
Austin Schuh1f3764e2015-04-18 23:00:09 -0700470 WaitUntilDoneOrCanceled(::std::move(drive));
471 if (ShouldExitAuto()) return;
Austin Schuh9c414f42015-04-19 20:01:56 -0700472 LOG(INFO, "Driving next to the can.\n");
473 drive = SetDriveGoal(0.65, kStackingSecondDrive);
474
475 WaitUntilDoneOrCanceled(::std::move(stack));
476 if (ShouldExitAuto()) return;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700477
478 // Lower the claw to knock the tote.
479 LOG(INFO, "Lowering the claw to knock the tote\n");
480 SetClawStateNoWait(0.0, 0.0, true, kFastClaw);
481
482 // Lift the fridge.
483 MoveFridge(0.0, 0.3, true, kFridgeXProfile, kFridgeYProfile);
484
485 time::SleepFor(time::Time::InSeconds(0.1));
486 if (ShouldExitAuto()) return;
487
Austin Schuh9c414f42015-04-19 20:01:56 -0700488 WaitUntilDoneOrCanceled(::std::move(drive));
489 if (ShouldExitAuto()) return;
490
Austin Schuh1f3764e2015-04-18 23:00:09 -0700491 LOG(INFO, "Knocking the can over\n");
Austin Schuh9c414f42015-04-19 20:01:56 -0700492 drive = SetDriveGoal(0.40, kFastKnockDrive, 1.05, kComboTurn);
Austin Schuh1f3764e2015-04-18 23:00:09 -0700493 WaitUntilDoneOrCanceled(::std::move(drive));
494 if (ShouldExitAuto()) return;
495
496 LOG(INFO, "Turning back to aim\n");
497 drive = SetDriveGoal(0.0, kFastDrive, -0.60);
498 WaitUntilDoneOrCanceled(::std::move(drive));
499 if (ShouldExitAuto()) return;
500
501
502 SetClawStateNoWait(0.0, 4.0, false, kFastClaw);
503 LOG(INFO, "Now driving to the last tote\n");
504 drive = SetDriveGoal(1.05, kFastDrive);
505 WaitUntilNear(0.05);
506
507 SetClawState(0.0, 7.0, true, kFastClaw);
508 if (ShouldExitAuto()) return;
509
510 time::SleepFor(time::Time::InSeconds(0.2));
511 if (ShouldExitAuto()) return;
512
513 WaitUntilDoneOrCanceled(::std::move(drive));
514 if (ShouldExitAuto()) return;
515 SetClawState(0.0, 6.0, true, kFastClaw);
516
517 LOG(INFO, "Racing over\n");
518 //StepDrive(2.5, -1.4);
519 drive = SetDriveGoal(2.5, kRaceDrive, -1.4, kRaceTurn);
520
521 time::SleepFor(time::Time::InSeconds(0.5));
522
523 LOG(INFO, "Moving totes out\n");
524 MoveFridge(0.6, 0.32, true, kFridgeXProfile, kFridgeYProfile);
525
526 WaitForFridge();
527 if (ShouldExitAuto()) return;
528
529 LOG(INFO, "Lowering totes\n");
530 MoveFridge(0.6, 0.15, false, kFridgeXProfile, kFridgeYProfile);
531
532 WaitForFridge();
533 if (ShouldExitAuto()) return;
534
535 time::SleepFor(time::Time::InSeconds(0.1));
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700536
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700537 if (ShouldExitAuto()) return;
538
Austin Schuh1f3764e2015-04-18 23:00:09 -0700539 LOG(INFO, "Retracting\n");
540 MoveFridge(0.0, 0.10, false, kFridgeFastXProfile, kFridgeYProfile);
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700541
Austin Schuh1f3764e2015-04-18 23:00:09 -0700542 SetClawState(0.0, 0.0, false, kFastClaw);
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700543
Austin Schuh1f3764e2015-04-18 23:00:09 -0700544 if (ShouldExitAuto()) return;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700545
Austin Schuh1f3764e2015-04-18 23:00:09 -0700546 WaitUntilDoneOrCanceled(::std::move(drive));
547 if (ShouldExitAuto()) return;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700548
Austin Schuh1f3764e2015-04-18 23:00:09 -0700549 LOG(INFO, "Backing away to let the stack ago\n");
550 drive = SetDriveGoal(-0.1, kRaceBackupDrive);
551 WaitUntilDoneOrCanceled(::std::move(drive));
Austin Schuh9c414f42015-04-19 20:01:56 -0700552
553 WaitForFridge();
554 if (ShouldExitAuto()) return;
Austin Schuh47017412013-03-10 11:50:46 -0700555}
556
557} // namespace autonomous
558} // namespace frc971