Skip to content

Commit 1447797

Browse files
author
yizhenzhang
committed
add pull requests from pal-robotics/gazebo_ros_link_attacher
pal-robotics#11
1 parent be9ed40 commit 1447797

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

include/gazebo_ros_link_attacher.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
/*
2-
* Desc: Gazebo link attacher plugin.
3-
* Author: Sammy Pfeiffer ([email protected])
4-
* Date: 05/04/2016
5-
*/
61

2+
/*...
73
#ifndef GAZEBO_ROS_LINK_ATTACHER_HH
84
#define GAZEBO_ROS_LINK_ATTACHER_HH
95
@@ -70,8 +66,12 @@ namespace gazebo
7066
gazebo_ros_link_attacher::Attach::Response &res);
7167
bool detach_callback(gazebo_ros_link_attacher::Attach::Request &req,
7268
gazebo_ros_link_attacher::Attach::Response &res);
69+
void OnUpdate();
7370

7471
std::vector<fixedJoint> joints;
72+
std::vector<fixedJoint> detach_vector;
73+
74+
event::ConnectionPtr beforePhysicsUpdateConnection;
7575

7676
/// \brief The physics engine.
7777
physics::PhysicsEnginePtr physics;
@@ -84,4 +84,3 @@ namespace gazebo
8484
}
8585

8686
#endif
87-

src/gazebo_ros_link_attacher.cpp

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace gazebo
1515
GazeboRosLinkAttacher::GazeboRosLinkAttacher() :
1616
nh_("link_attacher_node")
1717
{
18+
std::vector<fixedJoint> vect;
19+
this->detach_vector = vect;
20+
this->beforePhysicsUpdateConnection = event::Events::ConnectBeforePhysicsUpdate(std::bind(&GazeboRosLinkAttacher::OnUpdate, this));
1821
}
1922

2023

@@ -126,7 +129,6 @@ namespace gazebo
126129
failed in void gazebo::physics::Entity::PublishPose():
127130
/tmp/buildd/gazebo2-2.2.3/gazebo/physics/Entity.cc(225):
128131
An entity without a parent model should not happen
129-
130132
* If SetModel is given the same model than CreateJoint given
131133
* Gazebo crashes with
132134
* ***** Internal Program Error - assertion (self->inertial != __null)
@@ -151,7 +153,8 @@ namespace gazebo
151153
// search for the instance of joint and do detach
152154
fixedJoint j;
153155
if(this->getJoint(model1, link1, model2, link2, j)){
154-
j.joint->Detach();
156+
this->detach_vector.push_back(j);
157+
ROS_INFO_STREAM("Detach joint request pushed in the detach vector");
155158
return true;
156159
}
157160

@@ -210,4 +213,24 @@ namespace gazebo
210213
return true;
211214
}
212215

213-
}
216+
// thanks to https://answers.gazebosim.org/question/12118/intermittent-segmentation-fault-possibly-by-custom-worldplugin-attaching-and-detaching-child/?answer=24271#post-id-24271
217+
void GazeboRosLinkAttacher::OnUpdate()
218+
{
219+
if(!this->detach_vector.empty())
220+
{
221+
ROS_INFO_STREAM("Received before physics update callback... Detaching joints");
222+
std::vector<fixedJoint>::iterator it;
223+
it = this->detach_vector.begin();
224+
fixedJoint j;
225+
while (it != this->detach_vector.end())
226+
{
227+
j = *it;
228+
j.joint->Detach();
229+
ROS_INFO_STREAM("Joint detached !");
230+
++it;
231+
}
232+
detach_vector.clear();
233+
}
234+
}
235+
236+
}

0 commit comments

Comments
 (0)