0

i´m using webots and i have a robot. The point is that i want to see consumption's motors of the robot. I have seen this in documentation webots https://cyberbotics.com/doc/reference/motor#energy-consumption. I have actived this note, battery, and i have tried to see it like another field, for example position. But battery field always is 0. I dont know what I try next. I think the documents is a little poor.

In fact, I didnt have succes implementing this. Anyone know how to do this?

Thank you

eldanks
  • 11
  • 2

1 Answers1

1

The first thing to do is to sepcify 3 components in the 'battery' field of your robot node:

this field should contain three values: the first one corresponds to the present energy level of the robot in Joules (J), the second is the maximum energy the robot can hold in Joules, and the third is the energy recharge speed in Watts ([W]=[J]/[s])

https://cyberbotics.com/doc/reference/robot#field-summary

Then from the controller, you should use the robot/battery API to enable the sensors and retrieve the battery state:

These functions allow you to measure the present energy level of the robot battery. First, it is necessary to enable battery sensor measurements by calling the wb_robot_battery_sensor_enable function. The sampling_period parameter is expressed in milliseconds and defines how frequently measurements are performed. After the battery sensor is enabled a value can be read from it by calling the wb_robot_battery_sensor_get_value function. The returned value corresponds to the present energy level of the battery expressed in Joules (J), if the battery field is empty, this function will return -1.0.

https://cyberbotics.com/doc/reference/robot#wb_robot_battery_sensor_enable

You can find an example of battery simulation available directly by default in Webots:

https://www.cyberbotics.com/doc/guide/samples-devices#battery-wbt

David Mansolino
  • 1,713
  • 7
  • 13
  • Thank you for your answer, it was very usefull and i have done all that you say. But, when i do all of this my program break down and exit. I have activated the node battery, and I enable and use the function to get the float of battery, when I put 0 or a negative number in battery, functions return the same number, and when its positive simply the program doesnt work. I dont know if i forget something – eldanks Oct 07 '20 at 16:48
  • What do you mean by the program exits? Is it Webots or your controller that exits? In any case, I would recommend investigating what are the differences between your simulation and this one: https://www.cyberbotics.com/doc/guide/samples-devices#battery-wbt This will help you understanding where does the problem come from. – David Mansolino Oct 08 '20 at 06:27