blob: 97c2310e06e579a7cf988ee25f1505d6dd24067b [file] [log] [blame]
Austin Schuh47017412013-03-10 11:50:46 -07001#include "stdio.h"
2
Austin Schuh47017412013-03-10 11:50:46 -07003#include "aos/common/control_loop/Timing.h"
4#include "aos/common/time.h"
Austin Schuh6be011a2013-03-19 10:07:02 +00005#include "aos/common/util/trapezoid_profile.h"
Brian Silverman598800f2013-05-09 17:08:42 -07006#include "aos/common/logging/logging.h"
7
8#include "frc971/autonomous/auto.q.h"
Austin Schuh6be011a2013-03-19 10:07:02 +00009#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
Brian Silverman431500a2013-10-28 19:50:15 -0700343 const double WRIST_UP =
344 constants::GetValues().wrist_hall_effect_start_angle - 0.4;
Brian Silvermance86bac2013-03-31 19:07:24 -0700345 const double WRIST_DOWN = -0.580;
Brian Silverman36690622013-09-22 19:43:10 -0700346 const double WRIST_DOWN_TWO = WRIST_DOWN - 0.012;
347 const double ANGLE_ONE = 0.509;
348 const double ANGLE_TWO = 0.673;
Brian Silvermance86bac2013-03-31 19:07:24 -0700349
350 ResetIndex();
351 SetWristGoal(1.0); // wrist must calibrate itself on power-up
352 SetAngle_AdjustGoal(ANGLE_TWO); // make it still move a bit
353 SetShooterVelocity(0.0); // or else it keeps spinning from last time
354 ResetDrivetrain();
355
Brian Silverman304b2bf2013-04-04 17:54:41 -0700356 //::aos::time::SleepFor(::aos::time::Time::InSeconds(20));
Brian Silvermance86bac2013-03-31 19:07:24 -0700357 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000358
Brian Silverman3b89ed82013-03-22 18:59:16 -0700359 control_loops::drivetrain.position.FetchLatest();
360 while (!control_loops::drivetrain.position.get()) {
361 LOG(WARNING, "No previous drivetrain position packet, trying to fetch again\n");
362 control_loops::drivetrain.position.FetchNextBlocking();
363 }
364 left_initial_position =
365 control_loops::drivetrain.position->left_encoder;
366 right_initial_position =
367 control_loops::drivetrain.position->right_encoder;
368
Brian Silverman3b89ed82013-03-22 18:59:16 -0700369 StopDrivetrain();
Austin Schuh6be011a2013-03-19 10:07:02 +0000370
Brian Silverman7f09f972013-03-22 23:11:39 -0700371 SetWristGoal(WRIST_UP); // wrist must calibrate itself on power-up
Austin Schuh6be011a2013-03-19 10:07:02 +0000372 SetAngle_AdjustGoal(ANGLE_ONE);
Brian Silvermane296ebd2013-04-05 13:51:13 -0700373 SetShooterVelocity(395.0);
Brian Silvermanb8d389f2013-03-19 22:54:06 -0700374 WaitForIndexReset();
Brian Silverman7f09f972013-03-22 23:11:39 -0700375 if (ShouldExitAuto()) return;
376 PreloadIndex(); // spin to top and put 1 disc into loader
Austin Schuh6be011a2013-03-19 10:07:02 +0000377
378 if (ShouldExitAuto()) return;
379 WaitForWrist();
380 if (ShouldExitAuto()) return;
381 WaitForAngle_Adjust();
Brian Silverman7f09f972013-03-22 23:11:39 -0700382 ShootIndex(); // tilt up, shoot, repeat until empty
383 // calls WaitForShooter
384 ShootNDiscs(3); // ShootNDiscs returns if ShouldExitAuto
Austin Schuh6be011a2013-03-19 10:07:02 +0000385 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000386
Brian Silverman7f09f972013-03-22 23:11:39 -0700387 StartIndex(); // take in up to 4 discs
Austin Schuh6be011a2013-03-19 10:07:02 +0000388
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700389 if (false) {
390 const double kDistanceToCenterMeters = 3.11023;
391 const double kMaxPickupDistance = 2.5;
392 const double kTurnToCenterDegrees = 78.2;
Austin Schuh6be011a2013-03-19 10:07:02 +0000393
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700394 // Drive back to the center line.
395 SetDriveGoal(-kDistanceToCenterMeters);
396 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000397
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700398 SetWristGoal(WRIST_DOWN);
399 // Turn towards the center.
400 DriveSpin(kTurnToCenterDegrees * M_PI / 180.0);
401 if (ShouldExitAuto()) return;
402 WaitForWrist();
403 if (ShouldExitAuto()) return;
Austin Schuhfae53362013-03-23 04:39:48 +0000404
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700405 // Pick up at most 4 discs and drive at most kMaxPickupDistance.
406 DriveForwardPickUp(kMaxPickupDistance, WRIST_UP);
Austin Schuhfae53362013-03-23 04:39:48 +0000407
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700408 SetWristGoal(WRIST_UP);
409 DriveSpin(-kTurnToCenterDegrees * M_PI / 180.0);
410 if (ShouldExitAuto()) return;
411 // Drive back to where we were.
412 SetDriveGoal(kDistanceToCenterMeters);
413 if (ShouldExitAuto()) return;
Austin Schuhfae53362013-03-23 04:39:48 +0000414
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700415 ShootNDiscs(4);
416 if (ShouldExitAuto()) return;
417 } else {
Austin Schuh9f97ce62013-04-04 05:48:28 +0000418 // Delay to let the disc out of the shooter.
Brian Silverman304b2bf2013-04-04 17:54:41 -0700419 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700420 SetWristGoal(WRIST_DOWN);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700421 StartIndex(); // take in up to 4 discs
422
423 if (ShouldExitAuto()) return;
424 WaitForWrist(); // wrist must be down before moving
425 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
Austin Schuh9f97ce62013-04-04 05:48:28 +0000426 SetAngle_AdjustGoal(ANGLE_TWO);
427 SetShooterVelocity(375.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700428
429 if (ShouldExitAuto()) return;
430 WaitForIndex(); // ready to pick up discs
431
Brian Silverman36690622013-09-22 19:43:10 -0700432 // How long we're going to drive in total.
Brian Silverman7bd7fad2013-10-11 17:59:02 -0700433 static const double kDriveDistance = 2.84;
Brian Silverman36690622013-09-22 19:43:10 -0700434 // How long to drive slowly to pick up the 2 disks under the pyramid.
435 static const double kFirstDrive = 0.4;
436 // How long to drive slowly to pick up the last 2 disks.
Brian Silverman7bd7fad2013-10-11 17:59:02 -0700437 static const double kLastDrive = 0.34;
Brian Silverman36690622013-09-22 19:43:10 -0700438 // How fast to drive when picking up disks.
439 static const double kPickupVelocity = 0.6;
440 // Where to take the second set of shots from.
Brian Silvermance86bac2013-03-31 19:07:24 -0700441 static const double kSecondShootDistance = 2.0;
Brian Silverman36690622013-09-22 19:43:10 -0700442
443 // Go slowly to grab the 2 disks under the pyramid.
444 SetDriveGoal(kFirstDrive, kPickupVelocity);
445 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.1));
446 SetDriveGoal(kDriveDistance - kFirstDrive - kLastDrive, 2.0);
Brian Silvermance86bac2013-03-31 19:07:24 -0700447 SetWristGoal(WRIST_DOWN_TWO);
Brian Silverman36690622013-09-22 19:43:10 -0700448 // Go slowly at the end to pick up the last 2 disks.
449 SetDriveGoal(kLastDrive, kPickupVelocity);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700450 if (ShouldExitAuto()) return;
451
Brian Silvermance86bac2013-03-31 19:07:24 -0700452 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.5));
453 SetDriveGoal(kSecondShootDistance - kDriveDistance, 2.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700454 PreloadIndex();
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700455
456 if (ShouldExitAuto()) return;
457 WaitForAngle_Adjust();
458 if (ShouldExitAuto()) return;
459 ShootIndex();
460 if (ShouldExitAuto()) return;
461 }
Austin Schuh47017412013-03-10 11:50:46 -0700462}
463
464} // namespace autonomous
465} // namespace frc971