External Speed Load
Class Description
- class gym_electric_motor.physical_systems.mechanical_loads.ExternalSpeedLoad(speed_profile, load_initializer=None, tau=0.0001, speed_profile_kwargs=None, **kwargs)[source]
External speed mechanical load system which will set the speed to a predefined speed-function/ speed-profile.
- Parameters:
speed_profile (float -> float) –
A callable(t, **speed_profile_args) -> float which takes a timestep t and custom further arguments and returns a speed omega .. rubric:: Example
(lambda t, amplitude, freq: amplitude*numpy.sin(2*pi*f))) with additional parameters:
amplitude(float), freq(float), time(float)
tau (float) – discrete time step of the system
speed_profile_kwargs (dict) – further arguments for speed_profile
kwargs (dict) – Arguments to be passed to superclass
MechanicalLoad
- HAS_JACOBIAN = False
Parameter indicating if the class is implementing the optional jacobian function
- get_state_space(omega_range)
- 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, **__)
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=None)[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)
- next_generator()
Sets a new reference generator for a new episode.
- property nominal_values
Returns: dict(float): Mapping of the motor states to their nominal values
- property omega
Returns: float: Function-value for omega in rad/s at time-step t.
- property random_generator
The random generator that has to be used to draw the random numbers.
- reset(**kwargs)[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)
- seed(seed=None)
The function to set the seed.
This function is called by within the global seed call of the environment. The environment passes the sub-seed to this component that is generated based on the source-seed of the env.
- Parameters:
seed ((np.random.SeedSequence, None)) – Seed sequence to derive new seeds and reference generators at every episode start. Default: None (a new SeedSequence is generated).
- Returns:
A list containing all seeds within this RandomComponent. In general, this list has length 1. If the RandomComponent holds further RandomComponent instances, the list has to contain also these entropies. The entropy of this instance has to be placed always at first place.
- Return type:
List(int)
- property seed_sequence
The base seed sequence that generates the sub generators and sub seeds at every environment reset.
- set_j_rotor(j_rotor)
- 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.