blob: 42f4ca9c9b1fd743c1e6c53829a3a9cc012ed6c9 [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};
133const ProfileParams kStackingDrive = {2.0, 1.5};
134const ProfileParams kFastTurn = {3.0, 10.0};
135const ProfileParams kComboTurn = {1.2, 8.0};
136const ProfileParams kRaceTurn = {4.0, 10.0};
137const ProfileParams kRaceDrive = {2.0, 2.0};
138const ProfileParams kRaceBackupDrive = {2.0, 5.0};
139
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -0800140::std::unique_ptr<::frc971::actors::DrivetrainAction> SetDriveGoal(
Austin Schuh1f3764e2015-04-18 23:00:09 -0700141 double distance, const ProfileParams drive_params, double theta = 0, const ProfileParams &turn_params = kFastTurn) {
Austin Schuha4faacc2014-03-09 00:50:50 -0800142 LOG(INFO, "Driving to %f\n", distance);
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -0800143
144 ::frc971::actors::DrivetrainActionParams params;
145 params.left_initial_position = left_initial_position;
146 params.right_initial_position = right_initial_position;
147 params.y_offset = distance;
148 params.theta_offset = theta;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700149 params.maximum_turn_acceleration = turn_params.acceleration;
150 params.maximum_turn_velocity = turn_params.velocity;
151 params.maximum_velocity = drive_params.velocity;
152 params.maximum_acceleration = drive_params.acceleration;
Ben Fredrickson9fb2ab12015-02-16 16:42:08 -0800153 auto drivetrain_action = actors::MakeDrivetrainAction(params);
154
Austin Schuh80ff2e12014-03-08 12:06:19 -0800155 drivetrain_action->Start();
Brian Silvermanad9e0002014-04-13 14:55:57 -0700156 left_initial_position +=
157 distance - theta * constants::GetValues().turn_width / 2.0;
158 right_initial_position +=
Daniel Pettib0733be2014-11-14 22:44:03 -0800159 distance + theta * constants::GetValues().turn_width / 2.0;
Austin Schuh80ff2e12014-03-08 12:06:19 -0800160 return ::std::move(drivetrain_action);
161}
162
Austin Schuh1f3764e2015-04-18 23:00:09 -0700163const ProfileParams kFridgeYProfile{1.0, 4.0};
164const ProfileParams kFridgeXProfile{1.0, 2.0};
165const ProfileParams kFridgeFastXProfile{1.2, 5.0};
166
167static double fridge_goal_x = 0.0;
168static double fridge_goal_y = 0.0;
169
170void MoveFridge(double x, double y, bool grabbers, const ProfileParams x_params,
171 const ProfileParams y_params) {
172 auto new_fridge_goal = fridge_queue.goal.MakeMessage();
173 new_fridge_goal->profiling_type = 1;
174
175 new_fridge_goal->max_y_velocity = y_params.velocity;
176 new_fridge_goal->max_y_acceleration = y_params.acceleration;
177 new_fridge_goal->y = y;
178 fridge_goal_y = y;
179 new_fridge_goal->y_velocity = 0.0;
180
181 new_fridge_goal->max_x_velocity = x_params.velocity;
182 new_fridge_goal->max_x_acceleration = x_params.acceleration;
183 new_fridge_goal->x = x;
184 fridge_goal_x = x;
185 new_fridge_goal->x_velocity = 0.0;
186
187 new_fridge_goal->grabbers.top_front = grabbers;
188 new_fridge_goal->grabbers.top_back = grabbers;
189 new_fridge_goal->grabbers.bottom_front = grabbers;
190 new_fridge_goal->grabbers.bottom_back = grabbers;
191
192 if (!new_fridge_goal.Send()) {
193 LOG(ERROR, "Sending fridge goal failed.\n");
194 return;
Brian Silverman3b89ed82013-03-22 18:59:16 -0700195 }
Austin Schuh1f3764e2015-04-18 23:00:09 -0700196}
197
198void WaitForFridge() {
199 while (true) {
200 if (ShouldExitAuto()) return;
201 control_loops::fridge_queue.status.FetchAnother();
202
203 constexpr double kProfileError = 1e-5;
204 constexpr double kXEpsilon = 0.03, kYEpsilon = 0.03;
205
206 if (control_loops::fridge_queue.status->state != 4) {
207 LOG(ERROR, "Fridge no longer running, aborting action\n");
208 return;
209 }
210
211 if (::std::abs(control_loops::fridge_queue.status->goal_x - fridge_goal_x) <
212 kProfileError &&
213 ::std::abs(control_loops::fridge_queue.status->goal_y - fridge_goal_y) <
214 kProfileError &&
215 ::std::abs(control_loops::fridge_queue.status->goal_x_velocity) <
216 kProfileError &&
217 ::std::abs(control_loops::fridge_queue.status->goal_y_velocity) <
218 kProfileError) {
219 LOG(INFO, "Profile done.\n");
220 if (::std::abs(control_loops::fridge_queue.status->x - fridge_goal_x) <
221 kXEpsilon &&
222 ::std::abs(control_loops::fridge_queue.status->y - fridge_goal_y) <
223 kYEpsilon) {
224 LOG(INFO, "Near goal, done.\n");
225 return;
226 }
227 }
228 }
229}
230
231void InitializeEncoders() {
232 control_loops::drivetrain_queue.status.FetchAnother();
Brian Silverman3b89ed82013-03-22 18:59:16 -0700233 left_initial_position =
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500234 control_loops::drivetrain_queue.status->filtered_left_position;
Brian Silverman3b89ed82013-03-22 18:59:16 -0700235 right_initial_position =
Brian Silvermanada5f2c2015-02-01 02:41:14 -0500236 control_loops::drivetrain_queue.status->filtered_right_position;
Austin Schuh80ff2e12014-03-08 12:06:19 -0800237}
238
Austin Schuh1f3764e2015-04-18 23:00:09 -0700239void WaitForClawZero() {
240 LOG(INFO, "Waiting for claw to zero.\n");
241 while (true) {
242 control_loops::claw_queue.status.FetchAnother();
243 LOG_STRUCT(DEBUG, "Got claw status", *control_loops::claw_queue.status);
244 if (control_loops::claw_queue.status->zeroed) {
245 LOG(INFO, "Claw zeroed\n");
246 return;
247 }
248
249 if (ShouldExitAuto()) return;
250 }
251}
252
253void WaitForFridgeZero() {
254 LOG(INFO, "Waiting for claw to zero.\n");
255 while (true) {
256 control_loops::fridge_queue.status.FetchAnother();
257 LOG_STRUCT(DEBUG, "Got fridge status", *control_loops::fridge_queue.status);
258 if (control_loops::fridge_queue.status->zeroed) {
259 LOG(INFO, "Fridge zeroed\n");
260 return;
261 }
262
263 if (ShouldExitAuto()) return;
264 }
265}
266
267constexpr ProfileParams kDefaultClawParams = {kClawAutoVelocity,
268 kClawAutoAcceleration};
269
270// Move the claw in a very small number of cycles.
271constexpr ProfileParams kInstantaneousClaw = {100.0, 100.0};
272constexpr ProfileParams kFastClaw = {8.0, 20.0};
273
274void SetClawStateNoWait(double angle, double intake_voltage,
275 double rollers_closed,
276 const ProfileParams &claw_params = kDefaultClawParams) {
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700277 auto message = control_loops::claw_queue.goal.MakeMessage();
278 message->angle = angle;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700279 message->max_velocity = claw_params.velocity;
280 message->max_acceleration = claw_params.acceleration;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700281 message->angular_velocity = 0.0;
282 message->intake = intake_voltage;
283 message->rollers_closed = rollers_closed;
284
285 LOG_STRUCT(DEBUG, "Sending claw goal", *message);
286 message.Send();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700287}
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700288
Austin Schuh1f3764e2015-04-18 23:00:09 -0700289void SetClawState(double angle, double intake_voltage, double rollers_closed,
290 const ProfileParams &claw_params = kDefaultClawParams) {
291 SetClawStateNoWait(angle, intake_voltage, rollers_closed, claw_params);
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700292 while (true) {
293 control_loops::claw_queue.status.FetchAnother();
294 const double current_angle = control_loops::claw_queue.status->angle;
295 LOG_STRUCT(DEBUG, "Got claw status", *control_loops::claw_queue.status);
296
297 // I believe all we can care about here is the angle. Other values will
298 // either be set or not, but there is nothing we can do about it. If it
299 // never gets there we do not care, auto is over for us.
300 if (::std::abs(current_angle - angle) < kAngleEpsilon) {
301 break;
302 }
Austin Schuh1f3764e2015-04-18 23:00:09 -0700303 if (ShouldExitAuto()) return;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700304 }
305}
306
Austin Schuh80ff2e12014-03-08 12:06:19 -0800307void HandleAuto() {
Austin Schuh577edf62014-04-13 10:33:05 -0700308 ::aos::time::Time start_time = ::aos::time::Time::Now();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700309 LOG(INFO, "Starting auto mode at %f\n", start_time.ToSeconds());
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700310 ::std::unique_ptr<::frc971::actors::DrivetrainAction> drive;
311 ::std::unique_ptr<::frc971::actors::PickupAction> pickup;
312 ::std::unique_ptr<::frc971::actors::StackAction> stack;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700313 ::std::unique_ptr<::frc971::actors::HeldToLiftAction> lift;
Austin Schuh80ff2e12014-03-08 12:06:19 -0800314
315 if (ShouldExitAuto()) return;
316 InitializeEncoders();
Austin Schuh1f3764e2015-04-18 23:00:09 -0700317 ResetDrivetrain();
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700318
Austin Schuh1f3764e2015-04-18 23:00:09 -0700319 WaitForClawZero();
320 WaitForFridgeZero();
Brian Silverman93936f72015-03-19 23:38:30 -0700321
Austin Schuh1f3764e2015-04-18 23:00:09 -0700322 // Initialize the fridge.
323 MoveFridge(0.0, 0.3, true, kFridgeXProfile, kFridgeYProfile);
Brian Silverman93936f72015-03-19 23:38:30 -0700324
Austin Schuh1f3764e2015-04-18 23:00:09 -0700325 LOG(INFO, "Lowering claw into position.\n");
326 SetClawState(0.0, 2.0, false, kInstantaneousClaw);
327 LOG(INFO, "Sucking in tote.\n");
328 SetClawState(0.0, 5.0, true, kInstantaneousClaw);
Brian Silverman93936f72015-03-19 23:38:30 -0700329
Austin Schuh1f3764e2015-04-18 23:00:09 -0700330 time::SleepFor(time::Time::InSeconds(0.7));
331 LOG(INFO, "Done sucking in tote\n");
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700332
Austin Schuh1f3764e2015-04-18 23:00:09 -0700333 // Now pick it up
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700334 {
335 actors::PickupParams params;
336 // Lift to here initially.
337 params.pickup_angle = 0.9;
338 // Start sucking here
339 params.suck_angle = 0.8;
340 // Go back down to here to finish sucking.
341 params.suck_angle_finish = 0.4;
342 // Pack the box back in here.
343 params.pickup_finish_angle = kClawTotePackAngle;
Austin Schuh1f3764e2015-04-18 23:00:09 -0700344 params.intake_time = 0.60;
345 params.intake_voltage = 6.5;
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700346 pickup = actors::MakePickupAction(params);
347 pickup->Start();
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700348 }
Austin Schuh1f3764e2015-04-18 23:00:09 -0700349
350 time::SleepFor(time::Time::InSeconds(0.9));
351 // Start turning.
352 LOG(INFO, "Turning in place\n");
353 drive = SetDriveGoal(0.0, kFastDrive, -0.18);
354
355 WaitUntilDoneOrCanceled(::std::move(drive));
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700356 if (ShouldExitAuto()) return;
357
Austin Schuh1f3764e2015-04-18 23:00:09 -0700358 LOG(INFO, "Now driving next to the can\n");
359 drive = SetDriveGoal(0.60, kFastDrive);
Brian Silverman5bfda6c2015-03-21 23:40:13 -0700360
Austin Schuh1f3764e2015-04-18 23:00:09 -0700361 WaitUntilDoneOrCanceled(::std::move(pickup));
362 if (ShouldExitAuto()) return;
363
364 // Now grab it in the fridge.
365 {
366 actors::StackParams params;
367
368 params.claw_out_angle = kClawTotePackAngle;
369 params.bottom = 0.020;
370 params.only_place = false;
371 params.arm_clearance = kArmRaiseLowerClearance;
372 params.over_box_before_place_height = 0.39;
373
374 stack = actors::MakeStackAction(params);
375 stack->Start();
376 }
377 WaitUntilDoneOrCanceled(::std::move(stack));
378 if (ShouldExitAuto()) return;
379
380 // Lower the claw to knock the tote.
381 LOG(INFO, "Lowering the claw to knock the tote\n");
382 SetClawStateNoWait(0.0, 0.0, true, kFastClaw);
383
384 time::SleepFor(time::Time::InSeconds(0.1));
385 if (ShouldExitAuto()) return;
386
387 WaitUntilDoneOrCanceled(::std::move(drive));
388 if (ShouldExitAuto()) return;
389
390 LOG(INFO, "Knocking the can over\n");
391 drive = SetDriveGoal(0.40, kFastKnockDrive, 1.00, kComboTurn);
392 WaitUntilDoneOrCanceled(::std::move(drive));
393 if (ShouldExitAuto()) return;
394 {
395 actors::HeldToLiftParams params;
396 params.arm_clearance = kArmRaiseLowerClearance;
397 params.clamp_pause_time = 0.1;
398 params.before_lift_settle_time = 0.1;
399 params.bottom_height = 0.020;
400 params.claw_out_angle = kClawStackClearance;
401 params.lift_params.lift_height = kStackUpHeight;
402 params.lift_params.lift_arm = kStackUpArm;
403
404 lift = actors::MakeHeldToLiftAction(params);
405 lift->Start();
406 }
407
408 LOG(INFO, "Turning back to aim\n");
409 drive = SetDriveGoal(0.0, kFastDrive, -0.70);
410 WaitUntilDoneOrCanceled(::std::move(drive));
411 if (ShouldExitAuto()) return;
412
413 SetClawStateNoWait(0.0, 4.0, false, kFastClaw);
414 LOG(INFO, "Now driving the second tote\n");
415 drive = SetDriveGoal(1.05, kFastDrive);
416
417 // Wait until we are almost at the tote, and then start intaking.
418 WaitUntilNear(0.20);
419
420 SetClawState(0.0, 6.0, true, kFastClaw);
421 WaitUntilDoneOrCanceled(::std::move(drive));
422 if (ShouldExitAuto()) return;
423
424 if (ShouldExitAuto()) return;
425 time::SleepFor(time::Time::InSeconds(0.3));
426
427 WaitUntilDoneOrCanceled(::std::move(lift));
428 if (ShouldExitAuto()) return;
429
430 LOG(INFO, "Done sucking in tote\n");
431 SetClawState(0.0, 0.0, true, kFastClaw);
432 if (ShouldExitAuto()) return;
433
434 // Now pick it up
435 {
436 actors::PickupParams params;
437 // Lift to here initially.
438 params.pickup_angle = 0.9;
439 // Start sucking here
440 params.suck_angle = 0.8;
441 // Go back down to here to finish sucking.
442 params.suck_angle_finish = 0.4;
443 // Pack the box back in here.
444 params.pickup_finish_angle = kClawTotePackAngle;
445 params.intake_time = 0.60;
446 params.intake_voltage = 6.5;
447 pickup = actors::MakePickupAction(params);
448 pickup->Start();
449 }
450
451 time::SleepFor(time::Time::InSeconds(0.9));
452 if (ShouldExitAuto()) return;
453
454 // Start turning.
455 LOG(INFO, "Turning in place\n");
456 drive = SetDriveGoal(0.65, kStackingDrive, -0.45);
457
458 WaitUntilDoneOrCanceled(::std::move(pickup));
459 if (ShouldExitAuto()) return;
460
461 // Now grab it in the fridge.
462 {
463 actors::StackParams params;
464
465 params.claw_out_angle = kClawTotePackAngle;
466 params.bottom = 0.020;
467 params.only_place = false;
468 params.arm_clearance = kArmRaiseLowerClearance;
469 params.over_box_before_place_height = 0.39;
470
471 stack = actors::MakeStackAction(params);
472 stack->Start();
473 }
474
475 WaitUntilDoneOrCanceled(::std::move(stack));
476 if (ShouldExitAuto()) return;
477
478 WaitUntilDoneOrCanceled(::std::move(drive));
479 if (ShouldExitAuto()) return;
480
481 // Lower the claw to knock the tote.
482 LOG(INFO, "Lowering the claw to knock the tote\n");
483 SetClawStateNoWait(0.0, 0.0, true, kFastClaw);
484
485 // Lift the fridge.
486 MoveFridge(0.0, 0.3, true, kFridgeXProfile, kFridgeYProfile);
487
488 time::SleepFor(time::Time::InSeconds(0.1));
489 if (ShouldExitAuto()) return;
490
491 LOG(INFO, "Knocking the can over\n");
492 drive = SetDriveGoal(0.40, kFastKnockDrive, 1.10, kComboTurn);
493 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;
545 WaitForFridge();
546 if (ShouldExitAuto()) return;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700547
Austin Schuh1f3764e2015-04-18 23:00:09 -0700548 WaitUntilDoneOrCanceled(::std::move(drive));
549 if (ShouldExitAuto()) return;
Ben Fredrickson0a6ad252015-03-15 18:51:42 -0700550
Austin Schuh1f3764e2015-04-18 23:00:09 -0700551 LOG(INFO, "Backing away to let the stack ago\n");
552 drive = SetDriveGoal(-0.1, kRaceBackupDrive);
553 WaitUntilDoneOrCanceled(::std::move(drive));
Austin Schuh47017412013-03-10 11:50:46 -0700554}
555
556} // namespace autonomous
557} // namespace frc971