args=({ 'constants': {}, 'alpha': 1e2, 'beta': 1e1 }, )) lambda1_n = numpy.array([lambda1(tt, ss) for tt, ss in zip(t, states)]) plt.figure() plt.plot(t, lambda1_n) # ============================================================================= 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()
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()
func1,lambda1 = system.state_space_post_invert(f,ma,eq_dd,return_lambda = True) states=pynamics.integration.integrate(func1,ini,t,rtol=tol,atol=tol, args=({'constants':system.constant_values},)) # Plot --- output plt.figure() artists = plt.plot(t,states[:,:3]) plt.legend(artists,['qA','qB','qC']) # Plot --- energy KE = system.get_KE() PE = system.getPEGravity(pNA) - system.getPESprings() energy_output = Output([KE-PE],system) energy_output.calc(states) energy_output.plot_time() # Motion points = [pNA,pAB,pBtip,pBC, pCD] points_output = PointsOutput(points,system) y = points_output.calc(states) points_output.plot_time(20) points_output.animate(fps = 30,lw=2) from matplotlib import animation, rc from IPython.display import HTML HTML(points_output.anim.to_html5_video()) """From the animation above, we see that because we set the neutral position of the device to stand straight (vertical sides for the four-bar mechanism), our device would not just freely drop to the ground.
states = pynamics.integration.integrate_odeint(func1, ini, t, rtol=1e-10, atol=1e-10, args=({ 'constants': constants, 'alpha': 1e2, 'beta': 1e1 }, )) # ============================================================================= 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()
statevariables = system.get_state_variables() ini = [initialvalues[item] for item in statevariables] tol = 1e-10 tinitial = 0 tfinal = 10 fps = 30 tstep = 1 / fps t = numpy.r_[tinitial:tfinal:tstep] constants = system.constant_values.copy() states = pynamics.integration.integrate_odeint(func1, ini, t, rtol=tol, atol=tol, args=({ 'constants': constants }, )) states_min = [qNA, qAB, qBC] states_min_out = Output(states_min, system) states_min_out.calc(states, t) states_min_out.plot_time() points = [pBase, pAB, pBC, pCtip] points_output = PointsOutput(points, system) points_output.calc(states, t) points_output.plot_time(20) # points_output.animate(fps = fps,movie_name = 'triple_pendulum_maximal.mp4',lw=2,marker='o',color=(1,0,0,1),linestyle='-')