Scenario API
skelarm.scenario
Load a full control scenario (robot + task + controller) from one TOML file.
A combined config mirrors the per-section schema used by :meth:Skeleton.from_toml:
[skeleton] and [initial] describe the robot and its start state, [task]
the goal (a task-space target with a movement duration), and [controller] which
controller drives the reach. :func:load_scenario reads all three.
Example::
[task]
type = "reaching" # the task kind (required)
target = [0.55, 1.21] # endpoint goal (x, y) in meters (required for reaching)
duration = 2.0 # simulated time (s)
dt = 0.002 # control step (s)
[controller]
type = "computed_torque"
kp = 200.0
kd = 30.0
Scenario
dataclass
A loaded control scenario: the robot, the task, the simulator, and the controller.
source_config keeps the original combined config (the parsed [skeleton] /
[initial] / [task] / [simulator] / [controller] tables) when the
scenario was loaded from a file, so a run can embed it for an exact, editable re-run;
it is None for scenarios built programmatically.
Source code in src/skelarm/scenario.py
Simulator
dataclass
Numerical-integration parameters for the dynamics, from the [simulator] table.
These are run/execution concerns, kept separate from the task (the desired motion).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt
|
float
|
Control / integration step (seconds). Also the MPC prediction step. |
0.002
|
enforce_limits
|
bool
|
Apply the joint limits as hard stops in the dynamics (default). When |
True
|
Source code in src/skelarm/scenario.py
from_dict(section)
classmethod
Build a Simulator from a [simulator] mapping (defaults when keys are absent).
Source code in src/skelarm/scenario.py
Task
dataclass
A task and the run conditions for it.
The required field is type — the kind of task, which determines what else is
needed. reaching (the only built-in) requires a target; other task types
(see :func:register_task_type) carry their own data on :attr:params and may
omit the target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type
|
str
|
The task kind (the |
required |
target
|
NDArray[float64] | None
|
The endpoint goal |
None
|
label
|
str | None
|
Optional name for the target, used to select it among multiple targets (multi-target tasks are defined later). |
None
|
color
|
str
|
Marker color for the target (any Qt/SVG color name or |
_DEFAULT_TARGET_COLOR
|
tolerance
|
float | None
|
Optional success distance in meters: the reach succeeds when the tip is
within this distance of the target, and the target marker's ring is drawn
at this radius. |
None
|
duration
|
float
|
Total simulated time / planned-motion horizon (seconds). |
2.0
|
schedule
|
str
|
Time-scaling schedule for planned-trajectory controllers. |
'minimum_jerk'
|
params
|
dict[str, Any]
|
Any extra |
dict()
|
Source code in src/skelarm/scenario.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 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 | |
from_dict(section)
classmethod
Build a Task from a [task] mapping.
type is required; it selects the task kind. The reaching type also
requires a target — either a [x, y] array (position only) or a table
with a pos and optional label / color / tolerance. Other task
types may omit the target. Any keys beyond the recognized ones are kept on
:attr:params for custom task types.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/skelarm/scenario.py
from_toml(file_path)
classmethod
Build a Task from the [task] table of a TOML file.
Source code in src/skelarm/scenario.py
require_target()
Return the task target, raising if this task type has none.
Use this from a controller that needs a point goal (e.g. the reaching controllers), so a task wired without a target fails with a clear message.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the task has no target. |
Source code in src/skelarm/scenario.py
active_target_index(task)
apply_active_target(task)
Set a multi-target task's first-class target (and marker attrs) to its active candidate.
Lets the active goal flow through the ordinary reaching pipeline (controller build,
marker drawing); the GUI switches it live by reassigning task.target / the
controller's target.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the active index is out of range. |
Source code in src/skelarm/scenario.py
build_controller(source, *, skeleton, task, dt=0.002)
Construct the controller described by a [controller] config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path | Mapping[str, Any]
|
A TOML file path (its |
required |
skeleton
|
Skeleton
|
The robot, posed at its start state; used to build joint references. |
required |
task
|
Task
|
The reaching task supplying the target and run conditions. |
required |
dt
|
float
|
The control / integration step (from |
0.002
|
Returns:
| Type | Description |
|---|---|
Controller
|
The configured controller. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the config has no |
Source code in src/skelarm/scenario.py
controller_types()
export_scenario_toml(log, path)
Write the log's embedded scenario config to an editable TOML file.
The output is a standard combined config ([skeleton] / [initial] /
[task] / [controller]) that :func:load_scenario reads back. Re-running
the unedited file reproduces the original run exactly for the deterministic
controllers, and individual values can be edited for comparison studies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
StateLog
|
A log produced by :func: |
required |
path
|
str | Path
|
Destination |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the log carries no embedded scenario config. |
Source code in src/skelarm/scenario.py
load_reference_log(path)
Load a .sklog.npz reference trajectory (e.g. from tools/trajectory_recorder.py).
Source code in src/skelarm/scenario.py
load_scenario(file_path)
Load a robot, task, and controller from one combined TOML file.
multi_target_specs(task)
Parse a multi-target task's targets list into (pos, label, color, tolerance) tuples.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the task carries no |
Source code in src/skelarm/scenario.py
reference_builders()
register_controller(name, builder)
Register a controller builder so [controller].type = name builds it.
The builder receives the [controller] table (without type) as a mapping,
the posed Skeleton, and the Task, and returns a :class:~skelarm.Controller.
Re-registering an existing name replaces it. Custom controllers are also usable
directly (construct the instance and pass it to :func:run_scenario /
:func:~skelarm.simulate_controlled); registration is only needed for the
config-driven path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The |
required |
builder
|
ControllerBuilder
|
A callable |
required |
Source code in src/skelarm/scenario.py
register_reference_builder(task_type, builder)
Register a joint-reference builder for a [task].type.
A tracking controller (computed torque, joint PD, inverse-dynamics PD, MPC) builds its reference by calling the builder registered for the scenario's task type. Use this to add a new trajectory-style task that drives the existing controllers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_type
|
str
|
The |
required |
builder
|
ReferenceBuilder
|
A callable |
required |
Source code in src/skelarm/scenario.py
register_task_type(name)
Allow name as a [task].type.
Task types are a label that a controller interprets; a custom task carries its
parameters on :attr:Task.params (any extra [task] keys). Register the type
so :meth:Task.from_dict accepts it, then read task.params from a matching
controller built via :func:register_controller.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The task-type string to allow (idempotent). |
required |
Source code in src/skelarm/scenario.py
rerun_log(log)
Reconstruct and re-simulate a scenario recorded by :func:run_scenario.
Rebuilds the scenario by reparsing the embedded source config (identical input
gives identical state) and re-runs with the recorded run parameters, so
deterministic controllers reproduce the original channels exactly (MPC, which
calls :func:scipy.optimize.minimize, reproduces within a small numerical
tolerance on the same platform).
Raises:
| Type | Description |
|---|---|
ValueError
|
If the log carries no reproduction metadata. |
Source code in src/skelarm/scenario.py
run_scenario(scenario, *, duration=None, dt=None, grav_vec=None, enforce_limits=None)
Simulate a scenario and embed its full config for later reproduction.
Runs :func:~skelarm.control.simulate_controlled and, when the scenario was
loaded from a config, stores the task, controller, initial state, and run
parameters in the log's [extra] table so :func:rerun_log can reconstruct
and re-simulate it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
Scenario
|
The robot, task, and controller to run. |
required |
duration
|
float | None
|
Simulated duration (seconds); defaults to |
None
|
dt
|
float | None
|
Control / integration step; defaults to |
None
|
grav_vec
|
NDArray[float64] | None
|
Gravity vector; defaults to zero (planar motion). |
None
|
enforce_limits
|
bool | None
|
Apply the joint limits as hard stops in the dynamics. |
None
|
Returns:
| Type | Description |
|---|---|
StateLog
|
The recorded run, with reproduction metadata when available. |
Source code in src/skelarm/scenario.py
scenario_from_config(data)
Build a Scenario from a parsed combined config and keep the config for re-runs.
Reuses the real parsers (:meth:Skeleton.from_config, :meth:Task.from_dict,
:func:build_controller), so rebuilding from an identical mapping reproduces the
robot, initial pose, task, and controller exactly.
Raises:
| Type | Description |
|---|---|
ValueError
|
If the config has no |
Source code in src/skelarm/scenario.py
scenario_from_log(log)
Reconstruct the scenario and run parameters embedded in a log by :func:run_scenario.
Returns:
| Type | Description |
|---|---|
tuple[Scenario, Mapping[str, Any]]
|
The rebuilt scenario (skeleton posed at the recorded initial state) and the
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the log carries no reproduction metadata (was not produced by
:func: |