我想用Sympy解决简单的2D运动学逆问题。我知道x和y位置的正运动学方程。
x = l1*cos(theta1) + l2*cos(theta1+theta2)
y = l1*sin(theta1) + l2*sin(theta1+theta2)如果我知道theta1和theta2这两个方程,如何用Sympy求解这两个方程?
发布于 2020-03-11 05:59:20
我不认为这些方程有解,但如果有,你可以使用下面的方法:
import sympy as sp
# Define symbols
theta1, theta2, l1, l2, x, y = sp.symbols("theta1 theta2 l1 l2 x y")
# Define equations, rearranged so expressions equal 0
eq1 = l1 * sp.cos(theta1) + l2 * sp.cos(theta1 + theta2) - x
eq2 = l1 * sp.sin(theta1) + l2 * sp.sin(theta1 + theta2) - y
# Solve for theta1 & theta2
solution = sp.solve([eq1, eq2], [theta1, theta2], dict=True)
print(solution)我试图使用渐近非线性解算器来解决类似的逆运动学问题,但注意到docs中的这条注释
目前的非线性求解不能很好地解决具有三角函数的方程组。solve可以用于这样的情况(但不能给出所有的解决方案)
https://stackoverflow.com/questions/55412194
复制相似问题