Skip to content

Commit 43c9f3d

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

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

include/gazebo_ros_link_attacher.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* Desc: Gazebo link attacher plugin.
34
* Author: Sammy Pfeiffer ([email protected])
@@ -70,8 +71,12 @@ namespace gazebo
7071
gazebo_ros_link_attacher::Attach::Response &res);
7172
bool detach_callback(gazebo_ros_link_attacher::Attach::Request &req,
7273
gazebo_ros_link_attacher::Attach::Response &res);
74+
void OnUpdate();
7375

7476
std::vector<fixedJoint> joints;
77+
std::vector<fixedJoint> detach_vector;
78+
79+
event::ConnectionPtr beforePhysicsUpdateConnection;
7580

7681
/// \brief The physics engine.
7782
physics::PhysicsEnginePtr physics;
@@ -83,5 +88,4 @@ namespace gazebo
8388

8489
}
8590

86-
#endif
87-
91+
#endif

src/gazebo_ros_link_attacher.cpp

+26-3
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)