Gazebo | Ignition | Community
Ask Your Question

How to create a link programetically and attach to one of the link in the model?

asked 2018-06-13 08:35:45 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

I am trying following code in model plugin to create and attach a new created link to the model.

void Load(physics::ModelPtr _parent, sdf::ElementPtr _sdf)

    // Store the pointer to the model
    this->model = _parent; 

    this->updateConnection = event::Events::ConnectWorldUpdateBegin(std::bind(&a_link_model::OnUpdate, this));

    hasLinkCreated = false;



if(true == hasLinkCreated)

this->a_link = this->model->CreateLink("link_a");

   ROS_ERROR("Link for %s not found in the world", "link_a");
// something wrong ??

hasLinkCreated = true;

However, the link is not existing in next line. Am I missing some conceptual stuff. I am coding for ODE (and Bullet later). The bool hasLinkCreated is making sure the createlink is attempted only once.

It prints

  ROS_ERROR("Link for %s not found in the world", "point_mass");

I am checking gazebo gui model link list to see if link was created. Please let me know if any more info is needed. This is my first question.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2018-06-15 17:20:30 -0600

From the documentation for CreateLink:

a LinkPtr to the new link created, returns NULL if link _name already exists.

You've said that this is in your OnUpdate function. Perhaps the first time it works, but on subsequent calls it is a duplicate so the function returns null?

edit flag offensive delete link more


Oh I am updating the question if allowed. OnUpdate is updating the link only once conditioned by a bool variable. Also even if it was created once the Gazebo gui should have the link listed, which was not. Thank you for pointing that out.

rick2050 gravatar imagerick2050 ( 2018-06-18 01:04:08 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-06-13 08:35:45 -0600

Seen: 101 times

Last updated: Jun 18 '18