pySimBlocks.blocks.systems.sofa.sofa_controller¶
- class pySimBlocks.blocks.systems.sofa.sofa_controller.SofaPysimBlocksController(name: str = 'SofaControllerGui')[source]¶
Bases:
_SofaControllerBase SOFA controller class bridging the SOFA simulation loop and pySimBlocks.
Supports two operating modes:
SOFA_MASTER (
SOFA_MASTER=True): SOFA drives the time loop. Aproject_yamlmust be provided. At each pySimBlocks step the controller reads SOFA outputs, runs one pySimBlocks step, and applies the resulting inputs back to SOFA.pySimBlocks master (
SOFA_MASTER=False): pySimBlocks drives the time loop. The controller acts as a pure I/O shell — no model is built or executed internally.Subclasses must implement
set_inputs()andget_outputs().- IS_READY¶
Set to True by
prepare_scene()when the scene is ready to start the control loop.
- SOFA_MASTER¶
If True, SOFA is the time master.
- inputs¶
Dict of input signals written by
set_inputs().
- outputs¶
Dict of output signals populated by
get_outputs().
- dt¶
SOFA simulation time step in seconds. Set automatically at runtime.
- project_yaml¶
Path to the pySimBlocks YAML project file.
- sim¶
The pySimBlocks
Simulatorinstance, or None.
- variables_to_log¶
List of signal names to log at each step.
- node¶
The SOFA node to which the controller is attached, set automatically at runtime.
- step_index¶
Total number of SOFA animation steps executed.
- verbose¶
If True, print logged variables at each control step.
- prepare_scene() None[source]¶
Optional hook executed before the pySimBlocks control loop starts.
Override this method to wait for a preparation condition (e.g. a fixed number of warm-up steps or scene stabilization). Set
self.IS_READY = Truewhen the scene is ready. The default implementation setsIS_READYimmediately.
- set_inputs() None[source]¶
Apply inputs from pySimBlocks to SOFA components.
- Raises:
NotImplementedError – Always — must be implemented by subclasses.
- get_outputs() None[source]¶
Read state from SOFA components and populate
self.outputs.Must always succeed and return consistent shapes across calls.
- Raises:
NotImplementedError – Always — must be implemented by subclasses.
- save() None[source]¶
Optional hook executed at each control step.
Override to save logs or export custom data. The default implementation does nothing.
- get_block(block_name: str)[source]¶
Return a block from the pySimBlocks model by name.
- Parameters:
block_name – Name of the block to retrieve.
- Returns:
The block instance with the specified name.
- Raises:
RuntimeError – If the simulator is not initialized or if the block is not found in the model.
- onAnimateBeginEvent(event) None[source]¶
SOFA callback executed before each physical integration step.
When
SOFA_MASTER=True, runs the following sequence at each pySimBlocks step:Read SOFA outputs via
get_outputs().Push them into the exchange block.
Advance pySimBlocks one step.
Retrieve controller inputs from the exchange block.
Apply them to SOFA via
set_inputs().
- Parameters:
event – SOFA animation event (unused).