Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 1 | #include "y2020/actors/autonomous_actor.h" |
| 2 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 3 | #include <chrono> |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 4 | #include <cinttypes> |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 5 | #include <cmath> |
| 6 | |
| 7 | #include "aos/logging/logging.h" |
James Kuszmaul | ddd2ba6 | 2020-03-08 22:17:13 -0700 | [diff] [blame] | 8 | #include "aos/util/math.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 9 | #include "frc971/control_loops/drivetrain/localizer_generated.h" |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 10 | #include "y2020/actors/auto_splines.h" |
Ravago Jones | c2a0802 | 2021-02-06 17:40:54 -0800 | [diff] [blame] | 11 | #include "y2020/control_loops/drivetrain/drivetrain_base.h" |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 12 | |
Austin Schuh | 3fb9e42 | 2021-03-31 20:11:32 -0700 | [diff] [blame] | 13 | DEFINE_bool(spline_auto, false, "If true, define a spline autonomous mode"); |
Austin Schuh | 3840ada | 2021-04-04 16:58:00 -0700 | [diff] [blame] | 14 | DEFINE_bool(ignore_vision, false, "If true, ignore vision"); |
| 15 | DEFINE_bool(galactic_search, false, |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 16 | "If true, do the galactic search autonomous"); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 17 | DEFINE_bool(bounce, false, "If true, run the AutoNav Bounce autonomous"); |
| 18 | DEFINE_bool(barrel, false, "If true, run the AutoNav Barrel autonomous"); |
Austin Schuh | 3840ada | 2021-04-04 16:58:00 -0700 | [diff] [blame] | 19 | DEFINE_bool(slalom, true, "If true, run the AutoNav Slalom autonomous"); |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 20 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 21 | namespace y2020 { |
| 22 | namespace actors { |
| 23 | |
| 24 | using ::aos::monotonic_clock; |
| 25 | using ::frc971::ProfileParametersT; |
| 26 | using frc971::control_loops::drivetrain::LocalizerControl; |
| 27 | namespace chrono = ::std::chrono; |
| 28 | |
| 29 | AutonomousActor::AutonomousActor(::aos::EventLoop *event_loop) |
| 30 | : frc971::autonomous::BaseAutonomousActor( |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 31 | event_loop, control_loops::drivetrain::GetDrivetrainConfig()), |
Ravago Jones | c2a0802 | 2021-02-06 17:40:54 -0800 | [diff] [blame] | 32 | localizer_control_sender_( |
| 33 | event_loop->MakeSender< |
| 34 | ::frc971::control_loops::drivetrain::LocalizerControl>( |
| 35 | "/drivetrain")), |
Austin Schuh | 67e127e | 2021-03-27 13:25:23 -0700 | [diff] [blame] | 36 | superstructure_goal_sender_( |
| 37 | event_loop->MakeSender<control_loops::superstructure::Goal>( |
| 38 | "/superstructure")), |
James Kuszmaul | ddd2ba6 | 2020-03-08 22:17:13 -0700 | [diff] [blame] | 39 | joystick_state_fetcher_( |
Ravago Jones | c2a0802 | 2021-02-06 17:40:54 -0800 | [diff] [blame] | 40 | event_loop->MakeFetcher<aos::JoystickState>("/aos")), |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 41 | path_fetcher_(event_loop->MakeFetcher<y2020::vision::GalacticSearchPath>( |
Austin Schuh | c6442fc | 2021-03-27 13:25:42 -0700 | [diff] [blame] | 42 | "/pi2/camera")), |
Ravago Jones | c2a0802 | 2021-02-06 17:40:54 -0800 | [diff] [blame] | 43 | auto_splines_() { |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 44 | set_max_drivetrain_voltage(2.0); |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 45 | replan_timer_ = event_loop->AddTimer([this]() { Replan(); }); |
| 46 | event_loop->OnRun([this, event_loop]() { |
| 47 | replan_timer_->Setup(event_loop->monotonic_now()); |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | void AutonomousActor::Replan() { |
| 52 | if (FLAGS_galactic_search) { |
| 53 | galactic_search_splines_ = { |
| 54 | .red_a = PlanSpline(std::bind(&AutonomousSplines::SplineRedA, |
| 55 | &auto_splines_, std::placeholders::_1), |
| 56 | SplineDirection::kForward), |
| 57 | .red_b = PlanSpline(std::bind(&AutonomousSplines::SplineRedB, |
| 58 | &auto_splines_, std::placeholders::_1), |
| 59 | SplineDirection::kForward), |
| 60 | .blue_a = PlanSpline(std::bind(&AutonomousSplines::SplineBlueA, |
| 61 | &auto_splines_, std::placeholders::_1), |
| 62 | SplineDirection::kForward), |
| 63 | .blue_b = PlanSpline(std::bind(&AutonomousSplines::SplineBlueB, |
| 64 | &auto_splines_, std::placeholders::_1), |
| 65 | SplineDirection::kForward)}; |
| 66 | } else if (FLAGS_bounce) { |
| 67 | bounce_splines_ = { |
| 68 | PlanSpline(std::bind(&AutonomousSplines::AutoNavBounce1, &auto_splines_, |
| 69 | std::placeholders::_1), |
| 70 | SplineDirection::kForward), |
| 71 | PlanSpline(std::bind(&AutonomousSplines::AutoNavBounce2, &auto_splines_, |
| 72 | std::placeholders::_1), |
| 73 | SplineDirection::kBackward), |
| 74 | PlanSpline(std::bind(&AutonomousSplines::AutoNavBounce3, &auto_splines_, |
| 75 | std::placeholders::_1), |
| 76 | SplineDirection::kForward), |
| 77 | PlanSpline(std::bind(&AutonomousSplines::AutoNavBounce4, &auto_splines_, |
| 78 | std::placeholders::_1), |
| 79 | SplineDirection::kBackward)}; |
| 80 | } else if (FLAGS_barrel) { |
| 81 | barrel_spline_ = |
| 82 | PlanSpline(std::bind(&AutonomousSplines::AutoNavBarrel, &auto_splines_, |
| 83 | std::placeholders::_1), |
| 84 | SplineDirection::kForward); |
| 85 | } else if (FLAGS_slalom) { |
| 86 | slalom_spline_ = |
| 87 | PlanSpline(std::bind(&AutonomousSplines::AutoNavSlalom, &auto_splines_, |
| 88 | std::placeholders::_1), |
| 89 | SplineDirection::kForward); |
| 90 | } else if (FLAGS_spline_auto) { |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 91 | test_spline_ = PlanSpline(std::bind(&AutonomousSplines::TestSpline, |
| 92 | &auto_splines_, std::placeholders::_1), |
| 93 | SplineDirection::kForward); |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 94 | } |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 95 | } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 96 | |
| 97 | void AutonomousActor::Reset() { |
| 98 | InitializeEncoders(); |
| 99 | ResetDrivetrain(); |
milind upadhyay | b2e840a | 2021-03-27 13:54:49 -0700 | [diff] [blame] | 100 | RetractIntake(); |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 101 | |
James Kuszmaul | ddd2ba6 | 2020-03-08 22:17:13 -0700 | [diff] [blame] | 102 | joystick_state_fetcher_.Fetch(); |
| 103 | CHECK(joystick_state_fetcher_.get() != nullptr) |
| 104 | << "Expect at least one JoystickState message before running auto..."; |
| 105 | alliance_ = joystick_state_fetcher_->alliance(); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | bool AutonomousActor::RunAction( |
Austin Schuh | 6fb0a6d | 2021-01-23 15:43:17 -0800 | [diff] [blame] | 109 | const ::frc971::autonomous::AutonomousActionParams *params) { |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 110 | Reset(); |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 111 | |
| 112 | // Queue up a replan to occur as soon as this action completes. |
| 113 | // TODO(james): Modify this so we don't replan during teleop. |
| 114 | replan_timer_->Setup(monotonic_now()); |
| 115 | |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 116 | AOS_LOG(INFO, "Params are %d\n", params->mode()); |
James Kuszmaul | ddd2ba6 | 2020-03-08 22:17:13 -0700 | [diff] [blame] | 117 | if (alliance_ == aos::Alliance::kInvalid) { |
| 118 | AOS_LOG(INFO, "Aborting autonomous due to invalid alliance selection."); |
| 119 | return false; |
| 120 | } |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 121 | if (FLAGS_galactic_search) { |
| 122 | GalacticSearch(); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 123 | } else if (FLAGS_bounce) { |
| 124 | AutoNavBounce(); |
| 125 | } else if (FLAGS_barrel) { |
| 126 | AutoNavBarrel(); |
| 127 | } else if (FLAGS_slalom) { |
| 128 | AutoNavSlalom(); |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 129 | } else if (FLAGS_spline_auto) { |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 130 | SplineAuto(); |
| 131 | } else { |
| 132 | return DriveFwd(); |
| 133 | } |
| 134 | return true; |
| 135 | } |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 136 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 137 | void AutonomousActor::SendStartingPosition(const Eigen::Vector3d &start) { |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 138 | // Set up the starting position for the blue alliance. |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 139 | |
| 140 | // TODO(james): Resetting the localizer breaks the left/right statespace |
| 141 | // controller. That is a bug, but we can fix that later by not resetting. |
| 142 | auto builder = localizer_control_sender_.MakeBuilder(); |
| 143 | |
| 144 | LocalizerControl::Builder localizer_control_builder = |
| 145 | builder.MakeBuilder<LocalizerControl>(); |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 146 | localizer_control_builder.add_x(start(0)); |
| 147 | localizer_control_builder.add_y(start(1)); |
| 148 | localizer_control_builder.add_theta(start(2)); |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 149 | localizer_control_builder.add_theta_uncertainty(0.00001); |
| 150 | if (!builder.Send(localizer_control_builder.Finish())) { |
| 151 | AOS_LOG(ERROR, "Failed to reset localizer.\n"); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void AutonomousActor::GalacticSearch() { |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 156 | CHECK(galactic_search_splines_); |
| 157 | |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 158 | path_fetcher_.Fetch(); |
Austin Schuh | 3fb9e42 | 2021-03-31 20:11:32 -0700 | [diff] [blame] | 159 | SplineHandle *spline = nullptr; |
| 160 | if (path_fetcher_.get()) { |
| 161 | if (path_fetcher_->alliance() == y2020::vision::Alliance::kUnknown) { |
| 162 | AOS_LOG(ERROR, "The galactic search path is unknown, doing nothing."); |
| 163 | return; |
| 164 | } |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 165 | if (path_fetcher_->alliance() == y2020::vision::Alliance::kRed) { |
| 166 | if (path_fetcher_->letter() == y2020::vision::Letter::kA) { |
| 167 | LOG(INFO) << "Red A"; |
| 168 | spline = &galactic_search_splines_->red_a; |
| 169 | } else { |
| 170 | LOG(INFO) << "Red B"; |
| 171 | CHECK(path_fetcher_->letter() == y2020::vision::Letter::kB); |
| 172 | spline = &galactic_search_splines_->red_b; |
| 173 | } |
| 174 | } else { |
| 175 | if (path_fetcher_->letter() == y2020::vision::Letter::kA) { |
| 176 | LOG(INFO) << "Blue A"; |
| 177 | spline = &galactic_search_splines_->blue_a; |
| 178 | } else { |
| 179 | LOG(INFO) << "Blue B"; |
| 180 | CHECK(path_fetcher_->letter() == y2020::vision::Letter::kB); |
Austin Schuh | 8806bed | 2021-03-31 20:12:00 -0700 | [diff] [blame] | 181 | spline = &galactic_search_splines_->blue_b; |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 182 | } |
| 183 | } |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 184 | } |
Austin Schuh | 3fb9e42 | 2021-03-31 20:11:32 -0700 | [diff] [blame] | 185 | if (FLAGS_ignore_vision) { |
| 186 | LOG(INFO) << "Forcing Red B"; |
| 187 | spline = &galactic_search_splines_->red_b; |
| 188 | } |
| 189 | |
| 190 | CHECK(spline != nullptr) |
| 191 | << "Expect at least one GalacticSearchPath message before running " |
| 192 | "auto..."; |
| 193 | |
| 194 | SendStartingPosition(spline->starting_position()); |
| 195 | |
| 196 | set_intake_goal(1.25); |
| 197 | set_roller_voltage(12.0); |
| 198 | SendSuperstructureGoal(); |
| 199 | |
| 200 | if (!spline->WaitForPlan()) return; |
| 201 | spline->Start(); |
| 202 | |
| 203 | if (!spline->WaitForSplineDistanceRemaining(0.02)) return; |
| 204 | RetractIntake(); |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 205 | } |
| 206 | |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 207 | void AutonomousActor::AutoNavBounce() { |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 208 | CHECK(bounce_splines_); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 209 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 210 | auto &splines = *bounce_splines_; |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 211 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 212 | SendStartingPosition(splines[0].starting_position()); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 213 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 214 | if (!splines[0].WaitForPlan()) return; |
| 215 | splines[0].Start(); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 216 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 217 | if (!splines[0].WaitForSplineDistanceRemaining(0.02)) return; |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 218 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 219 | if (!splines[1].WaitForPlan()) return; |
| 220 | splines[1].Start(); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 221 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 222 | if (!splines[1].WaitForSplineDistanceRemaining(0.02)) return; |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 223 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 224 | if (!splines[2].WaitForPlan()) return; |
| 225 | splines[2].Start(); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 226 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 227 | if (!splines[2].WaitForSplineDistanceRemaining(0.02)) return; |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 228 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 229 | if (!splines[3].WaitForPlan()) return; |
| 230 | splines[3].Start(); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 231 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 232 | if (!splines[3].WaitForSplineDistanceRemaining(0.02)) return; |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | void AutonomousActor::AutoNavBarrel() { |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 236 | CHECK(barrel_spline_); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 237 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 238 | SendStartingPosition(barrel_spline_->starting_position()); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 239 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 240 | if (!barrel_spline_->WaitForPlan()) return; |
| 241 | barrel_spline_->Start(); |
| 242 | |
| 243 | if (!barrel_spline_->WaitForSplineDistanceRemaining(0.02)) return; |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void AutonomousActor::AutoNavSlalom() { |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 247 | CHECK(slalom_spline_); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 248 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 249 | SendStartingPosition(slalom_spline_->starting_position()); |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 250 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 251 | if (!slalom_spline_->WaitForPlan()) return; |
| 252 | slalom_spline_->Start(); |
| 253 | |
| 254 | if (!slalom_spline_->WaitForSplineDistanceRemaining(0.02)) return; |
Ravago Jones | 9c326f5 | 2021-03-20 15:00:16 -0700 | [diff] [blame] | 255 | } |
| 256 | |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 257 | void AutonomousActor::SplineAuto() { |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 258 | CHECK(test_spline_); |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 259 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 260 | SendStartingPosition(test_spline_->starting_position()); |
James Kuszmaul | 5f6d1d4 | 2020-03-01 18:10:07 -0800 | [diff] [blame] | 261 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 262 | if (!test_spline_->WaitForPlan()) return; |
| 263 | test_spline_->Start(); |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 264 | |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 265 | if (!test_spline_->WaitForSplineDistanceRemaining(0.02)) return; |
kyle | 96c406e | 2021-02-27 14:07:22 -0800 | [diff] [blame] | 266 | } |
| 267 | |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 268 | ProfileParametersT MakeProfileParametersT(const float max_velocity, |
| 269 | const float max_acceleration) { |
| 270 | ProfileParametersT params; |
| 271 | params.max_velocity = max_velocity; |
| 272 | params.max_acceleration = max_acceleration; |
| 273 | return params; |
| 274 | } |
| 275 | |
| 276 | bool AutonomousActor::DriveFwd() { |
James Kuszmaul | 99af8b5 | 2021-03-28 10:50:15 -0700 | [diff] [blame] | 277 | SendStartingPosition({0, 0, 0}); |
Austin Schuh | fd1715f | 2021-01-30 16:58:24 -0800 | [diff] [blame] | 278 | const ProfileParametersT kDrive = MakeProfileParametersT(0.3f, 1.0f); |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 279 | const ProfileParametersT kTurn = MakeProfileParametersT(5.0f, 15.0f); |
Austin Schuh | fd1715f | 2021-01-30 16:58:24 -0800 | [diff] [blame] | 280 | StartDrive(1.0, 0.0, kDrive, kTurn); |
milind upadhyay | 47a0ab3 | 2020-11-25 19:34:41 -0800 | [diff] [blame] | 281 | return WaitForDriveDone(); |
| 282 | } |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 283 | |
| 284 | void AutonomousActor::SendSuperstructureGoal() { |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 285 | auto builder = superstructure_goal_sender_.MakeBuilder(); |
| 286 | |
| 287 | flatbuffers::Offset<StaticZeroingSingleDOFProfiledSubsystemGoal> |
| 288 | intake_offset; |
milind upadhyay | b9dec71 | 2021-03-20 15:47:51 -0700 | [diff] [blame] | 289 | |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 290 | { |
| 291 | StaticZeroingSingleDOFProfiledSubsystemGoal::Builder intake_builder = |
| 292 | builder.MakeBuilder<StaticZeroingSingleDOFProfiledSubsystemGoal>(); |
| 293 | |
milind upadhyay | b9dec71 | 2021-03-20 15:47:51 -0700 | [diff] [blame] | 294 | frc971::ProfileParameters::Builder profile_params_builder = |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 295 | builder.MakeBuilder<frc971::ProfileParameters>(); |
Austin Schuh | b39a21c | 2021-03-31 20:12:18 -0700 | [diff] [blame] | 296 | profile_params_builder.add_max_velocity(20.0); |
| 297 | profile_params_builder.add_max_acceleration(60.0); |
milind upadhyay | b9dec71 | 2021-03-20 15:47:51 -0700 | [diff] [blame] | 298 | flatbuffers::Offset<frc971::ProfileParameters> profile_params_offset = |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 299 | profile_params_builder.Finish(); |
| 300 | intake_builder.add_unsafe_goal(intake_goal_); |
| 301 | intake_builder.add_profile_params(profile_params_offset); |
| 302 | intake_offset = intake_builder.Finish(); |
| 303 | } |
| 304 | |
| 305 | superstructure::Goal::Builder superstructure_builder = |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 306 | builder.MakeBuilder<superstructure::Goal>(); |
milind upadhyay | b9dec71 | 2021-03-20 15:47:51 -0700 | [diff] [blame] | 307 | |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 308 | superstructure_builder.add_intake(intake_offset); |
| 309 | superstructure_builder.add_roller_voltage(roller_voltage_); |
Tyler Chatow | bf0609c | 2021-07-31 16:13:27 -0700 | [diff] [blame] | 310 | superstructure_builder.add_roller_speed_compensation( |
| 311 | kRollerSpeedCompensation); |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 312 | |
| 313 | if (!builder.Send(superstructure_builder.Finish())) { |
| 314 | AOS_LOG(ERROR, "Sending superstructure goal failed.\n"); |
| 315 | } |
Sabina Leaver | a0b43b4 | 2021-03-03 20:30:04 -0800 | [diff] [blame] | 316 | } |
milind upadhyay | 5e589d7 | 2021-03-27 13:47:18 -0700 | [diff] [blame] | 317 | |
| 318 | void AutonomousActor::RetractIntake() { |
| 319 | set_intake_goal(-0.89); |
| 320 | set_roller_voltage(0.0); |
| 321 | SendSuperstructureGoal(); |
| 322 | } |
| 323 | |
Stephan Massalt | d021f97 | 2020-01-05 20:41:23 -0800 | [diff] [blame] | 324 | } // namespace actors |
| 325 | } // namespace y2020 |