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 | 6f62154 | 2014-04-06 16:00:41 -0700 | [diff] [blame] | 9 | #include "aos/common/logging/queue_logging.h" |
Brian Silverman | 598800f | 2013-05-09 17:08:42 -0700 | [diff] [blame] | 10 | |
| 11 | #include "frc971/autonomous/auto.q.h" |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 12 | #include "frc971/constants.h" |
| 13 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
Daniel Petti | 3b1e48f | 2015-02-15 15:57:53 -0800 | [diff] [blame] | 14 | #include "frc971/actors/drivetrain_actor.h" |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 15 | #include "frc971/control_loops/claw/claw.q.h" |
Brian Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 16 | #include "frc971/control_loops/fridge/fridge.q.h" |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 17 | #include "frc971/actors/pickup_actor.h" |
| 18 | #include "frc971/actors/stack_actor.h" |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 19 | #include "frc971/actors/held_to_lift_actor.h" |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 20 | |
| 21 | using ::aos::time::Time; |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 22 | using ::frc971::control_loops::claw_queue; |
Brian Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 23 | using ::frc971::control_loops::fridge_queue; |
Brian Silverman | 93936f7 | 2015-03-19 23:38:30 -0700 | [diff] [blame] | 24 | using ::frc971::control_loops::drivetrain_queue; |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 25 | |
| 26 | namespace frc971 { |
| 27 | namespace autonomous { |
| 28 | |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 29 | constexpr double kClawAutoVelocity = 3.00; |
| 30 | constexpr double kClawAutoAcceleration = 6.0; |
| 31 | constexpr double kAngleEpsilon = 0.10; |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 32 | const double kClawTotePackAngle = 0.90; |
| 33 | const double kArmRaiseLowerClearance = -0.08; |
| 34 | const double kClawStackClearance = 0.55; |
| 35 | const double kStackUpHeight = 0.60; |
| 36 | const double kStackUpArm = 0.0; |
| 37 | |
| 38 | struct ProfileParams { |
| 39 | double velocity; |
| 40 | double acceleration; |
| 41 | }; |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 42 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 43 | namespace time = ::aos::time; |
| 44 | |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 45 | static double left_initial_position, right_initial_position; |
| 46 | |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 47 | bool 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 Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 56 | void StopDrivetrain() { |
| 57 | LOG(INFO, "Stopping the drivetrain\n"); |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 58 | control_loops::drivetrain_queue.goal.MakeWithBuilder() |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 59 | .control_loop_driving(true) |
Brian Silverman | ce86bac | 2013-03-31 19:07:24 -0700 | [diff] [blame] | 60 | .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 | |
| 68 | void ResetDrivetrain() { |
| 69 | LOG(INFO, "resetting the drivetrain\n"); |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 70 | control_loops::drivetrain_queue.goal.MakeWithBuilder() |
Brian Silverman | ce86bac | 2013-03-31 19:07:24 -0700 | [diff] [blame] | 71 | .control_loop_driving(false) |
Brian Silverman | 93335ae | 2015-01-26 20:43:39 -0500 | [diff] [blame] | 72 | //.highgear(false) |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 73 | .steering(0.0) |
| 74 | .throttle(0.0) |
Brian Silverman | 38ea9bf | 2014-04-19 22:57:54 -0700 | [diff] [blame] | 75 | .left_goal(left_initial_position) |
| 76 | .left_velocity_goal(0) |
| 77 | .right_goal(right_initial_position) |
| 78 | .right_velocity_goal(0) |
Austin Schuh | 6be011a | 2013-03-19 10:07:02 +0000 | [diff] [blame] | 79 | .Send(); |
| 80 | } |
| 81 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 82 | void WaitUntilDoneOrCanceled( |
| 83 | ::std::unique_ptr<aos::common::actions::Action> action) { |
| 84 | if (!action) { |
| 85 | LOG(ERROR, "No action, not waiting\n"); |
| 86 | return; |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 87 | } |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 88 | while (true) { |
| 89 | // Poll the running bit and auto done bits. |
Brian Silverman | 547abb3 | 2015-02-16 00:37:48 -0500 | [diff] [blame] | 90 | ::aos::time::PhasedLoopXMS(5, 2500); |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 91 | if (!action->Running() || ShouldExitAuto()) { |
| 92 | return; |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 97 | void 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 | |
| 113 | void 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 | |
| 131 | const ProfileParams kFastDrive = {2.0, 3.5}; |
| 132 | const ProfileParams kFastKnockDrive = {2.0, 3.0}; |
| 133 | const ProfileParams kStackingDrive = {2.0, 1.5}; |
| 134 | const ProfileParams kFastTurn = {3.0, 10.0}; |
| 135 | const ProfileParams kComboTurn = {1.2, 8.0}; |
| 136 | const ProfileParams kRaceTurn = {4.0, 10.0}; |
| 137 | const ProfileParams kRaceDrive = {2.0, 2.0}; |
| 138 | const ProfileParams kRaceBackupDrive = {2.0, 5.0}; |
| 139 | |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 140 | ::std::unique_ptr<::frc971::actors::DrivetrainAction> SetDriveGoal( |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 141 | double distance, const ProfileParams drive_params, double theta = 0, const ProfileParams &turn_params = kFastTurn) { |
Austin Schuh | a4faacc | 2014-03-09 00:50:50 -0800 | [diff] [blame] | 142 | LOG(INFO, "Driving to %f\n", distance); |
Ben Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 143 | |
| 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 Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 149 | 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 Fredrickson | 9fb2ab1 | 2015-02-16 16:42:08 -0800 | [diff] [blame] | 153 | auto drivetrain_action = actors::MakeDrivetrainAction(params); |
| 154 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 155 | drivetrain_action->Start(); |
Brian Silverman | ad9e000 | 2014-04-13 14:55:57 -0700 | [diff] [blame] | 156 | left_initial_position += |
| 157 | distance - theta * constants::GetValues().turn_width / 2.0; |
| 158 | right_initial_position += |
Daniel Petti | b0733be | 2014-11-14 22:44:03 -0800 | [diff] [blame] | 159 | distance + theta * constants::GetValues().turn_width / 2.0; |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 160 | return ::std::move(drivetrain_action); |
| 161 | } |
| 162 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 163 | const ProfileParams kFridgeYProfile{1.0, 4.0}; |
| 164 | const ProfileParams kFridgeXProfile{1.0, 2.0}; |
| 165 | const ProfileParams kFridgeFastXProfile{1.2, 5.0}; |
| 166 | |
| 167 | static double fridge_goal_x = 0.0; |
| 168 | static double fridge_goal_y = 0.0; |
| 169 | |
| 170 | void 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 Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 195 | } |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 196 | } |
| 197 | |
| 198 | void 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 | |
| 231 | void InitializeEncoders() { |
| 232 | control_loops::drivetrain_queue.status.FetchAnother(); |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 233 | left_initial_position = |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 234 | control_loops::drivetrain_queue.status->filtered_left_position; |
Brian Silverman | 3b89ed8 | 2013-03-22 18:59:16 -0700 | [diff] [blame] | 235 | right_initial_position = |
Brian Silverman | ada5f2c | 2015-02-01 02:41:14 -0500 | [diff] [blame] | 236 | control_loops::drivetrain_queue.status->filtered_right_position; |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 239 | void 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 | |
| 253 | void 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 | |
| 267 | constexpr ProfileParams kDefaultClawParams = {kClawAutoVelocity, |
| 268 | kClawAutoAcceleration}; |
| 269 | |
| 270 | // Move the claw in a very small number of cycles. |
| 271 | constexpr ProfileParams kInstantaneousClaw = {100.0, 100.0}; |
| 272 | constexpr ProfileParams kFastClaw = {8.0, 20.0}; |
| 273 | |
| 274 | void SetClawStateNoWait(double angle, double intake_voltage, |
| 275 | double rollers_closed, |
| 276 | const ProfileParams &claw_params = kDefaultClawParams) { |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 277 | auto message = control_loops::claw_queue.goal.MakeMessage(); |
| 278 | message->angle = angle; |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 279 | message->max_velocity = claw_params.velocity; |
| 280 | message->max_acceleration = claw_params.acceleration; |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 281 | 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 Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 287 | } |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 288 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 289 | void 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 Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 292 | 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 Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 303 | if (ShouldExitAuto()) return; |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 304 | } |
| 305 | } |
| 306 | |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 307 | void HandleAuto() { |
Austin Schuh | 577edf6 | 2014-04-13 10:33:05 -0700 | [diff] [blame] | 308 | ::aos::time::Time start_time = ::aos::time::Time::Now(); |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 309 | LOG(INFO, "Starting auto mode at %f\n", start_time.ToSeconds()); |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 310 | ::std::unique_ptr<::frc971::actors::DrivetrainAction> drive; |
| 311 | ::std::unique_ptr<::frc971::actors::PickupAction> pickup; |
| 312 | ::std::unique_ptr<::frc971::actors::StackAction> stack; |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 313 | ::std::unique_ptr<::frc971::actors::HeldToLiftAction> lift; |
Austin Schuh | 80ff2e1 | 2014-03-08 12:06:19 -0800 | [diff] [blame] | 314 | |
| 315 | if (ShouldExitAuto()) return; |
| 316 | InitializeEncoders(); |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 317 | ResetDrivetrain(); |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 318 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 319 | WaitForClawZero(); |
| 320 | WaitForFridgeZero(); |
Brian Silverman | 93936f7 | 2015-03-19 23:38:30 -0700 | [diff] [blame] | 321 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 322 | // Initialize the fridge. |
| 323 | MoveFridge(0.0, 0.3, true, kFridgeXProfile, kFridgeYProfile); |
Brian Silverman | 93936f7 | 2015-03-19 23:38:30 -0700 | [diff] [blame] | 324 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 325 | 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 Silverman | 93936f7 | 2015-03-19 23:38:30 -0700 | [diff] [blame] | 329 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 330 | time::SleepFor(time::Time::InSeconds(0.7)); |
| 331 | LOG(INFO, "Done sucking in tote\n"); |
Brian Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 332 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 333 | // Now pick it up |
Brian Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 334 | { |
| 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 Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 344 | params.intake_time = 0.60; |
| 345 | params.intake_voltage = 6.5; |
Brian Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 346 | pickup = actors::MakePickupAction(params); |
| 347 | pickup->Start(); |
Brian Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 348 | } |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 349 | |
| 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 Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 356 | if (ShouldExitAuto()) return; |
| 357 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 358 | LOG(INFO, "Now driving next to the can\n"); |
| 359 | drive = SetDriveGoal(0.60, kFastDrive); |
Brian Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 360 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 361 | 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 Silverman | 5bfda6c | 2015-03-21 23:40:13 -0700 | [diff] [blame] | 536 | |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 537 | if (ShouldExitAuto()) return; |
| 538 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 539 | LOG(INFO, "Retracting\n"); |
| 540 | MoveFridge(0.0, 0.10, false, kFridgeFastXProfile, kFridgeYProfile); |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 541 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 542 | SetClawState(0.0, 0.0, false, kFastClaw); |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 543 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 544 | if (ShouldExitAuto()) return; |
| 545 | WaitForFridge(); |
| 546 | if (ShouldExitAuto()) return; |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 547 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 548 | WaitUntilDoneOrCanceled(::std::move(drive)); |
| 549 | if (ShouldExitAuto()) return; |
Ben Fredrickson | 0a6ad25 | 2015-03-15 18:51:42 -0700 | [diff] [blame] | 550 | |
Austin Schuh | 1f3764e | 2015-04-18 23:00:09 -0700 | [diff] [blame^] | 551 | LOG(INFO, "Backing away to let the stack ago\n"); |
| 552 | drive = SetDriveGoal(-0.1, kRaceBackupDrive); |
| 553 | WaitUntilDoneOrCanceled(::std::move(drive)); |
Austin Schuh | 4701741 | 2013-03-10 11:50:46 -0700 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | } // namespace autonomous |
| 557 | } // namespace frc971 |