@@ -2178,9 +2178,9 @@ def indiv_calculation(link, link_col, q):
2178
2178
return Ain , bin
2179
2179
2180
2180
# 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 ):
2182
2182
2183
- n = robot .n
2183
+ n = self .n
2184
2184
2185
2185
# allocate intermediate variables
2186
2186
Xup = SE3 .Alloc (n )
@@ -2190,23 +2190,41 @@ def rne(robot, q, qd, qdd, symbolic=False, gravity=None):
2190
2190
a = SpatialAcceleration .Alloc (n )
2191
2191
f = SpatialForce .Alloc (n )
2192
2192
I = SpatialInertia .Alloc (n ) # noqa
2193
- s = [None for i in range (n )] # joint motion subspace
2193
+ s = [] # joint motion subspace
2194
+
2194
2195
if symbolic :
2195
2196
Q = np .empty ((n ,), dtype = "O" ) # joint torque/force
2196
2197
else :
2197
2198
Q = np .empty ((n ,)) # joint torque/force
2198
2199
2200
+ # A temp variable to handle static joints
2201
+ Ts = np .eye (4 )
2202
+
2203
+ # A counter through joints
2204
+ j = 0
2205
+
2199
2206
# 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 )
2204
2223
else :
2205
- Xtree [j ] = SE3 (link .Ts , check = False )
2206
- s [j ] = link .v .s
2224
+ Ts *= SE3 (link .Ts , check = False )
2207
2225
2208
2226
if gravity is None :
2209
- a_grav = - SpatialAcceleration (robot .gravity )
2227
+ a_grav = - SpatialAcceleration (self .gravity )
2210
2228
else :
2211
2229
a_grav = - SpatialAcceleration (gravity )
2212
2230
@@ -2215,13 +2233,13 @@ def rne(robot, q, qd, qdd, symbolic=False, gravity=None):
2215
2233
vJ = SpatialVelocity (s [j ] * qd [j ])
2216
2234
2217
2235
# transform from parent(j) to j
2218
- Xup [j ] = robot [j ].A (q [j ]).inv ()
2236
+ Xup [j ] = self [j ].A (q [j ]).inv ()
2219
2237
2220
- if robot [j ].parent is None :
2238
+ if self [j ].parent is None :
2221
2239
v [j ] = vJ
2222
2240
a [j ] = Xup [j ] * a_grav + SpatialAcceleration (s [j ] * qdd [j ])
2223
2241
else :
2224
- jp = robot [j ].parent .jindex
2242
+ jp = self [j ].parent .jindex
2225
2243
v [j ] = Xup [j ] * v [jp ] + vJ
2226
2244
a [j ] = Xup [j ] * a [jp ] + SpatialAcceleration (s [j ] * qdd [j ]) + v [j ] @ vJ
2227
2245
@@ -2233,8 +2251,8 @@ def rne(robot, q, qd, qdd, symbolic=False, gravity=None):
2233
2251
# next line could be np.dot(), but fails for symbolic arguments
2234
2252
Q [j ] = np .sum (f [j ].A * s [j ])
2235
2253
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
2238
2256
f [jp ] = f [jp ] + Xup [j ] * f [j ]
2239
2257
2240
2258
return Q
0 commit comments