Gazebo | Ignition | Community
Ask Your Question
0

Render plugin force for debugging

asked 2021-02-24 18:50:51 -0500

jonesv gravatar image

updated 2021-03-04 16:57:04 -0500

I have a plugin that is applying a force on a link, and I would want that plugin to inject a visual for that force into the link. For instance, say that the link is a box, and my plugin applies a force on the side of the box that makes it translate in the world, I would want my plugin to add an arrow showing that force.

Because I don't know how to make an arrow, for now let's say I just draw a sphere where that force applies. So in my plugin's Load function, I get the model and the SDF:

void MyPlugin::Load(physics::ModelPtr model, sdf::ElementPtr sdf)

I can get the link, say my_link, with model->GetLink("my_link"). And I would like to inject the following visual into it:

  <visual name='test_sphere_visual'>
    <pose>0 0 1</pose>
    <geometry>
      <sphere>
          <radius>0.05</radius>
      </sphere>
    </geometry>
  </visual>

I have been following the "spawn spheres" tutorial, where I successfully manage to create an msgs::Model from a string and inject it into the world. But in this case, instead of injecting a whole new model, I want to inject a visual into an existing link.

Is there a way to do that from a plugin?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2021-04-18 20:09:02 -0500

jonesv gravatar image

The only way I have found is to create a VisualPlugin and send the force as a message to it.

So in the Load() function of my ModelPlugin, I initialize a factory like this:

factory_pub_ = node_handle_->Advertise<msgs::Vector3d>("~/lift_force");

Which I then use to publish the force in the OnUpdate() function:

msgs::Vector3d force_msg;
force_msg.set_x(force.X());
force_msg.set_y(force.Y());
force_msg.set_z(force.Z());
factory_pub_->Publish(force_msg);

The next step is to fetch that value and draw it from the VisualPlugin

edit flag offensive delete link more
0

answered 2021-03-06 02:40:11 -0500

mz gravatar image

updated 2021-03-06 02:40:56 -0500

If there is any contact that's applying the force to the box, you can visualize the contact force by selecting in the menu View > Contacts.

If the force isn't covered by any of the items in the View menu, are you using ROS with Gazebo? If you are, a much easier way that's usually done is to visualize in RViz: http://wiki.ros.org/rviz

All the supported types, including arrows, are listed here http://wiki.ros.org/rviz/DisplayTypes...

Adding a visual dynamically is really not the usual way that this is done.

edit flag offensive delete link more

Comments

Thanks for the answer! It's a lift force coming from a plugin (it's a plane), so I guess that's not considered as a "contact" =). Actually it's exactly this force here: https://github.com/PX4/PX4-SITL_gazeb...: this->link->AddForceAtRelativePosition(force, this->cp);

Should I be able to find it in a ros topic? I would like to visualize the lift on the plane while it's flying, if that's possible at all...

jonesv gravatar imagejonesv ( 2021-04-17 19:18:41 -0500 )edit

I managed to send the force as a Vector3d to a VisualPlugin. Would you have a suggestion to draw the vector? Can a Visual draw a cylinder with a cone for instance (to represent an arrow)? I am trying with DynamicLine, but it feels like it's not the most efficient way...

jonesv gravatar imagejonesv ( 2021-04-18 19:47:01 -0500 )edit

(BTW I cannot upvote your question because I don't have the required karma...). I asked about the VisualPlugin here

jonesv gravatar imagejonesv ( 2021-04-18 20:09:49 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-02-24 18:50:51 -0500

Seen: 248 times

Last updated: Apr 18 '21