API
Model
- class pysimlink.Model(model_name: str, path_to_model: str, compile_type: str = 'grt', suffix: str = 'rtw', tmp_dir: anno.Optional[str] = None, force_rebuild: bool = False, skip_compile: bool = False, generator: str = None)[source]
- Instance of the simulink mode. This class compiles and imports the model once built. You can have multiple instances of the same model in one python runtime. - __init__(model_name: str, path_to_model: str, compile_type: str = 'grt', suffix: str = 'rtw', tmp_dir: anno.Optional[str] = None, force_rebuild: bool = False, skip_compile: bool = False, generator: str = None)[source]
- Parameters:
- model_name (str) – name of the root simulink model 
- path_to_model (str) – path to the directory containing code generated from the Simulink Coder or the packaged zip file 
- compile_type (str) – Makefile template used to generate code from Simulink Coder. Only GRT is supported. 
- suffix (str) – Simulink Coder folders are almost always suffixed with rtw (real time workshop). 
- tmp_dir (Optional[str]) – Path to the directory that will be used to build the model. Defaults to - __pycache__/model_name
- force_rebuild (bool) – force pysimlink to recompile the model from the source located at - path_to_model. Removes all build artifacts.
- skip_compile (bool) – skip compilation of the model. This is useful if you have already compiled the model and just want to import it. 
- generator (str) – Type of generator to use for cmake. defaults to - NMake Makefileson windows and- Unix Makefileson mac/linux.
 
 - orientations
- enumeration describing matrix orientations (row major, column major, etc.). This enumeration is likely the same among all models, but could change across MATLAB versions. 
 
 - get_block_param(block_path, param, model_name=None) ndarray[source]
- Get the value of a block parameter - Parameters:
- block_path – Path the block within the model 
- param – Name of the parameter to retrieve 
- model_name – Name of the model provided by - pysimlink.print_all_params(). None if there are no model references.
 
- Returns:
- np.ndarray with the value of the parameter 
 
 - get_model_param(param, model_name=None) ndarray[source]
- Get the value of a model parameter - Parameters:
- param – Name of the parameter to retrieve 
- model_name – Name of the model provided by - pysimlink.print_all_params(). None if there are no model references.
 
- Returns:
- np.ndarray with the value of the parameter 
 
 - get_models() list[str][source]
- Gets a list of all reference models (and the root model) in this model. - Returns:
- list of paths, one for each model 
 
 - get_params() list[anno.ModelInfo][source]
- Return an instance of all parameters, blocks, and signals in the _model - See - pysimlink.print_all_params()for iterating and printing the contents of this object- Returns:
- List of model info, one for each model (if reference models present). One ModelInfo if no reference models 
- Return type:
 
 - get_signal(block_path, model_name=None, sig_name='') ndarray[source]
- Get the value of a signal - Parameters:
- block_path – Path to the originating block 
- model_name – Name of the model provided by - pysimlink.print_all_params(). None if there are no model references (using- Nonewill retrieve from the root model).
- sig_name – Name of the signal 
 
- Returns:
- Value of the signal at the current timestep 
 
 - reset()[source]
- Reset the simulink model. This clears all signal values and reinstantiates the model. 
 - set_block_param(block: str, param: str, value: anno.ndarray, model_name: anno.Union[str, None] = None)[source]
- Set the parameter of a block within the model. - Parameters:
- block – Path to the block within the model 
- param – Name of the parameter to change 
- value – new value of the parameter 
- model_name – Name of the model provided by - pysimlink.print_all_params(). None if there are no model references.
 
- Raises:
- RuntimeError – If the value array is not the correct shape or orientation as the parameter to change 
 
 - set_model_param(param: str, value: anno.ndarray, model_name: anno.Union[str, None] = None)[source]
- Set a model parameter. - Parameters:
- param – Name of the parameter to change 
- value – new value of the parameter 
- model_name – Name of the model provided by - pysimlink.print_all_params(). None if there are no model references.
 
- Raises:
- RuntimeError – If the value array is not the correct shape or orientation as the parameter to change 
 
 - set_tFinal(tFinal: float)[source]
- Change the final timestep of the model - Parameters:
- tFinal – New final timestep of the model (seconds from zero). 
- Raises:
- ValueError – if tFinal is <= 0 
 
 - step(iterations: int = 1)[source]
- Step the simulink model - Parameters:
- iterations – Number of timesteps to step internally. - model.step(10)is equivalent to calling- for _ range(10): model.step(1)functionally, but compiled.
- Raises:
- RuntimeError – If the model encounters an error (these will be raised from simulink). Most commonly, this will be simulation complete. 
 
 - property step_size: float
- Get the step size of the model - Returns:
- step size of the fixed step solver. 
- Return type:
- float 
 
 - property tFinal: float
- Get the final timestep of the model. - Returns:
- Final timestep of the model (seconds from zero). 
- Return type:
- float 
 
 
Model Structures
- class pysimlink.types.ModelInfo(obj: anno.c_model_info)
- Object returned from - pysimlink.Model.get_params().- Note - This object only describes a single model. If a Simulink model contains model references, - pysimlink.Model.get_params()will return a list of this object, each describing a reference model.- model_name
- Name of the model this object describes - Type:
- str 
 
 - model_params
- List of all model parameters - Type:
- list[ - ModelParam]
 
 - block_params
- List of all block parameters - Type:
- list[ - BlockParam]
 
 
- class pysimlink.types.ModelParam(obj: anno.c_model_param)
- Represents a single model parameter. - model_param
- Name of the model parameter (these are usually stored withing the model workspace in simulink) - Type:
- str 
 
 
- class pysimlink.types.BlockParam(obj: anno.c_model_block_param)
- Represents a single parameter in a block. - If a block has n parameters, there will be n BlockParam instances. Each with the same - block_name.- block_name
- The name (usually including the path) to this block. - Type:
- str 
 
 - block_param
- The name of the parameter within the block - Type:
- str 
 
 
- class pysimlink.types.Signal(obj: anno.c_model_signal)
- Represents a single signal in the model. - block_name
- name and path to the block the signal originates from - Type:
- str 
 
 - signal_name
- name of the signal (empty if not named) - Type:
- str 
 
 
- class pysimlink.types.DataType(obj: anno.c_model_datatype)
- Contains data type information for a single parameter. - cDataType
- The c equivalent name of this datatype - Type:
- str 
 
 - pythonType
- The python name of this datatype - Type:
- str 
 
 - dims
- List of dimension sizes. (the shape of the array) - Type:
- list[int] 
 
 - orientation
- Enumeration indicating if this is a scalar, vector, column major or row major array. Since this enum is evaluated at compile time, it is imported from the compiled model. To check this value dynamically, use - pysimlink.Model.orientations.- Type:
- int