blob: 1a2a46a084c95f581b04b4ae4bed501f23f7865c [file] [log] [blame]
Austin Schuh47017412013-03-10 11:50:46 -07001#include "stdio.h"
2
3#include "aos/aos_core.h"
4#include "aos/common/control_loop/Timing.h"
5#include "aos/common/time.h"
Austin Schuh6be011a2013-03-19 10:07:02 +00006#include "aos/common/util/trapezoid_profile.h"
Austin Schuh47017412013-03-10 11:50:46 -07007#include "frc971/autonomous/auto.q.h"
Austin Schuh6be011a2013-03-19 10:07:02 +00008#include "aos/common/messages/RobotState.q.h"
9#include "frc971/constants.h"
10#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Austin Schuh47017412013-03-10 11:50:46 -070011#include "frc971/control_loops/wrist/wrist_motor.q.h"
12#include "frc971/control_loops/index/index_motor.q.h"
13#include "frc971/control_loops/shooter/shooter_motor.q.h"
14#include "frc971/control_loops/angle_adjust/angle_adjust_motor.q.h"
15
16using ::aos::time::Time;
17
18namespace frc971 {
19namespace autonomous {
20
Brian Silverman3b89ed82013-03-22 18:59:16 -070021static double left_initial_position, right_initial_position;
22
Austin Schuh6be011a2013-03-19 10:07:02 +000023bool ShouldExitAuto() {
24 ::frc971::autonomous::autonomous.FetchLatest();
25 bool ans = !::frc971::autonomous::autonomous->run_auto;
26 if (ans) {
27 LOG(INFO, "Time to exit auto mode\n");
28 }
29 return ans;
30}
31
Austin Schuh47017412013-03-10 11:50:46 -070032void SetShooterVelocity(double velocity) {
Austin Schuh6be011a2013-03-19 10:07:02 +000033 LOG(INFO, "Setting shooter velocity to %f\n", velocity);
Austin Schuh47017412013-03-10 11:50:46 -070034 control_loops::shooter.goal.MakeWithBuilder()
35 .velocity(velocity).Send();
36}
37
Austin Schuh6be011a2013-03-19 10:07:02 +000038void SetWristGoal(double goal) {
39 LOG(INFO, "Setting wrist to %f\n", goal);
40 control_loops::wrist.goal.MakeWithBuilder()
41 .goal(goal).Send();
42}
43
44void SetAngle_AdjustGoal(double goal) {
45 LOG(INFO, "Setting angle adjust to %f\n", goal);
46 control_loops::angle_adjust.goal.MakeWithBuilder()
47 .goal(goal).Send();
48}
49
50void StartIndex() {
51 LOG(INFO, "Starting index\n");
52 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070053 .goal_state(2)
54 .force_fire(false)
55 .override_index(false)
56 .Send();
Austin Schuh47017412013-03-10 11:50:46 -070057}
58
Austin Schuh6be011a2013-03-19 10:07:02 +000059void PreloadIndex() {
60 LOG(INFO, "Preloading index\n");
61 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070062 .goal_state(3)
63 .force_fire(false)
64 .override_index(false)
65 .Send();
Austin Schuh47017412013-03-10 11:50:46 -070066}
67
Austin Schuh6be011a2013-03-19 10:07:02 +000068void ShootIndex() {
69 LOG(INFO, "Shooting index\n");
70 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070071 .goal_state(4)
72 .force_fire(false)
73 .override_index(false)
74 .Send();
Austin Schuh47017412013-03-10 11:50:46 -070075}
76
Brian Silvermanb8d389f2013-03-19 22:54:06 -070077void ResetIndex() {
78 LOG(INFO, "Resetting index\n");
79 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070080 .goal_state(5)
81 .force_fire(false)
82 .override_index(false)
83 .Send();
Brian Silvermanb8d389f2013-03-19 22:54:06 -070084}
85
86void WaitForIndexReset() {
87 LOG(INFO, "Waiting for the indexer to reset\n");
88 control_loops::index_loop.status.FetchLatest();
89
90 // Fetch a couple index status packets to make sure that the indexer has run.
91 for (int i = 0; i < 5; ++i) {
92 LOG(DEBUG, "Fetching another index status packet\n");
93 control_loops::index_loop.status.FetchNextBlocking();
94 if (ShouldExitAuto()) return;
95 }
96 LOG(INFO, "Indexer is now reset.\n");
97}
98
Austin Schuh6be011a2013-03-19 10:07:02 +000099void WaitForWrist() {
100 LOG(INFO, "Waiting for the wrist\n");
101 control_loops::wrist.status.FetchLatest();
102
103 while (!control_loops::wrist.status.get()) {
104 LOG(WARNING, "No previous wrist packet, trying to fetch again\n");
105 control_loops::wrist.status.FetchNextBlocking();
106 }
107
108 while (!control_loops::wrist.status->done) {
109 control_loops::wrist.status.FetchNextBlocking();
110 LOG(DEBUG, "Got a new wrist status packet\n");
111 if (ShouldExitAuto()) return;
112 }
113 LOG(INFO, "Done waiting for the wrist\n");
114}
Austin Schuh6be011a2013-03-19 10:07:02 +0000115void WaitForIndex() {
116 LOG(INFO, "Waiting for the indexer to be ready to intake\n");
117 control_loops::index_loop.status.FetchLatest();
118
119 while (!control_loops::index_loop.status.get()) {
120 LOG(WARNING, "No previous index packet, trying to fetch again\n");
121 control_loops::index_loop.status.FetchNextBlocking();
122 }
123
124 while (!control_loops::index_loop.status->ready_to_intake) {
125 control_loops::index_loop.status.FetchNextBlocking();
126 if (ShouldExitAuto()) return;
127 }
128 LOG(INFO, "Indexer ready to intake\n");
129}
130
131void WaitForAngle_Adjust() {
132 LOG(INFO, "Waiting for the angle adjuster to finish\n");
133 control_loops::angle_adjust.status.FetchLatest();
134
135 while (!control_loops::angle_adjust.status.get()) {
136 LOG(WARNING, "No previous angle adjust packet, trying to fetch again\n");
137 control_loops::angle_adjust.status.FetchNextBlocking();
138 }
139
140 while (!control_loops::angle_adjust.status->done) {
141 control_loops::angle_adjust.status.FetchNextBlocking();
142 if (ShouldExitAuto()) return;
143 }
144 LOG(INFO, "Angle adjuster done\n");
145}
146
Austin Schuh47017412013-03-10 11:50:46 -0700147void WaitForShooter() {
Austin Schuh6be011a2013-03-19 10:07:02 +0000148 LOG(INFO, "Waiting for the shooter to spin up\n");
Austin Schuh47017412013-03-10 11:50:46 -0700149 control_loops::shooter.status.FetchLatest();
Austin Schuh6be011a2013-03-19 10:07:02 +0000150
151 while (!control_loops::shooter.status.get()) {
152 LOG(WARNING, "No previous shooteracket, trying to fetch again\n");
Austin Schuh47017412013-03-10 11:50:46 -0700153 control_loops::shooter.status.FetchNextBlocking();
154 }
Austin Schuh47017412013-03-10 11:50:46 -0700155
Austin Schuh6be011a2013-03-19 10:07:02 +0000156 while (!control_loops::shooter.status->ready) {
157 control_loops::shooter.status.FetchNextBlocking();
158 if (ShouldExitAuto()) return;
Austin Schuh47017412013-03-10 11:50:46 -0700159 }
Austin Schuh6be011a2013-03-19 10:07:02 +0000160 LOG(INFO, "Shooter ready to shoot\n");
Austin Schuh47017412013-03-10 11:50:46 -0700161}
162
Austin Schuh6be011a2013-03-19 10:07:02 +0000163void ShootNDiscs(int n) {
164 LOG(INFO, "Waiting until %d discs have been shot\n", n);
165 control_loops::index_loop.status.FetchLatest();
166
167 while (!control_loops::index_loop.status.get()) {
168 LOG(WARNING, "No previous index_loop packet, trying to fetch again\n");
169 control_loops::index_loop.status.FetchNextBlocking();
170 }
171
172 int final_disc_count = control_loops::index_loop.status->shot_disc_count + n;
173 LOG(DEBUG, "Disc count should be %d when done\n", final_disc_count);
174 while (final_disc_count > control_loops::index_loop.status->shot_disc_count) {
175 control_loops::index_loop.status.FetchNextBlocking();
176 if (ShouldExitAuto()) return;
177 }
178 LOG(INFO, "Shot %d discs\n", n);
Austin Schuh47017412013-03-10 11:50:46 -0700179}
180
Austin Schuh6be011a2013-03-19 10:07:02 +0000181void StopDrivetrain() {
182 LOG(INFO, "Stopping the drivetrain\n");
Austin Schuh47017412013-03-10 11:50:46 -0700183 control_loops::drivetrain.goal.MakeWithBuilder()
Brian Silverman3b89ed82013-03-22 18:59:16 -0700184 .control_loop_driving(true)
Brian Silvermance86bac2013-03-31 19:07:24 -0700185 .left_goal(left_initial_position)
186 .left_velocity_goal(0)
187 .right_goal(right_initial_position)
188 .right_velocity_goal(0)
189 .quickturn(false)
190 .Send();
191}
192
193void ResetDrivetrain() {
194 LOG(INFO, "resetting the drivetrain\n");
195 control_loops::drivetrain.goal.MakeWithBuilder()
196 .control_loop_driving(false)
Austin Schuh6be011a2013-03-19 10:07:02 +0000197 .highgear(false)
198 .steering(0.0)
199 .throttle(0.0)
Austin Schuh6be011a2013-03-19 10:07:02 +0000200 .Send();
201}
202
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700203void SetDriveGoal(double yoffset, double maximum_velocity = 1.5) {
Austin Schuh6be011a2013-03-19 10:07:02 +0000204 LOG(INFO, "Going to move %f\n", yoffset);
205
206 // Measured conversion to get the distance right.
Austin Schuh6be011a2013-03-19 10:07:02 +0000207 ::aos::util::TrapezoidProfile profile(::aos::time::Time::InMS(10));
208 ::Eigen::Matrix<double, 2, 1> driveTrainState;
209 const double goal_velocity = 0.0;
210 const double epsilon = 0.01;
211
Austin Schuhfae53362013-03-23 04:39:48 +0000212 profile.set_maximum_acceleration(2.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700213 profile.set_maximum_velocity(maximum_velocity);
Austin Schuh6be011a2013-03-19 10:07:02 +0000214
Austin Schuh6be011a2013-03-19 10:07:02 +0000215 while (true) {
Brian Silverman7f09f972013-03-22 23:11:39 -0700216 ::aos::time::PhasedLoop10MS(5000); // wait until next 10ms tick
Austin Schuh6be011a2013-03-19 10:07:02 +0000217 driveTrainState = profile.Update(yoffset, goal_velocity);
218
Brian Silverman3b89ed82013-03-22 18:59:16 -0700219 if (::std::abs(driveTrainState(0, 0) - yoffset) < epsilon) break;
Austin Schuh6be011a2013-03-19 10:07:02 +0000220 if (ShouldExitAuto()) return;
221
222 LOG(DEBUG, "Driving left to %f, right to %f\n",
223 driveTrainState(0, 0) + left_initial_position,
224 driveTrainState(0, 0) + right_initial_position);
225 control_loops::drivetrain.goal.MakeWithBuilder()
226 .control_loop_driving(true)
227 .highgear(false)
228 .left_goal(driveTrainState(0, 0) + left_initial_position)
229 .right_goal(driveTrainState(0, 0) + right_initial_position)
230 .left_velocity_goal(driveTrainState(1, 0))
231 .right_velocity_goal(driveTrainState(1, 0))
232 .Send();
233 }
Brian Silverman3b89ed82013-03-22 18:59:16 -0700234 left_initial_position += yoffset;
235 right_initial_position += yoffset;
Austin Schuh6be011a2013-03-19 10:07:02 +0000236 LOG(INFO, "Done moving\n");
237}
238
Brian Silverman13be6682013-03-22 21:02:07 -0700239// Drives forward while we can pick up discs up to max_distance (in meters).
Brian Silverman7992d6e2013-03-24 19:20:54 -0700240void DriveForwardPickUp(double max_distance, double wrist_angle) {
Brian Silverman13be6682013-03-22 21:02:07 -0700241 LOG(INFO, "going to pick up at a max distance of %f\n", max_distance);
Brian Silverman13be6682013-03-22 21:02:07 -0700242
243 static const ::aos::time::Time kPeriod = ::aos::time::Time::InMS(10);
244 ::aos::util::TrapezoidProfile profile(kPeriod);
245 ::Eigen::Matrix<double, 2, 1> driveTrainState;
246 const double goal_velocity = 0.0;
247 const double epsilon = 0.01;
248 static const double kMaximumAcceleration = 1.0;
249
250 profile.set_maximum_acceleration(kMaximumAcceleration);
251 profile.set_maximum_velocity(0.6);
252
Brian Silverman13be6682013-03-22 21:02:07 -0700253 bool driving_back = false;
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700254 const double kDestination = -0.20;
Brian Silverman13be6682013-03-22 21:02:07 -0700255
256 while (true) {
Brian Silverman7f09f972013-03-22 23:11:39 -0700257 ::aos::time::PhasedLoop10MS(5000); // wait until next 10ms tick
Brian Silvermanc6ba6ee2013-03-22 21:10:38 -0700258 driveTrainState = profile.Update(driving_back ? kDestination : max_distance,
259 goal_velocity);
Brian Silverman13be6682013-03-22 21:02:07 -0700260
261 if (ShouldExitAuto()) return;
262
Brian Silvermanc6ba6ee2013-03-22 21:10:38 -0700263 if (driving_back) {
264 if (::std::abs(driveTrainState(0, 0)) < epsilon) break;
265 } else if (::std::abs(driveTrainState(0, 0) - max_distance) < epsilon) {
266 LOG(INFO, "went the max distance; driving back\n");
267 driving_back = true;
Brian Silverman7992d6e2013-03-24 19:20:54 -0700268 profile.set_maximum_velocity(2.5);
269 SetWristGoal(wrist_angle);
Brian Silverman13be6682013-03-22 21:02:07 -0700270 }
271
272 if (control_loops::index_loop.status.FetchLatest()) {
273 if (control_loops::index_loop.status->hopper_disc_count >= 4) {
274 LOG(INFO, "done intaking; driving back\n");
275 driving_back = true;
Brian Silverman7992d6e2013-03-24 19:20:54 -0700276 profile.set_maximum_velocity(2.5);
277 SetWristGoal(wrist_angle);
Brian Silverman13be6682013-03-22 21:02:07 -0700278 }
279 } else {
280 LOG(WARNING, "getting index status failed\n");
281 }
282
283 LOG(DEBUG, "Driving left to %f, right to %f\n",
284 driveTrainState(0, 0) + left_initial_position,
285 driveTrainState(0, 0) + right_initial_position);
286 control_loops::drivetrain.goal.MakeWithBuilder()
287 .control_loop_driving(true)
288 .highgear(false)
289 .left_goal(driveTrainState(0, 0) + left_initial_position)
290 .right_goal(driveTrainState(0, 0) + right_initial_position)
291 .left_velocity_goal(driveTrainState(1, 0))
292 .right_velocity_goal(driveTrainState(1, 0))
293 .Send();
294 }
Austin Schuhfae53362013-03-23 04:39:48 +0000295 left_initial_position += kDestination;
296 right_initial_position += kDestination;
Brian Silverman13be6682013-03-22 21:02:07 -0700297 LOG(INFO, "Done moving\n");
298}
299
Brian Silverman3b89ed82013-03-22 18:59:16 -0700300void DriveSpin(double radians) {
301 LOG(INFO, "going to spin %f\n", radians);
302
303 ::aos::util::TrapezoidProfile profile(::aos::time::Time::InMS(10));
304 ::Eigen::Matrix<double, 2, 1> driveTrainState;
305 const double goal_velocity = 0.0;
306 const double epsilon = 0.01;
Brian Silverman13be6682013-03-22 21:02:07 -0700307 // in drivetrain "meters"
Brian Silverman3b89ed82013-03-22 18:59:16 -0700308 const double kRobotWidth = 0.4544;
309
Brian Silverman7992d6e2013-03-24 19:20:54 -0700310 profile.set_maximum_acceleration(1.5);
311 profile.set_maximum_velocity(0.8);
Brian Silverman3b89ed82013-03-22 18:59:16 -0700312
313 const double side_offset = kRobotWidth * radians / 2.0;
314
315 while (true) {
Brian Silverman7f09f972013-03-22 23:11:39 -0700316 ::aos::time::PhasedLoop10MS(5000); // wait until next 10ms tick
Brian Silverman3b89ed82013-03-22 18:59:16 -0700317 driveTrainState = profile.Update(side_offset, goal_velocity);
318
319 if (::std::abs(driveTrainState(0, 0) - side_offset) < epsilon) break;
320 if (ShouldExitAuto()) return;
321
322 LOG(DEBUG, "Driving left to %f, right to %f\n",
Brian Silverman7992d6e2013-03-24 19:20:54 -0700323 left_initial_position - driveTrainState(0, 0),
324 right_initial_position + driveTrainState(0, 0));
Brian Silverman3b89ed82013-03-22 18:59:16 -0700325 control_loops::drivetrain.goal.MakeWithBuilder()
326 .control_loop_driving(true)
327 .highgear(false)
Brian Silverman7992d6e2013-03-24 19:20:54 -0700328 .left_goal(left_initial_position - driveTrainState(0, 0))
329 .right_goal(right_initial_position + driveTrainState(0, 0))
330 .left_velocity_goal(-driveTrainState(1, 0))
331 .right_velocity_goal(driveTrainState(1, 0))
Brian Silverman3b89ed82013-03-22 18:59:16 -0700332 .Send();
333 }
Brian Silverman7992d6e2013-03-24 19:20:54 -0700334 left_initial_position -= side_offset;
335 right_initial_position += side_offset;
Brian Silverman3b89ed82013-03-22 18:59:16 -0700336 LOG(INFO, "Done moving\n");
337}
338
339// start with N discs in the indexer
Austin Schuh6be011a2013-03-19 10:07:02 +0000340void HandleAuto() {
341 LOG(INFO, "Handling auto mode\n");
Brian Silvermance86bac2013-03-31 19:07:24 -0700342
Austin Schuh6be011a2013-03-19 10:07:02 +0000343 double WRIST_UP;
Brian Silvermance86bac2013-03-31 19:07:24 -0700344 const double WRIST_DOWN = -0.580;
Brian Silvermane296ebd2013-04-05 13:51:13 -0700345 const double WRIST_DOWN_TWO = WRIST_DOWN - 0.005;
346 const double ANGLE_ONE = 0.520;
Brian Silverman304b2bf2013-04-04 17:54:41 -0700347 const double ANGLE_TWO = 0.677;
Brian Silvermance86bac2013-03-31 19:07:24 -0700348
349 ResetIndex();
350 SetWristGoal(1.0); // wrist must calibrate itself on power-up
351 SetAngle_AdjustGoal(ANGLE_TWO); // make it still move a bit
352 SetShooterVelocity(0.0); // or else it keeps spinning from last time
353 ResetDrivetrain();
354
Brian Silverman304b2bf2013-04-04 17:54:41 -0700355 //::aos::time::SleepFor(::aos::time::Time::InSeconds(20));
Brian Silvermance86bac2013-03-31 19:07:24 -0700356 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000357
358 ::aos::robot_state.FetchLatest();
Brian Silvermanc5277542013-03-22 13:33:07 -0700359 if (!::aos::robot_state.get() ||
Austin Schuh6be011a2013-03-19 10:07:02 +0000360 !constants::wrist_hall_effect_start_angle(&WRIST_UP)) {
361 LOG(ERROR, "Constants not ready\n");
362 return;
363 }
364 WRIST_UP -= 0.4;
365 LOG(INFO, "Got constants\n");
Austin Schuh6be011a2013-03-19 10:07:02 +0000366
Brian Silverman3b89ed82013-03-22 18:59:16 -0700367 control_loops::drivetrain.position.FetchLatest();
368 while (!control_loops::drivetrain.position.get()) {
369 LOG(WARNING, "No previous drivetrain position packet, trying to fetch again\n");
370 control_loops::drivetrain.position.FetchNextBlocking();
371 }
372 left_initial_position =
373 control_loops::drivetrain.position->left_encoder;
374 right_initial_position =
375 control_loops::drivetrain.position->right_encoder;
376
Brian Silverman3b89ed82013-03-22 18:59:16 -0700377 StopDrivetrain();
Austin Schuh6be011a2013-03-19 10:07:02 +0000378
Brian Silverman7f09f972013-03-22 23:11:39 -0700379 SetWristGoal(WRIST_UP); // wrist must calibrate itself on power-up
Austin Schuh6be011a2013-03-19 10:07:02 +0000380 SetAngle_AdjustGoal(ANGLE_ONE);
Brian Silvermane296ebd2013-04-05 13:51:13 -0700381 SetShooterVelocity(395.0);
Brian Silvermanb8d389f2013-03-19 22:54:06 -0700382 WaitForIndexReset();
Brian Silverman7f09f972013-03-22 23:11:39 -0700383 if (ShouldExitAuto()) return;
384 PreloadIndex(); // spin to top and put 1 disc into loader
Austin Schuh6be011a2013-03-19 10:07:02 +0000385
386 if (ShouldExitAuto()) return;
387 WaitForWrist();
388 if (ShouldExitAuto()) return;
389 WaitForAngle_Adjust();
Brian Silverman7f09f972013-03-22 23:11:39 -0700390 ShootIndex(); // tilt up, shoot, repeat until empty
391 // calls WaitForShooter
392 ShootNDiscs(3); // ShootNDiscs returns if ShouldExitAuto
Austin Schuh6be011a2013-03-19 10:07:02 +0000393 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000394
Brian Silverman7f09f972013-03-22 23:11:39 -0700395 StartIndex(); // take in up to 4 discs
Austin Schuh6be011a2013-03-19 10:07:02 +0000396
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700397 if (false) {
398 const double kDistanceToCenterMeters = 3.11023;
399 const double kMaxPickupDistance = 2.5;
400 const double kTurnToCenterDegrees = 78.2;
Austin Schuh6be011a2013-03-19 10:07:02 +0000401
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700402 // Drive back to the center line.
403 SetDriveGoal(-kDistanceToCenterMeters);
404 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000405
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700406 SetWristGoal(WRIST_DOWN);
407 // Turn towards the center.
408 DriveSpin(kTurnToCenterDegrees * M_PI / 180.0);
409 if (ShouldExitAuto()) return;
410 WaitForWrist();
411 if (ShouldExitAuto()) return;
Austin Schuhfae53362013-03-23 04:39:48 +0000412
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700413 // Pick up at most 4 discs and drive at most kMaxPickupDistance.
414 DriveForwardPickUp(kMaxPickupDistance, WRIST_UP);
Austin Schuhfae53362013-03-23 04:39:48 +0000415
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700416 SetWristGoal(WRIST_UP);
417 DriveSpin(-kTurnToCenterDegrees * M_PI / 180.0);
418 if (ShouldExitAuto()) return;
419 // Drive back to where we were.
420 SetDriveGoal(kDistanceToCenterMeters);
421 if (ShouldExitAuto()) return;
Austin Schuhfae53362013-03-23 04:39:48 +0000422
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700423 return;
Brian Silverman7992d6e2013-03-24 19:20:54 -0700424
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700425 ShootNDiscs(4);
426 if (ShouldExitAuto()) return;
427 } else {
Austin Schuh9f97ce62013-04-04 05:48:28 +0000428 // Delay to let the disc out of the shooter.
Brian Silverman304b2bf2013-04-04 17:54:41 -0700429 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700430 SetWristGoal(WRIST_DOWN);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700431 StartIndex(); // take in up to 4 discs
432
433 if (ShouldExitAuto()) return;
434 WaitForWrist(); // wrist must be down before moving
435 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
Austin Schuh9f97ce62013-04-04 05:48:28 +0000436 SetAngle_AdjustGoal(ANGLE_TWO);
437 SetShooterVelocity(375.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700438
439 if (ShouldExitAuto()) return;
440 WaitForIndex(); // ready to pick up discs
441
Brian Silvermance86bac2013-03-31 19:07:24 -0700442 static const double kDriveDistance = 2.8;
443 static const double kFirstDrive = 0.27;
444 static const double kSecondShootDistance = 2.0;
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700445 SetDriveGoal(kFirstDrive, 0.6);
Brian Silvermance86bac2013-03-31 19:07:24 -0700446 SetWristGoal(WRIST_DOWN_TWO);
447 SetDriveGoal(kDriveDistance - kFirstDrive, 2.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700448 if (ShouldExitAuto()) return;
449
Brian Silvermance86bac2013-03-31 19:07:24 -0700450 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.5));
451 SetDriveGoal(kSecondShootDistance - kDriveDistance, 2.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700452 PreloadIndex();
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700453
454 if (ShouldExitAuto()) return;
455 WaitForAngle_Adjust();
456 if (ShouldExitAuto()) return;
457 ShootIndex();
458 if (ShouldExitAuto()) return;
459 }
Austin Schuh47017412013-03-10 11:50:46 -0700460}
461
462} // namespace autonomous
463} // namespace frc971