x_car = x y_car = 0 car = mpl.patches.Rectangle((x_car-0.5*car_width, y_car-car_heigth), car_width, car_heigth, fill=True, facecolor='grey', linewidth=2.0) image.patches.append(car) return image if not 'no-pickle' in sys.argv: # here we save the simulation results so we don't have to run # the iteration again in case the following fails S.save(fname='ex6_ConstrainedDoubleIntegrator.pcl') if 'plot' in sys.argv or 'animate' in sys.argv: A = Animation(drawfnc=draw, simdata=S.sim_data, plotsys=[(0,'x'), (1,'dx')], plotinputs=[(0,'u')]) xmin = np.min(S.sim_data[1][:,0]) xmax = np.max(S.sim_data[1][:,0]) A.set_limits(xlim=(xmin - 0.1, xmax + 0.1), ylim=(-0.1,0.1)) if 'plot' in sys.argv: A.show(t=S.b) if 'animate' in sys.argv: A.animate() A.save('ex6_ConstrainedDoubleIntegrator.gif')
linewidth=2.0) image.patches.append(pendulum) image.patches.append(car) image.patches.append(joint) image.lines.append(rod) return image if not 'no-pickle' in sys.argv: # here we save the simulation results so we don't have to run # the iteration again in case the following fails S.save(fname='ex7_ConstrainedInvertedPendulum.pcl') if 'plot' in sys.argv or 'animate' in sys.argv: A = Animation(drawfnc=draw, simdata=S.sim_data, plotsys=[(0, 'x'), (1, 'dx')], plotinputs=[(0, 'u1')]) xmin = np.min(S.sim_data[1][:, 0]) xmax = np.max(S.sim_data[1][:, 0]) A.set_limits(xlim=(xmin - 0.5, xmax + 0.5), ylim=(-0.6, 0.6)) if 'plot' in sys.argv: A.show(t=S.b) if 'animate' in sys.argv: A.animate() A.save('ex7_ConstrainedInvertedPendulum.gif')
image.patches.append(joint) image.lines.append(rod) # and return the image return image sol_data = tt, xx, uu # to plot the curves of some trajectories along with the picture # we also pass the appropriate lists as arguments (see documentation) A = Animation(drawfnc=draw, simdata=sol_data, plotsys=[(0,'x'), (2,'phi')], plotinputs=[(0,'u')]) # as for now we have to explicitly set the limits of the figure # (may involve some trial and error) xmin = np.min(xx[:,0]); xmax = np.max(xx[:,0]) A.set_limits(xlim=(xmin - 0.5, xmax + 0.5), ylim=(-0.6,0.6)) if 'animate' in sys.argv: # if everything is set, we can start the animation # (might take some while) A.animate() # then we can save the animation as a `mp4` video file or as an animated `gif` file A.save('InvertedPendulum.gif') else: A.show(t=tt[-1])