Skip to content

Commit 5cd181f

Browse files
committed
Foobar
1 parent af03caa commit 5cd181f

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

photon-targeting/src/test/native/cpp/Test_Pose.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* SOFTWARE.
2323
*/
2424

25+
#include <random>
26+
2527
#include "cpnp/constrained_pnp.h"
2628
#include <gtest/gtest.h>
2729

@@ -140,6 +142,8 @@ TEST(PoseTest, Projection) {
140142
}
141143

142144
TEST(PoseTest, Naive) {
145+
for (int j = 0; j < 20; j++) {
146+
143147
cpnp::ProblemParams params;
144148

145149
params.f_x = 100;
@@ -151,9 +155,15 @@ TEST(PoseTest, Naive) {
151155
frc::Transform3d robot2camera {frc::Pose3d{}, frc::Pose3d{frc::Translation3d{-1.3_m, 0.25_m, 0_m}, frc::Rotation3d{0_rad, 0_rad, -1.5_rad}}};
152156
auto imgpoints = projectPoints(params.f_x, params.f_y, params.c_x, params.c_y, robot2camera.ToMatrix(), tags);
153157

158+
// Add +-1 px of noise to the image points
159+
std::random_device rd;
160+
std::mt19937 rng(rd());
161+
std::uniform_real_distribution<double> dist(-1.0, 1.0);
162+
154163
for (int i = 0; i < tags.cols(); ++i) {
155-
params.imagePoints.push_back(imgpoints(0, i));
156-
params.imagePoints.push_back(imgpoints(1, i));
164+
// Add some noise to imgpoints, and add it to our list
165+
params.imagePoints.push_back(imgpoints(0, i) + dist(rng));
166+
params.imagePoints.push_back(imgpoints(1, i) + dist(rng));
157167

158168
params.worldPoints.push_back(tags(0, i));
159169
params.worldPoints.push_back(tags(1, i));
@@ -166,12 +176,12 @@ TEST(PoseTest, Naive) {
166176

167177
fmt::println("Polynomial solve time: {}ms", std::chrono::duration_cast<std::chrono::nanoseconds>(t1-t0).count() / 1e6);
168178

169-
auto t2 = std::chrono::high_resolution_clock::now();
170-
auto naive_ret = cpnp::solve_naive(params);
171-
auto t3 = std::chrono::high_resolution_clock::now();
172-
173-
fmt::println("Naive solve time: {}ms", std::chrono::duration_cast<std::chrono::nanoseconds>(t3-t2).count() / 1e6);
179+
// auto t2 = std::chrono::high_resolution_clock::now();
180+
// auto naive_ret = cpnp::solve_naive(params);
181+
// auto t3 = std::chrono::high_resolution_clock::now();
174182

183+
// fmt::println("Naive solve time: {}ms", std::chrono::duration_cast<std::chrono::nanoseconds>(t3-t2).count() / 1e6);
175184
fmt::println("Polynomial method says robot is at:\n{}", polynomial_ret.ToMatrix());
176-
fmt::println("Naive method says robot is at:\n{}", naive_ret.ToMatrix());
185+
// fmt::println("Naive method says robot is at:\n{}", naive_ret.ToMatrix());
186+
}
177187
}

0 commit comments

Comments
 (0)