Robotics StackExchange | Archived questions

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)

}

Asked by Andrew Symington on 2017-08-03 12:59:24 UTC

Comments

Answers

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.

Asked by chapulina on 2017-08-03 13:23:58 UTC

Comments

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.

Asked by Andrew Symington on 2017-08-03 14:06:20 UTC