Ejemplo n.º 1
0
# initializer for a specific speed
load_init = {'states': {'omega': 20}}

if __name__ == '__main__':
    env = gem.make(
        'DcSeriesCont-v1',
        visualization=MotorDashboard(plots=['omega', 'i'], dark_mode=False),
        motor_parameter=dict(j_rotor=0.001),
        load_parameter=dict(a=0, b=0.1, c=0, j_load=0.001),
        ode_solver='scipy.solve_ivp',
        solver_kwargs=dict(),
        reference_generator=rg.SwitchedReferenceGenerator(
            sub_generators=[
                rg.SinusoidalReferenceGenerator(reference_state='omega'),
                rg.WienerProcessReferenceGenerator(reference_state='omega'),
                rg.StepReferenceGenerator(reference_state='omega')
            ],
            p=[0.2, 0.6, 0.2],
            super_episode_length=(1000, 10000)),

        # Pass the predefined initializers
        motor_initializer=gaussian_init,
        load_initializer=uniform_init,
    )

    # After the setup is done, we are ready to simulate the environment
    # We make use of a standard PI speed controller
    controller = Controller.make('pi_controller', env)
    start = time.time()
    cum_rew = 0
Ejemplo n.º 2
0
        #'DcExtExCont-v1', visualization=MotorDashboard(plots=['omega', 'torque', 'i_a', 'i_e', 'u_a', 'u_e'], visu_period=1), motor_parameter=dict(j_rotor=0.00005), load_parameter={'a': 0, 'b': 0, 'c': 0, 'j_load': 0},
        'DcPermExCont-v1',
        visualization=MotorDashboard(plots=['omega', 'torque', 'i', 'u'],
                                     visu_period=1),
        #'DcSeriesCont-v1', visualization=MotorDashboard(plots=['omega', 'torque', 'i', 'u'], visu_period=1),
        #'DcShuntCont-v1', visualization=MotorDashboard(plots=['omega', 'torque', 'i_a', 'i_e', 'u'], visu_period=1),
        ode_solver='scipy.solve_ivp',
        solver_kwargs=dict(),
        #load=ConstantSpeedLoad(omega_fixed=50 * np.pi / 30),
        reference_generator=rg.SwitchedReferenceGenerator(
            sub_generators=[
                rg.SinusoidalReferenceGenerator(reference_state=ref,
                                                amplitude_range=(0, 0.3),
                                                offset_range=(0, 0.2)),
                rg.WienerProcessReferenceGenerator(reference_state=ref,
                                                   amplitude_range=(0, 0.3),
                                                   offset_range=(0, 0.2)),
                rg.StepReferenceGenerator(reference_state=ref,
                                          amplitude_range=(0, 0.3),
                                          offset_range=(0, 0.2))
            ],
            p=[0.5, 0.25, 0.25],
            super_episode_length=(10000, 100000)),
    )

    try:
        controller = Controller.make('pid_controller',
                                     env,
                                     param_dict={
                                         'p_gain': 10,
                                         'i_gain': 15
Ejemplo n.º 3
0
    env = gem.make(
        'emotor-dc-series-cont-v1',
        # Pass an instance
        visualization=MotorDashboard(plotted_variables='all', visu_period=1),
        motor_parameter=dict(r_a=15e-3, r_e=15e-3, l_a=1e-3, l_e=1e-3),
        # Take standard class and pass parameters (Load)
        load_parameter=dict(a=0.01, b=.1, c=0.1, j_load=.06),

        # Pass a string (with extra parameters)
        ode_solver='euler',
        solver_kwargs={},
        # Pass a Class with extra parameters
        reference_generator=rg.SwitchedReferenceGenerator(
            sub_generators=[
                rg.SinusoidalReferenceGenerator,
                rg.WienerProcessReferenceGenerator(),
                rg.StepReferenceGenerator()
            ],
            p=[0.1, 0.8, 0.1],
            super_episode_length=(1000, 10000)))
    controller = Controller.make('cascaded_pi', env)
    state, reference = env.reset()
    start = time.time()
    cum_rew = 0
    for i in range(100000):
        env.render()
        action = controller.control(state, reference)
        (state, reference), reward, done, _ = env.step(action)
        cum_rew += reward
    print(cum_rew)
Ejemplo n.º 4
0
    """

    env = gem.make(
        'DcSeriesCont-v1',  # replace with 'DcSeriesDisc-v1' for discrete controllers
        state_filter=['omega', 'i'],
        # Pass an instance
        visualization=MotorDashboard(plots=['i', 'omega']),
        # Take standard class and pass parameters (Load)
        motor_parameter=dict(r_a=15e-3, r_e=15e-3, l_a=100e-3, l_e=100e-3),
        load_parameter=dict(a=0, b=.1, c=.1, j_load=0.04),
        # Pass a string (with extra parameters)
        ode_solver='scipy.solve_ivp',
        solver_kwargs={},
        # Pass a Class with extra parameters
        reference_generator=rg.WienerProcessReferenceGenerator())

    # Assign a PI-controller to the speed control problem
    controller = Controller.make('pi_controller', env)
    state, reference = env.reset()

    # get the system time to measure program duration
    start = time.time()

    cum_rew = 0
    for i in range(100000):

        # the render command updates the dashboard
        env.render()

        # the controller accepts state and reference to calculate a new action