1
我对SymPy,SciPy,NumPy等相当陌生,所以也许有更简单的方法来实现我的目标,即定义一个索引 4x4变换矩阵一个4杆连杆。除了使我的代码中的序列遍历序列{A ... A }之外,我没有对维度的任何迫切需求。当使用张量数组时,在SymPy中输入错误
下面的代码生成以下错误。
TypeError: unorderable types: slice() >= int()
在另一方面,像A0
更换A[:,:,i]
下方并产生一个4x4的阵列的符号如预期,所以也许我没有正确定义片 - 但是,没有其他的片排列似乎工作。 (我也有与代码的最后一行隐含行延续的问题,所以我把一切都在线。)
我会很感激在如何解决这个问题的任何建议。
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]])
这是完美的;这正是我所需要的。 非常感谢! –