0

Sensors are usually enabled with wb_XXX_enable(tag, sampling_period), and the sensor values can be retrieved with wb_XXX_get_values(tag).

How do we know if the values retrieved with wb_XXX_get_values(tag) are new values?

A naive approach would be saving the values and comparing it for every loop, but it won't work if the sensor values didn't change.

Inbae Jeong
  • 4,053
  • 25
  • 38

1 Answers1

2

Assuming you enable all your sensors at the first step of the controller (if it is not the case this method works also but is a bit more complex as you need to add an offset on the time for each sensor):

  1. At each step, for each sensor, you can get the sampling period with the period = wb_XXX_get_sampling_period(tag).
  2. Then you can get the current simulation time and convert it to milliseconds: int time = 1000 * wb_robot_get_time()
  3. Finally, you can compare the time with the sampling period of the sensor, if the modulo is 0, then it means the sensors was just updated: bool updated = time % period == 0.
David Mansolino
  • 1,713
  • 7
  • 13