Skip to content

Commit dc04dc0

Browse files
committed
Fix setting of hasdynamics attribute for URDF models
1 parent 52c2945 commit dc04dc0

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

roboticstoolbox/robot/Link.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ def _listen_dyn(func):
1515
Use this decorator for any property setter that updates a parameter that
1616
affects the result of inverse dynamics. This allows the C version of the
1717
parameters only having to be updated when they change, rather than on
18-
every call. This decorator signals the change by invoking the
19-
``.dynchanged()`` method of the robot that owns the link.
18+
every call. This decorator signals the change by:
19+
20+
- invoking the ``.dynchanged()`` method of the robot that owns the link.
21+
This assumes that the Link object is owned by a robot, this happens
22+
when the Link object is passed to a robot constructor.
23+
- setting the ``._hasdynamics`` attribute of the Link
2024
2125
Example::
2226
@@ -31,6 +35,7 @@ def m(self, m_new):
3135
def wrapper_listen_dyn(*args):
3236
if args[0]._robot is not None:
3337
args[0]._robot.dynchanged()
38+
args[0]._hasdynamics = True
3439
return func(*args)
3540
return wrapper_listen_dyn
3641

@@ -456,7 +461,11 @@ def hasdynamics(self):
456461
:return: Link has dynamic parameters
457462
:rtype: bool
458463
459-
Link has some assigned (non-default) dynamic parameters.
464+
Link has some assigned (non-default) dynamic parameters. These could
465+
have been assigned:
466+
467+
- at constructor time, eg. ``m=1.2``
468+
- by invoking a setter method, eg. ``link.m = 1.2``
460469
461470
Example:
462471

roboticstoolbox/tools/urdf/urdf.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,10 +636,10 @@ class Inertial(URDFType):
636636
"""
637637
_TAG = 'inertial'
638638

639-
def __init__(self, mass, inertia, origin=None):
640-
self.mass = mass
641-
self.inertia = inertia
642-
self.origin = origin
639+
def __init__(self, mass=None, inertia=None, origin=None):
640+
self._mass = mass
641+
self._inertia = inertia
642+
self._origin = origin
643643

644644
@property
645645
def mass(self):
@@ -1579,7 +1579,7 @@ def inertial(self, value):
15791579
raise TypeError('Expected Inertial object') # pragma nocover
15801580
# Set default inertial
15811581
if value is None:
1582-
value = Inertial(mass=0.0, inertia=np.eye(3))
1582+
value = Inertial()
15831583
self._inertial = value
15841584

15851585
@property
@@ -1696,14 +1696,16 @@ def __init__(self, name, links, joints=None,
16961696

16971697
# build the list of links in URDF file order
16981698
for link in self._links:
1699-
elink = rtb.ELink(name=link.name)
1699+
elink = rtb.ELink(name=link.name,
1700+
m=link.inertial.mass,
1701+
r=link.inertial.origin[:3, 3] if link.inertial.origin is not None else None,
1702+
I=link.inertial.inertia
1703+
)
17001704
elinks.append(elink)
17011705
elinkdict[link.name] = elink
17021706

17031707
# add the inertial parameters
1704-
elink.r = link.inertial.origin[:3, 3]
1705-
elink.m = link.inertial.mass
1706-
elink.inertia = link.inertial.inertia
1708+
17071709

17081710
# add the visuals to visual list
17091711
try:

0 commit comments

Comments
 (0)