I'm fairly new to SymPy, SciPy, NumPy etc., so perhaps there are easier ways to accomplish my goal, which is to define a sequence of indexed 4x4 transformation matrices for a 4-bar linkage. I don't have any pressing need for the 3rd dimension, except to make it easy to iterate through the sequence {A0 ... A3} in my code.
The code below generates the following error.
TypeError: unorderable types: slice() >= int()
On the other hand, replacing A[:,:,i]
with something like A0
below does generate a 4x4 symbolic array as expected, so perhaps I'm not defining the slice correctly--however, none of the other slice permutations seems to work either. (I'm also having problems with implied line continuation on the last line of code, so I put everything inline.)
I'd appreciate any suggestions on how to solve this issue.
from sympy import *
def plg_jac():
a_3, a_4, d_2, theta_1, theta_4 = symbols('a_3, a_4, d_2, theta_1, theta_4')
# The D-H table is defined by the following 4 vectors
a = Matrix([0, 0, a_3, -a_4])
alpha = Matrix([pi/2, pi/2, 0, 0])
d = Matrix([0, d_2, 0, 0])
theta = Matrix([theta_1, pi, 0, theta_4])
# Initialise a mutable 4x4x4 array
A = tensor.array.MutableDenseNDimArray(range(64), (4,4,4))
# Now define A0 ... A3, the transformation matrices between links i & i+1
for i in range(a.shape[0]):
A[:,:,i] = Array([[cos(theta[i]), -sin(theta[i])*cos(alpha[i]), sin(theta[i])*sin(alpha[i]), a[i]*cos(theta[i])], [sin(theta[i]), cos(theta[i])*cos(alpha[i]), -cos(theta[i])*sin(alpha[i]), a[i]*sin(theta[i])], [0, sin(alpha[i]), cos(alpha[i]), d[i]], [0, 0, 0, 1]])