Gazebo | Ignition | Community
Ask Your Question

Applying gazebo plugin up to certain height

asked 2019-09-02 07:40:46 -0500

uchiha_saail gravatar image

updated 2019-09-02 09:34:40 -0500

kumpakri gravatar image

How to modify certain plugin to apply up to certain height in gazebo world?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-09-02 08:14:24 -0500

kumpakri gravatar image

updated 2019-09-06 03:47:05 -0500

Using if statement.

if(height > x)
    do plugin job

You would need to edit the Buoyancy plugin yourself. See the source code here. The method void BuoyancyPlugin::OnUpdate() is called on every step to apply some forces on the model. So if you wrap the whole code inside this function with

if(link->WorldCoGPose().Pos().Z() < height)

the plugin will only take an effect when the model is under this level.

The API method name could differ depending on your Gazebo version which you haven't mention in any of your questions.

EDIT You will create the files and BuoyancyPlugin.hh in some of your packages, modify the said function and build it with your others plugins and packages (using catkin_make perhaps?). Just name it differently so that gazebo knows which plugin you are using.


You put the condition check of the link before the link is defined. Just put the IF after the link variable is filled with a legitimate value.

void BuoyancyPlugin1::OnUpdate()
  for (auto link : this->model->GetLinks())
    if(link->WorldCoGPose().Pos().Z() < 10){ 
        VolumeProperties volumeProperties = this->volPropsMap[link->GetId()];
        double volume = volumeProperties.volume;
        GZ_ASSERT(volume > 0, "Nonpositive volume found in volume properties!");

        // By Archimedes' principle,
        // buoyancy = -(mass*gravity)*fluid_density/object_density
        // object_density = mass/volume, so the mass term cancels.
        // Therefore,
        ignition::math::Vector3d buoyancy =
            -this->fluidDensity * volume * this->model->GetWorld()->Gravity();

        ignition::math::Pose3d linkFrame = link->WorldPose();
        // rotate buoyancy into the link frame before applying the force.
        ignition::math::Vector3d buoyancyLinkFrame =

        link->AddLinkForce(buoyancyLinkFrame, volumeProperties.cov);
edit flag offensive delete link more


I am using ROS Melodic and gazebo 9.0 , so can i call the buoyancy plugin in my custom plugin where i will write if condition so how to call the plugin inside plugin?

uchiha_saail gravatar imageuchiha_saail ( 2019-09-02 09:27:26 -0500 )edit

I have edited the answer. The code should now work for gazebo 9.

kumpakri gravatar imagekumpakri ( 2019-09-02 09:39:32 -0500 )edit

I tried putting the condition as mentioned by you , I am getting following error:

 request for member ‘WorldCoGPose’ in ‘link’, which is of non-class type ‘int(const char*, const char*) throw ()’
  if(link->WorldCoGPose().Pos().Z() < 10){

Also i am not using header file as using header file gives me error during catkin_make

uchiha_saail gravatar imageuchiha_saail ( 2019-09-03 02:27:15 -0500 )edit

Well, you need the header file unless you modify the source file further. the header file includes the needed libraries and declares the class variables. Those are vital for the code function.

Is your code available in a public repository?

kumpakri gravatar imagekumpakri ( 2019-09-03 03:40:00 -0500 )edit

Following is my repo for drag_test package

uchiha_saail gravatar imageuchiha_saail ( 2019-09-04 00:25:59 -0500 )edit

I tried even after adding header files, its giving me the same error as shown above

uchiha_saail gravatar imageuchiha_saail ( 2019-09-05 23:57:12 -0500 )edit

@uchiha_saail viz EDIT 2

kumpakri gravatar imagekumpakri ( 2019-09-06 05:59:37 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2019-09-02 07:40:46 -0500

Seen: 139 times

Last updated: Sep 06 '19