Field-Robotics-Japan / UnitySensors

ROS/ROS2 enabled Sensor models (Assets) on Unity
Apache License 2.0
205 stars 32 forks source link

Inconsistent publishing rate for sensors #166

Open alonsollorente opened 1 month ago

alonsollorente commented 1 month ago

Hi everyone!

I hope you can help me with this problem that I'm having. I'm trying to broadcast sensory data in ROS2 and going through some difficulties.

Thank you in advance for helping me out! I let you with a brief description of my problem.

Description of the bug There is an inconsistency in the publishing frequency of sensor data between ROS2 and Unity when using ros_tcp_endpoint. Despite setting the publishing rate to 10Hz for one LiDAR sensor and 100Hz for an IMU, the actual publishing rate observed is significantly lower and inconsistent, being in the case of the IMU around 35Hz. The ros2 topic hz /imu output can be seen:

image

To Reproduce Steps to reproduce the behavior:

image image

Environment set up:

RyodoTanaka commented 1 month ago

@alonsollorente Thank you for updating the issue. This issue is related to https://github.com/Field-Robotics-Japan/UnitySensors/issues/156 (It is written in Japanese, but discussing same topic) The main reason of this problem comes from using Update() function. To fix this, we should use FixUpdate() function. https://github.com/Field-Robotics-Japan/UnitySensors/blob/master/Assets/UnitySensorsROS/Runtime/Scripts/Publishers/RosMsgPublisher.cs#L39 https://github.com/Field-Robotics-Japan/UnitySensors/blob/master/Assets/UnitySensors/Runtime/Scripts/Sensors/IMU/IMUSensor.cs#L51

But, this problem is already fixed in develop branch. Thus, please try to use develop branch. Now, merging PR from develop into master is under development (https://github.com/Field-Robotics-Japan/UnitySensors/pull/163)

alonsollorente commented 1 month ago

Hi!

Thank you for the fast answer. I checked that the Update() function in the LiDAR publisher case is the same in the develop and master branch. I don't know if maybe I'm approaching it wrong...

Furthermore, I tried the project in the develop branch, and is still inconsistent in frequency for both sensors.

RyodoTanaka commented 1 month ago

@alonsollorente

the Update() function in the LiDAR publisher case is the same in the develop.

Yes, you are right. It is still not fixed in develop branch about LiDAR Publisher.

I tried the project in the develop branch, and is still inconsistent in frequency for both sensors.

About this, I need to find the reason why especially for IMU sensors. I think it takes a bit long time to fix. But if someone find the solution, comment it please.