Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 1 | #include "y2019/actors/autonomous_actor.h" |
| 2 | |
| 3 | #include <inttypes.h> |
| 4 | |
| 5 | #include <chrono> |
| 6 | #include <cmath> |
| 7 | |
| 8 | #include "aos/logging/logging.h" |
| 9 | #include "aos/util/phased_loop.h" |
| 10 | |
| 11 | #include "frc971/control_loops/drivetrain/drivetrain.q.h" |
| 12 | #include "frc971/control_loops/drivetrain/localizer.q.h" |
Austin Schuh | 6bcc230 | 2019-03-23 22:28:06 -0700 | [diff] [blame] | 13 | #include "y2019/actors/auto_splines.h" |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 14 | #include "y2019/control_loops/drivetrain/drivetrain_base.h" |
| 15 | |
| 16 | namespace y2019 { |
| 17 | namespace actors { |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 18 | using ::aos::monotonic_clock; |
| 19 | namespace chrono = ::std::chrono; |
| 20 | |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 21 | AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop) |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 22 | : frc971::autonomous::BaseAutonomousActor( |
Austin Schuh | 1bf8a21 | 2019-05-26 22:13:14 -0700 | [diff] [blame] | 23 | event_loop, control_loops::drivetrain::GetDrivetrainConfig()), |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 24 | localizer_control_sender_( |
| 25 | event_loop->MakeSender< |
| 26 | ::frc971::control_loops::drivetrain::LocalizerControl>( |
Austin Schuh | 170f495 | 2019-06-29 18:58:30 -0700 | [diff] [blame] | 27 | ".frc971.control_loops.drivetrain.localizer_control")), |
| 28 | superstructure_goal_sender_( |
| 29 | event_loop->MakeSender<::y2019::control_loops::superstructure:: |
| 30 | SuperstructureQueue::Goal>( |
| 31 | ".y2019.control_loops.superstructure.superstructure_queue.goal")), |
| 32 | superstructure_status_fetcher_(event_loop->MakeFetcher< |
| 33 | ::y2019::control_loops::superstructure:: |
| 34 | SuperstructureQueue::Status>( |
| 35 | ".y2019.control_loops.superstructure.superstructure_queue.status")) {} |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 36 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 37 | bool AutonomousActor::WaitForDriveXGreater(double x) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 38 | AOS_LOG(INFO, "Waiting until x > %f\n", x); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 39 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 40 | event_loop()->monotonic_now(), |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 41 | ::std::chrono::milliseconds(5) / 2); |
| 42 | |
| 43 | while (true) { |
| 44 | if (ShouldCancel()) { |
| 45 | return false; |
| 46 | } |
| 47 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 48 | drivetrain_status_fetcher_.Fetch(); |
| 49 | if (drivetrain_status_fetcher_->x > x) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 50 | AOS_LOG(INFO, "X at %f\n", drivetrain_status_fetcher_->x); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 51 | return true; |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | bool AutonomousActor::WaitForDriveYCloseToZero(double y) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 57 | AOS_LOG(INFO, "Waiting until |y| < %f\n", y); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 58 | ::aos::time::PhasedLoop phased_loop(::std::chrono::milliseconds(5), |
Austin Schuh | d32b362 | 2019-06-23 18:49:06 -0700 | [diff] [blame] | 59 | event_loop()->monotonic_now(), |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 60 | ::std::chrono::milliseconds(5) / 2); |
| 61 | |
| 62 | while (true) { |
| 63 | if (ShouldCancel()) { |
| 64 | return false; |
| 65 | } |
| 66 | phased_loop.SleepUntilNext(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 67 | drivetrain_status_fetcher_.Fetch(); |
| 68 | if (::std::abs(drivetrain_status_fetcher_->y) < y) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 69 | AOS_LOG(INFO, "Y at %f\n", drivetrain_status_fetcher_->y); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 70 | return true; |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 75 | void AutonomousActor::Reset(bool is_left) { |
| 76 | const double turn_scalar = is_left ? 1.0 : -1.0; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 77 | elevator_goal_ = 0.01; |
| 78 | wrist_goal_ = -M_PI / 2.0; |
| 79 | intake_goal_ = -1.2; |
| 80 | |
| 81 | suction_on_ = false; |
| 82 | suction_gamepiece_ = 1; |
| 83 | |
| 84 | elevator_max_velocity_ = 0.0; |
| 85 | elevator_max_acceleration_ = 0.0; |
| 86 | wrist_max_velocity_ = 0.0; |
| 87 | wrist_max_acceleration_ = 0.0; |
| 88 | |
| 89 | InitializeEncoders(); |
| 90 | SendSuperstructureGoal(); |
| 91 | |
| 92 | { |
Austin Schuh | eb99d07 | 2019-05-12 21:03:38 -0700 | [diff] [blame] | 93 | auto localizer_resetter = localizer_control_sender_.MakeMessage(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 94 | // Start on the left l2. |
| 95 | localizer_resetter->x = 1.0; |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 96 | localizer_resetter->y = 1.35 * turn_scalar; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 97 | localizer_resetter->theta = M_PI; |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 98 | localizer_resetter->theta_uncertainty = 0.00001; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 99 | if (!localizer_resetter.Send()) { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 100 | AOS_LOG(ERROR, "Failed to reset localizer.\n"); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
| 104 | // Wait for the drivetrain to run so it has time to reset the heading. |
| 105 | // Otherwise our drivetrain reset will do a 180 right at the start. |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 106 | WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); }); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 107 | AOS_LOG(INFO, "Heading is %f\n", |
| 108 | drivetrain_status_fetcher_->estimated_heading); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 109 | InitializeEncoders(); |
| 110 | ResetDrivetrain(); |
Austin Schuh | bd0a40f | 2019-06-30 14:56:31 -0700 | [diff] [blame] | 111 | WaitUntil([this]() { return drivetrain_status_fetcher_.Fetch(); }); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 112 | AOS_LOG(INFO, "Heading is %f\n", |
| 113 | drivetrain_status_fetcher_->estimated_heading); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 114 | |
| 115 | ResetDrivetrain(); |
| 116 | InitializeEncoders(); |
| 117 | } |
| 118 | |
| 119 | const ProfileParameters kJumpDrive = {2.0, 3.0}; |
| 120 | const ProfileParameters kDrive = {4.0, 3.0}; |
| 121 | const ProfileParameters kTurn = {5.0, 15.0}; |
| 122 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 123 | const ElevatorWristPosition kPanelHPIntakeForwrdPos{0.01, M_PI / 2.0}; |
| 124 | const ElevatorWristPosition kPanelHPIntakeBackwardPos{0.015, -M_PI / 2.0}; |
| 125 | |
| 126 | const ElevatorWristPosition kPanelForwardMiddlePos{0.75, M_PI / 2.0}; |
| 127 | const ElevatorWristPosition kPanelBackwardMiddlePos{0.78, -M_PI / 2.0}; |
| 128 | |
| 129 | const ElevatorWristPosition kPanelBackwardUpperPos{1.50, -M_PI / 2.0}; |
| 130 | |
| 131 | const ElevatorWristPosition kPanelCargoBackwardPos{0.0, -M_PI / 2.0}; |
| 132 | |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 133 | bool AutonomousActor::RunAction( |
| 134 | const ::frc971::autonomous::AutonomousActionParams ¶ms) { |
Austin Schuh | 77ed543 | 2019-07-07 20:41:36 -0700 | [diff] [blame] | 135 | const monotonic_clock::time_point start_time = monotonic_now(); |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 136 | const bool is_left = params.mode == 0; |
| 137 | |
| 138 | { |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 139 | AOS_LOG(INFO, "Starting autonomous action with mode %" PRId32 " %s\n", |
| 140 | params.mode, is_left ? "left" : "right"); |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 141 | } |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 142 | |
Austin Schuh | a964406 | 2019-03-28 14:31:52 -0700 | [diff] [blame] | 143 | const double turn_scalar = is_left ? 1.0 : -1.0; |
| 144 | |
| 145 | Reset(is_left); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 146 | enum class Mode { kTesting, kRocket, kCargoship }; |
| 147 | Mode mode = Mode::kCargoship; |
| 148 | if (mode == Mode::kRocket) { |
| 149 | SplineHandle spline1 = |
| 150 | PlanSpline(AutonomousSplines::HabToFarRocketTest(is_left), |
| 151 | SplineDirection::kBackward); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 152 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 153 | // Grab the disk, jump, wait until we have vacuum, then raise the elevator |
| 154 | set_elevator_goal(0.010); |
| 155 | set_wrist_goal(-M_PI / 2.0); |
| 156 | set_intake_goal(-1.2); |
| 157 | set_suction_goal(true, 1); |
| 158 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 159 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 160 | // if planned start the spline and plan the next |
| 161 | if (!spline1.WaitForPlan()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 162 | AOS_LOG(INFO, "Planned\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 163 | spline1.Start(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 164 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 165 | // If suction, move the superstructure to score |
| 166 | if (!WaitForGamePiece()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 167 | AOS_LOG(INFO, "Has game piece\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 168 | if (!spline1.WaitForSplineDistanceRemaining(3.5)) return true; |
| 169 | set_elevator_wrist_goal(kPanelBackwardMiddlePos); |
| 170 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 171 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 172 | if (!spline1.WaitForSplineDistanceRemaining(2.0)) return true; |
| 173 | set_elevator_wrist_goal(kPanelForwardMiddlePos); |
| 174 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 175 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 176 | // END SPLINE 1 |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 177 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 178 | if (!spline1.WaitForSplineDistanceRemaining(0.2)) return true; |
| 179 | LineFollowAtVelocity(1.3, 4); |
| 180 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1200))) return true; |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 181 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 182 | set_suction_goal(false, 1); |
| 183 | SendSuperstructureGoal(); |
| 184 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
| 185 | LineFollowAtVelocity(-1.0, 4); |
| 186 | SplineHandle spline2 = PlanSpline(AutonomousSplines::FarRocketToHP(is_left), |
| 187 | SplineDirection::kBackward); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 188 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 189 | if (!WaitForMilliseconds(::std::chrono::milliseconds(150))) return true; |
| 190 | if (!spline2.WaitForPlan()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 191 | AOS_LOG(INFO, "Planned\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 192 | // Drive back to hp and set the superstructure accordingly |
| 193 | spline2.Start(); |
| 194 | if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true; |
| 195 | set_elevator_wrist_goal(kPanelHPIntakeBackwardPos); |
| 196 | SendSuperstructureGoal(); |
| 197 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 198 | set_suction_goal(true, 1); |
| 199 | SendSuperstructureGoal(); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 200 | |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 201 | if (!spline2.WaitForSplineDistanceRemaining(1.6)) return true; |
| 202 | LineFollowAtVelocity(-1.6); |
| 203 | |
| 204 | // As soon as we pick up Panel 2 go score on the back rocket |
| 205 | if (!WaitForGamePiece()) return true; |
| 206 | LineFollowAtVelocity(1.5); |
| 207 | SplineHandle spline3 = PlanSpline(AutonomousSplines::HPToFarRocket(is_left), |
| 208 | SplineDirection::kForward); |
| 209 | if (!WaitForDriveXGreater(0.50)) return true; |
| 210 | if (!spline3.WaitForPlan()) return true; |
| 211 | spline3.Start(); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 212 | AOS_LOG(INFO, "Has game piece\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 213 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 214 | set_elevator_wrist_goal(kPanelBackwardMiddlePos); |
| 215 | SendSuperstructureGoal(); |
| 216 | if (!WaitForDriveXGreater(7.1)) return true; |
| 217 | LineFollowAtVelocity(-1.5, 4); |
| 218 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 219 | set_elevator_wrist_goal(kPanelBackwardUpperPos); |
| 220 | SendSuperstructureGoal(); |
| 221 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1500))) return true; |
| 222 | set_suction_goal(false, 1); |
| 223 | SendSuperstructureGoal(); |
| 224 | if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true; |
| 225 | LineFollowAtVelocity(1.0, 4); |
| 226 | SendSuperstructureGoal(); |
| 227 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
| 228 | } else if (mode == Mode::kCargoship) { |
| 229 | SplineHandle spline1 = |
| 230 | PlanSpline(AutonomousSplines::HABToSecondCargoShipBay(is_left), |
| 231 | SplineDirection::kBackward); |
| 232 | set_elevator_goal(0.01); |
| 233 | set_wrist_goal(-M_PI / 2.0); |
| 234 | set_intake_goal(-1.2); |
| 235 | set_suction_goal(true, 1); |
| 236 | SendSuperstructureGoal(); |
| 237 | |
| 238 | // if planned start the spline and plan the next |
| 239 | if (!spline1.WaitForPlan()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 240 | AOS_LOG(INFO, "Planned\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 241 | spline1.Start(); |
| 242 | |
| 243 | // If suction, move the superstructure to score |
| 244 | if (!WaitForGamePiece()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 245 | AOS_LOG(INFO, "Has game piece\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 246 | // unstick the hatch panel |
| 247 | if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true; |
| 248 | set_elevator_goal(0.5); |
| 249 | set_wrist_goal(-M_PI / 2.0); |
| 250 | SendSuperstructureGoal(); |
| 251 | if (!WaitForMilliseconds(::std::chrono::milliseconds(500))) return true; |
| 252 | set_elevator_wrist_goal(kPanelCargoBackwardPos); |
| 253 | SendSuperstructureGoal(); |
| 254 | |
| 255 | if (!spline1.WaitForSplineDistanceRemaining(0.8)) return true; |
| 256 | // Line follow in to the first disc. |
| 257 | LineFollowAtVelocity(-0.9, 2); |
| 258 | if (!WaitForDriveYCloseToZero(1.2)) return true; |
| 259 | |
| 260 | set_suction_goal(false, 1); |
| 261 | SendSuperstructureGoal(); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 262 | AOS_LOG(INFO, "Dropping disc 1 %f\n", |
| 263 | ::aos::time::DurationInSeconds(monotonic_now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 264 | |
| 265 | if (!WaitForDriveYCloseToZero(1.13)) return true; |
| 266 | if (!WaitForMilliseconds(::std::chrono::milliseconds(300))) return true; |
| 267 | |
| 268 | LineFollowAtVelocity(0.9, 2); |
| 269 | SplineHandle spline2 = |
| 270 | PlanSpline(AutonomousSplines::SecondCargoShipBayToHP(is_left), |
| 271 | SplineDirection::kForward); |
| 272 | if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true; |
| 273 | if (!spline2.WaitForPlan()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 274 | AOS_LOG(INFO, "Planned\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 275 | // Drive back to hp and set the superstructure accordingly |
| 276 | spline2.Start(); |
| 277 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
| 278 | set_elevator_wrist_goal(kPanelHPIntakeForwrdPos); |
| 279 | SendSuperstructureGoal(); |
| 280 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 281 | set_suction_goal(true, 1); |
| 282 | SendSuperstructureGoal(); |
| 283 | |
| 284 | if (!spline2.WaitForSplineDistanceRemaining(1.75)) return true; |
| 285 | LineFollowAtVelocity(1.5); |
| 286 | // As soon as we pick up Panel 2 go score on the rocket |
| 287 | if (!WaitForGamePiece()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 288 | AOS_LOG(INFO, "Got gamepiece %f\n", |
| 289 | ::aos::time::DurationInSeconds(monotonic_now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 290 | LineFollowAtVelocity(-4.0); |
| 291 | SplineHandle spline3 = |
| 292 | PlanSpline(AutonomousSplines::HPToThirdCargoShipBay(is_left), |
| 293 | SplineDirection::kBackward); |
| 294 | if (!WaitForDriveXGreater(0.55)) return true; |
| 295 | if (!spline3.WaitForPlan()) return true; |
| 296 | spline3.Start(); |
| 297 | // Wait until we are a bit out to lift. |
| 298 | if (!WaitForMilliseconds(::std::chrono::milliseconds(1000))) return true; |
| 299 | set_elevator_wrist_goal(kPanelCargoBackwardPos); |
| 300 | SendSuperstructureGoal(); |
| 301 | |
| 302 | if (!spline3.WaitForSplineDistanceRemaining(0.7)) return true; |
| 303 | // Line follow in to the second disc. |
| 304 | LineFollowAtVelocity(-0.7, 3); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 305 | AOS_LOG(INFO, "Drawing in disc 2 %f\n", |
| 306 | ::aos::time::DurationInSeconds(monotonic_now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 307 | if (!WaitForDriveYCloseToZero(1.2)) return true; |
| 308 | |
| 309 | set_suction_goal(false, 1); |
| 310 | SendSuperstructureGoal(); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 311 | AOS_LOG(INFO, "Dropping disc 2 %f\n", |
| 312 | ::aos::time::DurationInSeconds(monotonic_now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 313 | |
| 314 | if (!WaitForDriveYCloseToZero(1.13)) return true; |
| 315 | if (!WaitForMilliseconds(::std::chrono::milliseconds(200))) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 316 | AOS_LOG(INFO, "Backing up %f\n", |
| 317 | ::aos::time::DurationInSeconds(monotonic_now() - start_time)); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 318 | LineFollowAtVelocity(0.9, 3); |
| 319 | if (!WaitForMilliseconds(::std::chrono::milliseconds(400))) return true; |
| 320 | } else { |
| 321 | // Grab the disk, wait until we have vacuum, then jump |
| 322 | set_elevator_goal(0.01); |
| 323 | set_wrist_goal(-M_PI / 2.0); |
| 324 | set_intake_goal(-1.2); |
| 325 | set_suction_goal(true, 1); |
| 326 | SendSuperstructureGoal(); |
| 327 | |
| 328 | if (!WaitForGamePiece()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 329 | AOS_LOG(INFO, "Has game piece\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 330 | |
| 331 | StartDrive(-4.0, 0.0, kJumpDrive, kTurn); |
| 332 | if (!WaitForDriveNear(3.3, 10.0)) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 333 | AOS_LOG(INFO, "Lifting\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 334 | set_elevator_goal(0.30); |
| 335 | SendSuperstructureGoal(); |
| 336 | |
| 337 | if (!WaitForDriveNear(2.8, 10.0)) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 338 | AOS_LOG(INFO, "Off the platform\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 339 | |
| 340 | StartDrive(0.0, 1.00 * turn_scalar, kDrive, kTurn); |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 341 | AOS_LOG(INFO, "Turn started\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 342 | if (!WaitForSuperstructureDone()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 343 | AOS_LOG(INFO, "Superstructure done\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 344 | |
| 345 | if (!WaitForDriveNear(0.7, 10.0)) return true; |
| 346 | StartDrive(0.0, -0.35 * turn_scalar, kDrive, kTurn); |
| 347 | |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 348 | AOS_LOG(INFO, "Elevator up\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 349 | set_elevator_goal(0.78); |
| 350 | SendSuperstructureGoal(); |
| 351 | |
| 352 | if (!WaitForDriveDone()) return true; |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 353 | AOS_LOG(INFO, "Done driving\n"); |
Austin Schuh | b5b79a5 | 2019-05-08 20:32:07 -0700 | [diff] [blame] | 354 | |
| 355 | if (!WaitForSuperstructureDone()) return true; |
| 356 | } |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 357 | |
Austin Schuh | f257f3c | 2019-10-27 21:00:43 -0700 | [diff] [blame^] | 358 | AOS_LOG(INFO, "Done %f\n", |
| 359 | ::aos::time::DurationInSeconds(monotonic_now() - start_time)); |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 360 | |
Austin Schuh | 13379ba | 2019-03-12 21:06:46 -0700 | [diff] [blame] | 361 | return true; |
| 362 | } |
| 363 | |
| 364 | } // namespace actors |
| 365 | } // namespace y2019 |