Skip to content

Commit 65c676f

Browse files
authored
Merge pull request #240 from compas-dev/fix-tool-frame
Two fixes in one
2 parents e011ef2 + ed72dd6 commit 65c676f

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

CHANGELOG.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Unreleased
1717
**Fixed**
1818

1919
* Fixed bug in ``add_attached_tool`` of ``PlanningScene``
20+
* Fixed ``frame_id`` generation when tool name changes
21+
* Fixed freeze with some sync planning scene methods on Grasshopper/IronPython
2022

2123
**Deprecated**
2224

src/compas_fab/backends/ros/service_description.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from __future__ import division
99
from __future__ import print_function
1010

11+
import types
12+
13+
import compas
1114
from roslibpy import Service
1215
from roslibpy import ServiceRequest
1316

@@ -30,6 +33,14 @@ def __init__(self, name, service_type, request_class=None, response_class=None,
3033

3134
def call(self, client, request, callback, errback):
3235
def inner_handler(response_msg):
36+
if not compas.PY3:
37+
# IronPython sometimes decides it's a good idea to use an old-style class
38+
# to pass the response_msg around, so we need to make sure we turn it into
39+
# a proper ServiceResponse again
40+
# https://github.com/compas-dev/compas_fab/issues/235
41+
is_old_style_class = isinstance(response_msg, types.InstanceType)
42+
if is_old_style_class:
43+
response_msg = dict(response_msg)
3344
response_object = self.response_class.from_msg(response_msg)
3445

3546
# Validate the response if there's a validator function assigned
@@ -39,14 +50,12 @@ def inner_handler(response_msg):
3950
except Exception as e:
4051
errback(RosValidationError(e, response_object))
4152
return
42-
4353
callback(response_object)
4454

4555
if isinstance(request, tuple):
4656
request_msg = self.request_class(*request)
4757
else:
4858
request_msg = self.request_class(**request)
49-
5059
srv = Service(client, self.name, self.type)
5160
srv.call(ServiceRequest(request_msg.msg),
5261
callback=inner_handler, errback=errback)

src/compas_fab/robots/tool.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,25 @@ class Tool(object):
3737
def __init__(self, visual, frame_in_tool0_frame, collision=None,
3838
name="attached_tool", link_name=None):
3939
self.tool_model = ToolModel(visual, frame_in_tool0_frame, collision, name, link_name)
40-
self.attached_collision_meshes = self.get_attached_collision_meshes()
4140

4241
@classmethod
4342
def from_tool_model(cls, tool_model):
4443
tool = cls(None, None)
4544
tool.tool_model = tool_model
46-
tool.attached_collision_meshes = tool.get_attached_collision_meshes()
4745
return tool
4846

49-
def get_attached_collision_meshes(self):
50-
tool_attached_collision_meshes = []
47+
@property
48+
def attached_collision_meshes(self):
49+
acms = []
5150
for link in self.tool_model.iter_links():
52-
for item in link.collision:
51+
for i, item in enumerate(link.collision):
5352
meshes = Geometry._get_item_meshes(item)
5453
for mesh in meshes:
55-
collision_mesh = CollisionMesh(item, mesh)
54+
collision_mesh_name = '{}_collision_{}'.format(link.name, i)
55+
collision_mesh = CollisionMesh(mesh, collision_mesh_name)
5656
attached_collision_mesh = AttachedCollisionMesh(collision_mesh, self.link_name, [self.link_name])
57-
tool_attached_collision_meshes.append(attached_collision_mesh)
58-
return tool_attached_collision_meshes
57+
acms.append(attached_collision_mesh)
58+
return acms
5959

6060
@property
6161
def link_name(self):
@@ -89,7 +89,6 @@ def data(self):
8989
@data.setter
9090
def data(self, data):
9191
self.tool_model.data = data
92-
self.attached_collision_meshes = self.get_attached_collision_meshes()
9392

9493
@classmethod
9594
def from_data(cls, data):

0 commit comments

Comments
 (0)