Skip to content

Commit 6c20458

Browse files
committed
Merge branch 'master' of https://github.com/compas-dev/compas
2 parents eedf684 + c3e1331 commit 6c20458

File tree

4 files changed

+9
-105
lines changed

4 files changed

+9
-105
lines changed

src/compas/robots/model/geometry.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,35 +48,15 @@ class Origin(Frame):
4848

4949
def __init__(self, point, xaxis, yaxis):
5050
super(Origin, self).__init__(point, xaxis, yaxis)
51-
self.init = None # keep a copy to the initial, not transformed origin
5251

5352
@classmethod
5453
def from_urdf(cls, attributes, elements, text):
5554
xyz = _parse_floats(attributes.get('xyz', '0 0 0'))
5655
rpy = _parse_floats(attributes.get('rpy', '0 0 0'))
5756
return cls.from_euler_angles(rpy, static=True, axes='xyz', point=xyz)
5857

59-
@property
60-
def init_transformation(self):
61-
return Transformation.from_frame(self.init)
62-
63-
def create(self, transformation):
64-
self.transform(transformation)
65-
self.init = self.copy()
66-
67-
def reset_transform(self):
68-
if self.init:
69-
# TODO: Transform back into initial state does not always work...
70-
# T = init_transformation * Transformation.from_frame(self).inverse()
71-
# self.transform(T)
72-
cp = self.init.copy()
73-
self.point = cp.point
74-
self.xaxis = cp.xaxis
75-
self.yaxis = cp.yaxis
76-
7758
def scale(self, factor):
7859
self.point = self.point * factor
79-
self.init = self.copy()
8060

8161

8262
class BaseShape(object):

src/compas/robots/model/joint.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,18 @@ def __init__(self, xyz='0 0 0'):
114114
self.x = xyz[0]
115115
self.y = xyz[1]
116116
self.z = xyz[2]
117-
self.init = None
118117

119118
def copy(self):
120119
cls = type(self)
121120
return cls("%f %f %f" % (self.x, self.y, self.z))
122121

123-
def reset_transform(self):
124-
if self.init:
125-
cp = self.init.copy()
126-
self.x = cp.x
127-
self.y = cp.y
128-
self.z = cp.z
129-
130122
def transform(self, transformation):
131123
xyz = transform_vectors(
132124
[[self.x, self.y, self.z]], transformation.matrix)
133125
self.x = xyz[0][0]
134126
self.y = xyz[0][1]
135127
self.z = xyz[0][2]
136128

137-
def create(self, transformation):
138-
"""Stores the initial direction of the axis.
139-
140-
This is called when the robot is created.
141-
"""
142-
self.transform(transformation)
143-
self.init = self.copy()
144-
145129
@property
146130
def vector(self):
147131
return Vector(self.x, self.y, self.z)
@@ -208,6 +192,8 @@ def __init__(self, name, type, parent, child, origin=None, axis=None, calibratio
208192
self.attr = kwargs
209193
self.child_link = None
210194
self.position = 0
195+
self.init_origin = origin.copy() if origin else None
196+
self.init_axis = axis.copy() if axis else None
211197

212198
switcher = {
213199
Joint.REVOLUTE: self.calculate_revolute_transformation,
@@ -229,16 +215,16 @@ def current_transformation(self):
229215

230216
@property
231217
def init_transformation(self):
232-
if self.origin:
233-
return self.origin.init_transformation.copy()
218+
if self.init_origin:
219+
return Transformation.from_frame(self.init_origin)
234220
else:
235221
return Transformation()
236222

237223
def reset_transform(self):
238-
if self.origin:
239-
self.origin.reset_transform()
240-
if self.axis:
241-
self.axis.reset_transform()
224+
if self.init_origin:
225+
self.origin = self.init_origin.copy()
226+
if self.init_axis:
227+
self.axis = self.init_axis.copy()
242228

243229
def transform(self, transformation):
244230
if self.origin:

src/compas/robots/model/link.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -138,54 +138,6 @@ def __init__(self, name, type=None, visual=[], collision=[], inertial=None, **kw
138138
self.joints = []
139139
self.parent_joint = None
140140

141-
# TODO: Check
142-
def update(self, joint_state, parent_transformation, reset_transformation, collision=True):
143-
"""Recursive function to apply the transformations given by the joint
144-
state.
145-
146-
Joint_states are given absolute, so it is necessary to reset the current
147-
transformation.
148-
149-
Args:
150-
joint_state (dict): A dictionary with the joint names as keys and
151-
values in radians and m (depending on the joint type)
152-
parent_transformation (:class:`Transformation`): The transfomation
153-
of the parent joint
154-
reset_transformation (:class:`Transformation`): The transfomation
155-
to reset the current transformation of the link's geometry.
156-
collision (bool): If collision geometry should be transformed as
157-
well. Defaults to True.
158-
"""
159-
relative_transformation = parent_transformation * reset_transformation
160-
161-
for item in self.visual:
162-
item.geometry.shape.transform(relative_transformation)
163-
164-
if collision:
165-
for item in self.collision:
166-
item.geometry.shape.transform(relative_transformation)
167-
168-
for joint in self.joints:
169-
# 1. Get reset transformation
170-
reset_transformation = joint.calculate_reset_transformation()
171-
# 2. Reset
172-
joint.reset_transform()
173-
# joint.transform(reset_transformation) # why does this not work properly....
174-
175-
# 3. Calculate transformation for next joints in the chain
176-
if joint.name in joint_state.keys():
177-
position = joint_state[joint.name]
178-
transformation = joint.calculate_transformation(position)
179-
transformation = parent_transformation * transformation
180-
joint.position = position
181-
else:
182-
transformation = parent_transformation
183-
184-
# 4. Apply on joint
185-
joint.transform(transformation)
186-
# 4. Apply function to all children in the chain
187-
joint.child_link.update(joint_state, transformation, reset_transformation, collision)
188-
189141
# TODO: Check
190142
def scale(self, factor):
191143
from compas.geometry import Scale

src/compas/robots/model/robot.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -225,21 +225,6 @@ def iter_chain(self, start=None, end=None):
225225
for name in shortest_chain:
226226
yield name
227227

228-
def update(self, names, positions, collision=True):
229-
"""Updates the joints and link geometries.
230-
231-
Args:
232-
names (list of str): a list of the joints names that are updated
233-
positions (list_of float): a list of the respective joint positions,
234-
in radians and m
235-
collision (bool): If collision geometry should be transformed as
236-
well. Defaults to True.
237-
"""
238-
if len(names) != len(positions):
239-
return ValueError("len(names): %d is not len(positions) %d" % (len(names), len(positions)))
240-
joint_state = dict(zip(names, positions))
241-
self.root.update(joint_state, Transformation(), Transformation(), collision)
242-
243228
def get_configurable_joints(self):
244229
joints = self.iter_joints()
245230
return [joint for joint in joints if joint.is_configurable()]
@@ -322,6 +307,7 @@ def axes(self):
322307
axes.append(joint.axis.vector)
323308
return axes
324309

310+
# TODO: Check
325311
def scale(self, factor):
326312
names = self.get_configurable_joint_names()
327313
# bring to init configuration

0 commit comments

Comments
 (0)