-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathclassic_controllers_synch_motor_example.py
More file actions
76 lines (60 loc) · 2.71 KB
/
classic_controllers_synch_motor_example.py
File metadata and controls
76 lines (60 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from gym_electric_motor.envs.motors import ActionType, ControlType, Motor, MotorType
from classic_controllers import Controller
from externally_referenced_state_plot import ExternallyReferencedStatePlot
import gym_electric_motor as gem
from gym_electric_motor.visualization import MotorDashboard
if __name__ == "__main__":
"""
motor type: 'PMSM' Permanent Magnet Synchronous Motor
'SynRM' Synchronous Reluctance Motor
control type: 'SC' Speed Control
'TC' Torque Control
'CC' Current Control
action_type: 'Cont' Continuous Action Space in ABC-Coordinates
'Finite' Discrete Action Space
"""
"""
motor_type = "PMSM"
control_type = "TC"
action_type = "Cont"
"""
motor = Motor(
MotorType.PermanentMagnetSynchronousMotor,
ControlType.TorqueControl,
ActionType.Continuous
)
# definition of the plotted variables
external_ref_plots = [
ExternallyReferencedStatePlot(state) for state in ["omega", "torque", "i_sd", "i_sq", "u_sd", "u_sq"]
]
motor_dashboard = MotorDashboard(additional_plots=external_ref_plots)
# initialize the gym-electric-motor environment
env = gem.make(
motor.env_id(), visualization=motor_dashboard
)
"""
initialize the controller
Args:
environment gym-electric-motor environment
external_ref_plots (optional) plots of the environment, to plot all reference values
stages (optional) structure of the controller
automated_gain (optional) if True (default), the controller will be tune automatically
a (optional) tuning parameter of the Symmetrical Optimum (default: 4)
additionally for TC or SC:
torque_control (optional) mode of the torque controller, 'interpolate' (default), 'analytical' or 'online'
plot_torque(optional) plot some graphs of the torque controller (default: True)
plot_modulation (optional) plot some graphs of the modulation controller (default: False)
"""
controller = Controller.make(
env, external_ref_plots=external_ref_plots, torque_control="analytical"
)
(state, reference), _ = env.reset()
# simulate the environment
for i in range(10001):
action = controller.control(state, reference)
(state, reference), reward, terminated, truncated, _ = env.step(action)
if terminated:
env.reset()
controller.reset()
motor_dashboard.show()
env.close()