How to get location of an object within a script knowing its name

Hello everyone,

I’m into a ROS2 project using Gazebo garden.

I was wondering how to get an object position knowing its name ?

I tried using transport, but I don’t know how to use it properly.

I was doing something like that:

bool executed = ign_node.Request(topic_name, name, timeout,result_2,success);

I’m calling the topic “/world/world_name/pose/info”. But it’s not working, timing out.
I’m using the type gz::msgs::Pose for request and result. It might not the the proper type ?



I think you need to subscribe that topic for getting pose information.
This works for me.

I subscribe to the topic “/model/NameOfTheModel/odometry” like this…

node.Subscribe("/model/NameOfTheModel/odometry", &SpecificWorker::odometry_cb, this)

and in the method “odometry_cb” of my class “SpecificWorker” I get the pose information. In this case the odometry topic use “gz::msgs::Odometry” type.

void SpecificWorker::odometry_cb(const gz::msgs::Odometry &_msg)
    // X-Position value
    float position_x = _msg.pose().position().x();

Of course you can access to all the attributes of the Odometry class, here it’s the API access

This could be done for any topic you need to subscribe, you only need to look for what data structure is Transport using in that specific topic with the “Topic Viewer” plugin in your simulation.

I hope this can help you to resolve your problem.

Sorry for not replying. But the answer I’ve finally found was doing a bridge in my launch file like:

                + "@"
                + "geometry_msgs/msg/PoseStamped[gz.msgs.Pose",
            parameters=[{"use_sim_time": use_sim_time}],
            remappings=[(topic_name_pos_object, "/object_pose")],