Factories¶
shinro.factories
ControllerFactory¶
Source code in src/shinro/factories/controller_factory.py
create
¶
create(backend: ArrayBackend = None, plant=None, derive_model: bool = False)
Construct the registered controller from the config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ArrayBackend
|
Array backend for the controller. |
None
|
plant
|
Optional plant for derived-value injection — |
None
|
|
derive_model
|
bool
|
Derive the model from the plant (plant-only mode). |
False
|
Source code in src/shinro/factories/controller_factory.py
EstimatorFactory¶
Source code in src/shinro/factories/estimator_factory.py
create
¶
create(backend: ArrayBackend = None, plant=None, derive_model: bool = False)
Construct the registered estimator from the config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ArrayBackend
|
Array backend for the estimator. |
None
|
plant
|
Optional plant for derived-value injection — |
None
|
|
derive_model
|
bool
|
Derive the model from the plant (plant-only mode). |
False
|
Source code in src/shinro/factories/estimator_factory.py
TrajectoryFactory¶
Scenario¶
Fully composed control loop plus scenario parameters.
sim is the RobotSim instance (engine + plants) for MuJoCo-
backed scenarios, or None for plant-only scenarios where the plant
self-integrates its analytical dynamics. plant is the primary plant
driven by the controller; controller, estimator and trajectory
are the other loop roles. For feedforward scenarios (e.g. phase_list
pick-and-place) controller and estimator are None and the
schedule itself is the control. config is the raw TOML dict (used by
the runner and the tests for tolerances, noise, etc.).
A scenario is a runnable simulation: run executes the whole loop
(closed-loop or feedforward, chosen by whether controller is set),
driven entirely by the TOML — duration, dt, noise, adversarial faults,
input limits and tolerances. iter_run yields one
shinro.simulation.runner.StepRecord per step for live rendering
or early stopping; reset restores the TOML initial state and
clears controller/estimator state.
run
¶
Run the scenario to completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
int | None
|
Number of steps. Defaults to |
None
|
seed
|
int | None
|
Noise RNG seed. Overrides |
None
|
Returns:
| Type | Description |
|---|---|
|
A |
|
|
|
|
|
|
Source code in src/shinro/factories/scenario_factory.py
iter_run
¶
Iterate over the run, yielding one StepRecord per step.
For live rendering or early stopping; run collects the same
records into a shinro.simulation.runner.SimResult.
Source code in src/shinro/factories/scenario_factory.py
reset
¶
Restore the TOML initial state and clear controller/estimator state.
Deterministic reproduction is scenario.reset(); scenario.run(seed=0).
Source code in src/shinro/factories/scenario_factory.py
ScenarioFactory¶
Build a Scenario from a single TOML config.
Config sections
[scenario] name, description, duration, dt, tolerance, input_limits [physics] free_joint, model_path [plant] name (sim-backed) OR type + config + initial_state (plant-only) [controller] type, config (optional) [estimator] type, config (optional) [trajectory] type, config [sim] config (path to the RobotSim TOML; optional) [noise] measurement (optional) [adversarial] inject_at, value (optional)
Two modes:
-
Sim-backed (default): the plant is looked up by
[plant].nameon theRobotSimbuilt from[sim]. When[physics].free_jointis set, the LeKiwi MJCF is rewritten so the arm hangs off a mobile free-jointed base. -
Plant-only: when
[sim]is absent, the plant is built directly from the registry via[plant].type(registered name) and[plant].config(path to a plant TOML).[plant].initial_stateoptionally seeds the state. The plant self-integrates its analytical dynamics — no MuJoCo engine.[scenario].dtmust equal the plant's owndt(the plant integrates at its own time step).
The plant TOML is the single source of physics truth. Controller/estimator
configs never need to restate it: dt is filled from plant.dt when
omitted (a declared dt that disagrees is a loud error), and in
plant-only mode an omitted A_dynamics/B_dynamics model is derived
from the plant via shinro.utils.linearization.linearize_plant
(upright equilibrium) and first-order Euler discretization.
Source code in src/shinro/factories/scenario_factory.py
build
¶
build(backend: ArrayBackend | None = None) -> Scenario
Build and validate the full scenario.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ArrayBackend | None
|
Array backend for controller/estimator/trajectory. Defaults to numpy (the physics engine is always numpy-backed). |
None
|
Returns:
| Type | Description |
|---|---|
Scenario
|
A composed |
Raises:
| Type | Description |
|---|---|
KeyError
|
If a required section or registry type is missing. |
ValueError
|
If component dimensions disagree with the plant. |
Source code in src/shinro/factories/scenario_factory.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |