James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 1 | #include "y2019/control_loops/drivetrain/localizer.h" |
| 2 | |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 3 | #include <queue> |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 4 | #include <random> |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 5 | |
| 6 | #include "aos/testing/random_seed.h" |
| 7 | #include "aos/testing/test_shm.h" |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 8 | #include "frc971/control_loops/drivetrain/splinedrivetrain.h" |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 9 | #include "frc971/control_loops/drivetrain/trajectory.h" |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 10 | #include "gflags/gflags.h" |
| 11 | #if defined(SUPPORT_PLOT) |
| 12 | #include "third_party/matplotlib-cpp/matplotlibcpp.h" |
| 13 | #endif |
| 14 | #include "gtest/gtest.h" |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 15 | #include "y2019/constants.h" |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 16 | #include "y2019/control_loops/drivetrain/drivetrain_base.h" |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 17 | |
| 18 | DEFINE_bool(plot, false, "If true, plot"); |
| 19 | |
| 20 | namespace y2019 { |
| 21 | namespace control_loops { |
| 22 | namespace testing { |
| 23 | |
| 24 | using ::y2019::constants::Field; |
| 25 | |
| 26 | constexpr size_t kNumCameras = 4; |
| 27 | constexpr size_t kNumTargetsPerFrame = 3; |
| 28 | |
| 29 | typedef TypedLocalizer<kNumCameras, Field::kNumTargets, Field::kNumObstacles, |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 30 | kNumTargetsPerFrame, double> |
| 31 | TestLocalizer; |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 32 | typedef typename TestLocalizer::Camera TestCamera; |
James Kuszmaul | f4ede20 | 2020-02-14 08:47:40 -0800 | [diff] [blame] | 33 | typedef typename TestLocalizer::Target Target; |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 34 | typedef typename TestCamera::Pose Pose; |
| 35 | typedef typename TestCamera::LineSegment Obstacle; |
| 36 | |
| 37 | typedef TestLocalizer::StateIdx StateIdx; |
| 38 | |
| 39 | using ::frc971::control_loops::drivetrain::DrivetrainConfig; |
| 40 | |
| 41 | // When placing the cameras on the robot, set them all kCameraOffset out from |
| 42 | // the center, to test that we really can handle cameras that aren't at the |
| 43 | // center-of-mass. |
| 44 | constexpr double kCameraOffset = 0.1; |
| 45 | |
| 46 | #if defined(SUPPORT_PLOT) |
| 47 | // Plots a line from a vector of Pose's. |
| 48 | void PlotPlotPts(const ::std::vector<Pose> &poses, |
| 49 | const ::std::map<::std::string, ::std::string> &kwargs) { |
| 50 | ::std::vector<double> x; |
| 51 | ::std::vector<double> y; |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 52 | for (const Pose &p : poses) { |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 53 | x.push_back(p.abs_pos().x()); |
| 54 | y.push_back(p.abs_pos().y()); |
| 55 | } |
| 56 | matplotlibcpp::plot(x, y, kwargs); |
| 57 | } |
| 58 | #endif |
| 59 | |
| 60 | struct LocalizerTestParams { |
| 61 | // Control points for the spline to make the robot follow. |
| 62 | ::std::array<float, 6> control_pts_x; |
| 63 | ::std::array<float, 6> control_pts_y; |
| 64 | // The actual state to start the robot at. By setting voltage errors and the |
| 65 | // such you can introduce persistent disturbances. |
| 66 | TestLocalizer::State true_start_state; |
| 67 | // The initial state of the estimator. |
| 68 | TestLocalizer::State known_start_state; |
| 69 | // Whether or not to add Gaussian noise to the sensors and cameras. |
| 70 | bool noisify; |
| 71 | // Whether or not to add unmodelled disturbances. |
| 72 | bool disturb; |
| 73 | // The tolerances for the estimator and for the trajectory following at |
| 74 | // the end of the spline: |
| 75 | double estimate_tolerance; |
| 76 | double goal_tolerance; |
| 77 | }; |
| 78 | |
| 79 | class ParameterizedLocalizerTest |
| 80 | : public ::testing::TestWithParam<LocalizerTestParams> { |
| 81 | public: |
| 82 | ::aos::testing::TestSharedMemory shm_; |
| 83 | |
| 84 | // Set up three targets in a row, at (-1, 0), (0, 0), and (1, 0). |
| 85 | // Make the right-most target (1, 0) be facing away from the camera, and give |
| 86 | // the middle target some skew. |
| 87 | // Place one camera facing forward, the other facing backward, and set the |
| 88 | // robot at (0, -5) with the cameras each 0.1m from the center. |
| 89 | // Place one obstacle in a place where it can block the left-most target (-1, |
| 90 | // 0). |
| 91 | ParameterizedLocalizerTest() |
| 92 | : field_(), |
| 93 | targets_(field_.targets()), |
| 94 | modeled_obstacles_(field_.obstacles()), |
| 95 | true_obstacles_(field_.obstacles()), |
| 96 | dt_config_(drivetrain::GetDrivetrainConfig()), |
| 97 | // Pull the noise for the encoders/gyros from the R matrix: |
| 98 | encoder_noise_(::std::sqrt( |
| 99 | dt_config_.make_kf_drivetrain_loop().observer().coefficients().R( |
| 100 | 0, 0))), |
| 101 | gyro_noise_(::std::sqrt( |
| 102 | dt_config_.make_kf_drivetrain_loop().observer().coefficients().R( |
| 103 | 2, 2))), |
| 104 | // As per the comments in localizer.h, we set the field of view and |
| 105 | // noise parameters on the robot_cameras_ so that they see a bit more |
| 106 | // than the true_cameras_. The robot_cameras_ are what is passed to the |
| 107 | // localizer and used to generate "expected" targets. The true_cameras_ |
| 108 | // are what we actually use to generate targets to pass to the |
| 109 | // localizer. |
| 110 | robot_cameras_{ |
| 111 | {TestCamera({&robot_pose_, {0.0, kCameraOffset, 0.0}, M_PI_2}, |
| 112 | M_PI_2 * 1.1, robot_noise_parameters_, targets_, |
| 113 | modeled_obstacles_), |
| 114 | TestCamera({&robot_pose_, {kCameraOffset, 0.0, 0.0}, 0.0}, |
| 115 | M_PI_2 * 1.1, robot_noise_parameters_, targets_, |
| 116 | modeled_obstacles_), |
| 117 | TestCamera({&robot_pose_, {-kCameraOffset, 0.0, 0.0}, M_PI}, |
| 118 | M_PI_2 * 1.1, robot_noise_parameters_, targets_, |
| 119 | modeled_obstacles_), |
| 120 | TestCamera({&robot_pose_, {0.0, -kCameraOffset, 0.0}, -M_PI_2}, |
| 121 | M_PI_2 * 1.1, robot_noise_parameters_, targets_, |
| 122 | modeled_obstacles_)}}, |
| 123 | true_cameras_{ |
| 124 | {TestCamera({&true_robot_pose_, {0.0, kCameraOffset, 0.0}, M_PI_2}, |
| 125 | M_PI_2 * 0.9, true_noise_parameters_, targets_, |
| 126 | true_obstacles_), |
| 127 | TestCamera({&true_robot_pose_, {kCameraOffset, 0.0, 0.0}, 0.0}, |
| 128 | M_PI_2 * 0.9, true_noise_parameters_, targets_, |
| 129 | true_obstacles_), |
| 130 | TestCamera({&true_robot_pose_, {-kCameraOffset, 0.0, 0.0}, M_PI}, |
| 131 | M_PI_2 * 0.9, true_noise_parameters_, targets_, |
| 132 | true_obstacles_), |
| 133 | TestCamera( |
| 134 | {&true_robot_pose_, {-0.0, -kCameraOffset, 0.0}, -M_PI_2}, |
| 135 | M_PI_2 * 0.9, true_noise_parameters_, targets_, |
| 136 | true_obstacles_)}}, |
| 137 | localizer_(dt_config_, &robot_pose_), |
| 138 | spline_drivetrain_(dt_config_) { |
| 139 | // We use the default P() for initialization. |
| 140 | localizer_.ResetInitialState(t0_, GetParam().known_start_state, |
| 141 | localizer_.P()); |
| 142 | } |
| 143 | |
| 144 | void SetUp() { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 145 | flatbuffers::DetachedBuffer goal_buffer; |
| 146 | { |
| 147 | flatbuffers::FlatBufferBuilder fbb; |
| 148 | |
| 149 | flatbuffers::Offset<flatbuffers::Vector<float>> spline_x_offset = |
| 150 | fbb.CreateVector<float>(GetParam().control_pts_x.begin(), |
| 151 | GetParam().control_pts_x.size()); |
| 152 | |
| 153 | flatbuffers::Offset<flatbuffers::Vector<float>> spline_y_offset = |
| 154 | fbb.CreateVector<float>(GetParam().control_pts_y.begin(), |
| 155 | GetParam().control_pts_y.size()); |
| 156 | |
| 157 | frc971::MultiSpline::Builder multispline_builder(fbb); |
| 158 | |
| 159 | multispline_builder.add_spline_count(1); |
| 160 | multispline_builder.add_spline_x(spline_x_offset); |
| 161 | multispline_builder.add_spline_y(spline_y_offset); |
| 162 | |
| 163 | flatbuffers::Offset<frc971::MultiSpline> multispline_offset = |
| 164 | multispline_builder.Finish(); |
| 165 | |
| 166 | frc971::control_loops::drivetrain::SplineGoal::Builder spline_builder( |
| 167 | fbb); |
| 168 | |
| 169 | spline_builder.add_spline_idx(1); |
| 170 | spline_builder.add_spline(multispline_offset); |
| 171 | |
| 172 | flatbuffers::Offset<frc971::control_loops::drivetrain::SplineGoal> |
| 173 | spline_offset = spline_builder.Finish(); |
| 174 | |
| 175 | frc971::control_loops::drivetrain::Goal::Builder goal_builder(fbb); |
| 176 | |
| 177 | goal_builder.add_spline(spline_offset); |
| 178 | goal_builder.add_controller_type( |
Austin Schuh | 872723c | 2019-12-25 14:38:09 -0800 | [diff] [blame] | 179 | frc971::control_loops::drivetrain::ControllerType::SPLINE_FOLLOWER); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 180 | goal_builder.add_spline_handle(1); |
| 181 | |
| 182 | fbb.Finish(goal_builder.Finish()); |
| 183 | |
| 184 | goal_buffer = fbb.Release(); |
| 185 | } |
| 186 | aos::FlatbufferDetachedBuffer<frc971::control_loops::drivetrain::Goal> goal( |
| 187 | std::move(goal_buffer)); |
| 188 | |
Alex Perry | cc3ee4c | 2019-02-09 21:20:41 -0800 | [diff] [blame] | 189 | // Let the spline drivetrain compute the spline. |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 190 | while (true) { |
Austin Schuh | b574fe4 | 2019-12-06 23:51:47 -0800 | [diff] [blame] | 191 | // We need to keep sending the goal. There are conditions when the |
| 192 | // trajectory lock isn't grabbed the first time, and we want to keep |
| 193 | // banging on it to keep trying. Otherwise we deadlock. |
| 194 | spline_drivetrain_.SetGoal(&goal.message()); |
| 195 | |
Alex Perry | cc3ee4c | 2019-02-09 21:20:41 -0800 | [diff] [blame] | 196 | ::std::this_thread::sleep_for(::std::chrono::milliseconds(5)); |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 197 | |
| 198 | flatbuffers::FlatBufferBuilder fbb; |
| 199 | |
| 200 | flatbuffers::Offset<frc971::control_loops::drivetrain::TrajectoryLogging> |
| 201 | trajectory_logging_offset = |
| 202 | spline_drivetrain_.MakeTrajectoryLogging(&fbb); |
| 203 | |
| 204 | ::frc971::control_loops::drivetrain::Status::Builder status_builder(fbb); |
| 205 | status_builder.add_trajectory_logging(trajectory_logging_offset); |
| 206 | spline_drivetrain_.PopulateStatus(&status_builder); |
| 207 | fbb.Finish(status_builder.Finish()); |
| 208 | aos::FlatbufferDetachedBuffer<::frc971::control_loops::drivetrain::Status> |
| 209 | status(fbb.Release()); |
| 210 | |
| 211 | if (status.message().trajectory_logging()->planning_state() == |
Austin Schuh | 872723c | 2019-12-25 14:38:09 -0800 | [diff] [blame] | 212 | ::frc971::control_loops::drivetrain::PlanningState::PLANNED) { |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 213 | break; |
| 214 | } |
| 215 | } |
| 216 | spline_drivetrain_.SetGoal(&goal.message()); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void TearDown() { |
| 220 | printf("Each iteration of the simulation took on average %f seconds.\n", |
| 221 | avg_time_.count()); |
| 222 | #if defined(SUPPORT_PLOT) |
| 223 | if (FLAGS_plot) { |
| 224 | matplotlibcpp::figure(); |
| 225 | matplotlibcpp::plot(simulation_t_, simulation_vl_, {{"label", "Vl"}}); |
| 226 | matplotlibcpp::plot(simulation_t_, simulation_vr_, {{"label", "Vr"}}); |
| 227 | matplotlibcpp::legend(); |
| 228 | |
| 229 | matplotlibcpp::figure(); |
| 230 | matplotlibcpp::plot(spline_x_, spline_y_, {{"label", "spline"}}); |
| 231 | matplotlibcpp::plot(simulation_x_, simulation_y_, {{"label", "robot"}}); |
| 232 | matplotlibcpp::plot(estimated_x_, estimated_y_, |
| 233 | {{"label", "estimation"}}); |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 234 | for (const Target &target : targets_) { |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 235 | PlotPlotPts(target.PlotPoints(), {{"c", "g"}}); |
| 236 | } |
| 237 | for (const Obstacle &obstacle : true_obstacles_) { |
| 238 | PlotPlotPts(obstacle.PlotPoints(), {{"c", "k"}}); |
| 239 | } |
| 240 | // Go through and plot true/expected camera targets for a few select |
| 241 | // time-steps. |
| 242 | ::std::vector<const char *> colors{"m", "y", "c"}; |
| 243 | int jj = 0; |
| 244 | for (size_t ii = 0; ii < simulation_x_.size(); ii += 400) { |
| 245 | *true_robot_pose_.mutable_pos() << simulation_x_[ii], simulation_y_[ii], |
| 246 | 0.0; |
| 247 | true_robot_pose_.set_theta(simulation_theta_[ii]); |
| 248 | for (const TestCamera &camera : true_cameras_) { |
| 249 | for (const auto &plot_pts : camera.PlotPoints()) { |
| 250 | PlotPlotPts(plot_pts, {{"c", colors[jj]}}); |
| 251 | } |
| 252 | } |
| 253 | for (const TestCamera &camera : robot_cameras_) { |
| 254 | *robot_pose_.mutable_pos() << estimated_x_[ii], estimated_y_[ii], 0.0; |
| 255 | robot_pose_.set_theta(estimated_theta_[ii]); |
| 256 | const auto &all_plot_pts = camera.PlotPoints(); |
| 257 | *robot_pose_.mutable_pos() = true_robot_pose_.rel_pos(); |
| 258 | robot_pose_.set_theta(true_robot_pose_.rel_theta()); |
| 259 | for (const auto &plot_pts : all_plot_pts) { |
| 260 | PlotPlotPts(plot_pts, {{"c", colors[jj]}, {"ls", "--"}}); |
| 261 | } |
| 262 | } |
| 263 | jj = (jj + 1) % colors.size(); |
| 264 | } |
| 265 | matplotlibcpp::legend(); |
| 266 | |
| 267 | matplotlibcpp::figure(); |
| 268 | matplotlibcpp::plot( |
| 269 | simulation_t_, spline_x_, |
| 270 | {{"label", "spline x"}, {"c", "g"}, {"ls", ""}, {"marker", "o"}}); |
| 271 | matplotlibcpp::plot(simulation_t_, simulation_x_, |
| 272 | {{"label", "simulated x"}, {"c", "g"}}); |
| 273 | matplotlibcpp::plot(simulation_t_, estimated_x_, |
| 274 | {{"label", "estimated x"}, {"c", "g"}, {"ls", "--"}}); |
| 275 | |
| 276 | matplotlibcpp::plot( |
| 277 | simulation_t_, spline_y_, |
| 278 | {{"label", "spline y"}, {"c", "b"}, {"ls", ""}, {"marker", "o"}}); |
| 279 | matplotlibcpp::plot(simulation_t_, simulation_y_, |
| 280 | {{"label", "simulated y"}, {"c", "b"}}); |
| 281 | matplotlibcpp::plot(simulation_t_, estimated_y_, |
| 282 | {{"label", "estimated y"}, {"c", "b"}, {"ls", "--"}}); |
| 283 | |
| 284 | matplotlibcpp::plot(simulation_t_, simulation_theta_, |
| 285 | {{"label", "simulated theta"}, {"c", "r"}}); |
| 286 | matplotlibcpp::plot( |
| 287 | simulation_t_, estimated_theta_, |
| 288 | {{"label", "estimated theta"}, {"c", "r"}, {"ls", "--"}}); |
| 289 | matplotlibcpp::legend(); |
| 290 | |
| 291 | matplotlibcpp::show(); |
| 292 | } |
| 293 | #endif |
| 294 | } |
| 295 | |
| 296 | protected: |
| 297 | // Returns a random number with a gaussian distribution with a mean of zero |
| 298 | // and a standard deviation of std, if noisify = true. |
| 299 | // If noisify is false, then returns 0.0. |
| 300 | double Normal(double std) { |
| 301 | if (GetParam().noisify) { |
| 302 | return normal_(gen_) * std; |
| 303 | } |
| 304 | return 0.0; |
| 305 | } |
| 306 | // Adds random noise to the given target view. |
| 307 | void Noisify(TestCamera::TargetView *view) { |
| 308 | view->reading.heading += Normal(view->noise.heading); |
| 309 | view->reading.distance += Normal(view->noise.distance); |
| 310 | view->reading.height += Normal(view->noise.height); |
| 311 | view->reading.skew += Normal(view->noise.skew); |
| 312 | } |
| 313 | // The differential equation for the dynamics of the system. |
| 314 | TestLocalizer::State DiffEq(const TestLocalizer::State &X, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 315 | const Eigen::Vector2d &voltage) { |
| 316 | TestLocalizer::Input U; |
| 317 | U.setZero(); |
| 318 | U(0) = voltage(0); |
| 319 | U(1) = voltage(1); |
| 320 | return localizer_.DiffEq(X, U, true); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | Field field_; |
| 324 | ::std::array<Target, Field::kNumTargets> targets_; |
| 325 | // The obstacles that are passed to the camera objects for the localizer. |
| 326 | ::std::array<Obstacle, Field::kNumObstacles> modeled_obstacles_; |
| 327 | // The obstacles that are used for actually simulating the cameras. |
| 328 | ::std::array<Obstacle, Field::kNumObstacles> true_obstacles_; |
| 329 | |
| 330 | DrivetrainConfig<double> dt_config_; |
| 331 | |
| 332 | // Noise information for the actual simulated cameras (true_*) and the |
| 333 | // parameters that the localizer should use for modelling the cameras. Note |
| 334 | // how the max_viewable_distance is larger for the localizer, so that if |
| 335 | // there is any error in the estimation, it still thinks that it can see |
| 336 | // any targets that might actually be in range. |
| 337 | TestCamera::NoiseParameters true_noise_parameters_ = { |
| 338 | .max_viewable_distance = 10.0, |
| 339 | .heading_noise = 0.02, |
| 340 | .nominal_distance_noise = 0.06, |
| 341 | .nominal_skew_noise = 0.1, |
| 342 | .nominal_height_noise = 0.01}; |
| 343 | TestCamera::NoiseParameters robot_noise_parameters_ = { |
| 344 | .max_viewable_distance = 11.0, |
| 345 | .heading_noise = 0.02, |
| 346 | .nominal_distance_noise = 0.06, |
| 347 | .nominal_skew_noise = 0.1, |
| 348 | .nominal_height_noise = 0.01}; |
| 349 | |
| 350 | // Standard deviations of the noise for the encoders/gyro. |
| 351 | double encoder_noise_, gyro_noise_; |
| 352 | |
| 353 | Pose robot_pose_; |
| 354 | ::std::array<TestCamera, 4> robot_cameras_; |
| 355 | Pose true_robot_pose_; |
| 356 | ::std::array<TestCamera, 4> true_cameras_; |
| 357 | |
| 358 | TestLocalizer localizer_; |
| 359 | |
| 360 | ::frc971::control_loops::drivetrain::SplineDrivetrain spline_drivetrain_; |
| 361 | |
| 362 | // All the data we want to end up plotting. |
| 363 | ::std::vector<double> simulation_t_; |
| 364 | |
| 365 | ::std::vector<double> spline_x_; |
| 366 | ::std::vector<double> spline_y_; |
| 367 | ::std::vector<double> estimated_x_; |
| 368 | ::std::vector<double> estimated_y_; |
| 369 | ::std::vector<double> estimated_theta_; |
| 370 | ::std::vector<double> simulation_x_; |
| 371 | ::std::vector<double> simulation_y_; |
| 372 | ::std::vector<double> simulation_theta_; |
| 373 | |
| 374 | ::std::vector<double> simulation_vl_; |
| 375 | ::std::vector<double> simulation_vr_; |
| 376 | |
| 377 | // Simulation start time |
| 378 | ::aos::monotonic_clock::time_point t0_; |
| 379 | |
| 380 | // Average duration of each iteration; used for debugging and getting a |
| 381 | // sanity-check on what performance looks like--uses a real system clock. |
| 382 | ::std::chrono::duration<double> avg_time_; |
| 383 | |
| 384 | ::std::mt19937 gen_{static_cast<uint32_t>(::aos::testing::RandomSeed())}; |
| 385 | ::std::normal_distribution<> normal_; |
| 386 | }; |
| 387 | |
James Kuszmaul | 6f941b7 | 2019-03-08 18:12:25 -0800 | [diff] [blame] | 388 | using ::std::chrono::milliseconds; |
| 389 | |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 390 | // Tests that, when we attempt to follow a spline and use the localizer to |
| 391 | // perform the state estimation, we end up roughly where we should and that |
| 392 | // the localizer has a valid position estimate. |
| 393 | TEST_P(ParameterizedLocalizerTest, SplineTest) { |
| 394 | // state stores the true state of the robot throughout the simulation. |
| 395 | TestLocalizer::State state = GetParam().true_start_state; |
| 396 | |
| 397 | ::aos::monotonic_clock::time_point t = t0_; |
| 398 | |
| 399 | // The period with which we should take frames from the cameras. Currently, |
| 400 | // we just trigger all the cameras at once, rather than offsetting them or |
| 401 | // anything. |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 402 | const int camera_period = 5; // cycles |
James Kuszmaul | 6f941b7 | 2019-03-08 18:12:25 -0800 | [diff] [blame] | 403 | // The amount of time to delay the camera images from when they are taken, for |
| 404 | // each camera. |
| 405 | const ::std::array<milliseconds, 4> camera_latencies{ |
| 406 | {milliseconds(45), milliseconds(50), milliseconds(55), |
| 407 | milliseconds(100)}}; |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 408 | |
James Kuszmaul | 6f941b7 | 2019-03-08 18:12:25 -0800 | [diff] [blame] | 409 | // A queue of camera frames for each camera so that we can add a time delay to |
| 410 | // the data coming from the cameras. |
| 411 | ::std::array< |
| 412 | ::std::queue<::std::tuple< |
| 413 | ::aos::monotonic_clock::time_point, const TestCamera *, |
| 414 | ::aos::SizedArray<TestCamera::TargetView, kNumTargetsPerFrame>>>, |
| 415 | 4> |
| 416 | camera_queues; |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 417 | |
| 418 | // Start time, for debugging. |
| 419 | const auto begin = ::std::chrono::steady_clock::now(); |
| 420 | |
| 421 | size_t i; |
| 422 | for (i = 0; !spline_drivetrain_.IsAtEnd(); ++i) { |
| 423 | // Get the current state estimate into a matrix that works for the |
| 424 | // trajectory code. |
| 425 | ::Eigen::Matrix<double, 5, 1> known_state; |
| 426 | TestLocalizer::State X_hat = localizer_.X_hat(); |
| 427 | known_state << X_hat(StateIdx::kX, 0), X_hat(StateIdx::kY, 0), |
| 428 | X_hat(StateIdx::kTheta, 0), X_hat(StateIdx::kLeftVelocity, 0), |
| 429 | X_hat(StateIdx::kRightVelocity, 0); |
| 430 | |
| 431 | spline_drivetrain_.Update(true, known_state); |
| 432 | |
Alex Perry | cb7da4b | 2019-08-28 19:35:56 -0700 | [diff] [blame] | 433 | ::frc971::control_loops::drivetrain::OutputT output; |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 434 | output.left_voltage = 0; |
| 435 | output.right_voltage = 0; |
| 436 | spline_drivetrain_.SetOutput(&output); |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 437 | Eigen::Vector2d U(output.left_voltage, output.right_voltage); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 438 | |
| 439 | const ::Eigen::Matrix<double, 5, 1> goal_state = |
| 440 | spline_drivetrain_.CurrentGoalState(); |
| 441 | simulation_t_.push_back( |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 442 | ::aos::time::DurationInSeconds(t.time_since_epoch())); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 443 | spline_x_.push_back(goal_state(0, 0)); |
| 444 | spline_y_.push_back(goal_state(1, 0)); |
| 445 | simulation_x_.push_back(state(StateIdx::kX, 0)); |
| 446 | simulation_y_.push_back(state(StateIdx::kY, 0)); |
| 447 | simulation_theta_.push_back(state(StateIdx::kTheta, 0)); |
| 448 | estimated_x_.push_back(known_state(0, 0)); |
| 449 | estimated_y_.push_back(known_state(1, 0)); |
| 450 | estimated_theta_.push_back(known_state(StateIdx::kTheta, 0)); |
| 451 | |
| 452 | simulation_vl_.push_back(U(0)); |
| 453 | simulation_vr_.push_back(U(1)); |
| 454 | U(0, 0) = ::std::max(::std::min(U(0, 0), 12.0), -12.0); |
| 455 | U(1, 0) = ::std::max(::std::min(U(1, 0), 12.0), -12.0); |
| 456 | |
| 457 | state = ::frc971::control_loops::RungeKuttaU( |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 458 | [this](const ::Eigen::Matrix<double, 12, 1> &X, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 459 | const ::Eigen::Matrix<double, 2, 1> &U) { return DiffEq(X, U); }, |
James Kuszmaul | 651fc3f | 2019-05-15 21:14:25 -0700 | [diff] [blame] | 460 | state, U, ::aos::time::DurationInSeconds(dt_config_.dt)); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 461 | |
| 462 | // Add arbitrary disturbances at some arbitrary interval. The main points of |
| 463 | // interest here are that we (a) stop adding disturbances at the very end of |
| 464 | // the trajectory, to allow us to actually converge to the goal, and (b) |
| 465 | // scale disturbances by the corruent velocity. |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 466 | // TODO(james): Figure out how to persist good accelerometer values through |
| 467 | // the disturbances. |
James Kuszmaul | c73bb22 | 2019-04-07 12:15:35 -0700 | [diff] [blame] | 468 | if (GetParam().disturb && i % 75 == 0) { |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 469 | // Scale the disturbance so that when we have near-zero velocity we don't |
| 470 | // have much disturbance. |
| 471 | double disturbance_scale = ::std::min( |
| 472 | 1.0, ::std::sqrt(::std::pow(state(StateIdx::kLeftVelocity, 0), 2) + |
| 473 | ::std::pow(state(StateIdx::kRightVelocity, 0), 2)) / |
| 474 | 3.0); |
| 475 | TestLocalizer::State disturbance; |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 476 | disturbance << 0.02, 0.02, 0.001, 0.03, 0.02, 0.0, 0.0, 0.0, 0.0, 0.0, |
| 477 | 0.0, 0.0; |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 478 | disturbance *= disturbance_scale; |
| 479 | state += disturbance; |
| 480 | } |
| 481 | |
| 482 | t += dt_config_.dt; |
| 483 | *true_robot_pose_.mutable_pos() << state(StateIdx::kX, 0), |
| 484 | state(StateIdx::kY, 0), 0.0; |
| 485 | true_robot_pose_.set_theta(state(StateIdx::kTheta, 0)); |
| 486 | const double left_enc = state(StateIdx::kLeftEncoder, 0); |
| 487 | const double right_enc = state(StateIdx::kRightEncoder, 0); |
| 488 | |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 489 | const double gyro = (state(StateIdx::kRightVelocity) - |
| 490 | state(StateIdx::kLeftVelocity)) / |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 491 | dt_config_.robot_radius / 2.0; |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 492 | const TestLocalizer::State xdot = DiffEq(state, U); |
| 493 | const Eigen::Vector3d accel( |
| 494 | localizer_.CalcLongitudinalVelocity(xdot) - |
| 495 | gyro * state(StateIdx::kLateralVelocity), |
| 496 | gyro * localizer_.CalcLongitudinalVelocity(state), 1.0); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 497 | |
| 498 | localizer_.UpdateEncodersAndGyro(left_enc + Normal(encoder_noise_), |
| 499 | right_enc + Normal(encoder_noise_), |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 500 | gyro + Normal(gyro_noise_), U, accel, t); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 501 | |
James Kuszmaul | 6f941b7 | 2019-03-08 18:12:25 -0800 | [diff] [blame] | 502 | for (size_t cam_idx = 0; cam_idx < camera_queues.size(); ++cam_idx) { |
| 503 | auto &camera_queue = camera_queues[cam_idx]; |
| 504 | // Clear out the camera frames that we are ready to pass to the localizer. |
| 505 | while (!camera_queue.empty() && ::std::get<0>(camera_queue.front()) < |
| 506 | t - camera_latencies[cam_idx]) { |
| 507 | const auto tuple = camera_queue.front(); |
| 508 | camera_queue.pop(); |
| 509 | ::aos::monotonic_clock::time_point t_obs = ::std::get<0>(tuple); |
| 510 | const TestCamera *camera = ::std::get<1>(tuple); |
| 511 | ::aos::SizedArray<TestCamera::TargetView, kNumTargetsPerFrame> views = |
| 512 | ::std::get<2>(tuple); |
| 513 | localizer_.UpdateTargets(*camera, views, t_obs); |
| 514 | } |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 515 | |
James Kuszmaul | 6f941b7 | 2019-03-08 18:12:25 -0800 | [diff] [blame] | 516 | // Actually take all the images and store them in the queue. |
| 517 | if (i % camera_period == 0) { |
| 518 | for (size_t jj = 0; jj < true_cameras_.size(); ++jj) { |
| 519 | const auto target_views = true_cameras_[jj].target_views(); |
| 520 | ::aos::SizedArray<TestCamera::TargetView, kNumTargetsPerFrame> |
| 521 | pass_views; |
| 522 | for (size_t ii = 0; |
| 523 | ii < ::std::min(kNumTargetsPerFrame, target_views.size()); |
| 524 | ++ii) { |
| 525 | TestCamera::TargetView view = target_views[ii]; |
| 526 | Noisify(&view); |
| 527 | pass_views.push_back(view); |
| 528 | } |
| 529 | camera_queue.emplace(t, &robot_cameras_[jj], pass_views); |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 530 | } |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 531 | } |
| 532 | } |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | const auto end = ::std::chrono::steady_clock::now(); |
| 536 | avg_time_ = (end - begin) / i; |
| 537 | TestLocalizer::State estimate_err = state - localizer_.X_hat(); |
| 538 | EXPECT_LT(estimate_err.template topRows<7>().norm(), |
| 539 | GetParam().estimate_tolerance); |
| 540 | // Check that none of the states that we actually care about (x/y/theta, and |
| 541 | // wheel positions/speeds) are too far off, individually: |
James Kuszmaul | 7f1a408 | 2019-04-14 10:50:44 -0700 | [diff] [blame] | 542 | EXPECT_LT(estimate_err.template topRows<3>().cwiseAbs().maxCoeff(), |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 543 | GetParam().estimate_tolerance / 3.0) |
| 544 | << "Estimate error: " << estimate_err.transpose(); |
| 545 | Eigen::Matrix<double, 5, 1> final_trajectory_state; |
| 546 | final_trajectory_state << state(StateIdx::kX, 0), state(StateIdx::kY, 0), |
| 547 | state(StateIdx::kTheta, 0), state(StateIdx::kLeftVelocity, 0), |
| 548 | state(StateIdx::kRightVelocity, 0); |
| 549 | const Eigen::Matrix<double, 5, 1> final_trajectory_state_err = |
| 550 | final_trajectory_state - spline_drivetrain_.CurrentGoalState(); |
| 551 | EXPECT_LT(final_trajectory_state_err.norm(), GetParam().goal_tolerance) |
| 552 | << "Goal error: " << final_trajectory_state_err.transpose(); |
| 553 | } |
| 554 | |
| 555 | INSTANTIATE_TEST_CASE_P( |
| 556 | LocalizerTest, ParameterizedLocalizerTest, |
| 557 | ::testing::Values( |
| 558 | // Checks a "perfect" scenario, where we should track perfectly. |
| 559 | LocalizerTestParams({ |
| 560 | /*control_pts_x=*/{{0.0, 3.0, 3.0, 0.0, 1.0, 1.0}}, |
| 561 | /*control_pts_y=*/{{-5.0, -5.0, 2.0, 2.0, 2.0, 3.0}}, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 562 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 563 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 564 | .finished(), |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 565 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 566 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 567 | .finished(), |
| 568 | /*noisify=*/false, |
| 569 | /*disturb=*/false, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 570 | /*estimate_tolerance=*/1e-2, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 571 | /*goal_tolerance=*/2e-2, |
| 572 | }), |
| 573 | // Checks "perfect" estimation, but start off the spline and check |
| 574 | // that we can still follow it. |
| 575 | LocalizerTestParams({ |
| 576 | /*control_pts_x=*/{{0.0, 3.0, 3.0, 0.0, 1.0, 1.0}}, |
| 577 | /*control_pts_y=*/{{-5.0, -5.0, 2.0, 2.0, 2.0, 3.0}}, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 578 | (TestLocalizer::State() << 0.0, -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 579 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 580 | .finished(), |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 581 | (TestLocalizer::State() << 0.0, -4.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 582 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 583 | .finished(), |
| 584 | /*noisify=*/false, |
| 585 | /*disturb=*/false, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 586 | /*estimate_tolerance=*/1e-2, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 587 | /*goal_tolerance=*/2e-2, |
| 588 | }), |
| 589 | // Repeats perfect scenario, but add sensor noise. |
| 590 | LocalizerTestParams({ |
| 591 | /*control_pts_x=*/{{0.0, 3.0, 3.0, 0.0, 1.0, 1.0}}, |
| 592 | /*control_pts_y=*/{{-5.0, -5.0, 2.0, 2.0, 2.0, 3.0}}, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 593 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 594 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 595 | .finished(), |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 596 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 597 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 598 | .finished(), |
| 599 | /*noisify=*/true, |
| 600 | /*disturb=*/false, |
James Kuszmaul | ea314d9 | 2019-02-18 19:45:06 -0800 | [diff] [blame] | 601 | /*estimate_tolerance=*/0.4, |
James Kuszmaul | a5632fe | 2019-03-23 20:28:33 -0700 | [diff] [blame] | 602 | /*goal_tolerance=*/0.4, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 603 | }), |
| 604 | // Repeats perfect scenario, but add initial estimator error. |
| 605 | LocalizerTestParams({ |
| 606 | /*control_pts_x=*/{{0.0, 3.0, 3.0, 0.0, 1.0, 1.0}}, |
| 607 | /*control_pts_y=*/{{-5.0, -5.0, 2.0, 2.0, 2.0, 3.0}}, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 608 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 609 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 610 | .finished(), |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 611 | (TestLocalizer::State() << 0.1, -5.1, -0.01, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 612 | 0.0, 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 613 | .finished(), |
| 614 | /*noisify=*/false, |
| 615 | /*disturb=*/false, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 616 | /*estimate_tolerance=*/1e-2, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 617 | /*goal_tolerance=*/2e-2, |
| 618 | }), |
| 619 | // Repeats perfect scenario, but add voltage + angular errors: |
| 620 | LocalizerTestParams({ |
| 621 | /*control_pts_x=*/{{0.0, 3.0, 3.0, 0.0, 1.0, 1.0}}, |
| 622 | /*control_pts_y=*/{{-5.0, -5.0, 2.0, 2.0, 2.0, 3.0}}, |
| 623 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 624 | 0.5, 0.02, 0.0, 0.0) |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 625 | .finished(), |
| 626 | (TestLocalizer::State() << 0.1, -5.1, -0.01, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 627 | 0.0, 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 628 | .finished(), |
| 629 | /*noisify=*/false, |
| 630 | /*disturb=*/false, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 631 | /*estimate_tolerance=*/1e-2, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 632 | /*goal_tolerance=*/2e-2, |
| 633 | }), |
| 634 | // Add disturbances while we are driving: |
| 635 | LocalizerTestParams({ |
| 636 | /*control_pts_x=*/{{0.0, 3.0, 3.0, 0.0, 1.0, 1.0}}, |
| 637 | /*control_pts_y=*/{{-5.0, -5.0, 2.0, 2.0, 2.0, 3.0}}, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 638 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 639 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 640 | .finished(), |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 641 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 642 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 643 | .finished(), |
| 644 | /*noisify=*/false, |
| 645 | /*disturb=*/true, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 646 | /*estimate_tolerance=*/4e-2, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 647 | /*goal_tolerance=*/0.15, |
| 648 | }), |
| 649 | // Add noise and some initial error in addition: |
| 650 | LocalizerTestParams({ |
| 651 | /*control_pts_x=*/{{0.0, 3.0, 3.0, 0.0, 1.0, 1.0}}, |
| 652 | /*control_pts_y=*/{{-5.0, -5.0, 2.0, 2.0, 2.0, 3.0}}, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 653 | (TestLocalizer::State() << 0.0, -5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 654 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 655 | .finished(), |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 656 | (TestLocalizer::State() << 0.1, -5.1, 0.03, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 657 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 658 | .finished(), |
| 659 | /*noisify=*/true, |
| 660 | /*disturb=*/true, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 661 | /*estimate_tolerance=*/0.5, |
| 662 | /*goal_tolerance=*/1.0, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 663 | }), |
| 664 | // Try another spline, just in case the one I was using is special for |
| 665 | // some reason; this path will also go straight up to a target, to |
| 666 | // better simulate what might happen when trying to score: |
| 667 | LocalizerTestParams({ |
| 668 | /*control_pts_x=*/{{0.5, 3.5, 4.0, 8.0, 11.0, 10.2}}, |
| 669 | /*control_pts_y=*/{{1.0, 1.0, -3.0, -2.0, -3.5, -3.65}}, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 670 | (TestLocalizer::State() << 0.6, 1.01, 0.01, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 671 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 672 | .finished(), |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 673 | (TestLocalizer::State() << 0.5, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, |
James Kuszmaul | 3c5b4d3 | 2020-02-11 17:22:14 -0800 | [diff] [blame] | 674 | 0.0, 0.0, 0.0, 0.0) |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 675 | .finished(), |
| 676 | /*noisify=*/true, |
| 677 | /*disturb=*/false, |
James Kuszmaul | 7f1a408 | 2019-04-14 10:50:44 -0700 | [diff] [blame] | 678 | // TODO(james): Improve tests so that we aren't constantly |
| 679 | // readjusting the tolerances up. |
James Kuszmaul | c40c26e | 2019-03-24 16:26:43 -0700 | [diff] [blame] | 680 | /*estimate_tolerance=*/0.3, |
James Kuszmaul | 074429e | 2019-03-23 16:01:49 -0700 | [diff] [blame] | 681 | /*goal_tolerance=*/0.7, |
James Kuszmaul | 1057ce8 | 2019-02-09 17:58:24 -0800 | [diff] [blame] | 682 | }))); |
| 683 | |
| 684 | } // namespace testing |
| 685 | } // namespace control_loops |
| 686 | } // namespace y2019 |