Exemplo n.º 1
0
 def test_non_method_jacobian(self):
     # Jacobian([x * cos(y), x * sin(y), x ** 2], [x, y]) returns
     # the following 3x2 matrix:
     #
     #  = |cos(y)   -x * sin(y)|
     #    |sin(y)    x * cos(y)|
     #    | 2 * x             0|
     J = sym.Jacobian([x * sym.cos(y), x * sym.sin(y), x ** 2], [x, y])
     self._check_scalar(J[0, 0], sym.cos(y))
     self._check_scalar(J[1, 0], sym.sin(y))
     self._check_scalar(J[2, 0], 2 * x)
     self._check_scalar(J[0, 1], - x * sym.sin(y))
     self._check_scalar(J[1, 1], x * sym.cos(y))
     self._check_scalar(J[2, 1], 0)
Exemplo n.º 2
0
 def test_non_method_jacobian(self):
     # Jacobian([x * cos(y), x * sin(y), x ** 2], [x, y]) returns
     # the following 3x2 matrix:
     #
     #  = |cos(y)   -x * sin(y)|
     #    |sin(y)    x * cos(y)|
     #    | 2 * x             0|
     J = sym.Jacobian([x * sym.cos(y), x * sym.sin(y), x ** 2], [x, y])
     npc.assert_equal(J[0, 0], sym.cos(y))
     npc.assert_equal(J[1, 0], sym.sin(y))
     npc.assert_equal(J[2, 0], 2 * x)
     npc.assert_equal(J[0, 1], - x * sym.sin(y))
     npc.assert_equal(J[1, 1], x * sym.cos(y))
     npc.assert_equal(J[2, 1], sym.Expression(0))
Exemplo n.º 3
0
 def test_functions_with_float(self):
     # TODO(eric.cousineau): Use concrete values once vectorized methods are
     # supported.
     v_x = 1.0
     v_y = 1.0
     self.assertEqualStructure(sym.abs(v_x), np.abs(v_x))
     self.assertNotEqualStructure(sym.abs(v_x), 0.5*np.abs(v_x))
     self._check_scalar(sym.abs(v_x), np.abs(v_x))
     self._check_scalar(sym.abs(v_x), np.abs(v_x))
     self._check_scalar(sym.exp(v_x), np.exp(v_x))
     self._check_scalar(sym.sqrt(v_x), np.sqrt(v_x))
     self._check_scalar(sym.pow(v_x, v_y), v_x ** v_y)
     self._check_scalar(sym.sin(v_x), np.sin(v_x))
     self._check_scalar(sym.cos(v_x), np.cos(v_x))
     self._check_scalar(sym.tan(v_x), np.tan(v_x))
     self._check_scalar(sym.asin(v_x), np.arcsin(v_x))
     self._check_scalar(sym.acos(v_x), np.arccos(v_x))
     self._check_scalar(sym.atan(v_x), np.arctan(v_x))
     self._check_scalar(sym.atan2(v_x, v_y), np.arctan2(v_x, v_y))
     self._check_scalar(sym.sinh(v_x), np.sinh(v_x))
     self._check_scalar(sym.cosh(v_x), np.cosh(v_x))
     self._check_scalar(sym.tanh(v_x), np.tanh(v_x))
     self._check_scalar(sym.min(v_x, v_y), min(v_x, v_y))
     self._check_scalar(sym.max(v_x, v_y), max(v_x, v_y))
     self._check_scalar(sym.ceil(v_x), np.ceil(v_x))
     self._check_scalar(sym.floor(v_x), np.floor(v_x))
     self._check_scalar(
         sym.if_then_else(
             sym.Expression(v_x) > sym.Expression(v_y),
             v_x, v_y),
         v_x if v_x > v_y else v_y)
Exemplo n.º 4
0
 def test_functions_with_variable(self):
     self.assertEqual(str(sym.abs(x)), "abs(x)")
     self.assertEqual(str(sym.exp(x)), "exp(x)")
     self.assertEqual(str(sym.sqrt(x)), "sqrt(x)")
     self.assertEqual(str(sym.pow(x, y)), "pow(x, y)")
     self.assertEqual(str(sym.sin(x)), "sin(x)")
     self.assertEqual(str(sym.cos(x)), "cos(x)")
     self.assertEqual(str(sym.tan(x)), "tan(x)")
     self.assertEqual(str(sym.asin(x)), "asin(x)")
     self.assertEqual(str(sym.acos(x)), "acos(x)")
     self.assertEqual(str(sym.atan(x)), "atan(x)")
     self.assertEqual(str(sym.atan2(x, y)), "atan2(x, y)")
     self.assertEqual(str(sym.sinh(x)), "sinh(x)")
     self.assertEqual(str(sym.cosh(x)), "cosh(x)")
     self.assertEqual(str(sym.tanh(x)), "tanh(x)")
     self.assertEqual(str(sym.min(x, y)), "min(x, y)")
     self.assertEqual(str(sym.max(x, y)), "max(x, y)")
     self.assertEqual(str(sym.ceil(x)), "ceil(x)")
     self.assertEqual(str(sym.floor(x)), "floor(x)")
     self.assertEqual(str(sym.if_then_else(x > y, x, y)),
                      "(if (x > y) then x else y)")
Exemplo n.º 5
0
 def test_functions_with_variable(self):
     numpy_compare.assert_equal(sym.abs(x), "abs(x)")
     numpy_compare.assert_equal(sym.exp(x), "exp(x)")
     numpy_compare.assert_equal(sym.sqrt(x), "sqrt(x)")
     numpy_compare.assert_equal(sym.pow(x, y), "pow(x, y)")
     numpy_compare.assert_equal(sym.sin(x), "sin(x)")
     numpy_compare.assert_equal(sym.cos(x), "cos(x)")
     numpy_compare.assert_equal(sym.tan(x), "tan(x)")
     numpy_compare.assert_equal(sym.asin(x), "asin(x)")
     numpy_compare.assert_equal(sym.acos(x), "acos(x)")
     numpy_compare.assert_equal(sym.atan(x), "atan(x)")
     numpy_compare.assert_equal(sym.atan2(x, y), "atan2(x, y)")
     numpy_compare.assert_equal(sym.sinh(x), "sinh(x)")
     numpy_compare.assert_equal(sym.cosh(x), "cosh(x)")
     numpy_compare.assert_equal(sym.tanh(x), "tanh(x)")
     numpy_compare.assert_equal(sym.min(x, y), "min(x, y)")
     numpy_compare.assert_equal(sym.max(x, y), "max(x, y)")
     numpy_compare.assert_equal(sym.ceil(x), "ceil(x)")
     numpy_compare.assert_equal(sym.floor(x), "floor(x)")
     numpy_compare.assert_equal(sym.if_then_else(x > y, x, y),
                                "(if (x > y) then x else y)")
Exemplo n.º 6
0
 def test_functions_with_expression(self):
     self.assertEqual(str(sym.abs(e_x)), "abs(x)")
     self.assertEqual(str(sym.exp(e_x)), "exp(x)")
     self.assertEqual(str(sym.sqrt(e_x)), "sqrt(x)")
     self.assertEqual(str(sym.pow(e_x, e_y)), "pow(x, y)")
     self.assertEqual(str(sym.sin(e_x)), "sin(x)")
     self.assertEqual(str(sym.cos(e_x)), "cos(x)")
     self.assertEqual(str(sym.tan(e_x)), "tan(x)")
     self.assertEqual(str(sym.asin(e_x)), "asin(x)")
     self.assertEqual(str(sym.acos(e_x)), "acos(x)")
     self.assertEqual(str(sym.atan(e_x)), "atan(x)")
     self.assertEqual(str(sym.atan2(e_x, e_y)), "atan2(x, y)")
     self.assertEqual(str(sym.sinh(e_x)), "sinh(x)")
     self.assertEqual(str(sym.cosh(e_x)), "cosh(x)")
     self.assertEqual(str(sym.tanh(e_x)), "tanh(x)")
     self.assertEqual(str(sym.min(e_x, e_y)), "min(x, y)")
     self.assertEqual(str(sym.max(e_x, e_y)), "max(x, y)")
     self.assertEqual(str(sym.ceil(e_x)), "ceil(x)")
     self.assertEqual(str(sym.floor(e_x)), "floor(x)")
     self.assertEqual(str(sym.if_then_else(e_x > e_y, e_x, e_y)),
                      "(if (x > y) then x else y)")
Exemplo n.º 7
0
 def test_functions_with_float(self):
     # TODO(eric.cousineau): Use concrete values once vectorized methods are
     # supported.
     v_x = 1.0
     v_y = 1.0
     # WARNING: If these math functions have `float` overloads that return
     # `float`, then `assertEqual`-like tests are meaningful (current state,
     # and before `math` overloads were introduced).
     # If these math functions implicitly cast `float` to `Expression`, then
     # `assertEqual` tests are meaningless, as it tests `__nonzero__` for
     # `Formula`, which will always be True.
     self.assertEqual(sym.abs(v_x), 0.5*np.abs(v_x))
     self.assertNotEqual(str(sym.abs(v_x)), str(0.5*np.abs(v_x)))
     self._check_scalar(sym.abs(v_x), np.abs(v_x))
     self._check_scalar(sym.abs(v_x), np.abs(v_x))
     self._check_scalar(sym.exp(v_x), np.exp(v_x))
     self._check_scalar(sym.sqrt(v_x), np.sqrt(v_x))
     self._check_scalar(sym.pow(v_x, v_y), v_x ** v_y)
     self._check_scalar(sym.sin(v_x), np.sin(v_x))
     self._check_scalar(sym.cos(v_x), np.cos(v_x))
     self._check_scalar(sym.tan(v_x), np.tan(v_x))
     self._check_scalar(sym.asin(v_x), np.arcsin(v_x))
     self._check_scalar(sym.acos(v_x), np.arccos(v_x))
     self._check_scalar(sym.atan(v_x), np.arctan(v_x))
     self._check_scalar(sym.atan2(v_x, v_y), np.arctan2(v_x, v_y))
     self._check_scalar(sym.sinh(v_x), np.sinh(v_x))
     self._check_scalar(sym.cosh(v_x), np.cosh(v_x))
     self._check_scalar(sym.tanh(v_x), np.tanh(v_x))
     self._check_scalar(sym.min(v_x, v_y), min(v_x, v_y))
     self._check_scalar(sym.max(v_x, v_y), max(v_x, v_y))
     self._check_scalar(sym.ceil(v_x), np.ceil(v_x))
     self._check_scalar(sym.floor(v_x), np.floor(v_x))
     self._check_scalar(
       sym.if_then_else(
         sym.Expression(v_x) > sym.Expression(v_y),
         v_x, v_y),
       v_x if v_x > v_y else v_y)
Exemplo n.º 8
0
 def test_method_jacobian(self):
     # (x * cos(y)).Jacobian([x, y]) returns [cos(y), -x * sin(y)].
     J = (x * sym.cos(y)).Jacobian([x, y])
     npc.assert_equal(J[0], sym.cos(y))
     npc.assert_equal(J[1], -x * sym.sin(y))
Exemplo n.º 9
0
a=1 # The half of the length of the vertical side
b=1 # The half the length of the horizonatl side
# Dynamics:
mysystem.C=np.zeros((3,3))
g=9.8
mysystem.tau_g=np.array([0,-g,0])
mysystem.B=np.zeros((3,0))

# Mass Matrix
M=1
I=M/3.0*a**2
mysystem.M=blk(*[M,M,I])
mysystem.M_inv=np.linalg.inv(mysystem.M)

# Contact Point 1: The ground with left corner
phi_1= y - a * sym.cos(theta) - b * sym.sin(theta)
psi_1= - (x + a * sym.sin(theta) - b * sym.cos(theta) )
J_1n=np.array([0,1,-b*sym.cos(theta)-a*sym.sin(theta)]).reshape(3,1)
J_1t=np.array([1,0,a*sym.cos(theta)+b*sym.sin(theta)]).reshape(3,1)
J_1=np.hstack((J_1n,J_1t))
C1=contact_point_symbolic_2D(mysystem,phi=phi_1,psi=psi_1,J=J_1,friction=0.9,name="contact point")
#C1.sliding=False
#C1.sticking=False
C1.no_contact=False


# Contact Point 2: The ground with right corner
phi_2= y - a * sym.cos(theta) + b * sym.sin(theta)
psi_2= - ( x + a * sym.sin(theta) + b * sym.cos(theta) )
J_2n=np.array([0,1,b*sym.cos(theta)-a*sym.sin(theta)]).reshape(3,1)
J_2t=np.array([1,0,a*sym.cos(theta)-b*sym.sin(theta)]).reshape(3,1)
Exemplo n.º 10
0
 def test_method_jacobian(self):
     # (x * cos(y)).Jacobian([x, y]) returns [cos(y), -x * sin(y)].
     J = (x * sym.cos(y)).Jacobian([x, y])
     self.assertEqual(J[0], sym.cos(y))
     self.assertEqual(J[1], -x * sym.sin(y))
Exemplo n.º 11
0
def Rotate(t):
    return np.array([[sym.cos(t), -sym.sin(t)], [sym.sin(t), sym.cos(t)]])
Exemplo n.º 12
0
R = 1  # The radius of the carrot
p = 4 * R / (3 * np.pi)
# Dynamics:
mysystem.C = np.zeros((3, 3))
g = 9.8
mysystem.tau_g = np.array([0, -g, 0])
mysystem.B = np.zeros((3, 0))

# Mass Matrix
M = 1
I = M * R**2 * (1 / 2.0 - 16 / (9 * np.pi**2))
h = 0.05
mysystem.M = blk(*[M, M, I])
mysystem.M_inv = np.linalg.inv(mysystem.M)

x_c = x - p * sym.sin(theta)
y_c = y + p * sym.cos(theta)

x_R = x_c + R * sym.sin(theta_m)
y_R = y_c - R * sym.cos(theta_m)
"""
Ground
"""
phi_1 = y_c - R
psi_1 = -R * theta - x_c
J_1n = np.array([0, 1, -p * sym.sin(theta)]).reshape(3, 1)
J_1t = np.array([1, 0, R - p * sym.cos(theta)]).reshape(3, 1)
J_1 = np.hstack((J_1n, J_1t))
C1 = contact_point_symbolic_2D(mysystem,
                               phi=phi_1,
                               psi=psi_1,
Exemplo n.º 13
0
    def __init__(self, M1=1., I1=1., M2=10., I2=10., r1=0.5, r2=0.4, KL=1e3, KL2=1e5, BL2=125, KG=1e4, BG=75, k0=1., \
                 g=9.8, ground_height_function=lambda x: 0, initial_state=np.asarray([0.,0.,0.,1.5,1.0,0.,0.,0.,0.,0.])):
        '''
        2D hopper with actuated piston at the end of the leg.
        The model of the hopper follows the one described in "Hopping in Legged Systems" (Raibert, 1984)
        '''
        self.M1 = M1
        self.I1 = I1
        self.M2 = M2
        self.I2 = I2
        self.r1 = r1
        self.r2 = r2
        self.KL = KL
        self.KL2 = KL2
        self.BL2 = BL2
        self.k0 = k0
        self.KG = KG
        self.BG = BG
        self.g = g
        self.ground_height_function = ground_height_function

        # state machine for touchdown detection
        self.xTD = sym.Variable('xTD')
        self.was_in_contact = False

        # Symbolic variables
        # State variables are s = [theta1, theta2, x0, y0, w]
        # self.x = [s, sdot]
        # Inputs are self.u = [tau, chi]
        self.x = np.array([sym.Variable('x_' + str(i)) for i in range(10)])
        self.u = np.array([sym.Variable('u_' + str(i)) for i in range(2)])

        # Initial state
        self.initial_env = {}
        for i, state in enumerate(initial_state):
            self.initial_env[self.x[i]] = state
        self.initial_env[self.xTD] = 0
        # print(self.initial_env)

        # Dynamic modes
        FK_extended = self.KL * (self.k0 - self.x[4] + self.u[1])
        FK_retracted = self.KL2 * (self.k0 - self.x[4] +
                                   self.u[1]) - self.BL2 * self.x[9]
        FX_contact = -self.KG * (
            self.x[2] - self.xTD) - self.BG * self.x[7]  #FIXME: handling xTD
        FX_flight = 0.
        FY_contact = -self.KG * (self.x[3] - self.ground_height_function(
            self.x[2])) - self.BG * (self.x[8])
        FY_flight = 0.

        W = self.x[4] - self.r1

        # EOM is obtained from Raibert 1984 paper, Appendix I eqn 40~44
        # The EOM is in the following form
        # a1*theta1_ddot + a2*theta2_ddot + a3*x0_ddot + a4*w_ddot = A
        # b1*theta1_ddot + b2*theta2_ddot + b3*y0_ddot + b4*w_ddot = B
        # c1*theta1_ddot + c2*x0_ddot = C
        # d1*theta1_ddot + d2*y0_ddot = D
        # e1*theta1_ddot + e2*theta2_ddot = E

        a1 = sym.cos(self.x[0]) * (self.M2 * W * self.x[4] + self.I1)
        a2 = self.M2 * self.r2 * W * sym.cos(self.x[1])
        a3 = self.M2 * W
        a4 = self.M2 * W * sym.sin(self.x[0])

        b1 = -sym.sin(self.x[0]) * (self.M2 * W * self.x[4] + self.I1)
        b2 = -self.M2 * self.r2 * W * sym.sin(self.x[1])
        b3 = self.M2 * W
        b4 = self.M2 * W * sym.cos(self.x[1])

        c1 = sym.cos(self.x[0]) * (self.M1 * self.r1 * W - self.I1)
        c2 = self.M1 * W

        d1 = -sym.sin(self.x[0]) * (self.M1 * self.r1 * W - self.I1)
        d2 = self.M1 * W

        e1 = -sym.cos(self.x[1] - self.x[0]) * self.I1 * self.r2
        e2 = self.I2 * self.x[4]

        # free flight with extended leg
        flight_extended_conditions = np.asarray([
            self.k0 - self.x[4] + self.u[1] > 0,
            self.x[3] - self.ground_height_function(self.x[2]) > 0
        ])

        A_flight_extended = W * self.M2 * (self.x[5] ** 2 * W * sym.sin(self.x[0]) - 2 * self.x[5] * self.x[9] * sym.cos(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.sin(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.sin(self.x[0])) - \
                            self.r1 * FX_flight * (sym.cos(self.x[0]) ** 2) + sym.cos(self.x[0]) * (self.r1 * FY_flight * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_extended * W * sym.sin(self.x[0])

        B_flight_extended = W * self.M2 * (self.x[5] ** 2 * W * sym.cos(self.x[0]) + 2 * self.x[5] * self.x[9] * sym.sin(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.cos(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - g) + \
                            self.r1 * FX_flight * sym.cos(self.x[0]) * sym.sin(self.x[0]) - sym.sin(self.x[0]) * (self.r1 * FY_flight * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_extended * W * sym.cos(self.x[0])

        C_flight_extended = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.sin(self.x[0]) - FK_extended * sym.sin(self.x[0]) + FX_flight) - \
                            sym.cos(self.x[0]) * (FY_flight * self.r1 * sym.sin(self.x[0]) - FX_flight * self.r1 * sym.cos(self.x[0]) - self.u[0])

        D_flight_extended = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - FK_extended * sym.cos(self.x[0]) + FY_flight - self.M1 * self.g) - \
                            sym.sin(self.x[0]) * (FY_flight * self.r1 * sym.sin(self.x[0]) - FX_flight * self.r1 * sym.cos(self.x[0]) - self.u[0])

        E_flight_extended = W * (FK_extended * self.r2 * sym.sin(self.x[1] - self.x[0]) + self.u[0]) - self.r2 * sym.cos(self.x[1] - self.x[0]) * \
                            (self.r1 * FY_flight * sym.sin(self.x[0]) - self.r1 * FX_flight * sym.cos(self.x[0]) - self.u[0])

        theta1_ddot_flight_extended = ((a4*b2/b4-a2)*E_flight_extended/e2-a3*C_flight_extended/c2+a4*b3*D_flight_extended/(b4*d2)+\
                                      A_flight_extended-a4*B_flight_extended/b4)/\
                                      (a1-b1*a4/b4-(a2-a4*b2/b4)*e1/e2-a3*c1/c2+a4*b3*d1/(b4*d2))

        theta2_ddot_flight_extended = (E_flight_extended -
                                       e1 * theta1_ddot_flight_extended) / e2

        x_ddot_flight_extended = (C_flight_extended -
                                  c1 * theta1_ddot_flight_extended) / c2

        y_ddot_flight_extended = (D_flight_extended -
                                  d1 * theta1_ddot_flight_extended) / d2

        w_ddot_flight_extended = (A_flight_extended+B_flight_extended-(a1+b1)*theta1_ddot_flight_extended-(a2+b2)*theta2_ddot_flight_extended-\
                                  a3*x_ddot_flight_extended-b3*y_ddot_flight_extended)/(a4+b4)

        flight_extended_ddots = np.asarray([
            theta1_ddot_flight_extended, theta2_ddot_flight_extended,
            x_ddot_flight_extended, y_ddot_flight_extended,
            w_ddot_flight_extended
        ])

        flight_extended_dynamics = np.hstack(
            (self.x[5:], flight_extended_ddots))

        # free flight with retracted leg
        flight_retracted_conditions = np.asarray([
            self.k0 - self.x[4] + self.u[1] <= 0,
            self.x[3] - self.ground_height_function(self.x[2]) > 0
        ])

        A_flight_retracted = W * self.M2 * (self.x[5] ** 2 * W * sym.sin(self.x[0]) - 2 * self.x[5] * self.x[9] * sym.cos(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.sin(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.sin(self.x[0])) - \
                            self.r1 * FX_flight * (sym.cos(self.x[0]) ** 2) + sym.cos(self.x[0]) * (self.r1 * FY_flight * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_retracted * W * sym.sin(self.x[0])

        B_flight_retracted = W * self.M2 * (self.x[5] ** 2 * W * sym.cos(self.x[0]) + 2 * self.x[5] * self.x[9] * sym.sin(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.cos(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - g) + \
                            self.r1 * FX_flight * sym.cos(self.x[0]) * sym.sin(self.x[0]) - sym.sin(self.x[0]) * (self.r1 * FY_flight * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_retracted * W * sym.cos(self.x[0])

        C_flight_retracted = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.sin(self.x[0]) - FK_retracted * sym.sin(self.x[0]) + FX_flight) - \
                            sym.cos(self.x[0]) * (FY_flight * self.r1 * sym.sin(self.x[0]) - FX_flight * self.r1 * sym.cos(self.x[0]) - self.u[0])

        D_flight_retracted = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - FK_retracted * sym.cos(self.x[0]) + FY_flight - self.M1 * self.g) - \
                            sym.sin(self.x[0]) * (FY_flight * self.r1 * sym.sin(self.x[0]) - FX_flight * self.r1 * sym.cos(self.x[0]) - self.u[0])

        E_flight_retracted = W * (FK_retracted * self.r2 * sym.sin(self.x[1] - self.x[0]) + self.u[0]) - self.r2 * sym.cos(self.x[1] - self.x[0]) * \
                            (self.r1 * FY_flight * sym.sin(self.x[0]) - self.r1 * FX_flight * sym.cos(self.x[0]) - self.u[0])

        theta1_ddot_flight_retracted = ((a4*b2/b4-a2)*E_flight_retracted/e2-a3*C_flight_retracted/c2+a4*b3*D_flight_retracted/(b4*d2)+\
                                      A_flight_retracted-a4*B_flight_retracted/b4)/\
                                      (a1-b1*a4/b4-(a2-a4*b2/b4)*e1/e2-a3*c1/c2+a4*b3*d1/(b4*d2))

        theta2_ddot_flight_retracted = (E_flight_retracted -
                                        e1 * theta1_ddot_flight_retracted) / e2

        x_ddot_flight_retracted = (C_flight_retracted -
                                   c1 * theta1_ddot_flight_retracted) / c2

        y_ddot_flight_retracted = (D_flight_retracted -
                                   d1 * theta1_ddot_flight_retracted) / d2

        w_ddot_flight_retracted = (A_flight_retracted+B_flight_retracted-(a1+b1)*theta1_ddot_flight_retracted-(a2+b2)*theta2_ddot_flight_retracted-\
                                  a3*x_ddot_flight_retracted-b3*y_ddot_flight_retracted)/(a4+b4)

        flight_retracted_ddots = np.asarray([
            theta1_ddot_flight_retracted, theta2_ddot_flight_retracted,
            x_ddot_flight_retracted, y_ddot_flight_retracted,
            w_ddot_flight_retracted
        ])

        flight_retracted_dynamics = np.hstack(
            (self.x[5:], flight_retracted_ddots))

        # contact with extended leg
        contact_extended_conditions = np.asarray([
            self.k0 - self.x[4] + self.u[1] > 0,
            self.x[3] - self.ground_height_function(self.x[2]) <= 0
        ])

        A_contact_extended = W * self.M2 * (self.x[5] ** 2 * W * sym.sin(self.x[0]) - 2 * self.x[5] * self.x[9] * sym.cos(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.sin(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.sin(self.x[0])) - \
                            self.r1 * FX_contact * (sym.cos(self.x[0]) ** 2) + sym.cos(self.x[0]) * (self.r1 * FY_contact * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_extended * W * sym.sin(self.x[0])

        B_contact_extended = W * self.M2 * (self.x[5] ** 2 * W * sym.cos(self.x[0]) + 2 * self.x[5] * self.x[9] * sym.sin(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.cos(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - g) + \
                            self.r1 * FX_contact * sym.cos(self.x[0]) * sym.sin(self.x[0]) - sym.sin(self.x[0]) * (self.r1 * FY_contact * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_extended * W * sym.cos(self.x[0])

        C_contact_extended = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.sin(self.x[0]) - FK_extended * sym.sin(self.x[0]) + FX_contact) - \
                            sym.cos(self.x[0]) * (FY_contact * self.r1 * sym.sin(self.x[0]) - FX_contact * self.r1 * sym.cos(self.x[0]) - self.u[0])

        D_contact_extended = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - FK_extended * sym.cos(self.x[0]) + FY_contact - self.M1 * self.g) - \
                            sym.sin(self.x[0]) * (FY_contact * self.r1 * sym.sin(self.x[0]) - FX_contact * self.r1 * sym.cos(self.x[0]) - self.u[0])

        E_contact_extended = W * (FK_extended * self.r2 * sym.sin(self.x[1] - self.x[0]) + self.u[0]) - self.r2 * sym.cos(self.x[1] - self.x[0]) * \
                            (self.r1 * FY_contact * sym.sin(self.x[0]) - self.r1 * FX_contact * sym.cos(self.x[0]) - self.u[0])

        theta1_ddot_contact_extended = ((a4*b2/b4-a2)*E_contact_extended/e2-a3*C_contact_extended/c2+a4*b3*D_contact_extended/(b4*d2)+\
                                      A_contact_extended-a4*B_contact_extended/b4)/\
                                      (a1-b1*a4/b4-(a2-a4*b2/b4)*e1/e2-a3*c1/c2+a4*b3*d1/(b4*d2))

        theta2_ddot_contact_extended = (E_contact_extended -
                                        e1 * theta1_ddot_contact_extended) / e2

        x_ddot_contact_extended = (C_contact_extended -
                                   c1 * theta1_ddot_contact_extended) / c2

        y_ddot_contact_extended = (D_contact_extended -
                                   d1 * theta1_ddot_contact_extended) / d2

        w_ddot_contact_extended = (A_contact_extended+B_contact_extended-(a1+b1)*theta1_ddot_contact_extended-(a2+b2)*theta2_ddot_contact_extended-\
                                  a3*x_ddot_contact_extended-b3*y_ddot_contact_extended)/(a4+b4)

        contact_extended_ddots = np.asarray([
            theta1_ddot_contact_extended, theta2_ddot_contact_extended,
            x_ddot_contact_extended, y_ddot_contact_extended,
            w_ddot_contact_extended
        ])

        contact_extended_dynamics = np.hstack(
            (self.x[5:], contact_extended_ddots))

        # contact with retracted leg
        contact_retracted_conditions = np.asarray([
            self.k0 - self.x[4] + self.u[1] <= 0,
            self.x[3] - self.ground_height_function(self.x[2]) <= 0
        ])
        A_contact_retracted = W * self.M2 * (self.x[5] ** 2 * W * sym.sin(self.x[0]) - 2 * self.x[5] * self.x[9] * sym.cos(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.sin(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.sin(self.x[0])) - \
                            self.r1 * FX_contact * (sym.cos(self.x[0]) ** 2) + sym.cos(self.x[0]) * (self.r1 * FY_contact * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_retracted * W * sym.sin(self.x[0])

        B_contact_retracted = W * self.M2 * (self.x[5] ** 2 * W * sym.cos(self.x[0]) + 2 * self.x[5] * self.x[9] * sym.sin(self.x[0]) + \
                                           self.r2 * self.x[6] ** 2 * sym.cos(self.x[1]) + self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - g) + \
                            self.r1 * FX_contact * sym.cos(self.x[0]) * sym.sin(self.x[0]) - sym.sin(self.x[0]) * (self.r1 * FY_contact * sym.sin(self.x[0]) - self.u[0]) + \
                            FK_retracted * W * sym.cos(self.x[0])

        C_contact_retracted = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.sin(self.x[0]) - FK_retracted * sym.sin(self.x[0]) + FX_contact) - \
                            sym.cos(self.x[0]) * (FY_contact * self.r1 * sym.sin(self.x[0]) - FX_contact * self.r1 * sym.cos(self.x[0]) - self.u[0])

        D_contact_retracted = W * (self.M1 * self.r1 * self.x[5] ** 2 * sym.cos(self.x[0]) - FK_retracted * sym.cos(self.x[0]) + FY_contact - self.M1 * self.g) - \
                            sym.sin(self.x[0]) * (FY_contact * self.r1 * sym.sin(self.x[0]) - FX_contact * self.r1 * sym.cos(self.x[0]) - self.u[0])

        E_contact_retracted = W * (FK_retracted * self.r2 * sym.sin(self.x[1] - self.x[0]) + self.u[0]) - self.r2 * sym.cos(self.x[1] - self.x[0]) * \
                            (self.r1 * FY_contact * sym.sin(self.x[0]) - self.r1 * FX_contact * sym.cos(self.x[0]) - self.u[0])

        theta1_ddot_contact_retracted = ((a4*b2/b4-a2)*E_contact_retracted/e2-a3*C_contact_retracted/c2+a4*b3*D_contact_retracted/(b4*d2)+\
                                      A_contact_retracted-a4*B_contact_retracted/b4)/\
                                      (a1-b1*a4/b4-(a2-a4*b2/b4)*e1/e2-a3*c1/c2+a4*b3*d1/(b4*d2))

        theta2_ddot_contact_retracted = (
            E_contact_retracted - e1 * theta1_ddot_contact_retracted) / e2

        x_ddot_contact_retracted = (C_contact_retracted -
                                    c1 * theta1_ddot_contact_retracted) / c2

        y_ddot_contact_retracted = (D_contact_retracted -
                                    d1 * theta1_ddot_contact_retracted) / d2

        w_ddot_contact_retracted = (A_contact_retracted+B_contact_retracted-(a1+b1)*theta1_ddot_contact_retracted-(a2+b2)*theta2_ddot_contact_retracted-\
                                  a3*x_ddot_contact_retracted-b3*y_ddot_contact_retracted)/(a4+b4)

        contact_retracted_ddots = np.asarray([
            theta1_ddot_contact_retracted, theta2_ddot_contact_retracted,
            x_ddot_contact_retracted, y_ddot_contact_retracted,
            w_ddot_contact_retracted
        ])

        contact_retracted_dynamics = np.hstack(
            (self.x[5:], contact_retracted_ddots))

        self.f_list = np.asarray([
            flight_extended_dynamics, flight_retracted_dynamics,
            contact_extended_dynamics, contact_retracted_dynamics
        ])
        self.f_type_list = np.asarray(
            ['continuous', 'continuous', 'continuous', 'continuous'])
        self.c_list = np.asarray([
            flight_extended_conditions, flight_retracted_conditions,
            contact_extended_conditions, contact_retracted_conditions
        ])

        DTHybridSystem.__init__(self, self.f_list, self.f_type_list, self.x, self.u, self.c_list, \
                                self.initial_env)
Exemplo n.º 14
0
    def __init__(self, m=5, J=500, m_l=1, J_l=0.5, l1=0.0, l2=0.0, k_g=2e3, b_g=20, \
                 g=9.8, flight_step_size = 1e-2, contact_step_size = 5e-3, descend_step_size_switch_threshold=2e-2, \
                 ground_height_function=lambda x: 0, initial_state=np.asarray([0.,0.,0.,1.5,1.0,0.,0.,0.,0.,0.])):
        '''
        2D hopper with actuated piston at the end of the leg.
        The model of the hopper follows the one described in "Hopping in Legged Systems" (Raibert, 1984)
        '''
        self.m = m
        self.J = J
        self.m_l = m_l
        self.J_l = J_l
        self.l1 = l1
        self.l2 = l2
        self.k_g_y = k_g
        self.k_g_x = 2e3
        self.b_g_x = 200
        self.b_g = b_g
        self.g = g
        self.ground_height_function = ground_height_function
        self.r0 = 1.5
        # state machine for touchdown detection
        self.xTD = sym.Variable('xTD')
        self.was_in_contact = False

        # Symbolic variables
        # State variables are s = [x_ft, y_ft, theta, phi, r]
        # self.x = [s, sdot]
        # Inputs are self.u = [tau, chi]
        self.x = np.array([sym.Variable('x_' + str(i)) for i in range(10)])
        self.u = np.array([sym.Variable('u_' + str(i)) for i in range(2)])

        # Initial state
        self.initial_env = {}
        for i, state in enumerate(initial_state):
            self.initial_env[self.x[i]] = state
        self.initial_env[self.xTD] = 0
        self.k0 = 800
        self.b_leg = 2
        self.k0_stabilize = 40
        self.b0_stabilize = 10
        self.k0_restore = 60
        self.b0_restore = 15
        # self.flight_step_size = flight_step_size
        # self.contact_step_size = contact_step_size
        # self.descend_step_size_switch_threshold = descend_step_size_switch_threshold
        # self.hover_step_size_switch_threshold=-0.75
        # print(self.initial_env)

        # Dynamic modes
        Fx_contact = -self.k_g_x * (self.x[0] -
                                    self.xTD) - self.b_g_x * self.x[5]
        Fx_flight = 0.
        Fy_contact = -self.k_g_y * (self.x[1] - self.ground_height_function(
            self.x[0])) - self.b_g * self.x[6] * (1 - np.exp(self.x[1] * 16))
        Fy_flight = 0.

        R = self.x[4] - self.l1
        # EOM is obtained from Russ Tedrake's Thesis
        a1 = -self.m_l * R
        a2 = (self.J_l - self.m_l * R * self.l1) * sym.cos(self.x[2])
        b1 = self.m_l * R
        b2 = (self.J_l - self.m_l * R * self.l1) * sym.sin(self.x[2])
        c1 = self.m * R
        c2 = (self.J_l + self.m * R * self.x[4]) * sym.cos(self.x[2])
        c3 = self.m * R * self.l2 * sym.cos(self.x[3])
        c4 = self.m * R * sym.sin(self.x[2])
        d1 = -self.m * R
        d2 = (self.J_l + self.m * R * self.x[4]) * sym.sin(self.x[2])
        d3 = self.m * R * self.l2 * sym.sin(self.x[3])
        d4 = -self.m * R * sym.cos(self.x[2])
        e1 = self.J_l * self.l2 * sym.cos(self.x[2] - self.x[3])
        e2 = -self.J * R
        self.b_r_ascend = 0.
        r_diff = self.x[4] - self.r0
        F_leg_flight = -self.k0_restore * r_diff - self.b0_restore * self.x[9]
        F_leg_ascend = -self.u[1] * r_diff - self.b_r_ascend * self.x[
            9]  #self.u[1] * (1-np.exp(10*r_diff_upper)/(np.exp(10*r_diff_upper)+1))#+(- self.k0_stabilize * r_diff_upper - self.b0_stabilize * self.x[9])*(np.exp(10*r_diff_upper)/(np.exp(10*r_diff_upper)+1))
        F_leg_descend = -self.k0 * r_diff - self.b_leg * self.x[9]
        # F_leg_descend = F_leg_ascend

        self.tau_p = 400.
        self.tau_d = 10.
        hip_x_dot = self.x[5] + self.x[9] * sym.sin(
            self.x[2]) + self.x[4] * sym.cos(self.x[2]) * self.x[7]
        hip_y_dot = self.x[6] + self.x[9] * sym.cos(
            self.x[2]) - self.x[4] * sym.sin(self.x[2]) * self.x[7]
        alpha_des_ascend = 0.6 * sym.atan(hip_x_dot / (
            -hip_y_dot - 1e-6))  #-sym.atan(self.x[5]/self.x[6]) # point toward
        alpha_des_descend = 0.6 * sym.atan(
            hip_x_dot / (hip_y_dot + 1e-6))  # point toward landing point
        tau_leg_flight_ascend = (self.tau_p * (alpha_des_ascend - self.x[2]) -
                                 self.tau_d * self.x[7]) * -1
        tau_leg_flight_descend = (self.tau_p *
                                  (alpha_des_descend - self.x[2]) -
                                  self.tau_d * self.x[7]) * -1
        tau_leg_contact = self.u[0]

        def get_ddots(Fx, Fy, F_leg, u0):
            alpha = (self.l1 * Fy * sym.sin(self.x[2]) -
                     self.l1 * Fx * sym.cos(self.x[2]) - u0)
            A = sym.cos(self.x[2]) * alpha - R * (
                Fx - F_leg * sym.sin(self.x[2]) -
                self.m_l * self.l1 * self.x[7]**2 * sym.sin(self.x[2]))
            B = sym.sin(self.x[2]) * alpha + R * (
                self.m_l * self.l1 * self.x[7]**2 * sym.cos(self.x[2]) + Fy -
                F_leg * sym.cos(self.x[2]) - self.m_l * self.g)
            C = sym.cos(self.x[2]) * alpha + R * F_leg * sym.sin(
                self.x[2]) + self.m * R * (
                    self.x[4] * self.x[7]**2 * sym.sin(self.x[2]) +
                    self.l2 * self.x[8]**2 * sym.sin(self.x[3]) -
                    2 * self.x[9] * self.x[7] * sym.cos(self.x[2]))
            D = sym.sin(self.x[2]) * alpha - R * (
                F_leg * sym.cos(self.x[2]) - self.m * self.g) - self.m * R * (
                    2 * self.x[9] * self.x[7] * sym.sin(self.x[2]) +
                    self.x[4] * self.x[7]**2 * sym.cos(self.x[2]) +
                    self.l2 * self.x[8]**2 * sym.cos(self.x[3]))
            E = self.l2 * sym.cos(self.x[2] - self.x[3]) * alpha - R * (
                self.l2 * F_leg * sym.sin(self.x[3] - self.x[2]) + u0)

            return np.asarray([(A*b1*c2*d4*e2 - A*b1*c3*d4*e1 - A*b1*c4*d2*e2 + A*b1*c4*d3*e1 + A*b2*c4*d1*e2 - B*a2*c4*d1*e2 - C*a2*b1*d4*e2 + D*a2*b1*c4*e2 + E*a2*b1*c3*d4 - E*a2*b1*c4*d3)/(a1*b1*c2*d4*e2 - a1*b1*c3*d4*e1 - a1*b1*c4*d2*e2 + a1*b1*c4*d3*e1 + a1*b2*c4*d1*e2 - a2*b1*c1*d4*e2), \
                               (A*b2*c1*d4*e2 + B*a1*c2*d4*e2 - B*a1*c3*d4*e1 - B*a1*c4*d2*e2 + B*a1*c4*d3*e1 - B*a2*c1*d4*e2 - C*a1*b2*d4*e2 + D*a1*b2*c4*e2 + E*a1*b2*c3*d4 - E*a1*b2*c4*d3)/(a1*b1*c2*d4*e2 - a1*b1*c3*d4*e1 - a1*b1*c4*d2*e2 + a1*b1*c4*d3*e1 + a1*b2*c4*d1*e2 - a2*b1*c1*d4*e2), \
                               -(A*b1*c1*d4*e2 - B*a1*c4*d1*e2 - C*a1*b1*d4*e2 + D*a1*b1*c4*e2 + E*a1*b1*c3*d4 - E*a1*b1*c4*d3)/(a1*b1*c2*d4*e2 - a1*b1*c3*d4*e1 - a1*b1*c4*d2*e2 + a1*b1*c4*d3*e1 + a1*b2*c4*d1*e2 - a2*b1*c1*d4*e2), \
                               (A*b1*c1*d4*e1 - B*a1*c4*d1*e1 - C*a1*b1*d4*e1 + D*a1*b1*c4*e1 + E*a1*b1*c2*d4 - E*a1*b1*c4*d2 + E*a1*b2*c4*d1 - E*a2*b1*c1*d4)/(a1*b1*c2*d4*e2 - a1*b1*c3*d4*e1 - a1*b1*c4*d2*e2 + a1*b1*c4*d3*e1 + a1*b2*c4*d1*e2 - a2*b1*c1*d4*e2), \
                               (A*b1*c1*d2*e2 - A*b1*c1*d3*e1 - A*b2*c1*d1*e2 - B*a1*c2*d1*e2 + B*a1*c3*d1*e1 + B*a2*c1*d1*e2 - C*a1*b1*d2*e2 + C*a1*b1*d3*e1 + C*a1*b2*d1*e2 + D*a1*b1*c2*e2 - D*a1*b1*c3*e1 - D*a2*b1*c1*e2 - E*a1*b1*c2*d3 + E*a1*b1*c3*d2 - E*a1*b2*c3*d1 + E*a2*b1*c1*d3)/(a1*b1*c2*d4*e2 - a1*b1*c3*d4*e1 - a1*b1*c4*d2*e2 + a1*b1*c4*d3*e1 + a1*b2*c4*d1*e2 - a2*b1*c1*d4*e2)])

        flight_ascend_dynamics = np.hstack(
            (self.x[5:],
             get_ddots(Fx_flight, Fy_flight, F_leg_flight,
                       tau_leg_flight_ascend)))
        flight_descend_dynamics = np.hstack(
            (self.x[5:],
             get_ddots(Fx_flight, Fy_flight, F_leg_flight,
                       tau_leg_flight_descend)))
        contact_descend_dynamics = np.hstack(
            (self.x[5:],
             get_ddots(Fx_contact, Fy_contact, F_leg_descend,
                       tau_leg_contact)))
        contact_ascend_dynamics = np.hstack(
            (self.x[5:],
             get_ddots(Fx_contact, Fy_contact, F_leg_ascend, tau_leg_contact)))

        flight_ascend_conditions = np.asarray([
            self.x[1] > self.ground_height_function(self.x[0]), hip_y_dot > 0
        ])
        flight_descend_conditions = np.asarray([
            self.x[1] > self.ground_height_function(self.x[0]), hip_y_dot <= 0
        ])
        contact_descend_coditions = np.asarray([
            self.x[1] <= self.ground_height_function(self.x[0]), self.x[9] < 0
        ])
        contact_ascend_coditions = np.asarray([
            self.x[1] <= self.ground_height_function(self.x[0]), self.x[9] >= 0
        ])

        self.f_list = np.asarray([
            flight_ascend_dynamics, flight_descend_dynamics,
            contact_descend_dynamics, contact_ascend_dynamics
        ])
        self.f_type_list = np.asarray(
            ['continuous', 'continuous', 'continuous', 'continuous'])
        self.c_list = np.asarray([
            flight_ascend_conditions, flight_descend_conditions,
            contact_descend_coditions, contact_ascend_coditions
        ])

        DTHybridSystem.__init__(self, self.f_list, self.f_type_list, self.x, self.u, self.c_list, \
                                self.initial_env, input_limits=np.vstack([[-500,1.4e3], [500,2.5e3]]))
Exemplo n.º 15
0
mysystem.q_o = np.array([x, y, theta])
mysystem.q_m = np.array([x_1, y_1, x_2, y_2])

# Dynamics:
mysystem.C = np.zeros((3, 3))
g = 9.8
mysystem.tau_g = np.array([0, -g, 0])
mysystem.B = np.zeros((3, 0))

M = 1
I = M / 3.0
mysystem.M = blk(*[M, M, I])
mysystem.M_inv = np.linalg.inv(mysystem.M)
h = 0.05

psi_1 = (x_1 - x) * sym.cos(theta) + (y_1 - y) * sym.sin(theta)
phi_1 = -((x_1 - x) * sym.sin(-theta) + (y_1 - y) * sym.cos(theta))
J_1n = np.array([-sym.sin(theta), sym.cos(theta), psi_1]).reshape(3, 1)
J_1t = np.array([sym.cos(theta), sym.sin(theta), 0]).reshape(3, 1)
J_1 = np.hstack((J_1n, J_1t))
C1 = contact_point_symbolic_2D(mysystem,
                               phi=phi_1,
                               psi=psi_1,
                               J=J_1,
                               friction=0.3,
                               name="contact point")
#C1.sliding=False
#C1.no_contact=False

psi_2 = (x_2 - x) * sym.cos(theta) + (y_2 - y) * sym.sin(theta)
phi_2 = -((x_2 - x) * sym.sin(-theta) + (y_2 - y) * sym.cos(theta))
Exemplo n.º 16
0
 def final_state_constraint(x):
     pole_length = 0.5
     wall_x = 2.
     return x[0] + pole_length * sym.sin(x[1]) - wall_x
Exemplo n.º 17
0
 def dist_pole_wall(x):
     pole_x = pole_length * sym.sin(x[1]) + x[0]
     return wall_x - pole_x
def sin(x):
    if isinstance(x, AutoDiffXd):
        return x.sin()
    elif isinstance(x, Variable):
        return sym.sin(x)
    return math.sin(x)
Exemplo n.º 19
0
 def test_method_jacobian(self):
     # (x * cos(y)).Jacobian([x, y]) returns [cos(y), -x * sin(y)].
     J = (x * sym.cos(y)).Jacobian([x, y])
     self._check_scalar(J[0], sym.cos(y))
     self._check_scalar(J[1], -x * sym.sin(y))
Exemplo n.º 20
0
 def test_method_jacobian(self):
     # (x * cos(y)).Jacobian([x, y]) returns [cos(y), -x * sin(y)].
     J = (x * sym.cos(y)).Jacobian([x, y])
     numpy_compare.assert_equal(J[0], sym.cos(y))
     numpy_compare.assert_equal(J[1], -x * sym.sin(y))
Exemplo n.º 21
0
 def test_method_jacobian(self):
     # (x * cos(y)).Jacobian([x, y]) returns [cos(y), -x * sin(y)].
     J = (x * sym.cos(y)).Jacobian([x, y])
     self._check_scalar(J[0], sym.cos(y))
     self._check_scalar(J[1], -x * sym.sin(y))
Exemplo n.º 22
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  6 19:09:04 2019

@author: sadra
"""

import numpy as np
import pydrake.symbolic as sym

from PWA_lib.Manipulation.contact_point_pydrake import contact_point_symbolic
from PWA_lib.Manipulation.system_symbolic_pydrake import system_symbolic

mysystem = system_symbolic("my system")
q = np.array([sym.Variable("q%i" % i) for i in range(3)])

J = np.array([q[0]**2 * sym.sin(q[2]), q[1]**3 * sym.cos(q[2])])

z = sym.Jacobian(J, q)

E = {q[i]: i + 1 for i in range(3)}

z_v = sym.Evaluate(z, E)