In the context of my simulation, I need to programmatically get the position of robots and objects in the world (in global coordinate system). How can this be done?

I'm using Webots R2023a.

  • $\begingroup$ Hi Daniel Dias, please read the meta answer robotics.meta.stackexchange.com/a/1485/37 and the question associated with it. You have been flagged as a member of a possible voting ring, and we would like to help avoid that in the future. $\endgroup$
    – Mark Booth
    Dec 12, 2022 at 22:21

1 Answer 1


There are different functions depending whether this information must be accessed in a normal controller, in a Supervisor controller or in a physics plugin. All the functions described below will return the 3D position in meters and expressed in the global (world) coordinate system.

Get position using the robot's controller

If one is not available already, you need to first add a GPS node to your robot. You can get a reference to this device using the wb_robot_get_device function, enable it with wb_gps_enable and retrieve the values with wb_gps_get_values. Note that the GPS's resolution field must be 0 (the default), otherwise the results will be noisy. It should also be noted that the GPS can be placed on a robot's part (arm, foot, etc.) to get the world/global coordinates of that particular part.

Get position using a Supervisor

To get the 3D position of any Transform (or derived) node using the Supervisor API you can use the wb_supervisor_node_get_position function. Another possible approach of getting the 3D position of any Transform (or derived) node placed at the root of the Scene Tree (the nodes visible when the Scene Tree is completely collapsed), is to use the wb_supervisor_field_get_sf_vec3f to read the value of the translation field of that object.

Get position using a physics plugin

After adding a physics plugin to your world (under the WorldInfo node), you can retrieve the information directly from the physics engine by using ODE's dBodyGetPosition function. Note that this function returns the position of the center of mass of the body, which may be different from the center of the Solid.

Lastly, the position of a robot can also be approximated by using odometry or SLAM techniques. This is usually more realistic because most robots don't have a GPS and therefore have no mean of precisely determining their position.

Disclaimer: I'm a software developer of Webots


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.