Skip to content

Commit 8e2b19c

Browse files
[Symforce] Codegen ToYawPitchRoll for C++ Rot3
I changed `Rot3::ToYawPitchRoll()` to use the same implementation as we do in the symbolic python version. Previously we were converting the quaternion to a rotation matrix and then using built-in Eigen functions to get the Euler angles, but this could give ambiguous results. For example, if you construct a rotation with YPR (-10, 10, -10) degrees, it can sometimes be reconstructed as something like YPR (170, 170, -180) degrees. Computing Euler angles directly from the quaternion is much more stable (and it's probably much faster). Topic: symforce_rot3_cpp_to_yaw_pitch_roll GitOrigin-RevId: 85de520542ba265dced379a6655f42d536cd32d7
1 parent 52d2b5d commit 8e2b19c

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

gen/cpp/sym/rot3.cc

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gen/cpp/sym/rot3.h

+2-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

symforce/codegen/backends/cpp/templates/geo_package/custom_methods/rot3.h.jinja

-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,6 @@
4040
return Rot3(Eigen::Quaternion<Scalar>(mat));
4141
}
4242

43-
// Euler angles
44-
// TODO(hayk): Could codegen this.
45-
46-
Vector3 ToYawPitchRoll() const {
47-
return ToRotationMatrix().eulerAngles(2, 1, 0);
48-
}
49-
5043
// Generate a random element in SO3
5144
template <typename Generator>
5245
static Rot3 Random(Generator& gen) {

symforce/codegen/geo_package_codegen.py

+6
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ def codegen_mul(group: T.Type, multiplicand_type: T.Type) -> Codegen:
111111
name="from_yaw_pitch_roll",
112112
config=config,
113113
),
114+
Codegen.function(
115+
func=lambda self: sf.V3(self.to_yaw_pitch_roll()),
116+
input_types=[sf.Rot3],
117+
name="to_yaw_pitch_roll",
118+
config=config,
119+
),
114120
],
115121
sf.Pose2: [
116122
codegen_mul(sf.Pose2, sf.Vector2),

0 commit comments

Comments
 (0)