summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMichael Welter <michael@welter-4d.de>2025-03-23 09:30:20 +0100
committerMichael Welter <michael@welter-4d.de>2025-03-23 11:39:18 +0100
commit4d6bc2080669fc4806e53793dab4191dcdf448ce (patch)
tree6939e0c00734a93649488c5b536fc91ce0f52456
parent64dd7913e52fb78f88c5515bd9aebfc0c1e82647 (diff)
tracker/nn: Fix roll output
Roll is now (hopefully) computed from the correct matrix row. It turns out it was using values from row 2 instead of 1. Makes more sense to measure roll based on the y-component of local axes. Must have slipped in the matrix row somehow. Reference to wikipedia is added.
-rw-r--r--tracker-neuralnet/ftnoir_tracker_neuralnet.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
index 01747707..3a6b85b1 100644
--- a/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
+++ b/tracker-neuralnet/ftnoir_tracker_neuralnet.cpp
@@ -667,14 +667,20 @@ void NeuralNetTracker::data(double *data)
const auto& my = tmp.R.col(1);
const auto& mz = tmp.R.col(2);
+ // For reference: https://en.wikipedia.org/wiki/Euler_angles. Section "Rotation matrix". The relevant matrix is
+ // under "Tait-Bryan angles", row with "Y_alpha Z_beta X_gamma = ...".
+ // Because for the NN tracker x is forward, and y is up. We can see that the x axis is independent of roll. Thus it
+ // is relatively easy to figure out the yaw and pitch angles (alpha and beta).
const float yaw = std::atan2(mx(2), mx(0));
const float pitch = -std::atan2(-mx(1), std::sqrt(mx(2)*mx(2)+mx(0)*mx(0)));
- const float roll = std::atan2(-my(2), mz(2));
+ // For the roll angle we recognize that the matrix entries in the second row contain cos(pitch)*cos(roll), and
+ // cos(pitch)*sin(roll). Using atan2 eliminates the common pitch factor and we obtain the roll angle.
+ const float roll = std::atan2(-mz(1), my(1));
{
constexpr double rad2deg = 180/M_PI;
data[Yaw] = rad2deg * yaw;
data[Pitch] = rad2deg * pitch;
- data[Roll] = rad2deg * roll;
+ data[Roll] = -rad2deg * roll;
// convert to cm
data[TX] = -tmp.t[2] * 0.1;