From 80d6209bc220537f1613bac416ffc6167597c78a Mon Sep 17 00:00:00 2001 From: HauckeBa Date: Fri, 15 Nov 2024 15:51:59 +0100 Subject: [PATCH 1/3] fix an issue with gem controllers towards the integrated execution of the environment. --- src/gem_controllers/gem_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gem_controllers/gem_controller.py b/src/gem_controllers/gem_controller.py index 228a3d4d..ab358e22 100644 --- a/src/gem_controllers/gem_controller.py +++ b/src/gem_controllers/gem_controller.py @@ -153,7 +153,7 @@ def control_environment(self, env, n_steps, max_episode_length=np.inf, render_en render_env(bool): Flag, if the states of the environment should be plotted. """ - state, reference = env.reset() + (state, reference), _ = env.reset() if self.block_diagram: self.block_diagram.open() self.reset() @@ -165,7 +165,7 @@ def control_environment(self, env, n_steps, max_episode_length=np.inf, render_en (state, reference), _, done, _ = env.step(action) # Simulate one step of the environment if done or current_episode_length >= max_episode_length: # Reset the environment and controller - state, reference = env.reset() + (state, reference), _ = env.reset() self.reset() current_episode_length = 0 current_episode_length = current_episode_length + 1 From 84c684d118b7d03d9210891d987284f29dec6042 Mon Sep 17 00:00:00 2001 From: HauckeBa Date: Fri, 15 Nov 2024 16:07:26 +0100 Subject: [PATCH 2/3] small fix to address the gymnasium syntax --- src/gem_controllers/gem_controller.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gem_controllers/gem_controller.py b/src/gem_controllers/gem_controller.py index ab358e22..8083c5e8 100644 --- a/src/gem_controllers/gem_controller.py +++ b/src/gem_controllers/gem_controller.py @@ -162,8 +162,8 @@ def control_environment(self, env, n_steps, max_episode_length=np.inf, render_en if render_env: env.render() # Plot the states action = self.control(state, reference) # Calculate the action - (state, reference), _, done, _ = env.step(action) # Simulate one step of the environment - if done or current_episode_length >= max_episode_length: + (state, reference), _, trun, done, _ = env.step(action) # Simulate one step of the environment + if done or trun or current_episode_length >= max_episode_length: # Reset the environment and controller (state, reference), _ = env.reset() self.reset() From acdc6b12b04d439c881955aac3a210aecb747748 Mon Sep 17 00:00:00 2001 From: HauckeBa Date: Fri, 15 Nov 2024 16:20:24 +0100 Subject: [PATCH 3/3] update changelog towards the gem_controllers changes and added the gem_controllers example --- CHANGELOG.md | 1 + examples/gem_controllers/example.py | 37 +++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 examples/gem_controllers/example.py diff --git a/CHANGELOG.md b/CHANGELOG.md index b21a29dc..cd80819f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Dropped support for Python 3.8 - Linted and formatted all files - Changed max. steps in some test files to improve test speed by 30% +- Changed the syntax from gem_controller.py to be compatible with the gymnasium interface ## Fixed - #244 Sphinx docu build - #233 EESM ODE update diff --git a/examples/gem_controllers/example.py b/examples/gem_controllers/example.py new file mode 100644 index 00000000..dec6f9b3 --- /dev/null +++ b/examples/gem_controllers/example.py @@ -0,0 +1,37 @@ +import gym_electric_motor as gem +import gem_controllers as gc +from gym_electric_motor.physical_system_wrappers import FluxObserver + + + +if __name__ == '__main__': + + # choose the action space + action_space = 'Cont' # 'Cont' or 'Finite' + + # choose the control task + control_task = 'CC' # 'SC' (speed control), 'TC' (torque control) or 'CC' (current control) + + # chosse the motor type + motor_type = 'PMSM' # 'PermExDc', 'ExtExDc', 'SeriesDc', 'ShuntDc', 'PMSM', 'EESM', 'SynRM' or 'SCIM' + + env_id = action_space + '-' + control_task + '-' + motor_type + '-v0' + + # using a flux observer for the SCIM + physical_system_wrappers = (FluxObserver(),) if motor_type == 'SCIM' else () + + # Initilize the environment + env = gem.make(env_id, physical_system_wrappers=physical_system_wrappers) + + # Initialize the controller + c = gc.GemController.make( + env, + env_id, + a=8, + block_diagram=True, + current_safety_margin=0.25, + save_block_diagram_as=(), + ) + + # Control the environment + c.control_environment(env, n_steps=30000, render_env=True, max_episode_length=10000) \ No newline at end of file