0

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);


}
eren
  • 1
  • 1
  • I think this is not really a C++ question. But with what I know of 3D stuff.... your translation and rotation are not doing anything. You should calculate average 3D position of ALL the points and then use that to translate all the points toward the origing. e.g. if average is (2,3,4) then translate by (-2,-3,-4) for x,y, z. – Pepijn Kramer Jan 29 '23 at 15:24
  • Alright i will try this! Thank you. But even without an average, when i try to get the object to another position by setting the translation x,y,z values to random values, nothing changes in RVIZ. The object doesnt move. Do i need to change anything else to move it? Thanks in advance! – eren Jan 29 '23 at 15:54
  • Ok that maybe something library specific I cannot help you with. – Pepijn Kramer Jan 29 '23 at 16:13

1 Answers1

0

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.

static_transform_node = Node(
    package="tf2_ros",
    executable="static_transform_publisher",
    arguments=["x", "y", "z", "roll", "pitch", "yaw", "parent_frame_id", "child_frame_id"],
    output="screen",
    )

Note: the quotes in the arguments are required

ref: https://wiki.ros.org/tf2_ros#static_transform_publisher

MarcNN
  • 11
  • 2
  • Thank you very much for the suggestion! I was able to change between the frames in RVIZ but non of them showed the change in position. Sorry for the basic question but do i need a seperate node for the transformer? I put it in my callback function in my package, where i have a node, not only for the transformer but also publishing the pointcloud. End the result was this error message: Message Filter dropping message: frame 'map' at time xyz for reason 'Unknown' Do i need a listener to the broadcast publisher too? Maybe the problem is, that i dont have one. – eren Jan 29 '23 at 19:30
  • First, I would use the map as the parent frame, the object as the child. Then, use rqt and see if you’re actually getting published on the correct topics. You should be able to see your transform values. – MarcNN Jan 30 '23 at 14:20