Joint created in runtime is not working properly
Hello everyone!
I recently had a problem where I needed to edit a robot in runtime, adding new joints and links to it. After asking this question in this thread the way to go was to create a new Model and attach both models, which is working. However, whenever a link is attached to a different model, I end up loosing the last link in that model, so it was needed to recreate it everytime an attachment was made. The problem here is that this is giving me some overhead, so in order to get a better performance I tried the previous thread suggestion like this:
std::string modelNameStr( parentModelName );
gazebo::physics::ModelPtr model = GetModelPtr(modelNameStr);
gazebo::physics::LinkPtr model1Link = model->GetLink("Rope_Segment_2");
LOGGER.Write(Log::INFO,"Model jointCount : %d \n", model->GetJointCount() );
gazebo::physics::ModelPtr model2 = GetModelPtr("Bola");
gazebo::physics::LinkPtr model2Link = model2->GetLink("Link0");
newJoint = world->GetPhysicsEngine()->CreateJoint( "revolute", model );
newJoint->SetName("Joint3");
newJoint->SetModel( model );
newJoint->Load(model1Link, model2Link, model2Link->GetWorldPose() );
newJoint->Attach(model1Link, model2Link);
newJoint->SetAxis(0, gazebo::math::Vector3(0.0f,1.0f,0.0f) );
newJoint->SetLowerLimit( 0, gazebo::math::Angle( 0.0f ) );
newJoint->SetUpperLimit( 0, gazebo::math::Angle( 0.2f ) );
LOGGER.Write(Log::INFO,"Model jointCount : %d \n", model->GetJointCount() );
if( model->GetJoint("Joint3") == NULL )
LOGGER.Write(Log::INFO,"Model GetJoint : FALSE \n" );
else
LOGGER.Write(Log::INFO,"Model GetJoint : OK \n" );
And the result is that both Logger.Write gives me the same number and the last If also returns FALSE. In the other hand, if I keep the reference to this newly created Joint Im still able to access it and make it work like a normal joint would. So for me it seems that this new Joint is created somewhere but its just not being added to the joint list or something like it.
Anyone know what am I doing wrong?
Thanks!
Asked by Trmotta on 2015-01-16 11:27:09 UTC
Answers
Hi,
there is an issue report on this here. When joints are created dynamically the Joints vector doesn't get updated in Gazebo, that's the reason you cannot visualise the new joints or in your case to get the correct size of the list.
Cheers, Andrei
Asked by AndreiHaidu on 2015-01-17 15:01:51 UTC
Comments
Thank you once again, Andrei. Ill be hoping for it to be fixed by the end of the month with the new release of Gazebo 5.0.
Asked by Trmotta on 2015-01-19 08:07:35 UTC
Comments