i have a very simple and maybe stupid question, sorry i am new to this kinf of stuff. I had a file of points, published them to a topic as a pointcloud and subscribed from another node to the topic to modify the poincloud and published it again. Everthing is fine so far. The problem is that the pointcloud (the object) ist not in the origin when i visualize it in RVIZ. It is somewhere at the edge of the platform in RVIZ. How can i make the pointcloud move to the origin in a easy way? So far i have tried some solutions with the tf2 package. Tried to transform the frame of the object to the map frame, where i want to have the object at the ent. But doenst seem to work. I am missing something. The question is, is this the right and easiest approach for this or is there a better way. If its the right approach, what am i missing?
I put this code in my callback function:
geometry_msgs::msg::TransformStamped transform;
transform.header.stamp = this->get_clock()->now();
transform.header.frame_id = "object_frame";
transform.child_frame_id = "map";
// Set the position of the object relative to the Rviz frame
transform.transform.translation.x = 0.0;
transform.transform.translation.y = 0.0;
transform.transform.translation.z = 0.0;
// Set the orientation of the object relative to the Rviz frame
transform.transform.rotation.x = 0.0;
transform.transform.rotation.y = 0.0;
transform.transform.rotation.z = 0.0;
transform.transform.rotation.w = 1.0;
tf_broadcaster->sendTransform(transform);
And the following to my publisher function:
void Preprocessor::publish_pointcloud_supervoxel()
{
// Convert the PointCloud to a PointCloud2 message
auto pcl_msg_supervoxel = std::make_shared<sensor_msgs::msg::PointCloud2>();
//sensor_msgs::msg::PointCloud2 pcl_msg_supervoxel;
pcl::toROSMsg(*colored_supervoxel_cloud, *pcl_msg_supervoxel);
//pcl_msg_supervoxel->width = adjacent_supervoxel_centers.size();
pcl_msg_supervoxel->header.frame_id = "map";
pcl_msg_supervoxel->header.stamp = this->get_clock()->now();
// Publish the message
supervoxel_publisher->publish(*pcl_msg_supervoxel);
}
Not knowing your rviz setup, have you checked if the Global options:fixed frame in rviz is set to the correct frame?
You can try a static transform and see if that is reflected in rviz. This would be in the launch file.
Note: the quotes in the arguments are required
ref: https://wiki.ros.org/tf2_ros#static_transform_publisher