Skip to content

Commit afb6c6b

Browse files
committed
fix(ros2): correct degree-to-radian conversion in transform publisher
The rotation conversion was incorrectly using M_PI_2 (pi/2) instead of M_PI (pi) in the degree-to-radian formula, producing angles that were half the correct value. Also negate the y-axis translation at the source instead of after quaternion computation for consistency with ROS coordinate conventions. Signed-off-by: Yutaka Kondo <yutaka.kondo@youtalk.jp>
1 parent fee14f4 commit afb6c6b

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

LibCarla/source/carla/ros2/publishers/CarlaTransformPublisher.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@ geometry_msgs::msg::Transform CarlaTransformPublisher::ComputeTransform(std::str
3030
}
3131
}
3232

33+
// Better readability
3334
const float tx = transform.location.x;
34-
const float ty = transform.location.y;
35+
const float ty = transform.location.y * -1.0f;
3536
const float tz = transform.location.z;
3637

37-
const float rx = (transform.rotation.pitch * -1.0f) * (float(M_PI_2) / 180.0f);
38-
const float ry = (transform.rotation.yaw * -1.0f) * (float(M_PI_2) / 180.0f);
39-
const float rz = transform.rotation.roll * (float(M_PI_2) / 180.0f);
38+
// Rotations was not correctly computed Radians = Degrees * (π / 180)
39+
const float DEG_TO_RAD = float(M_PI) / 180.0f;
40+
const float rx = (transform.rotation.pitch * -1.0f) * DEG_TO_RAD;
41+
const float ry = (transform.rotation.yaw * -1.0f) * DEG_TO_RAD;
42+
const float rz = transform.rotation.roll * DEG_TO_RAD;
4043

4144
const float cr = cosf(rz * 0.5f);
4245
const float sr = sinf(rz * 0.5f);
@@ -48,7 +51,7 @@ geometry_msgs::msg::Transform CarlaTransformPublisher::ComputeTransform(std::str
4851
geometry_msgs::msg::Transform tf;
4952

5053
tf.translation().x(tx);
51-
tf.translation().y(-ty);
54+
tf.translation().y(ty);
5255
tf.translation().z(tz);
5356

5457
tf.rotation().w(cr * cp * cy + sr * sp * sy);

0 commit comments

Comments
 (0)