In [2]:
import numpy as np
import matplotlib.pyplot as plt
from sympy import *
In [3]:
init_printing(use_latex=True)
In [4]:
#estos son simbolos especiales que los toma como letras griegas directamente(muuy groso)
theta_1, theta_2, theta_3, L_1, L_2, L_3 = symbols('theta_1, theta_2 theta_3 L_1 L_2 L_3')
In [6]:
#jacobiano simbolico
a11 = -L_1*sin(theta_1) - L_2*sin(theta_1+theta_2) - L_3*sin(theta_1+theta_2+theta_3)
a12 = -L_2*sin(theta_1+theta_2) - L_3*sin(theta_1+theta_2+theta_3)
a13 = -L_3*sin(theta_1+theta_2+theta_3)
a21 = L_1*cos(theta_1) + L_2*cos(theta_1+theta_2) + L_3*cos(theta_1+theta_2+theta_3)
a22 = L_2*cos(theta_1+theta_2) + L_3*cos(theta_1+theta_2+theta_3)
a23 = L_3*cos(theta_1+theta_2+theta_3)
a31 = 1
a32 = 1
a33 = 1
J = Matrix([[a11,a12,a13],[a21,a22,a23],[a31,a32,a33]])
J
Out[6]:
In [7]:
#reemplazando las longitudes de los links
J_real = J.subs([(L_1,4),(L_2,3),(L_3,2)])
J_real
Out[7]:
In [9]:
J_real_inv = J_real.inv()
J_real_inv.simplify()
J_real_inv
Out[9]:
In [10]:
#creamos una funcion numerica a partir de la simbolica
f1 = lambdify((theta_1,theta_2,theta_3),J_real,'numpy')
In [11]:
f1(.3,.2,.2)
Out[11]:
In [12]:
f2 = lambdify((theta_1,theta_2,theta_3),J_real_inv,'numpy')
In [16]:
f2(.1,np.pi/2,1)
Out[16]:
In [ ]: