blob: e7c48a58492a7bbbfb527d8e7ce01ac4fbcd27fd [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"
Austin Schuh6be011a2013-03-19 10:07:02 +00006#include "aos/common/messages/RobotState.q.h"
Brian Silverman598800f2013-05-09 17:08:42 -07007#include "aos/common/logging/logging.h"
8
9#include "frc971/autonomous/auto.q.h"
Austin Schuh6be011a2013-03-19 10:07:02 +000010#include "frc971/constants.h"
11#include "frc971/control_loops/drivetrain/drivetrain.q.h"
Austin Schuh47017412013-03-10 11:50:46 -070012#include "frc971/control_loops/wrist/wrist_motor.q.h"
13#include "frc971/control_loops/index/index_motor.q.h"
14#include "frc971/control_loops/shooter/shooter_motor.q.h"
15#include "frc971/control_loops/angle_adjust/angle_adjust_motor.q.h"
16
17using ::aos::time::Time;
18
19namespace frc971 {
20namespace autonomous {
21
Brian Silverman3b89ed82013-03-22 18:59:16 -070022static double left_initial_position, right_initial_position;
23
Austin Schuh6be011a2013-03-19 10:07:02 +000024bool ShouldExitAuto() {
25 ::frc971::autonomous::autonomous.FetchLatest();
26 bool ans = !::frc971::autonomous::autonomous->run_auto;
27 if (ans) {
28 LOG(INFO, "Time to exit auto mode\n");
29 }
30 return ans;
31}
32
Austin Schuh47017412013-03-10 11:50:46 -070033void SetShooterVelocity(double velocity) {
Austin Schuh6be011a2013-03-19 10:07:02 +000034 LOG(INFO, "Setting shooter velocity to %f\n", velocity);
Austin Schuh47017412013-03-10 11:50:46 -070035 control_loops::shooter.goal.MakeWithBuilder()
36 .velocity(velocity).Send();
37}
38
Austin Schuh6be011a2013-03-19 10:07:02 +000039void SetWristGoal(double goal) {
40 LOG(INFO, "Setting wrist to %f\n", goal);
41 control_loops::wrist.goal.MakeWithBuilder()
42 .goal(goal).Send();
43}
44
45void SetAngle_AdjustGoal(double goal) {
46 LOG(INFO, "Setting angle adjust to %f\n", goal);
47 control_loops::angle_adjust.goal.MakeWithBuilder()
48 .goal(goal).Send();
49}
50
51void StartIndex() {
52 LOG(INFO, "Starting index\n");
53 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070054 .goal_state(2)
55 .force_fire(false)
56 .override_index(false)
57 .Send();
Austin Schuh47017412013-03-10 11:50:46 -070058}
59
Austin Schuh6be011a2013-03-19 10:07:02 +000060void PreloadIndex() {
61 LOG(INFO, "Preloading index\n");
62 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070063 .goal_state(3)
64 .force_fire(false)
65 .override_index(false)
66 .Send();
Austin Schuh47017412013-03-10 11:50:46 -070067}
68
Austin Schuh6be011a2013-03-19 10:07:02 +000069void ShootIndex() {
70 LOG(INFO, "Shooting index\n");
71 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070072 .goal_state(4)
73 .force_fire(false)
74 .override_index(false)
75 .Send();
Austin Schuh47017412013-03-10 11:50:46 -070076}
77
Brian Silvermanb8d389f2013-03-19 22:54:06 -070078void ResetIndex() {
79 LOG(INFO, "Resetting index\n");
80 control_loops::index_loop.goal.MakeWithBuilder()
Brian Silverman180e2b82013-04-08 14:29:56 -070081 .goal_state(5)
82 .force_fire(false)
83 .override_index(false)
84 .Send();
Brian Silvermanb8d389f2013-03-19 22:54:06 -070085}
86
87void WaitForIndexReset() {
88 LOG(INFO, "Waiting for the indexer to reset\n");
89 control_loops::index_loop.status.FetchLatest();
90
91 // Fetch a couple index status packets to make sure that the indexer has run.
92 for (int i = 0; i < 5; ++i) {
93 LOG(DEBUG, "Fetching another index status packet\n");
94 control_loops::index_loop.status.FetchNextBlocking();
95 if (ShouldExitAuto()) return;
96 }
97 LOG(INFO, "Indexer is now reset.\n");
98}
99
Austin Schuh6be011a2013-03-19 10:07:02 +0000100void WaitForWrist() {
101 LOG(INFO, "Waiting for the wrist\n");
102 control_loops::wrist.status.FetchLatest();
103
104 while (!control_loops::wrist.status.get()) {
105 LOG(WARNING, "No previous wrist packet, trying to fetch again\n");
106 control_loops::wrist.status.FetchNextBlocking();
107 }
108
109 while (!control_loops::wrist.status->done) {
110 control_loops::wrist.status.FetchNextBlocking();
111 LOG(DEBUG, "Got a new wrist status packet\n");
112 if (ShouldExitAuto()) return;
113 }
114 LOG(INFO, "Done waiting for the wrist\n");
115}
Austin Schuh6be011a2013-03-19 10:07:02 +0000116void WaitForIndex() {
117 LOG(INFO, "Waiting for the indexer to be ready to intake\n");
118 control_loops::index_loop.status.FetchLatest();
119
120 while (!control_loops::index_loop.status.get()) {
121 LOG(WARNING, "No previous index packet, trying to fetch again\n");
122 control_loops::index_loop.status.FetchNextBlocking();
123 }
124
125 while (!control_loops::index_loop.status->ready_to_intake) {
126 control_loops::index_loop.status.FetchNextBlocking();
127 if (ShouldExitAuto()) return;
128 }
129 LOG(INFO, "Indexer ready to intake\n");
130}
131
132void WaitForAngle_Adjust() {
133 LOG(INFO, "Waiting for the angle adjuster to finish\n");
134 control_loops::angle_adjust.status.FetchLatest();
135
136 while (!control_loops::angle_adjust.status.get()) {
137 LOG(WARNING, "No previous angle adjust packet, trying to fetch again\n");
138 control_loops::angle_adjust.status.FetchNextBlocking();
139 }
140
141 while (!control_loops::angle_adjust.status->done) {
142 control_loops::angle_adjust.status.FetchNextBlocking();
143 if (ShouldExitAuto()) return;
144 }
145 LOG(INFO, "Angle adjuster done\n");
146}
147
Austin Schuh47017412013-03-10 11:50:46 -0700148void WaitForShooter() {
Austin Schuh6be011a2013-03-19 10:07:02 +0000149 LOG(INFO, "Waiting for the shooter to spin up\n");
Austin Schuh47017412013-03-10 11:50:46 -0700150 control_loops::shooter.status.FetchLatest();
Austin Schuh6be011a2013-03-19 10:07:02 +0000151
152 while (!control_loops::shooter.status.get()) {
153 LOG(WARNING, "No previous shooteracket, trying to fetch again\n");
Austin Schuh47017412013-03-10 11:50:46 -0700154 control_loops::shooter.status.FetchNextBlocking();
155 }
Austin Schuh47017412013-03-10 11:50:46 -0700156
Austin Schuh6be011a2013-03-19 10:07:02 +0000157 while (!control_loops::shooter.status->ready) {
158 control_loops::shooter.status.FetchNextBlocking();
159 if (ShouldExitAuto()) return;
Austin Schuh47017412013-03-10 11:50:46 -0700160 }
Austin Schuh6be011a2013-03-19 10:07:02 +0000161 LOG(INFO, "Shooter ready to shoot\n");
Austin Schuh47017412013-03-10 11:50:46 -0700162}
163
Austin Schuh6be011a2013-03-19 10:07:02 +0000164void ShootNDiscs(int n) {
165 LOG(INFO, "Waiting until %d discs have been shot\n", n);
166 control_loops::index_loop.status.FetchLatest();
167
168 while (!control_loops::index_loop.status.get()) {
169 LOG(WARNING, "No previous index_loop packet, trying to fetch again\n");
170 control_loops::index_loop.status.FetchNextBlocking();
171 }
172
173 int final_disc_count = control_loops::index_loop.status->shot_disc_count + n;
174 LOG(DEBUG, "Disc count should be %d when done\n", final_disc_count);
175 while (final_disc_count > control_loops::index_loop.status->shot_disc_count) {
176 control_loops::index_loop.status.FetchNextBlocking();
177 if (ShouldExitAuto()) return;
178 }
179 LOG(INFO, "Shot %d discs\n", n);
Austin Schuh47017412013-03-10 11:50:46 -0700180}
181
Austin Schuh6be011a2013-03-19 10:07:02 +0000182void StopDrivetrain() {
183 LOG(INFO, "Stopping the drivetrain\n");
Austin Schuh47017412013-03-10 11:50:46 -0700184 control_loops::drivetrain.goal.MakeWithBuilder()
Brian Silverman3b89ed82013-03-22 18:59:16 -0700185 .control_loop_driving(true)
Brian Silvermance86bac2013-03-31 19:07:24 -0700186 .left_goal(left_initial_position)
187 .left_velocity_goal(0)
188 .right_goal(right_initial_position)
189 .right_velocity_goal(0)
190 .quickturn(false)
191 .Send();
192}
193
194void ResetDrivetrain() {
195 LOG(INFO, "resetting the drivetrain\n");
196 control_loops::drivetrain.goal.MakeWithBuilder()
197 .control_loop_driving(false)
Austin Schuh6be011a2013-03-19 10:07:02 +0000198 .highgear(false)
199 .steering(0.0)
200 .throttle(0.0)
Austin Schuh6be011a2013-03-19 10:07:02 +0000201 .Send();
202}
203
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700204void SetDriveGoal(double yoffset, double maximum_velocity = 1.5) {
Austin Schuh6be011a2013-03-19 10:07:02 +0000205 LOG(INFO, "Going to move %f\n", yoffset);
206
207 // Measured conversion to get the distance right.
Austin Schuh6be011a2013-03-19 10:07:02 +0000208 ::aos::util::TrapezoidProfile profile(::aos::time::Time::InMS(10));
209 ::Eigen::Matrix<double, 2, 1> driveTrainState;
210 const double goal_velocity = 0.0;
211 const double epsilon = 0.01;
212
Austin Schuhfae53362013-03-23 04:39:48 +0000213 profile.set_maximum_acceleration(2.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700214 profile.set_maximum_velocity(maximum_velocity);
Austin Schuh6be011a2013-03-19 10:07:02 +0000215
Austin Schuh6be011a2013-03-19 10:07:02 +0000216 while (true) {
Brian Silverman7f09f972013-03-22 23:11:39 -0700217 ::aos::time::PhasedLoop10MS(5000); // wait until next 10ms tick
Austin Schuh6be011a2013-03-19 10:07:02 +0000218 driveTrainState = profile.Update(yoffset, goal_velocity);
219
Brian Silverman3b89ed82013-03-22 18:59:16 -0700220 if (::std::abs(driveTrainState(0, 0) - yoffset) < epsilon) break;
Austin Schuh6be011a2013-03-19 10:07:02 +0000221 if (ShouldExitAuto()) return;
222
223 LOG(DEBUG, "Driving left to %f, right to %f\n",
224 driveTrainState(0, 0) + left_initial_position,
225 driveTrainState(0, 0) + right_initial_position);
226 control_loops::drivetrain.goal.MakeWithBuilder()
227 .control_loop_driving(true)
228 .highgear(false)
229 .left_goal(driveTrainState(0, 0) + left_initial_position)
230 .right_goal(driveTrainState(0, 0) + right_initial_position)
231 .left_velocity_goal(driveTrainState(1, 0))
232 .right_velocity_goal(driveTrainState(1, 0))
233 .Send();
234 }
Brian Silverman3b89ed82013-03-22 18:59:16 -0700235 left_initial_position += yoffset;
236 right_initial_position += yoffset;
Austin Schuh6be011a2013-03-19 10:07:02 +0000237 LOG(INFO, "Done moving\n");
238}
239
Brian Silverman13be6682013-03-22 21:02:07 -0700240// Drives forward while we can pick up discs up to max_distance (in meters).
Brian Silverman7992d6e2013-03-24 19:20:54 -0700241void DriveForwardPickUp(double max_distance, double wrist_angle) {
Brian Silverman13be6682013-03-22 21:02:07 -0700242 LOG(INFO, "going to pick up at a max distance of %f\n", max_distance);
Brian Silverman13be6682013-03-22 21:02:07 -0700243
244 static const ::aos::time::Time kPeriod = ::aos::time::Time::InMS(10);
245 ::aos::util::TrapezoidProfile profile(kPeriod);
246 ::Eigen::Matrix<double, 2, 1> driveTrainState;
247 const double goal_velocity = 0.0;
248 const double epsilon = 0.01;
249 static const double kMaximumAcceleration = 1.0;
250
251 profile.set_maximum_acceleration(kMaximumAcceleration);
252 profile.set_maximum_velocity(0.6);
253
Brian Silverman13be6682013-03-22 21:02:07 -0700254 bool driving_back = false;
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700255 const double kDestination = -0.20;
Brian Silverman13be6682013-03-22 21:02:07 -0700256
257 while (true) {
Brian Silverman7f09f972013-03-22 23:11:39 -0700258 ::aos::time::PhasedLoop10MS(5000); // wait until next 10ms tick
Brian Silvermanc6ba6ee2013-03-22 21:10:38 -0700259 driveTrainState = profile.Update(driving_back ? kDestination : max_distance,
260 goal_velocity);
Brian Silverman13be6682013-03-22 21:02:07 -0700261
262 if (ShouldExitAuto()) return;
263
Brian Silvermanc6ba6ee2013-03-22 21:10:38 -0700264 if (driving_back) {
265 if (::std::abs(driveTrainState(0, 0)) < epsilon) break;
266 } else if (::std::abs(driveTrainState(0, 0) - max_distance) < epsilon) {
267 LOG(INFO, "went the max distance; driving back\n");
268 driving_back = true;
Brian Silverman7992d6e2013-03-24 19:20:54 -0700269 profile.set_maximum_velocity(2.5);
270 SetWristGoal(wrist_angle);
Brian Silverman13be6682013-03-22 21:02:07 -0700271 }
272
273 if (control_loops::index_loop.status.FetchLatest()) {
274 if (control_loops::index_loop.status->hopper_disc_count >= 4) {
275 LOG(INFO, "done intaking; driving back\n");
276 driving_back = true;
Brian Silverman7992d6e2013-03-24 19:20:54 -0700277 profile.set_maximum_velocity(2.5);
278 SetWristGoal(wrist_angle);
Brian Silverman13be6682013-03-22 21:02:07 -0700279 }
280 } else {
281 LOG(WARNING, "getting index status failed\n");
282 }
283
284 LOG(DEBUG, "Driving left to %f, right to %f\n",
285 driveTrainState(0, 0) + left_initial_position,
286 driveTrainState(0, 0) + right_initial_position);
287 control_loops::drivetrain.goal.MakeWithBuilder()
288 .control_loop_driving(true)
289 .highgear(false)
290 .left_goal(driveTrainState(0, 0) + left_initial_position)
291 .right_goal(driveTrainState(0, 0) + right_initial_position)
292 .left_velocity_goal(driveTrainState(1, 0))
293 .right_velocity_goal(driveTrainState(1, 0))
294 .Send();
295 }
Austin Schuhfae53362013-03-23 04:39:48 +0000296 left_initial_position += kDestination;
297 right_initial_position += kDestination;
Brian Silverman13be6682013-03-22 21:02:07 -0700298 LOG(INFO, "Done moving\n");
299}
300
Brian Silverman3b89ed82013-03-22 18:59:16 -0700301void DriveSpin(double radians) {
302 LOG(INFO, "going to spin %f\n", radians);
303
304 ::aos::util::TrapezoidProfile profile(::aos::time::Time::InMS(10));
305 ::Eigen::Matrix<double, 2, 1> driveTrainState;
306 const double goal_velocity = 0.0;
307 const double epsilon = 0.01;
Brian Silverman13be6682013-03-22 21:02:07 -0700308 // in drivetrain "meters"
Brian Silverman3b89ed82013-03-22 18:59:16 -0700309 const double kRobotWidth = 0.4544;
310
Brian Silverman7992d6e2013-03-24 19:20:54 -0700311 profile.set_maximum_acceleration(1.5);
312 profile.set_maximum_velocity(0.8);
Brian Silverman3b89ed82013-03-22 18:59:16 -0700313
314 const double side_offset = kRobotWidth * radians / 2.0;
315
316 while (true) {
Brian Silverman7f09f972013-03-22 23:11:39 -0700317 ::aos::time::PhasedLoop10MS(5000); // wait until next 10ms tick
Brian Silverman3b89ed82013-03-22 18:59:16 -0700318 driveTrainState = profile.Update(side_offset, goal_velocity);
319
320 if (::std::abs(driveTrainState(0, 0) - side_offset) < epsilon) break;
321 if (ShouldExitAuto()) return;
322
323 LOG(DEBUG, "Driving left to %f, right to %f\n",
Brian Silverman7992d6e2013-03-24 19:20:54 -0700324 left_initial_position - driveTrainState(0, 0),
325 right_initial_position + driveTrainState(0, 0));
Brian Silverman3b89ed82013-03-22 18:59:16 -0700326 control_loops::drivetrain.goal.MakeWithBuilder()
327 .control_loop_driving(true)
328 .highgear(false)
Brian Silverman7992d6e2013-03-24 19:20:54 -0700329 .left_goal(left_initial_position - driveTrainState(0, 0))
330 .right_goal(right_initial_position + driveTrainState(0, 0))
331 .left_velocity_goal(-driveTrainState(1, 0))
332 .right_velocity_goal(driveTrainState(1, 0))
Brian Silverman3b89ed82013-03-22 18:59:16 -0700333 .Send();
334 }
Brian Silverman7992d6e2013-03-24 19:20:54 -0700335 left_initial_position -= side_offset;
336 right_initial_position += side_offset;
Brian Silverman3b89ed82013-03-22 18:59:16 -0700337 LOG(INFO, "Done moving\n");
338}
339
340// start with N discs in the indexer
Austin Schuh6be011a2013-03-19 10:07:02 +0000341void HandleAuto() {
342 LOG(INFO, "Handling auto mode\n");
Brian Silvermance86bac2013-03-31 19:07:24 -0700343
Austin Schuh6be011a2013-03-19 10:07:02 +0000344 double WRIST_UP;
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
359 ::aos::robot_state.FetchLatest();
Brian Silvermanc5277542013-03-22 13:33:07 -0700360 if (!::aos::robot_state.get() ||
Austin Schuh6be011a2013-03-19 10:07:02 +0000361 !constants::wrist_hall_effect_start_angle(&WRIST_UP)) {
362 LOG(ERROR, "Constants not ready\n");
363 return;
364 }
365 WRIST_UP -= 0.4;
366 LOG(INFO, "Got constants\n");
Austin Schuh6be011a2013-03-19 10:07:02 +0000367
Brian Silverman3b89ed82013-03-22 18:59:16 -0700368 control_loops::drivetrain.position.FetchLatest();
369 while (!control_loops::drivetrain.position.get()) {
370 LOG(WARNING, "No previous drivetrain position packet, trying to fetch again\n");
371 control_loops::drivetrain.position.FetchNextBlocking();
372 }
373 left_initial_position =
374 control_loops::drivetrain.position->left_encoder;
375 right_initial_position =
376 control_loops::drivetrain.position->right_encoder;
377
Brian Silverman3b89ed82013-03-22 18:59:16 -0700378 StopDrivetrain();
Austin Schuh6be011a2013-03-19 10:07:02 +0000379
Brian Silverman7f09f972013-03-22 23:11:39 -0700380 SetWristGoal(WRIST_UP); // wrist must calibrate itself on power-up
Austin Schuh6be011a2013-03-19 10:07:02 +0000381 SetAngle_AdjustGoal(ANGLE_ONE);
Brian Silvermane296ebd2013-04-05 13:51:13 -0700382 SetShooterVelocity(395.0);
Brian Silvermanb8d389f2013-03-19 22:54:06 -0700383 WaitForIndexReset();
Brian Silverman7f09f972013-03-22 23:11:39 -0700384 if (ShouldExitAuto()) return;
385 PreloadIndex(); // spin to top and put 1 disc into loader
Austin Schuh6be011a2013-03-19 10:07:02 +0000386
387 if (ShouldExitAuto()) return;
388 WaitForWrist();
389 if (ShouldExitAuto()) return;
390 WaitForAngle_Adjust();
Brian Silverman7f09f972013-03-22 23:11:39 -0700391 ShootIndex(); // tilt up, shoot, repeat until empty
392 // calls WaitForShooter
393 ShootNDiscs(3); // ShootNDiscs returns if ShouldExitAuto
Austin Schuh6be011a2013-03-19 10:07:02 +0000394 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000395
Brian Silverman7f09f972013-03-22 23:11:39 -0700396 StartIndex(); // take in up to 4 discs
Austin Schuh6be011a2013-03-19 10:07:02 +0000397
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700398 if (false) {
399 const double kDistanceToCenterMeters = 3.11023;
400 const double kMaxPickupDistance = 2.5;
401 const double kTurnToCenterDegrees = 78.2;
Austin Schuh6be011a2013-03-19 10:07:02 +0000402
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700403 // Drive back to the center line.
404 SetDriveGoal(-kDistanceToCenterMeters);
405 if (ShouldExitAuto()) return;
Austin Schuh6be011a2013-03-19 10:07:02 +0000406
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700407 SetWristGoal(WRIST_DOWN);
408 // Turn towards the center.
409 DriveSpin(kTurnToCenterDegrees * M_PI / 180.0);
410 if (ShouldExitAuto()) return;
411 WaitForWrist();
412 if (ShouldExitAuto()) return;
Austin Schuhfae53362013-03-23 04:39:48 +0000413
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700414 // Pick up at most 4 discs and drive at most kMaxPickupDistance.
415 DriveForwardPickUp(kMaxPickupDistance, WRIST_UP);
Austin Schuhfae53362013-03-23 04:39:48 +0000416
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700417 SetWristGoal(WRIST_UP);
418 DriveSpin(-kTurnToCenterDegrees * M_PI / 180.0);
419 if (ShouldExitAuto()) return;
420 // Drive back to where we were.
421 SetDriveGoal(kDistanceToCenterMeters);
422 if (ShouldExitAuto()) return;
Austin Schuhfae53362013-03-23 04:39:48 +0000423
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700424 return;
Brian Silverman7992d6e2013-03-24 19:20:54 -0700425
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700426 ShootNDiscs(4);
427 if (ShouldExitAuto()) return;
428 } else {
Austin Schuh9f97ce62013-04-04 05:48:28 +0000429 // Delay to let the disc out of the shooter.
Brian Silverman304b2bf2013-04-04 17:54:41 -0700430 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700431 SetWristGoal(WRIST_DOWN);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700432 StartIndex(); // take in up to 4 discs
433
434 if (ShouldExitAuto()) return;
435 WaitForWrist(); // wrist must be down before moving
436 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.25));
Austin Schuh9f97ce62013-04-04 05:48:28 +0000437 SetAngle_AdjustGoal(ANGLE_TWO);
438 SetShooterVelocity(375.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700439
440 if (ShouldExitAuto()) return;
441 WaitForIndex(); // ready to pick up discs
442
Brian Silverman36690622013-09-22 19:43:10 -0700443 // How long we're going to drive in total.
Brian Silvermance86bac2013-03-31 19:07:24 -0700444 static const double kDriveDistance = 2.8;
Brian Silverman36690622013-09-22 19:43:10 -0700445 // How long to drive slowly to pick up the 2 disks under the pyramid.
446 static const double kFirstDrive = 0.4;
447 // How long to drive slowly to pick up the last 2 disks.
448 static const double kLastDrive = 0.3;
449 // How fast to drive when picking up disks.
450 static const double kPickupVelocity = 0.6;
451 // Where to take the second set of shots from.
Brian Silvermance86bac2013-03-31 19:07:24 -0700452 static const double kSecondShootDistance = 2.0;
Brian Silverman36690622013-09-22 19:43:10 -0700453
454 // Go slowly to grab the 2 disks under the pyramid.
455 SetDriveGoal(kFirstDrive, kPickupVelocity);
456 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.1));
457 SetDriveGoal(kDriveDistance - kFirstDrive - kLastDrive, 2.0);
Brian Silvermance86bac2013-03-31 19:07:24 -0700458 SetWristGoal(WRIST_DOWN_TWO);
Brian Silverman36690622013-09-22 19:43:10 -0700459 // Go slowly at the end to pick up the last 2 disks.
460 SetDriveGoal(kLastDrive, kPickupVelocity);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700461 if (ShouldExitAuto()) return;
462
Brian Silvermance86bac2013-03-31 19:07:24 -0700463 ::aos::time::SleepFor(::aos::time::Time::InSeconds(0.5));
464 SetDriveGoal(kSecondShootDistance - kDriveDistance, 2.0);
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700465 PreloadIndex();
Brian Silvermaned2cbde2013-03-31 01:56:14 -0700466
467 if (ShouldExitAuto()) return;
468 WaitForAngle_Adjust();
469 if (ShouldExitAuto()) return;
470 ShootIndex();
471 if (ShouldExitAuto()) return;
472 }
Austin Schuh47017412013-03-10 11:50:46 -0700473}
474
475} // namespace autonomous
476} // namespace frc971