soft4pes.sim#

Simulation environment.

Submodules#

Classes#

Simulation

Simulation environment.

Package Contents#

class soft4pes.sim.Simulation(sys, ctr, Ts_sim, disc_method='forward_euler')[source]#

Simulation environment.

Parameters:
  • sys (system object) – System model.

  • ctr (controller object) – Control system.

  • Ts_sim (float) – Simulation sampling interval [s].

sys#

System model.

Type:

system object

ctr#

Control system.

Type:

controller object.

Ts_sim#

Simulation sampling interval [s].

Type:

float

t_stop#

Simulation stop time [s].

Type:

float

matrices#

Discrete state-space matrices of the simulated system.

Type:

SimpleNamespace

simulation_data#

Data from the simulation.

Type:

dict

simulate(t_stop)[source]#

Simulate the system.

Parameters:

t_stop (float) – Simulation length [s]. Simulation start time is always 0 s, i.e. kTs = 0.

save_data(filename='sim_data.mat', path='')[source]#

Save the simulation data to a .mat file.

Parameters:
  • filename (str, optional) – Name of the file to save the data to. The default filename is ‘sim_data.mat’.

  • path (str, optional) – Directory path to save the file to. The path can be absolute or relative to the current directory. The default saving directory is the current directory.

process_simulation_data(data)[source]#

Recursively convert lists of arrays in a SimpleNamespace to NumPy arrays.

Parameters:

data (SimpleNamespace or list of ndarray) – The data to be converted. Can be a SimpleNamespace or a list of arrays.

Returns:

A SimpleNamespace with lists of arrays converted to NumPy arrays, or a NumPy array if the input is a list of arrays.

Return type:

SimpleNamespace or ndarray