How to get a ModelPtr from a VisualPlugin
Let's assume I have a model with a 'body' base link that connected to some link 'link1' through a fixed joint. Now I attach a visual to 'link1' with an associated VisualPlugin. Let's say that I want to adjust the pose of this visual by listening to a transform coming form ROS, but the transform itself is prefixed by the model name, which by convention matches the name of the gazebo model to which the link is attached.
More specifically for the code snippet below, how do I extract a ModelPtr for the base link to which the Visual is attached, using only the VisualPtr being passed into the Load(...) callback.
// Gazbeo includes
#include <gazebo/common/common.hh>
#include <gazebo/physics/physics.hh>
#include <gazebo/rendering/rendering.hh>
namespace gazebo {
class GazeboVisualPluginOptions : public VisualPlugin {
public:
GazeboVisualPluginOptions() {}
virtual ~GazeboVisualPluginOptions() {}
protected:
// Called when the plugin is loaded into the simulator
void Load(rendering::VisualPtr visual, sdf::ElementPtr sdf) {
physics::ModelPtr model = ???
}
};
// Register this plugin with the simulator
GZ_REGISTER_VISUAL_PLUGIN(GazeboVisualPluginOptions)
}