def post_process(states10, constants10, points10, system10, t10, fit_states10,
                 vel):
    states = states10
    constants = constants10
    points = points10
    system = system10
    t = t10
    fit_states = fit_states10

    points_output = PointsOutput(points, system, constant_values=constants)
    y1 = points_output.calc(states)
    plt.figure()
    plt.plot(*(y1[::int(len(y1) / 20)].T) * 1000)
    plt.axis('equal')
    plt.title(str(vel))

    plt.figure()
    q_states = numpy.c_[(states[:, 2], states[:, 3], states[:, 4],
                         states[:, 7], states[:, 8], states[:, 9])]
    plt.plot(t, numpy.rad2deg(q_states))
    plt.plot(t, numpy.rad2deg(fit_states), '--')
    print('final states:' + str(numpy.rad2deg(q_states[-1, :])))
    plt.title(str(vel))
    # plt.figure()
    points_output.animate(fps=1 / tstep,
                          movie_name='render'
                          '.mp4',
                          lw=2,
                          marker='o',
                          color=(1, 0, 0, 1),
                          linestyle='-')
    return y1
# =============================================================================
KE = system.get_KE()
PE = system.getPEGravity(0 * N.x) - system.getPESprings()
energy = Output([KE - PE])
energy.calc(states, t)
energy.plot_time()
# =============================================================================
points_list = [p1, p2]
#points_list = [item2 for item in points_list for item2 in [item.dot(N.x),item.dot(N.y)]]
#points = Output(points_list)
#y = points.calc(states,t)
#y = y.reshape((-1,2,2))

#plt.figure()
#plt.plot(y[:,1,0],y[:,1,1])
#plt.axis('equal')

states2 = Output([x, q])
states2.calc(states, t)

plt.figure()
plt.plot(states[:, 0])
plt.figure()
plt.plot(states[:, 1])

points2 = PointsOutput(points_list)
points2.calc(states, t)
#points2.plot_time()
points2.animate(fps=30, movie_name='cart_pendulum.mp4', lw=2)
pCcm=0*N.x
w1 = N.get_w_to(C)


IC = Dyadic.build(C,Ixx,Iyy,Izz)

BodyC = Body('BodyC',C,pCcm,mC,IC)

system.addforcegravity(-g*N.y)

# system.addforce(1*C.x+2*C.y+3*C.z,w1)

points = [1*C.x,0*C.x,1*C.y,0*C.y,1*C.z]

f,ma = system.getdynamics()

# func1 = system.state_space_pre_invert(f,ma)
func1 = system.state_space_post_invert(f,ma)

ini = [initialvalues[item] for item in system.get_state_variables()]

states=pynamics.integration.integrate_odeint(func1,ini,t,rtol = tol, atol=tol,args=({'constants':system.constant_values},))

po = PointsOutput(points,system)
po.calc(states,t)
po.animate(fps = 30,lw=2)

so = Output([qA,qB,qC])
so.calc(states,t)
so.plot_time()
KE = system.get_KE()
PE = system.getPEGravity(pNA)-system.getPESprings()

output = Output([x1,y1,KE-PE,x,y],system)
y = output.calc(states)

plt.figure(1)
plt.plot(y[:,0],y[:,1])
plt.axis('equal')

plt.figure(2)
plt.plot(y[:,2])

plt.figure(3)
plt.plot(t,y[:,4])
plt.show()

plt.figure(4)
plt.plot(t,states[:,2])
plt.show()



points = [pNA,pAcm]
#points = [item for item2 in points for item in [item2.dot(system.newtonian.x),item2.dot(system.newtonian.y)]]
points_output = PointsOutput(points,system)
y = points_output.calc(states)
points_output.animate(fps = 100,movie_name = 'single_dof_bouncer.mp4',lw=2,marker='o',color=(1,0,0,1),linestyle='')

# In[29]:

points = [pm1, pNA, pAB, pBC, pC1, pC2]
points_output = PointsOutput(points, system)
y = points_output.calc(states)
points_output.plot_time(5)

# #### Motion Animation
# in normal Python the next lines of code produce an animation using matplotlib

# In[30]:

points_output.animate(fps=fps,
                      movie_name='render.mp4',
                      lw=2,
                      marker='o',
                      color=(1, 0, 0, 1),
                      linestyle='-')
#a()

# To plot the animation in jupyter you need a couple extra lines of code...

# In[31]:

# from matplotlib import animation, rc
# from IPython.display import HTML
# HTML(points_output.anim.to_html5_video())

# ### Constraint Forces

# This line of code computes the constraint forces once the system's states have been solved for.
Example #6
0
ParticleA = Particle(pAB, mA, 'ParticleA', system)
ParticleB = Particle(pAB2, mA, 'ParticleB', system)

system.addforce(-b * vAB, vAB)
system.addforce(-b * vAB2, vAB2)
system.addforcegravity(-g * N.y)

v = pAB2 - pNA2
u = (v.dot(v))**.5

eq1 = [(v.dot(v)) - lA**2]
eq1_dd = system.derivative(system.derivative(eq1[0]))
eq = [eq1_dd]

f, ma = system.getdynamics()
func = system.state_space_post_invert(f,
                                      ma,
                                      eq,
                                      constants=system.constant_values)
states = pynamics.integration.integrate(func,
                                        ini,
                                        t,
                                        rtol=1e-12,
                                        atol=1e-12,
                                        hmin=1e-14)

points = [pNA, pAB, pNA, pNA2, pAB2]
points_output = PointsOutput(points, system)
points_output.calc(states)
points_output.animate(fps=30, lw=2)
Example #7
0
func1 = system.state_space_post_invert(f,
                                       ma,
                                       eq_dd,
                                       constants=system.constant_values,
                                       variable_functions={my_signal: ft2})
states = pynamics.integration.integrate_odeint(func1,
                                               ini1,
                                               t,
                                               rtol=tol,
                                               atol=tol)

KE = system.get_KE()
PE = system.getPEGravity(0 * N.x) - system.getPESprings()
energy = Output([KE - PE, toeforce, heelforce])
energy.calc(states)
energy.plot_time()

#torque_plot = Output([torque])
#torque_plot.calc(states)
#torque_plot.plot_time()

points = [pDtip, pCD, pOC, pOA, pAB, pBtip, pE1, pE2, pBtip]
points = PointsOutput(points)
y = points.calc(states)
y = y.reshape((-1, 9, 2))
plt.figure()
for item in y[::30]:
    plt.plot(*(item.T))

points.animate(fps=30, movie_name='parallel_five_bar_jumper_foot.mp4', lw=2)
Example #8
0
#eq1_dd=[system.derivative(system.derivative(item)) for item in eq1]

eq = []
#a = [0-pm2.dot(N.y)]
#b = [(item+abs(item)) for item in a]

f, ma = system.getdynamics()
func = system.state_space_post_invert(f, ma)
#func = system.state_space_post_invert2(f,ma,eq1_dd,eq1_d,eq1,eq_active = b)
states = pynamics.integration.integrate_odeint(func,
                                               ini,
                                               t,
                                               rtol=error,
                                               atol=error,
                                               args=({
                                                   'constants':
                                                   system.constant_values
                                               }, ))
#states = states[0]

points = [pm1, pm2]
po = PointsOutput(points, system, constant_values=system.constant_values)
y = po.calc(states)

plt.figure()
for item in y:
    plt.plot(*(item.T), lw=2, marker='o')
plt.axis('equal')
#
po.animate(fps=30, movie_name='bouncy-mod.mp4', lw=2, marker='o')
Example #9
0
f,ma = system.getdynamics()
#func = system.state_space_post_invert(f,ma,eq)
func = system.state_space_post_invert2(f,ma,eq1_dd,eq1_d,eq1,eq_active = b)
states=pynamics.integration.integrate_odeint(func,ini,t,rtol = error, atol = error, args=({'alpha':alpha,'beta':beta, 'constants':system.constant_values},),full_output = 1,mxstep = int(1e5))
states = states[0]

KE = system.get_KE()
PE = system.getPEGravity(pNA) - system.getPESprings()

output = Output([x1,x2,l, KE-PE],system)
y = output.calc(states)
pynamics.toc()

plt.figure(0)
plt.plot(t,y[:,0])
plt.plot(t,y[:,1])
plt.axis('equal')

plt.figure(1)
plt.plot(t,y[:,2])
plt.axis('equal')

plt.figure(2)
plt.plot(t,y[:,3])
#plt.axis('equal')
points = [Particle1.pCM,Particle2.pCM]
points = PointsOutput(points)
points.calc(states)
points.animate(fps = 30, movie_name='bouncy.mp4',lw=2)
Example #10
0
system.addforce(f_aero_C, vcp)
system.addforce(f_aero_E, ve)

points = [pC1, pC2]

#ang = [wNC.dot(C.x),wNC.dot(C.y),wNC.dot(C.z)]

f, ma = system.getdynamics()
func1 = system.state_space_post_invert(f, ma)
states = pynamics.integration.integrate_odeint(func1,
                                               ini,
                                               t,
                                               args=({
                                                   'constants':
                                                   system.constant_values
                                               }, ))

#output = Output(ang,system)
#output.calc(states)
#output.plot_time()

po = PointsOutput(points, system)
y = po.calc(states)
#po.plot_time()
#y = y.reshape((-1,2,2))
plt.figure()
for item in y:
    plt.plot(*(item.T), lw=2, marker='o')
#
po.animate(fps=30, movie_name='glider.mp4', lw=2, marker='o')
Example #11
0
# # =============================================================================
# KE = system.get_KE()
# PE = system.getPEGravity(0*N.x) - system.getPESprings()
# energy = Output([KE-PE], constant_values = constants)
# energy.calc(states,t)
# energy.plot_time()
# # =============================================================================

# positions = Output(system.get_q(0), constant_values = constants)
# positions.calc(states,t)
# positions.plot_time()

# speeds = Output(system.get_q(1), constant_values = constants)
# speeds.calc(states,t)
# speeds.plot_time()

# y= Output([G*qB_d], constant_values=constants)
# y.calc(states,t)
# y.plot_time()

points = [pAcm, pBcm]
po = PointsOutput(points, constant_values=constants)
po.calc(states, t)
po.plot_time()
po.animate(fps=fps,
           movie_name='triple_pendulum.mp4',
           lw=2,
           marker='o',
           color=(1, 0, 0, 1),
           linestyle='-')
Example #12
0
eq_dd = [system.derivative(item) for item in eq_d]
#
f, ma = system.getdynamics()
func1 = system.state_space_post_invert(f,
                                       ma,
                                       eq_dd,
                                       constants=constants,
                                       variable_functions={my_signal: ft2})
states = pynamics.integration.integrate(func1, ini1, t, rtol=tol, atol=tol)

#KE = system.get_KE()
#PE = system.getPEGravity(0*N.x) - system.getPESprings()
#energy = Output([KE-PE], constant_values=constants)
#energy.calc(states)
#energy.plot_time()

#torque_plot = Output([torque])
#torque_plot.calc(states)
#torque_plot.plot_time()

points = [pDtip, pCD, pC1C2, pOC, pOA, pA1A2, pAB, pBtip]
points_output = PointsOutput(points, constant_values=constants)
y = points_output.calc(states)
y = y.reshape((-1, len(points), 2))
plt.figure()
for item in y[::30]:
    plt.plot(*(item.T))

points_output.animate(
    fps=30, movie_name='parallel_five_bar_jumper_motor_compliance.mp4', lw=2)
Example #13
0
def Cal_system(initial_states, drag_direction, tinitial, tstep, tfinal,
               fit_vel, f1, f2):

    g_k, g_b_damping, g_b_damping1 = [0.30867935, 1.42946955, 1.08464536]
    system = System()
    pynamics.set_system(__name__, system)

    global_q = True

    lO = Constant(7 / 1000, 'lO', system)
    lA = Constant(33 / 1000, 'lA', system)
    lB = Constant(33 / 1000, 'lB', system)
    lC = Constant(33 / 1000, 'lC', system)

    mO = Constant(10 / 1000, 'mA', system)
    mA = Constant(2.89 / 1000, 'mA', system)
    mB = Constant(2.89 / 1000, 'mB', system)
    mC = Constant(2.89 / 1000, 'mC', system)
    k = Constant(g_k, 'k', system)
    k1 = Constant(0.4, 'k1', system)

    friction_perp = Constant(f1, 'f_perp', system)
    friction_par = Constant(f2, 'f_par', system)
    b_damping = Constant(g_b_damping, 'b_damping', system)
    b_damping1 = Constant(g_b_damping1, 'b_damping1', system)

    preload0 = Constant(0 * pi / 180, 'preload0', system)
    preload1 = Constant(0 * pi / 180, 'preload1', system)
    preload2 = Constant(0 * pi / 180, 'preload2', system)
    preload3 = Constant(0 * pi / 180, 'preload3', system)

    Ixx_O = Constant(1, 'Ixx_O', system)
    Iyy_O = Constant(1, 'Iyy_O', system)
    Izz_O = Constant(1, 'Izz_O', system)
    Ixx_A = Constant(1, 'Ixx_A', system)
    Iyy_A = Constant(1, 'Iyy_A', system)
    Izz_A = Constant(1, 'Izz_A', system)
    Ixx_B = Constant(1, 'Ixx_B', system)
    Iyy_B = Constant(1, 'Iyy_B', system)
    Izz_B = Constant(1, 'Izz_B', system)
    Ixx_C = Constant(1, 'Ixx_C', system)
    Iyy_C = Constant(1, 'Iyy_C', system)
    Izz_C = Constant(1, 'Izz_C', system)

    y, y_d, y_dd = Differentiable('y', system)
    qO, qO_d, qO_dd = Differentiable('qO', system)
    qA, qA_d, qA_dd = Differentiable('qA', system)
    qB, qB_d, qB_dd = Differentiable('qB', system)
    qC, qC_d, qC_dd = Differentiable('qC', system)

    fit_states = initial_states

    initialvalues = {}
    initialvalues[y] = fit_states[0]
    initialvalues[y_d] = fit_states[5]
    initialvalues[qO] = 0
    initialvalues[qO_d] = 0
    initialvalues[qA] = fit_states[2]
    initialvalues[qA_d] = fit_states[7]
    initialvalues[qB] = fit_states[3]
    initialvalues[qB_d] = fit_states[8]
    initialvalues[qC] = fit_states[4]
    initialvalues[qC_d] = fit_states[9]

    statevariables = system.get_state_variables()
    ini = [initialvalues[item] for item in statevariables]

    N = Frame('N')
    O = Frame('O')
    A = Frame('A')
    B = Frame('B')
    C = Frame('C')

    system.set_newtonian(N)
    if not global_q:
        O.rotate_fixed_axis_directed(N, [0, 0, 1], qO, system)
        A.rotate_fixed_axis_directed(O, [0, 0, 1], qA, system)
        B.rotate_fixed_axis_directed(A, [0, 0, 1], qB, system)
        C.rotate_fixed_axis_directed(B, [0, 0, 1], qC, system)
    else:
        O.rotate_fixed_axis_directed(N, [0, 0, 1], qO, system)
        A.rotate_fixed_axis_directed(N, [0, 0, 1], qA, system)
        B.rotate_fixed_axis_directed(N, [0, 0, 1], qB, system)
        C.rotate_fixed_axis_directed(N, [0, 0, 1], qC, system)

    pNO = 0 * N.x + y * N.y
    pOA = lO * N.x + y * N.y
    pAB = pOA + lA * A.x
    pBC = pAB + lB * B.x
    pCtip = pBC + lC * C.x

    pOcm = pNO + lO / 2 * N.x
    pAcm = pOA + lA / 2 * A.x
    pBcm = pAB + lB / 2 * B.x
    pCcm = pBC + lC / 2 * C.x

    wNO = N.getw_(O)
    wOA = N.getw_(A)
    wAB = A.getw_(B)
    wBC = B.getw_(C)

    IO = Dyadic.build(O, Ixx_O, Iyy_O, Izz_O)
    IA = Dyadic.build(A, Ixx_A, Iyy_A, Izz_A)
    IB = Dyadic.build(B, Ixx_B, Iyy_B, Izz_B)
    IC = Dyadic.build(C, Ixx_C, Iyy_C, Izz_C)

    BodyO = Body('BodyO', O, pOcm, mO, IO, system)
    BodyA = Body('BodyA', A, pAcm, mA, IA, system)
    BodyB = Body('BodyB', B, pBcm, mB, IB, system)
    BodyC = Body('BodyC', C, pCcm, mC, IC, system)

    # vOcm = pOcm.time_derivative()
    vAcm = pAcm.time_derivative()
    vBcm = pBcm.time_derivative()
    vCcm = pCcm.time_derivative()

    # system.add_spring_force1(k1+10000*(qA+abs(qA)),(qA-qO-preload1)*N.z,wOA)
    # system.add_spring_force1(k+10000*(qB+abs(qB)),(qB-qA-preload2)*N.z,wAB)
    # system.add_spring_force1(k+10000*(qC+abs(qC)),(qC-qB-preload3)*N.z,wBC)

    system.add_spring_force1(k1, (qA - qO - preload1) * N.z, wOA)
    system.add_spring_force1(k, (qB - qA - preload2) * N.z, wAB)
    system.add_spring_force1(k, (qC - qB - preload3) * N.z, wBC)

    #new Method use nJoint
    nvAcm = 1 / vAcm.length() * vAcm
    nvBcm = 1 / vBcm.length() * vBcm
    nvCcm = 1 / vCcm.length() * vCcm

    vSoil = drag_direction * 1 * N.y
    nSoil = 1 / vSoil.length() * vSoil

    if fit_vel == 0:
        vSoil = 1 * 1 * N.y
        nSoil = 1 / vSoil.length() * vSoil

        faperp = friction_perp * nSoil.dot(A.y) * A.y
        fapar = friction_par * nSoil.dot(A.x) * A.x
        system.addforce(-(faperp + fapar), vAcm)

        fbperp = friction_perp * nSoil.dot(B.y) * B.y
        fbpar = friction_par * nSoil.dot(B.x) * B.x
        system.addforce(-(fbperp + fbpar), vBcm)

        fcperp = friction_perp * nSoil.dot(C.y) * C.y
        fcpar = friction_par * nSoil.dot(C.x) * C.x
        system.addforce(-(fcperp + fcpar), vCcm)
    else:
        faperp = friction_perp * nvAcm.dot(A.y) * A.y
        fapar = friction_par * nvAcm.dot(A.x) * A.x
        system.addforce(-(faperp + fapar), vAcm)

        fbperp = friction_perp * nvBcm.dot(B.y) * B.y
        fbpar = friction_par * nvBcm.dot(B.x) * B.x
        system.addforce(-(fbperp + fbpar), vBcm)

        fcperp = friction_perp * nvCcm.dot(C.y) * C.y
        fcpar = friction_par * nvCcm.dot(C.x) * C.x
        system.addforce(-(fcperp + fcpar), vCcm)

    system.addforce(-b_damping1 * wOA, wOA)
    system.addforce(-b_damping * wAB, wAB)
    system.addforce(-b_damping * wBC, wBC)

    eq = []
    eq_d = [(system.derivative(item)) for item in eq]

    eq_d.append(y_d - fit_vel)
    eq_dd = [(system.derivative(item)) for item in eq_d]

    f, ma = system.getdynamics()
    func1 = system.state_space_post_invert(f, ma, eq_dd)

    points = [pNO, pOA, pAB, pBC, pCtip]

    constants = system.constant_values
    states = pynamics.integration.integrate_odeint(func1,
                                                   ini,
                                                   t,
                                                   args=({
                                                       'constants': constants
                                                   }, ))

    points_output = PointsOutput(points, system, constant_values=constants)
    y = points_output.calc(states)
    final = numpy.asarray(states[-1, :])
    time1 = time.time()
    points_output.animate(fps=30,
                          movie_name=str(time1) + 'video_1.mp4',
                          lw=2,
                          marker='o',
                          color=(1, 0, 0, 1),
                          linestyle='-')
    return final, states, y, system
def Cal_robot(direction, given_l, omega1, t1, t2, ini_states, name1, system,
              video_on, x1):
    time_a = time.time()
    pynamics.set_system(__name__, system)
    given_k, given_b = x1
    global_q = True

    damping_r = 0
    tinitial = 0
    tfinal = (t1 - t2) / omega1
    tstep = 1 / 30
    t = numpy.r_[tinitial:tfinal:tstep]

    tol_1 = 1e-6
    tol_2 = 1e-6
    lO = Constant(27.5 / 1000, 'lO', system)
    lR = Constant(40.5 / 1000, 'lR', system)
    lA = Constant(given_l / 1000, 'lA', system)
    lB = Constant(given_l / 1000, 'lB', system)
    lC = Constant(given_l / 1000, 'lC', system)

    mO = Constant(154.5 / 1000, 'mO', system)
    mR = Constant(9.282 / 1000, 'mR', system)
    mA = Constant(given_l * 2.75 * 0.14450000000000002 / 1000, 'mA', system)
    mB = Constant(given_l * 2.75 * 0.14450000000000002 / 1000, 'mB', system)
    mC = Constant(given_l * 2.75 * 0.14450000000000002 / 1000, 'mC', system)
    k = Constant(given_k, 'k', system)

    friction_perp = Constant(13 / 3, 'f_perp', system)
    friction_par = Constant(-2 / 3, 'f_par', system)
    friction_arm_perp = Constant(5.6, 'fr_perp', system)
    friction_arm_par = Constant(-0.2, 'fr_par', system)
    b_damping = Constant(given_b, 'b_damping', system)

    preload0 = Constant(0 * pi / 180, 'preload0', system)
    preload1 = Constant(0 * pi / 180, 'preload1', system)
    preload2 = Constant(0 * pi / 180, 'preload2', system)
    preload3 = Constant(0 * pi / 180, 'preload3', system)

    Ixx_O = Constant(1, 'Ixx_O', system)
    Iyy_O = Constant(1, 'Iyy_O', system)
    Izz_O = Constant(1, 'Izz_O', system)
    Ixx_R = Constant(1, 'Ixx_R', system)
    Iyy_R = Constant(1, 'Iyy_R', system)
    Izz_R = Constant(1, 'Izz_R', system)
    Ixx_A = Constant(1, 'Ixx_A', system)
    Iyy_A = Constant(1, 'Iyy_A', system)
    Izz_A = Constant(1, 'Izz_A', system)
    Ixx_B = Constant(1, 'Ixx_B', system)
    Iyy_B = Constant(1, 'Iyy_B', system)
    Izz_B = Constant(1, 'Izz_B', system)
    Ixx_C = Constant(1, 'Ixx_C', system)
    Iyy_C = Constant(1, 'Iyy_C', system)
    Izz_C = Constant(1, 'Izz_C', system)

    y, y_d, y_dd = Differentiable('y', system)
    qO, qO_d, qO_dd = Differentiable('qO', system)
    qR, qR_d, qR_dd = Differentiable('qR', system)
    qA, qA_d, qA_dd = Differentiable('qA', system)
    qB, qB_d, qB_dd = Differentiable('qB', system)
    qC, qC_d, qC_dd = Differentiable('qC', system)

    initialvalues = {}
    initialvalues[y] = ini_states[0] + tol_1
    initialvalues[qO] = ini_states[1] + tol_1
    initialvalues[qR] = ini_states[2] + tol_1
    initialvalues[qA] = ini_states[3] + tol_1
    initialvalues[qB] = ini_states[4] + tol_1
    initialvalues[qC] = ini_states[5] + tol_1

    initialvalues[y_d] = ini_states[6] + tol_1
    initialvalues[qO_d] = ini_states[7] + tol_1
    initialvalues[qR_d] = ini_states[8] + tol_1
    initialvalues[qA_d] = ini_states[9] + tol_1
    initialvalues[qB_d] = ini_states[10] + tol_1
    initialvalues[qC_d] = ini_states[11] + tol_1

    statevariables = system.get_state_variables()
    ini = [initialvalues[item] for item in statevariables]
    N = Frame('N')
    O = Frame('O')
    R = Frame('R')
    A = Frame('A')
    B = Frame('B')
    C = Frame('C')

    system.set_newtonian(N)
    if not global_q:
        O.rotate_fixed_axis_directed(N, [0, 0, 1], qO, system)
        R.rotate_fixed_axis_directed(O, [0, 0, 1], qR, system)
        A.rotate_fixed_axis_directed(R, [0, 0, 1], qA, system)
        B.rotate_fixed_axis_directed(A, [0, 0, 1], qB, system)
        C.rotate_fixed_axis_directed(B, [0, 0, 1], qC, system)
    else:
        O.rotate_fixed_axis_directed(N, [0, 0, 1], qO, system)
        R.rotate_fixed_axis_directed(N, [0, 0, 1], qR, system)
        A.rotate_fixed_axis_directed(N, [0, 0, 1], qA, system)
        B.rotate_fixed_axis_directed(N, [0, 0, 1], qB, system)
        C.rotate_fixed_axis_directed(N, [0, 0, 1], qC, system)

    pNO = 0 * N.x + y * N.y
    pOR = pNO + lO * N.x
    pRA = pOR + lR * R.x
    pAB = pRA + lA * A.x
    pBC = pAB + lB * B.x
    pCtip = pBC + lC * C.x

    pOcm = pNO + lO / 2 * N.x
    pRcm = pOR + lR / 2 * R.x
    pAcm = pRA + lA / 2 * A.x
    pBcm = pAB + lB / 2 * B.x
    pCcm = pBC + lC / 2 * C.x

    wNO = N.getw_(O)
    wOR = N.getw_(R)
    wRA = R.getw_(A)
    wAB = A.getw_(B)
    wBC = B.getw_(C)

    IO = Dyadic.build(O, Ixx_O, Iyy_O, Izz_O)
    IR = Dyadic.build(R, Ixx_R, Iyy_R, Izz_R)
    IA = Dyadic.build(A, Ixx_A, Iyy_A, Izz_A)
    IB = Dyadic.build(B, Ixx_B, Iyy_B, Izz_B)
    IC = Dyadic.build(C, Ixx_C, Iyy_C, Izz_C)

    BodyO = Body('BodyO', O, pOcm, mO, IO, system)
    BodyR = Body('BodyR', R, pRcm, mR, IR, system)
    BodyA = Body('BodyA', A, pAcm, mA, IA, system)
    BodyB = Body('BodyB', B, pBcm, mB, IB, system)
    BodyC = Body('BodyC', C, pCcm, mC, IC, system)

    j_tol = 3 * pi / 180
    inv_k = 10
    system.add_spring_force1(k + inv_k * (qA - qR + abs(qA - qR - j_tol)),
                             (qA - qR - preload1) * N.z, wRA)
    system.add_spring_force1(k + inv_k * (qB - qA + abs(qB - qA - j_tol)),
                             (qB - qA - preload2) * N.z, wAB)
    system.add_spring_force1(k + inv_k * (qC - qB + abs(qC - qB - j_tol)),
                             (qC - qB - preload3) * N.z, wBC)

    vOcm = y_d * N.y
    vRcm = pRcm.time_derivative()
    vAcm = pAcm.time_derivative()
    vBcm = pBcm.time_derivative()
    vCcm = pCcm.time_derivative()

    nvRcm = 1 / (vRcm.length() + tol_1) * vRcm
    nvAcm = 1 / (vAcm.length() + tol_1) * vAcm
    nvBcm = 1 / (vBcm.length() + tol_1) * vBcm
    nvCcm = 1 / (vCcm.length() + tol_1) * vCcm

    vSoil = -direction * 1 * N.y
    nSoil = 1 / vSoil.length() * vSoil
    foperp = 8 * nSoil
    system.addforce(-foperp, vOcm)

    frperp = friction_arm_perp * nvRcm.dot(R.y) * R.y
    frpar = friction_arm_par * nvRcm.dot(R.x) * R.x
    system.addforce(-(frperp + frpar), vRcm)

    faperp = friction_perp * nvAcm.dot(A.y) * A.y
    fapar = friction_par * nvAcm.dot(A.x) * A.x
    system.addforce(-(faperp + fapar), vAcm)

    fbperp = friction_perp * nvBcm.dot(B.y) * B.y
    fbpar = friction_par * nvBcm.dot(B.x) * B.x
    system.addforce(-(fbperp + fbpar), vBcm)

    fcperp = friction_perp * nvCcm.dot(C.y) * C.y
    fcpar = friction_par * nvCcm.dot(C.x) * C.x
    system.addforce(-(fcperp + fcpar), vCcm)

    system.addforce(-b_damping * 1 * wRA, wRA)
    system.addforce(-b_damping * 1 * wAB, wAB)
    system.addforce(-b_damping * 1 * wBC, wBC)

    eq = []
    eq_d = [(system.derivative(item)) for item in eq]
    eq_d.append(qR_d - omega1)
    eq_dd = [(system.derivative(item)) for item in eq_d]

    f, ma = system.getdynamics()
    func1 = system.state_space_post_invert(f, ma, eq_dd)
    points = [pNO, pOR, pRA, pAB, pBC, pCtip]

    constants = system.constant_values
    states = pynamics.integration.integrate_odeint(func1,
                                                   ini,
                                                   t,
                                                   args=({
                                                       'constants': constants
                                                   }, ))
    final = numpy.asarray(states[-1, :])

    logger1 = logging.getLogger('pynamics.system')
    logger2 = logging.getLogger('pynamics.integration')
    logger3 = logging.getLogger('pynamics.output')
    logger1.disabled = True
    logger2.disabled = True
    logger3.disabled = True
    points_output = PointsOutput(points, system, constant_values=constants)

    y1 = points_output.calc(states)
    if video_on == 1:
        plt.figure()
        plt.plot(*(y1[::int(len(y1) / 20)].T) * 1000)
        plt.axis('equal')
        plt.axis('equal')
        plt.title("Plate Configuration vs Distance")
        plt.xlabel("Configuration")
        plt.ylabel("Distance (mm)")

        plt.figure()
        plt.plot(t, numpy.rad2deg(states[:, 2]))
        plt.plot(t, numpy.rad2deg(states[:, 8]))
        plt.legend(["qR", "qR_d"])
        plt.hlines(numpy.rad2deg(t1), tinitial, tfinal)
        plt.hlines(numpy.rad2deg(t2), tinitial, tfinal)
        plt.title("Robot Arm angle and velocitues (qR and qR_d) over Time")
        plt.xlabel("Time (s)")
        plt.ylabel("Angles,Velocities (deg, deg/s)")

        plt.figure()
        q_states = numpy.c_[(states[:, 2], states[:, 3], states[:,
                                                                4], states[:,
                                                                           5])]
        plt.plot(t, numpy.rad2deg(q_states))
        plt.title("Joint Angule over Time")
        plt.xlabel("Time (s)")
        plt.ylabel("Joint Angles (deg)")
        plt.legend(["Arm", "Joint 1", "Joint 2", "Joint 3"])

        plt.figure()
        qd_states = numpy.c_[(states[:, 8], states[:,
                                                   9], states[:,
                                                              10], states[:,
                                                                          11])]
        plt.plot(t, numpy.rad2deg(qd_states))
        plt.legend(["qR_d", "qA_d", "qB_d", "qC_d"])
        plt.title("Joint Angular Velocities over Time")
        plt.xlabel("Time (s)")
        plt.ylabel("Joint Angular Velocities (deg/s)")
        plt.legend(["Arm", "Joint 1", "Joint 2", "Joint 3"])

        plt.figure()
        plt.plot(t, states[:, 0], '--')
        plt.plot(t, states[:, 6])
        plt.title("Robot Distance and Velocity over time")
        plt.xlabel("Time (s)")
        plt.ylabel("Distance (mm)")
        plt.legend(["Distance", "Velocity of the robot"])

        points_output.animate(fps=1 / tstep,
                              movie_name=name1,
                              lw=2,
                              marker='o',
                              color=(1, 0, 0, 1),
                              linestyle='-')
    else:
        pass
    return final, states, y1