Skip to content

Commit

Permalink
Added pole pair number to angle advancement (Issue #224) and added EE…
Browse files Browse the repository at this point in the history
…SM (Issue #231)
  • Loading branch information
XyDrKRulof committed May 29, 2024
1 parent 173e25c commit 35e1b30
Showing 1 changed file with 39 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from .physical_system_wrapper import PhysicalSystemWrapper


class DqToAbcActionProcessor(PhysicalSystemWrapper):
"""The DqToAbcActionProcessor converts an inner system with an AC motor and actions in abc coordinates to a
system to which actions in the dq-coordinate system can be applied.
Expand All @@ -31,12 +30,11 @@ def register_transformation(cls, motor_types):
def wrapper(callable_):
for motor_type in motor_types:
cls._registry[motor_type] = callable_

return wrapper

@classmethod
def make(cls, motor_type, *args, **kwargs):
assert motor_type in cls._registry.keys(), f"Not supported motor_type {motor_type}."
assert motor_type in cls._registry.keys(), f'Not supported motor_type {motor_type}.'
class_ = cls._registry[motor_type]
inst = class_(*args, **kwargs)
return inst
Expand All @@ -58,21 +56,20 @@ def __init__(self, angle_name, physical_system=None):

def set_physical_system(self, physical_system):
# Docstring of super class
assert isinstance(
physical_system.electrical_motor, ps.ThreePhaseMotor
), "The motor in the system has to derive from the ThreePhaseMotor to define transformations."
assert isinstance(physical_system.electrical_motor, ps.ThreePhaseMotor), \
'The motor in the system has to derive from the ThreePhaseMotor to define transformations.'
super().set_physical_system(physical_system)
self._omega_index = physical_system.state_names.index("omega")
self._omega_index = physical_system.state_names.index('omega')
self._angle_index = physical_system.state_names.index(self._angle_name)
assert self._angle_name in physical_system.state_names, (
f"Angle {self._angle_name} not in the states of the physical system. "
f"Probably a flux observer is required."
)
self._pole_pair_number = physical_system._electrical_motor.motor_parameter['p']
assert self._angle_name in physical_system.state_names, \
f'Angle {self._angle_name} not in the states of the physical system. ' \
f'Probably a flux observer is required.'

self._angle_advance = 0.5

# If dead time has been added to the system increase the angle advance by the amount of dead time steps
if hasattr(physical_system, "dead_time"):
if hasattr(physical_system, 'dead_time'):
self._angle_advance += physical_system.dead_time

return self
Expand All @@ -87,10 +84,12 @@ def reset(self, **kwargs):
return normalized_state

def _advance_angle(self, state):
return state[self._angle_index] + self._angle_advance * self._physical_system.tau * state[self._omega_index]
return state[self._angle_index] + self._angle_advance \
* self._physical_system.tau * state[self._omega_index] * self._pole_pair_number


class _ClassicDqToAbcActionProcessor(DqToAbcActionProcessor):

@property
def action_space(self):
return gymnasium.spaces.Box(-1, 1, shape=(2,), dtype=np.float64)
Expand All @@ -104,24 +103,25 @@ def simulate(self, action):
return normalized_state


DqToAbcActionProcessor.register_transformation(["PMSM"])(
lambda angle_name="epsilon", *args, **kwargs: _ClassicDqToAbcActionProcessor(angle_name, *args, **kwargs)
DqToAbcActionProcessor.register_transformation(['PMSM'])(
lambda angle_name='epsilon', *args, **kwargs: _ClassicDqToAbcActionProcessor(angle_name, *args, **kwargs)
)

DqToAbcActionProcessor.register_transformation(["SCIM"])(
lambda angle_name="psi_angle", *args, **kwargs: _ClassicDqToAbcActionProcessor(angle_name, *args, **kwargs)
DqToAbcActionProcessor.register_transformation(['SCIM'])(
lambda angle_name='psi_angle', *args, **kwargs: _ClassicDqToAbcActionProcessor(angle_name, *args, **kwargs)
)


@DqToAbcActionProcessor.register_transformation(["DFIM"])
@DqToAbcActionProcessor.register_transformation(['DFIM'])
class _DFIMDqToAbcActionProcessor(DqToAbcActionProcessor):

@property
def action_space(self):
return gymnasium.spaces.Box(-1, 1, shape=(4,))

def __init__(self, physical_system=None):
super().__init__("epsilon", physical_system=physical_system)
self._flux_angle_name = "psi_abs"
super().__init__('epsilon', physical_system=physical_system)
self._flux_angle_name = 'psi_abs'
self._flux_angle_index = None

def simulate(self, action):
Expand All @@ -144,5 +144,23 @@ def simulate(self, action):

def set_physical_system(self, physical_system):
super().set_physical_system(physical_system)
self._flux_angle_index = physical_system.state_names.index("psi_angle")
self._flux_angle_index = physical_system.state_names.index('psi_angle')
return self

@DqToAbcActionProcessor.register_transformation(['EESM'])
class _EESMDqToAbcActionProcessor(DqToAbcActionProcessor):
@property
def action_space(self):
return gymnasium.spaces.Box(-1, 1, shape=(3,))

def __init__(self, physical_system=None):
super().__init__('epsilon', physical_system=physical_system)

def simulate(self, action):
# Docstring of superclass
advanced_angle = self._advance_angle(self._state)
abc_action = self._transformation(action[:-1], advanced_angle)
abc_action = np.append(abc_action, action[-1])
normalized_state = self._physical_system.simulate(abc_action)
self._state = normalized_state * self._physical_system.limits
return normalized_state

0 comments on commit 35e1b30

Please sign in to comment.