Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | |
| 3 | #include <memory> |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 4 | |
Brian | 3afd6fc | 2014-04-02 20:41:49 -0700 | [diff] [blame] | 5 | #include "aos/common/util/phased_loop.h" |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 6 | #include "aos/common/time.h" |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 7 | #include "aos/common/util/trapezoid_profile.h" |
Brian Silverman | 598800f | 2013-05-09 17:08:42 -0700 | [diff] [blame] | 8 | #include "aos/common/logging/logging.h" |
Brian Silverman | 96d9cea | 2013-11-12 21:10:50 -0800 | [diff] [blame] | 9 | #include "aos/common/network/team_number.h" |
Brian Silverman | 6f62154 | 2014-04-06 16:00:41 -0700 | [diff] [blame] | 10 | #include "aos/common/logging/queue_logging.h" |
Brian Silverman | 598800f | 2013-05-09 17:08:42 -0700 | [diff] [blame] | 11 | |
| 12 | #include "frc971/autonomous/auto.q.h" |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 13 | #include "frc971/constants.h" |
| 14 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 15 | #include "frc971/control_loops/shooter/shooter.q.h" |
| 16 | #include "frc971/control_loops/claw/claw.q.h" |
| 17 | #include "frc971/actions/action_client.h" |
| 18 | #include "frc971/actions/shoot_action.h" |
| 19 | #include "frc971/actions/drivetrain_action.h" |
Brian Silverman | 6f62154 | 2014-04-06 16:00:41 -0700 | [diff] [blame] | 20 | #include "frc971/queues/hot_goal.q.h" |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 21 | |
| 22 | using ::aos::time::Time; |
| 23 | |
| 24 | namespace frc971 { |
| 25 | namespace autonomous { |
| 26 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 27 | namespace time = ::aos::time; |
| 28 | |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 29 | static double left_initial_position, right_initial_position; |
| 30 | |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 31 | bool ShouldExitAuto() { |
| 32 | ::frc971::autonomous::autonomous.FetchLatest(); |
| 33 | bool ans = !::frc971::autonomous::autonomous->run_auto; |
| 34 | if (ans) { |
| 35 | LOG(INFO, "Time to exit auto mode\n"); |
| 36 | } |
| 37 | return ans; |
| 38 | } |
| 39 | |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 40 | void StopDrivetrain() { |
| 41 | LOG(INFO, "Stopping the drivetrain\n"); |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 42 | control_loops::drivetrain.goal.MakeWithBuilder() |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 43 | .control_loop_driving(true) |
Brian Silverman | ce86bac | 2013-03-31 19:07:24 -0700 | [diff] [blame] | 44 | .left_goal(left_initial_position) |
| 45 | .left_velocity_goal(0) |
| 46 | .right_goal(right_initial_position) |
| 47 | .right_velocity_goal(0) |
| 48 | .quickturn(false) |
| 49 | .Send(); |
| 50 | } |
| 51 | |
| 52 | void ResetDrivetrain() { |
| 53 | LOG(INFO, "resetting the drivetrain\n"); |
| 54 | control_loops::drivetrain.goal.MakeWithBuilder() |
| 55 | .control_loop_driving(false) |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 56 | .highgear(false) |
| 57 | .steering(0.0) |
| 58 | .throttle(0.0) |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 59 | .Send(); |
| 60 | } |
| 61 | |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 62 | void DriveSpin(double radians) { |
| 63 | LOG(INFO, "going to spin %f\n", radians); |
| 64 | |
| 65 | ::aos::util::TrapezoidProfile profile(::aos::time::Time::InMS(10)); |
| 66 | ::Eigen::Matrix<double, 2, 1> driveTrainState; |
| 67 | const double goal_velocity = 0.0; |
| 68 | const double epsilon = 0.01; |
Brian Silverman | 13be668 | 2013-03-22 21:02:07 -0700 | [diff] [blame] | 69 | // in drivetrain "meters" |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 70 | const double kRobotWidth = 0.4544; |
| 71 | |
Brian Silverman | 7992d6e | 2013-03-24 19:20:54 -0700 | [diff] [blame] | 72 | profile.set_maximum_acceleration(1.5); |
| 73 | profile.set_maximum_velocity(0.8); |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 74 | |
| 75 | const double side_offset = kRobotWidth * radians / 2.0; |
| 76 | |
| 77 | while (true) { |
Brian Silverman | 7f09f97 | 2013-03-22 23:11:39 -0700 | [diff] [blame] | 78 | ::aos::time::PhasedLoop10MS(5000); // wait until next 10ms tick |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 79 | driveTrainState = profile.Update(side_offset, goal_velocity); |
| 80 | |
| 81 | if (::std::abs(driveTrainState(0, 0) - side_offset) < epsilon) break; |
| 82 | if (ShouldExitAuto()) return; |
| 83 | |
| 84 | LOG(DEBUG, "Driving left to %f, right to %f\n", |
Brian Silverman | 7992d6e | 2013-03-24 19:20:54 -0700 | [diff] [blame] | 85 | left_initial_position - driveTrainState(0, 0), |
| 86 | right_initial_position + driveTrainState(0, 0)); |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 87 | control_loops::drivetrain.goal.MakeWithBuilder() |
| 88 | .control_loop_driving(true) |
| 89 | .highgear(false) |
Brian Silverman | 7992d6e | 2013-03-24 19:20:54 -0700 | [diff] [blame] | 90 | .left_goal(left_initial_position - driveTrainState(0, 0)) |
| 91 | .right_goal(right_initial_position + driveTrainState(0, 0)) |
| 92 | .left_velocity_goal(-driveTrainState(1, 0)) |
| 93 | .right_velocity_goal(driveTrainState(1, 0)) |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 94 | .Send(); |
| 95 | } |
Brian Silverman | 7992d6e | 2013-03-24 19:20:54 -0700 | [diff] [blame] | 96 | left_initial_position -= side_offset; |
| 97 | right_initial_position += side_offset; |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 98 | LOG(INFO, "Done moving\n"); |
| 99 | } |
| 100 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 101 | void PositionClawVertically(double intake_power = 0.0, double centering_power = 0.0) { |
| 102 | if (!control_loops::claw_queue_group.goal.MakeWithBuilder() |
| 103 | .bottom_angle(0.0) |
| 104 | .separation_angle(0.0) |
| 105 | .intake(intake_power) |
| 106 | .centering(centering_power) |
| 107 | .Send()) { |
| 108 | LOG(WARNING, "sending claw goal failed\n"); |
| 109 | } |
| 110 | } |
Brian Silverman | ce86bac | 2013-03-31 19:07:24 -0700 | [diff] [blame] | 111 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 112 | void PositionClawBackIntake() { |
| 113 | if (!control_loops::claw_queue_group.goal.MakeWithBuilder() |
| 114 | .bottom_angle(-2.273474) |
| 115 | .separation_angle(0.0) |
| 116 | .intake(12.0) |
| 117 | .centering(12.0) |
| 118 | .Send()) { |
| 119 | LOG(WARNING, "sending claw goal failed\n"); |
| 120 | } |
| 121 | } |
Brian Silverman | ce86bac | 2013-03-31 19:07:24 -0700 | [diff] [blame] | 122 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 123 | void PositionClawForShot() { |
| 124 | // Turn the claw on, keep it straight up until the ball has been grabbed. |
| 125 | if (!control_loops::claw_queue_group.goal.MakeWithBuilder() |
Brian Silverman | 31b5b82 | 2014-03-14 18:50:39 -0700 | [diff] [blame] | 126 | .bottom_angle(0.86) |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 127 | .separation_angle(0.10) |
| 128 | .intake(4.0) |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 129 | .centering(1.0) |
| 130 | .Send()) { |
| 131 | LOG(WARNING, "sending claw goal failed\n"); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void SetShotPower(double power) { |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 136 | LOG(INFO, "Setting shot power to %f\n", power); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 137 | if (!control_loops::shooter_queue_group.goal.MakeWithBuilder() |
| 138 | .shot_power(power) |
| 139 | .shot_requested(false) |
| 140 | .unload_requested(false) |
| 141 | .load_requested(false) |
| 142 | .Send()) { |
| 143 | LOG(WARNING, "sending shooter goal failed\n"); |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | void WaitUntilDoneOrCanceled(Action *action) { |
| 148 | while (true) { |
| 149 | // Poll the running bit and auto done bits. |
| 150 | ::aos::time::PhasedLoop10MS(5000); |
| 151 | if (!action->Running() || ShouldExitAuto()) { |
| 152 | return; |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void Shoot() { |
| 158 | // Shoot. |
| 159 | auto shoot_action = actions::MakeShootAction(); |
| 160 | shoot_action->Start(); |
| 161 | WaitUntilDoneOrCanceled(shoot_action.get()); |
| 162 | } |
| 163 | |
| 164 | ::std::unique_ptr<TypedAction< ::frc971::actions::DrivetrainActionQueueGroup>> |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 165 | SetDriveGoal(double distance, double maximum_velocity = 1.7, double theta = 0) { |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 166 | LOG(INFO, "Driving to %f\n", distance); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 167 | auto drivetrain_action = actions::MakeDrivetrainAction(); |
| 168 | drivetrain_action->GetGoal()->left_initial_position = left_initial_position; |
| 169 | drivetrain_action->GetGoal()->right_initial_position = right_initial_position; |
| 170 | drivetrain_action->GetGoal()->y_offset = distance; |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 171 | drivetrain_action->GetGoal()->theta_offset = theta; |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 172 | drivetrain_action->GetGoal()->maximum_velocity = maximum_velocity; |
| 173 | drivetrain_action->Start(); |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 174 | left_initial_position += |
| 175 | distance - theta * constants::GetValues().turn_width / 2.0; |
| 176 | right_initial_position += |
| 177 | distance + theta * constants::GetValues().turn_width / 2. - |
| 178 | theta * constants::GetValues().turn_width / 2.00; |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 179 | return ::std::move(drivetrain_action); |
| 180 | } |
| 181 | |
| 182 | void InitializeEncoders() { |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 183 | control_loops::drivetrain.status.FetchLatest(); |
| 184 | while (!control_loops::drivetrain.status.get()) { |
Brian Silverman | 2c1e034 | 2014-04-11 16:15:01 -0700 | [diff] [blame] | 185 | LOG(WARNING, |
| 186 | "No previous drivetrain position packet, trying to fetch again\n"); |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 187 | control_loops::drivetrain.status.FetchNextBlocking(); |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 188 | } |
| 189 | left_initial_position = |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 190 | control_loops::drivetrain.status->filtered_left_position; |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 191 | right_initial_position = |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 192 | control_loops::drivetrain.status->filtered_right_position; |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 193 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 194 | } |
| 195 | |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 196 | void WaitUntilClawDone() { |
| 197 | while (true) { |
| 198 | // Poll the running bit and auto done bits. |
| 199 | ::aos::time::PhasedLoop10MS(5000); |
| 200 | control_loops::claw_queue_group.status.FetchLatest(); |
| 201 | control_loops::claw_queue_group.goal.FetchLatest(); |
| 202 | if (ShouldExitAuto()) { |
| 203 | return; |
| 204 | } |
| 205 | if (control_loops::claw_queue_group.status.get() == nullptr || |
| 206 | control_loops::claw_queue_group.goal.get() == nullptr) { |
| 207 | continue; |
| 208 | } |
| 209 | bool ans = |
| 210 | control_loops::claw_queue_group.status->zeroed && |
| 211 | (::std::abs(control_loops::claw_queue_group.status->bottom_velocity) < |
| 212 | 1.0) && |
| 213 | (::std::abs(control_loops::claw_queue_group.status->bottom - |
| 214 | control_loops::claw_queue_group.goal->bottom_angle) < |
| 215 | 0.10) && |
| 216 | (::std::abs(control_loops::claw_queue_group.status->separation - |
| 217 | control_loops::claw_queue_group.goal->separation_angle) < |
| 218 | 0.4); |
| 219 | if (ans) { |
| 220 | return; |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 225 | void HandleAuto() { |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 226 | // The front of the robot is 1.854 meters from the wall |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 227 | static const double kShootDistance = 3.15; |
| 228 | static const double kPickupDistance = 0.5; |
| 229 | static const double kTurnAngle = 0.3; |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 230 | ::aos::time::Time start_time = ::aos::time::Time::Now(); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 231 | LOG(INFO, "Handling auto mode\n"); |
Brian Silverman | b36ae1f | 2014-04-17 15:13:41 -0700 | [diff] [blame^] | 232 | |
Brian Silverman | 6f62154 | 2014-04-06 16:00:41 -0700 | [diff] [blame] | 233 | ::frc971::HotGoal start_counts; |
| 234 | hot_goal.FetchLatest(); |
Brian Silverman | b36ae1f | 2014-04-17 15:13:41 -0700 | [diff] [blame^] | 235 | bool start_counts_valid = true; |
Brian Silverman | 6f62154 | 2014-04-06 16:00:41 -0700 | [diff] [blame] | 236 | if (!hot_goal.get()) { |
Brian Silverman | b36ae1f | 2014-04-17 15:13:41 -0700 | [diff] [blame^] | 237 | LOG(WARNING, "no hot goal message. will ignore\n"); |
| 238 | start_counts_valid = false; |
Brian Silverman | 6f62154 | 2014-04-06 16:00:41 -0700 | [diff] [blame] | 239 | } else { |
| 240 | memcpy(&start_counts, hot_goal.get(), sizeof(start_counts)); |
| 241 | LOG_STRUCT(INFO, "counts at start", start_counts); |
| 242 | } |
Brian Silverman | b36ae1f | 2014-04-17 15:13:41 -0700 | [diff] [blame^] | 243 | (void)start_counts_valid; |
Brian Silverman | 6f62154 | 2014-04-06 16:00:41 -0700 | [diff] [blame] | 244 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 245 | ResetDrivetrain(); |
| 246 | |
| 247 | if (ShouldExitAuto()) return; |
| 248 | InitializeEncoders(); |
| 249 | |
| 250 | // Turn the claw on, keep it straight up until the ball has been grabbed. |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 251 | LOG(INFO, "Claw going up at %f\n", |
| 252 | (::aos::time::Time::Now() - start_time).ToSeconds()); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 253 | PositionClawVertically(12.0, 4.0); |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 254 | SetShotPower(115.0); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 255 | |
| 256 | // Wait for the ball to enter the claw. |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 257 | time::SleepFor(time::Time::InSeconds(0.25)); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 258 | if (ShouldExitAuto()) return; |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 259 | LOG(INFO, "Readying claw for shot at %f\n", |
| 260 | (::aos::time::Time::Now() - start_time).ToSeconds()); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 261 | |
| 262 | { |
| 263 | if (ShouldExitAuto()) return; |
| 264 | // Drive to the goal. |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 265 | auto drivetrain_action = SetDriveGoal(-kShootDistance, 2.5); |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 266 | time::SleepFor(time::Time::InSeconds(0.75)); |
| 267 | PositionClawForShot(); |
| 268 | LOG(INFO, "Waiting until drivetrain is finished\n"); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 269 | WaitUntilDoneOrCanceled(drivetrain_action.get()); |
| 270 | if (ShouldExitAuto()) return; |
| 271 | } |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 272 | |
| 273 | { |
| 274 | if (ShouldExitAuto()) return; |
| 275 | auto drivetrain_action = SetDriveGoal(0, 0, kTurnAngle); |
| 276 | WaitUntilDoneOrCanceled(drivetrain_action.get()); |
| 277 | if (ShouldExitAuto()) return; |
| 278 | } |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 279 | |
| 280 | // Shoot. |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 281 | LOG(INFO, "Shooting at %f\n", |
| 282 | (::aos::time::Time::Now() - start_time).ToSeconds()); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 283 | Shoot(); |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 284 | time::SleepFor(time::Time::InSeconds(0.05)); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 285 | |
| 286 | { |
| 287 | if (ShouldExitAuto()) return; |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 288 | auto drivetrain_action = SetDriveGoal(0, 0, -kTurnAngle); |
| 289 | WaitUntilDoneOrCanceled(drivetrain_action.get()); |
| 290 | if (ShouldExitAuto()) return; |
| 291 | } |
| 292 | |
| 293 | { |
| 294 | if (ShouldExitAuto()) return; |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 295 | // Intake the new ball. |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 296 | LOG(INFO, "Claw ready for intake at %f\n", |
| 297 | (::aos::time::Time::Now() - start_time).ToSeconds()); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 298 | PositionClawBackIntake(); |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 299 | auto drivetrain_action = |
| 300 | SetDriveGoal(kShootDistance + kPickupDistance, 2.5); |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 301 | LOG(INFO, "Waiting until drivetrain is finished\n"); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 302 | WaitUntilDoneOrCanceled(drivetrain_action.get()); |
| 303 | if (ShouldExitAuto()) return; |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 304 | LOG(INFO, "Wait for the claw at %f\n", |
| 305 | (::aos::time::Time::Now() - start_time).ToSeconds()); |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 306 | WaitUntilClawDone(); |
| 307 | if (ShouldExitAuto()) return; |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | // Drive back. |
| 311 | { |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 312 | LOG(INFO, "Driving back at %f\n", |
| 313 | (::aos::time::Time::Now() - start_time).ToSeconds()); |
Brian Silverman | b94069c | 2014-04-17 14:34:24 -0700 | [diff] [blame] | 314 | auto drivetrain_action = |
| 315 | SetDriveGoal(-(kShootDistance + kPickupDistance), 2.5); |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 316 | time::SleepFor(time::Time::InSeconds(0.3)); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 317 | if (ShouldExitAuto()) return; |
| 318 | PositionClawForShot(); |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 319 | LOG(INFO, "Waiting until drivetrain is finished\n"); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 320 | WaitUntilDoneOrCanceled(drivetrain_action.get()); |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 321 | WaitUntilClawDone(); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 322 | if (ShouldExitAuto()) return; |
| 323 | } |
| 324 | |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 325 | { |
| 326 | if (ShouldExitAuto()) return; |
| 327 | auto drivetrain_action = SetDriveGoal(0, 0, -kTurnAngle); |
| 328 | WaitUntilDoneOrCanceled(drivetrain_action.get()); |
| 329 | if (ShouldExitAuto()) return; |
| 330 | } |
| 331 | |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 332 | LOG(INFO, "Shooting at %f\n", |
| 333 | (::aos::time::Time::Now() - start_time).ToSeconds()); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 334 | // Shoot |
| 335 | Shoot(); |
| 336 | if (ShouldExitAuto()) return; |
| 337 | |
| 338 | // Get ready to zero when we come back up. |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 339 | time::SleepFor(time::Time::InSeconds(0.05)); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 340 | PositionClawVertically(0.0, 0.0); |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | } // namespace autonomous |
| 344 | } // namespace frc971 |