Skip to content

Commit 35dfe23

Browse files
authored
Merge pull request #110 from tetov/allow_skeleton_robot_instances
Fixes and documentation for compas_fab.robots.Robot.basic method
2 parents 097dd72 + fb360b3 commit 35dfe23

File tree

3 files changed

+88
-4
lines changed

3 files changed

+88
-4
lines changed

CHANGELOG.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ Unreleased
1717

1818
**Changed**
1919

20+
* Property :class:`compas_fab.robots.Robot.artist` does not try to scale robot
21+
geometry if links and/or joints are not defined.
22+
2023
**Removed**
2124

2225
**Fixed**

src/compas_fab/robots/robot.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,38 @@ def artist(self):
6464
@artist.setter
6565
def artist(self, artist):
6666
self._artist = artist
67-
self.scale(self._scale_factor)
68-
if self.attached_tool:
69-
self.artist.attach_tool(self.attached_tool)
67+
if len(self.model.joints) > 0 and len(self.model.links) > 0:
68+
self.scale(self._scale_factor)
69+
if self.attached_tool:
70+
self.artist.attach_tool(self.attached_tool)
7071

7172
@classmethod
7273
def basic(cls, name, joints=None, links=None, materials=None, **kwargs):
73-
"""Convenience method to create the most basic instance of a robot, based only on a name.
74+
"""Convenience method to create the most basic instance of a robot,
75+
based only on a name.
7476
7577
Parameters
7678
----------
7779
name : str
7880
Name of the robot
81+
joints : :class:`compas.robots.Joint`, optional
82+
links : :class:`compas.robots.Link`, optional
83+
materials : :class:`compas.robots.Material`, optional
84+
**kwargs
85+
Keyword arguments passed to :class:`compas.robots.RobotModel`
86+
and stored as :attr:`compas.robots.RobotModel.attr`.
87+
Accessible from :attr:`Robot.model.attr`.
7988
8089
Returns
8190
-------
8291
:class:`Robot`
8392
Newly created instance of a robot.
93+
94+
Examples
95+
--------
96+
>>> robot = Robot.basic('A robot')
97+
>>> robot.name
98+
'A robot'
8499
"""
85100
model = RobotModel(name, joints=joints or [], links=links or [],
86101
materials=materials or [], **kwargs)

tests/robots/test_robot.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
import os
3+
4+
import pytest
5+
from compas.robots import RobotModel
6+
7+
from compas_fab.robots import Robot
8+
from compas_fab.robots import RobotSemantics
9+
from compas_fab.robots.ur5 import Robot as Ur5Robot
10+
11+
BASE_FOLDER = os.path.dirname(__file__)
12+
13+
14+
@pytest.fixture
15+
def panda_srdf():
16+
return os.path.join(BASE_FOLDER, 'fixtures', 'panda_semantics.srdf')
17+
18+
19+
@pytest.fixture
20+
def panda_urdf():
21+
return os.path.join(BASE_FOLDER, 'fixtures', 'panda.urdf')
22+
23+
24+
@pytest.fixture
25+
def panda_joints(panda_urdf, panda_srdf):
26+
model = RobotModel.from_urdf_file(panda_urdf)
27+
semantics = RobotSemantics.from_srdf_file(panda_srdf, model)
28+
return semantics.get_configurable_joints()
29+
30+
31+
@pytest.fixture
32+
def ur5_joints():
33+
robot = Ur5Robot()
34+
return robot.model.joints
35+
36+
37+
@pytest.fixture
38+
def ur5_links():
39+
robot = Ur5Robot()
40+
return robot.model.links
41+
42+
43+
def test_basic_name_only():
44+
robot = Robot.basic('testbot')
45+
assert robot.artist is None
46+
47+
48+
def test_basic_name_joints_links(ur5_joints, ur5_links):
49+
robot = Robot.basic('testbot', joints=ur5_joints, links=ur5_links)
50+
assert len(robot.model.links) == 11
51+
assert len(robot.get_configurable_joint_names()) == 6
52+
53+
54+
def test_basic_name_joints(ur5_joints):
55+
robot = Robot.basic('testbot', joints=ur5_joints)
56+
assert len(robot.model.joints) == 10
57+
58+
59+
def test_basic_name_links(ur5_links):
60+
robot = Robot.basic('testbot', links=ur5_links)
61+
assert len(robot.model.links) == 11
62+
63+
64+
def test_basic_attr():
65+
robot = Robot.basic('testbot', location="rfl")
66+
assert robot.model.attr['location'] == "rfl"

0 commit comments

Comments
 (0)