Exemplo n.º 1
0
def exercise1():
    """ Exercise 1  """
    pylog.info("Executing Lab 4 : Exercise 1")
    pendulum = PendulumSystem()
    pendulum.parameters = PendulumParameters()

    pylog.info(
        "Find more information about Pendulum Parameters in SystemParameters.py"
    )
    pylog.info("Executing Lab 4 : Exercise 1")

    # Initialize a new pendulum system with default parameters
    pendulum = PendulumSystem()
    pendulum.parameters = PendulumParameters()

    pylog.info(
        "Find more information about Pendulum Parameters in SystemParameters.py"
    )

    # To change a parameter you could so by,
    # >>> pendulum.parameters.L = 1.5
    # The above line changes the length of the pendulum

    # You can instantiate multiple pendulum models with different parameters
    # For example,
    """
    >>> pendulum_1 = PendulumSystem()
    >>> pendulum_1.parameters = PendulumParameters()
    >>> pendulum_1.parameters.L = 0.5
    >>> parameters_2 = PendulumParameters()
    >>> parameters_2.L = 0.5
    >>> pendulum_2 = PendulumSystem(paramters=parameters_2)
    """
    # Above examples shows how to create two istances of the pendulum
    # and changing the different parameters using two different approaches

    pylog.warning("Loading default pendulum pendulum.parameters")
    pylog.info(pendulum.parameters.showParameters())

    # Simulation Parameters
    t_start = 0.0
    t_stop = 10.0
    dt = 0.01
    pylog.warning("Using large time step dt={}".format(dt))
    time = np.arange(t_start, t_stop, dt)
    x0 = [0.5, 0.0]

    res = integrate(pendulum_integration, x0, time, args=(pendulum, ))
    pylog.info("Instructions for applying pertubations")
    # Use pendulum_perturbation method to apply pertubations
    # Define the pertubations inside the function pendulum_perturbation
    # res = integrate(pendulum_perturbation, x0, time, args=(pendulum,))
    res.plot_state("State")
    res.plot_phase("Phase")

    # To animate the model, use the SystemAnimation class
    # Pass the res(states) and systems you wish to animate
    simulation1 = SystemAnimation(res, pendulum, handler="Pendulum animation")
    simulation2 = SystemAnimation(res,
                                  pendulum,
                                  handler="Pendulum animation 2")
    # If you want to disable the parameters in the animation plot
    # simulation2 = SystemAnimation(res, pendulum, handler="Pendulum animation 2", show_parameters=False)
    # To start the animation, use either simulation.animate() or plt.show()
    # simulation.animate()

    if DEFAULT["save_figures"] is False:
        plt.show()
    return
Exemplo n.º 2
0
def exercise1():
    """ Exercise 1  """
    pylog.info("Executing Lab 4 : Exercise 1")
    pendulum = PendulumSystem()
    pendulum.parameters = PendulumParameters()

    pylog.info(
        "Find more information about Pendulum Parameters in SystemParameters.py")
    pylog.info("Executing Lab 4 : Exercise 1")

    # Initialize a new pendulum system with default parameters
    pendulum = PendulumSystem()
    pendulum.parameters = PendulumParameters()

    pylog.info(
        "Find more information about Pendulum Parameters in SystemParameters.py")

    # To change a parameter you could so by,
    # >>> pendulum.parameters.L = 1.5
    # The above line changes the length of the pendulum

    # You can instantiate multiple pendulum models with different parameters
    # For example,
    """
    >>> pendulum_1 = PendulumSystem()
    >>> pendulum_1.parameters = PendulumParameters()
    >>> pendulum_1.parameters.L = 0.5
    >>> parameters_2 = PendulumParameters()
    >>> parameters_2.L = 0.5
    >>> pendulum_2 = PendulumSystem(paramters=parameters_2)
    """
    # Above examples shows how to create two istances of the pendulum
    # and changing the different parameters using two different approaches

    pendulum.parameters.k1 = 50
    pendulum.parameters.k2 = 50
    pendulum.parameters.s_theta_ref1 = 1.0
    pendulum.parameters.s_theta_ref2 = 1.0
    pendulum.parameters.b1 = 0.5
    pendulum.parameters.b2 = 0.5

    pylog.warning("Loading default pendulum pendulum.parameters")
    pylog.info(pendulum.parameters.showParameters())

    # Simulation Parameters
    t_start = 0.0
    t_stop = 10.0
    dt = 0.01
    pylog.warning("Using large time step dt={}".format(dt))
    time = np.arange(t_start, t_stop, dt)
    x0 = [0.5, 0.0]

    res = integrate(pendulum_integration, x0, time, args=(pendulum,))
    pylog.info("Instructions for applying pertubations")
    # Use pendulum_perturbation method to apply pertubations
    # Define the pertubations inside the function pendulum_perturbation
    # res = integrate(pendulum_perturbation, x0, time, args=(pendulum,))
    res.plot_state("State")
    res.plot_phase("Phase")

    x0 = [0.5, 0.1]
    pendulum_limit_cycle(x0, time, pendulum)
    pendulum_spring_constant(x0, time, pendulum)
    pendulum_spring_reference(x0, time, pendulum)
    pendulum_spring_damper(x0, time, pendulum)
    pendulum_set_position(x0, time, pendulum)


    if DEFAULT["save_figures"] is False:
        plt.show()
    return