Robotics StackExchange | Archived questions

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

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;

}

OnUpdate()

if(true == hasLinkCreated)
{
    return;
}

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

if(NULL==this->a_link)
{
   ROS_ERROR("Link for %s not found in the world", "link_a");
   return;
// 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.

Asked by rick2050 on 2018-06-13 08:35:45 UTC

Comments

Answers

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?

Asked by kev-the-dev on 2018-06-15 17:20:30 UTC

Comments

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.

Asked by rick2050 on 2018-06-18 01:04:08 UTC