How to locate another model from within a model plugin (find water from boat)
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?
Asked by tve on 2017-09-08 22:40:15 UTC
Answers
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");
Asked by chapulina on 2017-09-09 11:22:46 UTC
Comments
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.
Asked by tve on 2017-09-09 11:33:20 UTC
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.
Asked by chapulina on 2017-09-09 12:09:05 UTC
I see. And then pass the world plugin parameters to name the water model and all the boat models? That ought to work, thanks!
Asked by tve on 2017-09-09 13:29:33 UTC
Comments