示例#1
0
                            linewidth=2.0)

    image.patches.append(sphere1)
    image.patches.append(sphere2)
    image.patches.append(car)
    image.patches.append(joint)
    image.lines.append(rod1)
    image.lines.append(rod2)

    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='ex2_InvertedDualPendulumSwingUp.pcl')

if 'plot' in sys.argv or 'animate' in sys.argv:
    A = Animation(drawfnc=draw,
                  simdata=S.sim_data,
                  plotsys=[(0, 'x'), (2, 'phi1'), (4, 'phi2')],
                  plotinputs=[(0, 'u')])

    xmin = np.min(S.sim_data[1][:, 0])
    xmax = np.max(S.sim_data[1][:, 0])
    A.set_limits(xlim=(xmin - 1.0, xmax + 1.0), ylim=(-0.8, 0.8))

if 'plot' in sys.argv:
    A.show(t=S.b)

if 'animate' in sys.argv:
                           color='black',
                           zorder=1,
                           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()
示例#3
0
                      maxIt=3,
                      eps=1e-1,
                      sol_steps=100,
                      reltol=1e-3,
                      accIt=1,
                      show_ir=True)

# dt_sim=0.004
# time to run the iteration
x, u = S.solve()
if S.reached_accuracy:
    print "successed!"
else:
    print "Not successed!"

S.save(fname='pickles/model_trajectory' + str(Tb) + '.pcl')

import sys
import matplotlib as mpl
from pytrajectory.visualisation import Animation
from sympy import cos, sin

N = 3
# all rods have the same length
rod_lengths = [0.5] * N

# all pendulums have the same size
pendulum_sizes = [0.015] * N

car_width, car_height = [0.05, 0.02]
    # joint
    joint = mpl.patches.Circle((x_car, 0), 0.005, color='k')

    image.lines.append(rod)
    image.patches.append(sphere)
    image.patches.append(cart)
    image.patches.append(joint)

    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='ex1_InvertedPendulumTranslation.pcl')

if 'plot' in sys.argv or 'animate' in sys.argv:
    A = Animation(drawfnc=draw,
                  simdata=S.sim_data,
                  plotsys=[(0, 'x'), (2, 'phi')],
                  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.5, xmax + 0.5), ylim=(-0.3, 0.8))

if 'plot' in sys.argv:
    A.show(t=S.b)

if 'animate' in sys.argv:
示例#5
0
        print S.eqs.solver.res, "\n"
        print S.eqs.solver.x0[:9]
        sim_res.append(S.sim_data_xx[-1])
        residum_res.append(S.eqs.solver.res)
        if S.reached_accuracy:
            print "success", i
            userinput = raw_input("Press `q` to quit.\n")
            if userinput == "q":
                break
        else:
            print "fail"

        reslist.append(S.eqs.solver.x0)
        time.sleep(2)

    S.save(fname='model_trajectory.pcl')
    IPS()

import matplotlib as mpl
from pytrajectory.visualisation import Animation
from sympy import cos, sin

N = 3
# all rods have the same length
rod_lengths = [0.5] * N

# all pendulums have the same size
pendulum_sizes = [0.015] * N

car_width, car_height = [0.08, 0.04]
示例#6
0
    # pendulums
    sphere1 = mpl.patches.Circle((x1, y1), 0.01, color='k')
    sphere2 = mpl.patches.Circle((0, 0), 0.01, color='k')

    image.lines.append(rod1)
    image.lines.append(rod2)
    image.patches.append(sphere1)
    image.patches.append(sphere2)

    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='ex5_Acrobot.pcl')

if 'plot' in sys.argv or 'animate' in sys.argv:
    A = Animation(drawfnc=draw,
                  simdata=S.sim_data,
                  plotsys=[(0, 'phi1'), (2, 'phi2')],
                  plotinputs=[(0, 'u')])
    A.set_limits(xlim=(-1.1, 1.1), ylim=(-1.1, 1.1))

if 'plot' in sys.argv:
    A.show(t=S.b)

if 'animate' in sys.argv:
    A.animate()
    A.save('ex5_Acrobot.gif')
示例#7
0
    xx = S[:, 0].copy()
    yy = S[:, 1].copy()

    S[:, 0] = xx * cos(theta) - yy * sin(theta) + x
    S[:, 1] = yy * cos(theta) + xx * sin(theta) + y

    aircraft = mpl.patches.Polygon(S, closed=True, facecolor='0.75')
    image.patches.append(aircraft)

    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='ex3_Aircraft.pcl')

if 'plot' in sys.argv or 'animate' in sys.argv:
    A = Animation(drawfnc=draw,
                  simdata=S.sim_data,
                  plotsys=[(4, 'theta')],
                  plotinputs=[(0, 'F1'), (1, 'F2')])
    A.set_limits(xlim=(-1, 11), ylim=(-1, 7))

if 'plot' in sys.argv:
    A.show(t=S.b)

if 'animate' in sys.argv:
    A.animate()
    A.save('ex3_Aircraft.gif')
示例#8
0
    rod1 = mpl.lines.Line2D([0,x1],[0,y1],color='k',zorder=0,linewidth=2.0)
    rod2 = mpl.lines.Line2D([x1,x2],[y1,y2],color='k',zorder=0,linewidth=2.0)
    
    # pendulums
    sphere1 = mpl.patches.Circle((x1,y1),0.01,color='k')
    sphere2 = mpl.patches.Circle((0,0),0.01,color='k')
    
    image.lines.append(rod1)
    image.lines.append(rod2)
    image.patches.append(sphere1)
    image.patches.append(sphere2)
    
    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='ex4_UnderactuatedManipulator.pcl')

if 'plot' in sys.argv or 'animate' in sys.argv:
    A = Animation(drawfnc=draw, simdata=S.sim_data,
                  plotsys=[(0,'phi1'), (2,'phi2')], plotinputs=[(0,'u')])
    A.set_limits(xlim= (-0.1,0.6), ylim=(-0.4,0.65))

if 'plot' in sys.argv:
    A.show(t=S.b)

if 'animate' in sys.argv:
    A.animate()
    A.save('ex4_UnderactuatedManipulator.gif')
示例#9
0
                           linewidth=2.0)

    # finally we add the patches and line to the image
    image.patches.append(pendulum)
    image.patches.append(car)
    image.patches.append(joint)
    image.lines.append(rod)

    # and return the image
    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='ex0_InvertedPendulumSwingUp.pcl')

# now we can create an instance of the `Animation` class
# with our draw function and the simulation results
#

# this was aked for by one user:
# save the simulation data (solution of IVP) to csv

tt, xx, uu = S.sim_data
export_array = np.hstack((tt.reshape(-1, 1), xx, uu))

# to actually save the array uncomment the following:
# np.savetxt("ex0_result.csv", export_array, delimiter=",")

# first column: time
    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()
示例#11
0
    # add the patches and lines to the image
    image.patches.append(pendulum1)
    image.patches.append(pendulum2)
    image.patches.append(car)
    image.patches.append(joint)
    image.lines.append(rod1)
    image.lines.append(rod2)

    # and return the image
    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='ex8_ConstrainedDoublePendulum.pcl')

if 'plot' in sys.argv or 'animate' in sys.argv:
    # create Animation object
    A = Animation(drawfnc=draw,
                  simdata=S.sim_data,
                  plotsys=[(0, '$x$'), (1, '$\\dot{x}$')],
                  plotinputs=[(0, '$u$')])
    xmin = np.min(S.sim_data[1][:, 0])
    xmax = np.max(S.sim_data[1][:, 0])
    A.set_limits(xlim=(xmin - 1.0, xmax + 1.0), ylim=(-1.2, 1.2))

if 'plot' in sys.argv:
    A.show(t=S.b)

if 'animate' in sys.argv: