Skip to content

Commit 2bef5c8

Browse files
committed
Possible fix for #255 and #236
1 parent 2a64350 commit 2bef5c8

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

roboticstoolbox/robot/ERobot.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,9 +2178,9 @@ def indiv_calculation(link, link_col, q):
21782178
return Ain, bin
21792179

21802180
# inverse dynamics (recursive Newton-Euler) using spatial vector notation
2181-
def rne(robot, q, qd, qdd, symbolic=False, gravity=None):
2181+
def rne(self, q, qd, qdd, symbolic=False, gravity=None):
21822182

2183-
n = robot.n
2183+
n = self.n
21842184

21852185
# allocate intermediate variables
21862186
Xup = SE3.Alloc(n)
@@ -2190,23 +2190,41 @@ def rne(robot, q, qd, qdd, symbolic=False, gravity=None):
21902190
a = SpatialAcceleration.Alloc(n)
21912191
f = SpatialForce.Alloc(n)
21922192
I = SpatialInertia.Alloc(n) # noqa
2193-
s = [None for i in range(n)] # joint motion subspace
2193+
s = [] # joint motion subspace
2194+
21942195
if symbolic:
21952196
Q = np.empty((n,), dtype="O") # joint torque/force
21962197
else:
21972198
Q = np.empty((n,)) # joint torque/force
21982199

2200+
# A temp variable to handle static joints
2201+
Ts = np.eye(4)
2202+
2203+
# A counter through joints
2204+
j = 0
2205+
21992206
# initialize intermediate variables
2200-
for j, link in enumerate(robot):
2201-
I[j] = SpatialInertia(m=link.m, r=link.r)
2202-
if symbolic and link.Ts is None:
2203-
Xtree[j] = SE3(np.eye(4, dtype="O"), check=False)
2207+
for link in self.links:
2208+
if link.isjoint:
2209+
I[j] = SpatialInertia(m=link.m, r=link.r)
2210+
if symbolic and link.Ts is None:
2211+
Xtree[j] = SE3(np.eye(4, dtype="O"), check=False)
2212+
else:
2213+
Xtree[j] = Ts * SE3(link.Ts, check=False)
2214+
2215+
if link.v is not None:
2216+
s.append(link.v.s)
2217+
2218+
# Increment the joint counter
2219+
j += 1
2220+
2221+
# Reset the Ts tracker
2222+
Ts = np.eye(4)
22042223
else:
2205-
Xtree[j] = SE3(link.Ts, check=False)
2206-
s[j] = link.v.s
2224+
Ts *= SE3(link.Ts, check=False)
22072225

22082226
if gravity is None:
2209-
a_grav = -SpatialAcceleration(robot.gravity)
2227+
a_grav = -SpatialAcceleration(self.gravity)
22102228
else:
22112229
a_grav = -SpatialAcceleration(gravity)
22122230

@@ -2215,13 +2233,13 @@ def rne(robot, q, qd, qdd, symbolic=False, gravity=None):
22152233
vJ = SpatialVelocity(s[j] * qd[j])
22162234

22172235
# transform from parent(j) to j
2218-
Xup[j] = robot[j].A(q[j]).inv()
2236+
Xup[j] = self[j].A(q[j]).inv()
22192237

2220-
if robot[j].parent is None:
2238+
if self[j].parent is None:
22212239
v[j] = vJ
22222240
a[j] = Xup[j] * a_grav + SpatialAcceleration(s[j] * qdd[j])
22232241
else:
2224-
jp = robot[j].parent.jindex
2242+
jp = self[j].parent.jindex
22252243
v[j] = Xup[j] * v[jp] + vJ
22262244
a[j] = Xup[j] * a[jp] + SpatialAcceleration(s[j] * qdd[j]) + v[j] @ vJ
22272245

@@ -2233,8 +2251,8 @@ def rne(robot, q, qd, qdd, symbolic=False, gravity=None):
22332251
# next line could be np.dot(), but fails for symbolic arguments
22342252
Q[j] = np.sum(f[j].A * s[j])
22352253

2236-
if robot[j].parent is not None:
2237-
jp = robot[j].parent.jindex
2254+
if self[j].parent is not None:
2255+
jp = self[j].parent.jindex
22382256
f[jp] = f[jp] + Xup[j] * f[j]
22392257

22402258
return Q

0 commit comments

Comments
 (0)