Gazebo | Ignition | Community
Ask Your Question

How to locate another model from within a model plugin (find water from boat)

asked 2017-09-08 22:40:15 -0500

tve gravatar image

I'm writing a flotation model plugin to simulate the dynamics of boats. I'm attaching the flotation plugin to the boat models but I need to intersect each boat with the water surface, which is a heightmap (i.e. not flat). The question I have is what is the best way to refer to the model that represents the water? The model plugin for the boat gets a handle onto the boat model to which it is attached. Should the plugin configuration in the boat's SDF specify the name of the water model (e.g. "water" or perhaps "ocean", ...) and then have the plugin find the model by name in the world at initialization time? Or is there a different strategy I should follow?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-09-09 11:22:46 -0500

chapulina gravatar image

From the model plugin attached to the boat you have a pointer to the boat model, let's call it this->boatModel. Then you can get the ocean model like this:

physics::BasePtr parentBase = this->boatModel->GetParent();
physics::WorldPtr world = boost::dynamic_pointer_cast<physics::WorldPtr>(parentBase);
physics::ModelPtr oceanModel = world->GetModel("ocean");
edit flag offensive delete link more


Yup, I realize that, but this hard-codes the name of the ocean model. An step further would be to add an SDF parameter to the boat model that names the ocean model. But the boat model shouldn't really know what the ocean model name is, that relationship should be defined in the world. So my question isn't which gazebo calls to make to get from one to another but how to encode this type of relationship in a generic manner.

tve gravatar imagetve ( 2017-09-09 11:33:20 -0500 )edit

I see, it sounds like the functionality you want should be in a level above the boat and water, since it requires knowledge of both models. How about using a world plugin? Semantically, I think it makes sense, since the relationship between models sounds like something the world should handle.

chapulina gravatar imagechapulina ( 2017-09-09 12:09:05 -0500 )edit

I see. And then pass the world plugin parameters to name the water model and all the boat models? That ought to work, thanks!

tve gravatar imagetve ( 2017-09-09 13:29:33 -0500 )edit

Question Tools

1 follower


Asked: 2017-09-08 22:40:15 -0500

Seen: 363 times

Last updated: Sep 09 '17