Skip to content

FIX ROS2 transformation calculation #9123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ geometry_msgs::msg::Transform CarlaTransformPublisher::ComputeTransform(std::str
}
}

// Better readability
const float tx = transform.location.x;
const float ty = transform.location.y;
const float ty = transform.location.y * -1.0f;
const float tz = transform.location.z;

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

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

tf.translation().x(tx);
tf.translation().y(-ty);
tf.translation().y(ty);
tf.translation().z(tz);

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