Home | Tutorials | Wiki | Issues
Ask Your Question

How to get a ModelPtr from a VisualPlugin

asked 2017-08-03 12:59:24 -0500

Andrew Symington gravatar image

updated 2017-08-03 13:00:13 -0500

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 {
  GazeboVisualPluginOptions() {}
  virtual ~GazeboVisualPluginOptions() {}

  // 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

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2017-08-03 13:23:58 -0500

Visual plugins run in the rendering thread, while physics::Models are in the physics thread.

When running Gazebo, if you have cameras, you'll have 2 rendering threads, one in the gzserver process and another on the gzclient process.

The rendering thread which runs in the server, in theory could use the ignition::physics::get_world call to get the physics::WorldPtr and then you can use World::GetModel to get the model pointer.

If all you're interested in is the model pose though, I would recommend not mixing rendering and physics and instead either subscribing to the ROS transform within your visual plugin, or subscribing to the Gazebo topic ~/pose/local/info.

edit flag offensive delete link more


Thanks! I see the constraint now. The solution I am currently using is a ModelPlugin that uses the gazebo transport to send a visual message to ~/visual, which toggles the transparency. However, this has two limitations: (1) I would also like to configure the visual to not be seen by camera sensors, but I don't believe SetVisibilityFlags(...) is supported by msgs::Visual, and (2) the way URDF bundles links joined by fixed joints together makes Visual names awful to lookup.

Andrew Symington gravatar imageAndrew Symington ( 2017-08-03 14:06:20 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-08-03 12:59:24 -0500

Seen: 36 times

Last updated: Aug 03