# Measuring speed of movement in Webots

I have been experimenting with different fitness functions for my Webots robot simulation (in short: I'm using genetic algorithm to evolve interesting behaviour).

The idea I have now is to reward/punish Aibo based on its speed of movement. The movement is performed by setting new joint position, and currently it results in jerky random movements. I have been looking at the nodes available in Webots, but apart from GPS node (which is not available in Aibo) I couldn't find anything relevant.

What I want to achieve is to measure the distance from previous location to current location after each movement. How can I do this?

Some years ago I have used the supervisor to know the position of a simulated Khepera robot in Webots 4. The main components of the C code was the following:

Declarations:

  #define STEP 64

NodeRef robot_node;
float robot_data[4]={0,0,0,0};


Getting the node named Khepera:

  robot_node=(NodeRef)supervisor_node_get_from_def("KHEPERA");


Getting data from the node in every STEP milliseconds:

supervisor_field_get(robot_node,SUPERVISOR_FIELD_TRANSLATION|SUPERVISOR_FIELD_ROTATION_ANGLE,&robot_data,STEP);


All the above was called before the main cycle of the supervisor. The main cycle contained a robot_step(STEP); call to let the system fill the elements of the robot data structure (x,y,z,head coordinates) regularly.

Again it was Webots 4 may be there are better ways in Webots 7 to fulfill the task but it could be a starting point.

• I don't think this has changed much since version 4. I'm programming in Java so method names are a little different, but retrieving translation via supervisor looks very similar. Thank you! – Anna Pawlicka Feb 11 '13 at 8:42

I went to the source (Cyberbotics) and got these 2 solutions:

• Aibo has no GPS. And it's not straight forward to add it, because its node hierachy is hidden behind the prototype mechanism. The definition of the Aibo if however open-source: $WEBOTS/resources/projects/robots/aibo/protos/Aibo_ERS7.proto GPS can be added to the project (into the protos path) and modified as we wish. Adding GPS is as simple as adding a GPS node inside the direct children of the Robot node. • A supervisor allows to query the scene tree. This includes getting the position of the Aibo. This solution is clearer. The following example shows a supervisor retrieving information from the scene tree:$WEBOTS/projects/samples/devices/worlds/supervisor.wbt