Mechanical Loads

MechanicalLoad Base Class

class gym_electric_motor.physical_systems.mechanical_loads.MechanicalLoad(state_names=None, j_load=0.0, load_initializer=None)[source]

The MechanicalLoad is the base class for all the mechanical systems attached to the electrical motors rotor.

It contains an mechanical ode system as well as the state names, limits and nominal values of the mechanical quantities. The only required state is ‘omega’ as the rotational speed of the motor shaft in rad/s. ConstantSpeedLoad can be initialized with the initializer as an class parameter by instantiation. ExternalSpeedLoad takes the first value of the SpeedProfile as initial value.

Initialization is given by initializer(dict). Can be a constant state value or random value in given interval. dict should be like:

{ ‘states’(dict): with state names and initial values
‘interval’(array like): boundaries for each state

(only for random init), shape(num states, 2)

‘random_init’(str): ‘uniform’ or ‘normal’ ‘random_params(tuple): mue(float), sigma(int)

Example initializer(dict) for constant initialization:

{ ‘states’: {‘omega’: 16.0}}

Example initializer(dict) for random initialization:

{ ‘random_init’: ‘normal’}

Parameters:
  • state_names (list(str)) – List of the names of the states in the mechanical-ODE.

  • j_load (float) – Moment of inertia of the load affecting the motor shaft.

HAS_JACOBIAN = False

Parameter indicating if the class is implementing the optional jacobian function

get_state_space(omega_range)[source]
Parameters:

omega_range (Tuple(int,int)) – Lower and upper values the motor can generate for omega normalized to (-1, 1)

Returns:

Lowest and highest possible values for all states normalized to (-1, 1)

Return type:

Tuple(dict,dict)

initialize(state_space, state_positions, nominal_state, **__)[source]

Initializes the state of the load on an episode start.

Values can be given as a constant or sampled random out of a statistical distribution. Initial value is in range of the nominal values or a given interval.

Parameters:
  • nominal_state (list) – nominal values for each state given from physical system

  • state_space (gymnasium.spaces.Box) – normalized state space boundaries

  • state_positions (dict) – indexes of system states

property initializer

Returns: dict: The motors initial state and additional initializer parameters

property j_total

Returns: float: Total moment of inertia affecting the motor shaft.

property limits

Returns: dict(float): Mapping of the motor states to their limit values.

mechanical_jacobian(t, mechanical_state, torque)[source]

Calculation of the jacobians of the mechanical-ODE for each of the mechanical state.

Overriding this method is optional for each subclass. If it is overridden, the parameter HAS_JACOBIAN must also be set to True. Otherwise, the jacobian will not be called.

Parameters:
  • t (float) – Current time of the system.

  • mechanical_state (ndarray(float)) – Current state of the mechanical system.

  • torque (float) – Generated input torque by the electrical motor.

Returns:

[0]: Derivatives of the mechanical_state-odes over the mechanical_states shape:(states x states) [1]: Derivatives of the mechanical_state-odes over the torque shape:(states,)

Return type:

Tuple(ndarray, ndarray)

mechanical_ode(t, mechanical_state, torque)[source]

Calculation of the derivatives of the mechanical-ODE for each of the mechanical states.

Parameters:
  • t (float) – Current time of the system.

  • mechanical_state (ndarray(float)) – Current state of the mechanical system.

  • torque (float) – Generated input torque by the electrical motor.

Returns:

Derivatives of the mechanical state for the given input torque.

Return type:

ndarray(float)

property nominal_values

Returns: dict(float): Mapping of the motor states to their nominal values

reset(state_space, state_positions, nominal_state, **__)[source]

Reset the motors state to a new initial state. (Default 0)

Parameters:
  • nominal_state (list) – nominal values for each state given from physical system

  • state_space (gymnasium.Box) – normalized state space boundaries

  • state_positions (dict) – indexes of system states

Returns:

The initial motor states.

Return type:

numpy.ndarray(float)

set_j_rotor(j_rotor)[source]
Parameters:

j_rotor (float) – The moment of inertia of the rotor shaft of the motor.

property state_names

Returns: list(str): Names of the states in the mechanical-ODE.