Пример #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
'''


# We will have a look at a current control scenario here
const_sub_gen = [
    # operation at 10 % of the current limit
    rg.ConstReferenceGenerator(reference_state='i', reference_value=0.1),
    # operation at 90 % of the current limit
    rg.ConstReferenceGenerator(reference_state='i', reference_value=0.9),
    # operation at 110 % of the current limit,
    rg.ConstReferenceGenerator(reference_state='i', reference_value=1.1)
]

# since the case of 110 % current may lead to limit violation, we only assign a small probability of 2 % to it
const_switch_gen = rg.SwitchedReferenceGenerator(
    const_sub_gen, p=[0.49, 0.49, 0.02], super_episode_length=(1000, 2000)
)

# The ExternalSpeedLoad class allows to pass an arbitrary function of time which will then dictate the speed profile.
# As shown here it can also contain more parameters. Some examples:
# Parameterizable sine oscillation
sinus_lambda = (lambda t, frequency, amplitude, bias: amplitude * np.sin(2 * np.pi * frequency * t) + bias)
# Constant speed
constant_lambda = (lambda t, value: value)
# Parameterizable triangle oscillation
triangle_lambda = (lambda t, amplitude, frequency, bias: amplitude * signal.sawtooth(2 * np.pi * frequency * t,
                                                                                     width=0.5) + bias)
# Parameterizable sawtooth oscillation
saw_lambda = (lambda t, amplitude, frequency, bias: amplitude * signal.sawtooth(2 * np.pi * frequency * t,
                                                                                width=0.9) + bias)
Пример #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)
Пример #4
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
                                     })