pySimBlocks.blocks.systems.sofa.sofa_plant

pySimBlocks.blocks.systems.sofa.sofa_plant.sofa_worker(conn, scene_file, input_keys, output_keys, sample_time, block_name)[source]

Worker function executed in a subprocess to run the SOFA simulation.

class pySimBlocks.blocks.systems.sofa.sofa_plant.SofaPlant(name: str, scene_file: str, input_keys: list[str], output_keys: list[str], slider_params: Dict[str, List[float]] | None = None, sample_time: float | None = None)[source]

Bases: Block

SOFA-based dynamic plant block.

Executes a SOFA simulation as a dynamic system driven by pySimBlocks. SOFA runs in a separate subprocess. At each control step, inputs are sent to the worker process, the SOFA scene advances by one step, and updated outputs are returned.

scene_file

Resolved path to the SOFA scene file.

input_keys

Names of input ports sent to SOFA at each step.

output_keys

Names of output ports received from SOFA at each step.

slider_params

Optional ImGui slider configuration, mapping "BlockName.attr" to [min, max] bounds.

direct_feedthrough = False

True if outputs depend directly on inputs.

need_first = True
classmethod adapt_params(params: Dict[str, Any], params_dir: Path | None = None) Dict[str, Any][source]

Resolve a relative scene_file path against the project directory.

Parameters:
  • params – Raw parameter dict loaded from the YAML project file.

  • params_dir – Directory of the project file, for resolving relative paths. Must not be None.

Returns:

Parameter dict with scene_file resolved to an absolute path.

Raises:

ValueError – If params_dir is None or scene_file is missing from params.

initialize(t0: float) None[source]

Start the SOFA worker process and receive initial outputs.

Parameters:

t0 – Initial simulation time in seconds.

Raises:

RuntimeError – If the SOFA worker reports an error during startup.

output_update(t: float, dt: float) None[source]

Forward the committed state outputs to the output ports.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

state_update(t: float, dt: float) None[source]

Send inputs to SOFA, advance one step, and store the new outputs.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

Raises:

RuntimeError – If any input is missing or the SOFA worker reports an error.

finalize() None[source]

Shut down the SOFA worker process cleanly.