peci1 / gazebo_noisy_depth_camera

Noisy depth camera sensor for Gazebo
2 stars 1 forks source link

Noise has no effect due to wrong depth frame hook order #3

Open Martin-Oehler opened 1 month ago

Martin-Oehler commented 1 month ago

Hi, first of all thank you for this awesome plugin. It is beyond me why Gazebo does not offer any sensible noise model for depth images at all, given their wide-spread use in robotics.

At first, I could not see any change when loading this plugin and I figured out why. In this comment it says https://github.com/peci1/gazebo_noisy_depth_camera/blob/f0205b41d735073c07647d8ea0cc291224104553/src/NoisyDepthCameraSensor.cpp#L78

However, this assumption seems to be wrong (at least in my setup with ROS Noetic, Gazebo 11.11.0).

The NoisyDepthCameraSensor::init() method calls the DepthCameraSensor::Init(); before registering the callback to apply the noise model:https://github.com/peci1/gazebo_noisy_depth_camera/blob/f0205b41d735073c07647d8ea0cc291224104553/src/NoisyDepthCameraSensor.cpp#L56

But that function also calls Sensor::Init() here which in turns loads all the plugins first here.

Therefore, the plugins which publish the depth images are always loaded before registering the noise callback and the noise has no effect.

The only way I came up with to fix this is to basically copy the complete functionality of DepthCameraSensor and register the noise hook before Sensor::Init() (not committed yet, it is somewhat of a mess right now).

Best regards, Martin

peci1 commented 1 month ago

Hi, I'm not at the computer this week. Just a quick idea: do you use this plugin with https://github.com/peci1/gazebo_custom_sensor_preloader ? It won't work without it.

Or at least I think so. It's been some time since I worked on this.

Martin-Oehler commented 1 month ago

Yes, I guess otherwise the custom sensor plugin would not have been loaded at all. I verified that the hook order is the problem by printing the event id of the callback and also by adding prints to the noise callback as well as the depth camera plugin callback.

My changes regarding the ordering of the Sensor::Init() call also fixed the problem. I am just a bit confused how it could have worked previously. Maybe something in the Gazebo implementation changed.