How to use another plugin's variable in my plugin?

such as I make a model plugin, but I need some variables come from sensor plugin. I know topic communication is a pretty good method, but I think there is another way to avoid data serialization and deserialization.
I describe you the background, I want to get contact ploint between two objects though the SensorPlugin,and then, I will create a ModelPlugin to apply force to one of the objects along the normal of the contact point.
Could any people give me some suggestions?

I guess this is about Gazebo classic?

I can’t understand what you mean, I’m a novice about gazebo, could you explain more about Gazebo classic?

There are two major versions of Gazebo: Gazebo (formerly Ignition Gazebo), and Gazebo Classic. Gazebo versions are named like Fortress, Garden (or numbered 6, 7) and the simulator is launched by commands ign gazebo or gz sim. Gazebo Classic versions are 9 or 11 and the simulator is launched by commands gazebo or gzserver.

So which one are you using?

I use Gazebo classic 9 of ros melodic. Maybe I should introduce you my question in another type. How to instantiate another plugin internally, such as instantiating a sensor plugin internally within a model plugin. So I can call some variables of the sensor plugin in the model plugin.

This is not possible.

However, a sensor plugin is not needed. Your model plugin can directly access the contacts information. For inspiration, read around https://github.com/gazebosim/gazebo-classic/blob/3d7e7870c1c361215a23c8a055e35ddd26f34ac6/plugins/SimpleTrackedVehiclePlugin.cc#L206 and create a callback to the BeforePhysicsUpdate event.

Thank you very much for your help!

I succeed to accept your suggestion and achieve my aim, but there is another question about this. when I run my program, unless I open a new terminator and input gz topic -e /gazebo/default/physics/contacts, I cant get the contact data. Do you konw why?

I remember there was some config (probably of the contact manager) telling to generate contacts even if there is no “conaumer” of them…

I figure out it, the following can solve this problem.
this->contactmanager->SetNeverDropContacts(true);

2 Likes