Skip to content

Commit 682ced2

Browse files
authored
Merge pull request #805 from compas-dev/cfg_import
Fix missing import on RobotModel
2 parents 836c109 + 5dd4959 commit 682ced2

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
* Fixed box scaling.
2323
* Fixed a bug in `Polyline.divide_polyline_by_length` related to a floating point rounding error.
24+
* Fixed bug in `RobotModel.zero_configuration`.
2425

2526
### Removed
2627

src/compas/robots/configuration.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
from math import pi
66

77
from compas.base import Base
8-
from compas.robots.model.joint import Joint
98

109
__all__ = [
1110
'Configuration',
1211
'FixedLengthList',
1312
]
1413

14+
# These joint types known to configuration are a match
15+
# to the ones defined in `Joint` class, but we redefine here
16+
# to avoid a circular dependency
17+
_JOINT_REVOLUTE = 0
18+
_JOINT_CONTINUOUS = 1
19+
_JOINT_PRISMATIC = 2
20+
_JOINT_PLANAR = 5
21+
1522

1623
def joint_names_validator(joint_names, key=None, value=None):
1724
new_joint_names = list(joint_names)
@@ -266,7 +273,7 @@ def from_revolute_values(cls, values, joint_names=None):
266273
"""
267274
values = list(values)
268275
joint_names = list(joint_names or [])
269-
return cls.from_data({'joint_values': values, 'joint_types': [Joint.REVOLUTE] * len(values), 'joint_names': joint_names})
276+
return cls.from_data({'joint_values': values, 'joint_types': [_JOINT_REVOLUTE] * len(values), 'joint_names': joint_names})
270277

271278
@classmethod
272279
def from_prismatic_and_revolute_values(cls, prismatic_values, revolute_values, joint_names=None):
@@ -291,8 +298,8 @@ def from_prismatic_and_revolute_values(cls, prismatic_values, revolute_values, j
291298
revolute_values = list(revolute_values)
292299
joint_names = list(joint_names or [])
293300
values = prismatic_values + revolute_values
294-
joint_types = [Joint.PRISMATIC] * \
295-
len(prismatic_values) + [Joint.REVOLUTE] * len(revolute_values)
301+
joint_types = [_JOINT_PRISMATIC] * \
302+
len(prismatic_values) + [_JOINT_REVOLUTE] * len(revolute_values)
296303
return cls.from_data({'joint_values': values, 'joint_types': joint_types, 'joint_names': joint_names})
297304

298305
@classmethod
@@ -353,12 +360,12 @@ def prismatic_values(self):
353360
354361
E.g. positions on the external axis system.
355362
"""
356-
return [v for i, v in enumerate(self.joint_values) if self.joint_types[i] == Joint.PRISMATIC]
363+
return [v for i, v in enumerate(self.joint_values) if self.joint_types[i] == _JOINT_PRISMATIC]
357364

358365
@property
359366
def revolute_values(self):
360367
""":obj:`list` of :obj:`float` : Revolute joint values in radians."""
361-
return [v for i, v in enumerate(self.joint_values) if self.joint_types[i] == Joint.REVOLUTE]
368+
return [v for i, v in enumerate(self.joint_values) if self.joint_types[i] == _JOINT_REVOLUTE]
362369

363370
def copy(self):
364371
"""Create a copy of this :class:`Configuration`.
@@ -388,7 +395,7 @@ def scale(self, scale_factor):
388395
values_scaled = []
389396

390397
for value, joint_type in zip(self.joint_values, self.joint_types):
391-
if joint_type in (Joint.PLANAR, Joint.PRISMATIC):
398+
if joint_type in (_JOINT_PLANAR, _JOINT_PRISMATIC):
392399
value *= scale_factor
393400
values_scaled.append(value)
394401

@@ -457,7 +464,7 @@ def iter_differences(self, other):
457464

458465
for i, (v1, v2) in enumerate(value_pairs):
459466
diff = v1 - v2
460-
if self.joint_types[i] in [Joint.REVOLUTE, Joint.CONTINUOUS]:
467+
if self.joint_types[i] in [_JOINT_REVOLUTE, _JOINT_CONTINUOUS]:
461468
d1 = diff % (2 * pi)
462469
d1 = d1 if diff >= 0 else d1 - 2*pi
463470
d2 = d1 - 2*pi if diff >= 0 else d1 + 2*pi

src/compas/robots/model/robot.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,19 @@
99
from compas.base import Base
1010
from compas.datastructures import Mesh
1111
from compas.files import URDF
12-
from compas.files import URDFParser
1312
from compas.files import URDFElement
13+
from compas.files import URDFParser
1414
from compas.geometry import Frame
1515
from compas.geometry import Transformation
16+
from compas.robots import Configuration
1617
from compas.robots.model.geometry import Color
1718
from compas.robots.model.geometry import Geometry
1819
from compas.robots.model.geometry import Material
1920
from compas.robots.model.geometry import MeshDescriptor
2021
from compas.robots.model.geometry import Origin
2122
from compas.robots.model.geometry import Texture
22-
from compas.robots.model.geometry import _attr_to_data
2323
from compas.robots.model.geometry import _attr_from_data
24+
from compas.robots.model.geometry import _attr_to_data
2425
from compas.robots.model.joint import Axis
2526
from compas.robots.model.joint import Joint
2627
from compas.robots.model.joint import Limit
@@ -30,7 +31,6 @@
3031
from compas.robots.resources import DefaultMeshLoader
3132
from compas.topology import shortest_path
3233

33-
3434
__all__ = ['RobotModel']
3535

3636

@@ -1085,21 +1085,3 @@ def remove_joint(self, name):
10851085
URDFParser.install_parser(Material, 'robot/material')
10861086
URDFParser.install_parser(Color, 'robot/material/color')
10871087
URDFParser.install_parser(Texture, 'robot/material/texture')
1088-
1089-
1090-
if __name__ == '__main__':
1091-
import os
1092-
import doctest
1093-
from compas import HERE
1094-
from compas.geometry import Sphere # noqa: F401
1095-
from compas.robots import GithubPackageMeshLoader, Configuration # noqa: F401
1096-
1097-
ur5_urdf_file = os.path.join(HERE, '..', '..', 'tests', 'compas', 'robots', 'fixtures', 'ur5.xacro')
1098-
1099-
robot = RobotModel("robot", links=[], joints=[])
1100-
link0 = robot.add_link("world")
1101-
link1 = robot.add_link("link1")
1102-
link2 = robot.add_link("link2")
1103-
robot.add_joint("joint1", Joint.CONTINUOUS, link0, link1, Frame.worldXY(), (0, 0, 1))
1104-
robot.add_joint("joint2", Joint.CONTINUOUS, link1, link2, Frame.worldXY(), (0, 0, 1))
1105-
doctest.testmod(globs=globals())

tests/compas/robots/test_model.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import re
21
import os
2+
import re
33

44
import pytest
55

@@ -126,6 +126,12 @@ def test_ur5_urdf(ur5_file):
126126
assert len(list(filter(lambda i: i.type == Joint.REVOLUTE, r.joints))) == 6
127127

128128

129+
def test_zero_configuration(ur5_file):
130+
r = RobotModel.from_urdf_file(ur5_file)
131+
assert r.zero_configuration().joint_values == [0.0] * 6
132+
assert len(list(filter(lambda i: i.type == Joint.REVOLUTE, r.joints))) == 6
133+
134+
129135
def test_ur5_urdf_to_string(ur5_file):
130136
r_original = RobotModel.from_urdf_file(ur5_file)
131137
urdf = URDF.from_robot(r_original)
@@ -625,8 +631,9 @@ def test_ensure_geometry(urdf_file, urdf_file_with_shapes_only):
625631
import os
626632
from zipfile import ZipFile
627633
try:
628-
from StringIO import StringIO as ReaderIO
629634
from urllib import urlopen
635+
636+
from StringIO import StringIO as ReaderIO
630637
except ImportError:
631638
from io import BytesIO as ReaderIO
632639
from urllib.request import urlopen

0 commit comments

Comments
 (0)