urml-vda5050-runtime 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,34 @@
1
+ """urml_vda5050_runtime: VDA 5050 fleet-control reference runtime for URML.
2
+
3
+ Vda5050Adapter (+ Vda5050Config, load_vda5050_config)
4
+ Turns URML dispatch steps into VDA 5050 ``order`` / ``instantActions``
5
+ messages for one mobile robot and judges success from the robot's own
6
+ ``state``. **No ROS 2 dependency.** MQTT goes through ``paho-mqtt``,
7
+ imported lazily (the [mqtt] extra), so this module loads on every host.
8
+
9
+ InMemoryBroker + SimulatedVehicle
10
+ A hermetic stand-in for the broker and a VDA 5050 vehicle, for tests
11
+ and the offline demo.
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ from urml_vda5050_runtime._version import __version__
17
+ from urml_vda5050_runtime.adapter import Vda5050Adapter
18
+ from urml_vda5050_runtime.config import ActionSpec, EdgeSpec, NodeSpec, Vda5050Config, load_vda5050_config
19
+ from urml_vda5050_runtime.sim import SimulatedVehicle
20
+ from urml_vda5050_runtime.transport import InMemoryBroker, PahoTransport, Transport
21
+
22
+ __all__ = [
23
+ "ActionSpec",
24
+ "EdgeSpec",
25
+ "InMemoryBroker",
26
+ "NodeSpec",
27
+ "PahoTransport",
28
+ "SimulatedVehicle",
29
+ "Transport",
30
+ "Vda5050Adapter",
31
+ "Vda5050Config",
32
+ "__version__",
33
+ "load_vda5050_config",
34
+ ]
@@ -0,0 +1,3 @@
1
+ """Package version. Bumped per release."""
2
+
3
+ __version__ = "0.5.0"
@@ -0,0 +1,636 @@
1
+ """Vda5050Adapter: URML primitives to VDA 5050 orders, as the fleet control.
2
+
3
+ VDA 5050 is the open interface between a fleet control and mobile robots
4
+ (MIT-licensed, maintained by VDA / VDMA). In it, the fleet control owns
5
+ the route graph and sends each vehicle ``order`` messages (a node-edge
6
+ path with actions on it); the vehicle reports progress on ``state``. This
7
+ adapter plays the fleet-control role for one vehicle: every dispatch
8
+ step becomes one order, and the step succeeds only when the vehicle's
9
+ own state says the order ran to the end and every action FINISHED.
10
+
11
+ **No ROS 2 dependency** and no cloud: MQTT goes to whatever broker the
12
+ deployment names, usually on the site network. The URML runtime calls
13
+ this adapter only after the validator has passed the program against
14
+ the manifest and envelope. Nothing here is a path around that check.
15
+
16
+ ## Method coverage
17
+
18
+ - ``move_to`` -> an order along the shortest configured route from the
19
+ vehicle's ``lastNodeId`` to the location's node. URML ``speed`` caps
20
+ every edge's ``maximumSpeed``.
21
+ - ``dock`` -> an order to the station, ending in the service's action
22
+ (``charge`` -> ``startCharging``; ``park`` -> none). ``until: full``
23
+ waits for ``powerSupply.stateOfCharge``.
24
+ - ``grasp`` / ``release`` -> ``pick`` / ``drop`` at the current node,
25
+ with the node's ``stationName`` / ``stationType`` and the held
26
+ object's class as ``loadType``.
27
+ - ``detect`` -> ``detectObject`` at the current node, when the vehicle
28
+ declares it. ``pick_from`` composes detect + grasp, so it needs it too
29
+ (recorded in SPEC-GAPS.md).
30
+ - ``measure`` -> a fresh ``state``: battery charge, voltage, current,
31
+ position.
32
+ - ``call_program`` -> a configured vendor action (RFC-0015).
33
+ - ``wait`` -> local sleep; ``report`` -> local record (no cloud).
34
+
35
+ Returned as not supported: ``wait_for`` (the vehicle interface carries
36
+ no external events), ``scan``, ``capture``, ``speak``, ``listen``. The
37
+ drone trio is ``not_applicable_vda5050``.
38
+
39
+ When an order does not finish within ``order_timeout_seconds`` the
40
+ adapter sends ``cancelOrder`` before reporting the failure, so the
41
+ vehicle never keeps driving an order the program has given up on.
42
+ """
43
+
44
+ from __future__ import annotations
45
+
46
+ import threading
47
+ import time
48
+ import uuid
49
+ from collections.abc import Callable, Iterable
50
+ from typing import Any, Literal
51
+
52
+ from urml_ros2_runtime.substrate.base import (
53
+ CaptureResult,
54
+ DetectionResult,
55
+ ListenResult,
56
+ ManipulationResult,
57
+ MeasurementResult,
58
+ NavigationResult,
59
+ ProgramCallResult,
60
+ ScanResult,
61
+ SubstrateResult,
62
+ WaitResult,
63
+ )
64
+
65
+ from urml_vda5050_runtime.config import EdgeSpec, Vda5050Config
66
+ from urml_vda5050_runtime.messages import (
67
+ Action,
68
+ MessageFactory,
69
+ action_status,
70
+ blocking_errors,
71
+ describe_error,
72
+ errors_referencing,
73
+ is_idle,
74
+ )
75
+ from urml_vda5050_runtime.transport import PahoTransport, Transport, _require_paho
76
+
77
+ _NOT_SUPPORTED = (
78
+ "not_supported_on_vda5050: the VDA 5050 vehicle interface has no {capability}. "
79
+ "Pair the vehicle with a companion adapter; the URML program, manifest and validator are unchanged."
80
+ )
81
+ _NOT_APPLICABLE = "not_applicable_vda5050: {capability} has no meaning for a ground mobile robot."
82
+ _ORDER_MODES = frozenset({"AUTOMATIC", "SEMIAUTOMATIC", "INTERVENED"})
83
+
84
+
85
+ class _OrderOutcome:
86
+ def __init__(self, ok: bool, reason: str | None, state: dict[str, Any] | None) -> None:
87
+ self.ok = ok
88
+ self.reason = reason
89
+ self.state = state or {}
90
+
91
+
92
+ class Vda5050Adapter:
93
+ """Fleet-control-side VDA 5050 adapter implementing the URML ROSAdapter Protocol."""
94
+
95
+ BRAND = "vda5050"
96
+
97
+ def __init__(
98
+ self,
99
+ config: Vda5050Config,
100
+ transport: Transport | None = None,
101
+ *,
102
+ sleep: Callable[[float], None] = time.sleep,
103
+ ) -> None:
104
+ if transport is None:
105
+ _require_paho() # fail at construction, with the install hint, not mid-program
106
+ self._config = config
107
+ self._transport = transport
108
+ self._sleep = sleep
109
+ self._factory = MessageFactory(config)
110
+ self._cond = threading.Condition()
111
+ self._state: dict[str, Any] | None = None
112
+ self._connection_state: str | None = None
113
+ self._connected = False
114
+ self._reports: list[dict[str, Any]] = []
115
+ self._closed = False
116
+
117
+ # ------------------------------------------------------------------
118
+ # Connection and state
119
+ # ------------------------------------------------------------------
120
+
121
+ def _topic(self, name: str) -> str:
122
+ return f"{self._config.topic_prefix}/{name}"
123
+
124
+ def _on_state(self, _topic: str, payload: dict[str, Any]) -> None:
125
+ with self._cond:
126
+ self._state = payload
127
+ self._cond.notify_all()
128
+
129
+ def _on_connection(self, _topic: str, payload: dict[str, Any]) -> None:
130
+ with self._cond:
131
+ self._connection_state = payload.get("connectionState")
132
+ self._cond.notify_all()
133
+
134
+ def _connect(self) -> None:
135
+ if self._connected:
136
+ return
137
+ if self._transport is None:
138
+ self._transport = PahoTransport(
139
+ self._config.broker_host,
140
+ self._config.broker_port,
141
+ client_id=f"urml-fleet-{self._config.serial_number}",
142
+ )
143
+ self._transport.subscribe(self._topic("state"), self._on_state)
144
+ self._transport.subscribe(self._topic("connection"), self._on_connection)
145
+ self._connected = True
146
+
147
+ def _publish(self, name: str, payload: dict[str, Any]) -> None:
148
+ assert self._transport is not None
149
+ self._transport.publish(self._topic(name), payload)
150
+
151
+ def _wait(self, predicate: Callable[[dict[str, Any]], bool], timeout: float) -> dict[str, Any] | None:
152
+ """Block until the latest state satisfies ``predicate``; ``None`` on timeout."""
153
+ deadline = time.monotonic() + timeout
154
+ with self._cond:
155
+ while True:
156
+ if self._state is not None and predicate(self._state):
157
+ return dict(self._state)
158
+ remaining = deadline - time.monotonic()
159
+ if remaining <= 0:
160
+ return None
161
+ self._cond.wait(remaining)
162
+
163
+ def _fresh_state(self) -> dict[str, Any] | None:
164
+ """Ask for a state message (``stateRequest``) and return the reply."""
165
+ self._connect()
166
+ action_id = self._new_id("state")
167
+ self._publish("instantActions", self._factory.instant_actions([Action("stateRequest", action_id, "NONE")]))
168
+ reply = self._wait(
169
+ lambda s: action_status(s, action_id, instant=True) is not None, self._config.state_timeout_seconds
170
+ )
171
+ if reply is None:
172
+ # Not every vehicle echoes stateRequest; any state it has sent will do.
173
+ with self._cond:
174
+ return dict(self._state) if self._state is not None else None
175
+ return reply
176
+
177
+ @staticmethod
178
+ def _new_id(kind: str) -> str:
179
+ return f"urml-{kind}-{uuid.uuid4().hex[:12]}"
180
+
181
+ def close(self) -> None:
182
+ if self._closed:
183
+ return
184
+ if self._transport is not None:
185
+ self._transport.close()
186
+ self._closed = True
187
+
188
+ def __enter__(self) -> Vda5050Adapter:
189
+ return self
190
+
191
+ def __exit__(self, *_: object) -> None:
192
+ self.close()
193
+
194
+ # ------------------------------------------------------------------
195
+ # Order execution
196
+ # ------------------------------------------------------------------
197
+
198
+ def _preflight(self) -> tuple[str | None, str | None]:
199
+ """Return ``(current_location, None)`` or ``(None, failure_reason)``."""
200
+ state = self._fresh_state()
201
+ if state is None:
202
+ return None, (
203
+ f"vehicle_silent: no state message from {self._config.topic_prefix} within "
204
+ f"{self._config.state_timeout_seconds:g}s."
205
+ )
206
+ if self._connection_state in ("OFFLINE", "CONNECTION_BROKEN", "HIBERNATING"):
207
+ return None, f"vehicle_not_connected: connection state is {self._connection_state}."
208
+ mode = state.get("operatingMode")
209
+ if mode not in _ORDER_MODES:
210
+ return None, f"vehicle_not_available: operating mode is {mode}, which accepts no orders."
211
+ stop = (state.get("safetyState") or {}).get("activeEmergencyStop", "NONE")
212
+ if stop != "NONE":
213
+ return None, f"vehicle_emergency_stop: activeEmergencyStop is {stop}."
214
+ # Errors that reference an orderId describe a rejected order and clear when the next
215
+ # order is accepted (section 6.6.5.4), so only the others block a new order.
216
+ blocking = [
217
+ e
218
+ for e in blocking_errors(state)
219
+ if not any(r.get("referenceKey") == "orderId" for r in e.get("errorReferences") or [])
220
+ ]
221
+ if blocking:
222
+ return None, "vehicle_error: " + "; ".join(describe_error(e) for e in blocking)
223
+ if not is_idle(state):
224
+ return None, f"vehicle_busy: order {state.get('orderId')!r} is still running."
225
+ here = self._config.location_for_node_id(str(state.get("lastNodeId", "")))
226
+ if here is None:
227
+ return None, (
228
+ f"vehicle_position_unknown: lastNodeId {state.get('lastNodeId')!r} is not a configured node. "
229
+ "Localize the vehicle on the route graph (initializePosition) first."
230
+ )
231
+ return here, None
232
+
233
+ def _run_order(
234
+ self,
235
+ *,
236
+ start: str,
237
+ route: list[tuple[str, EdgeSpec]],
238
+ actions: Iterable[Action] = (),
239
+ speed: float | None = None,
240
+ ) -> _OrderOutcome:
241
+ actions = list(actions)
242
+ order_id = self._new_id("order")
243
+ goal = route[-1][0] if route else start
244
+ goal_node_id = self._config.nodes[goal].node_id
245
+ self._publish(
246
+ "order", self._factory.order(order_id=order_id, start=start, route=route, end_actions=actions, speed=speed)
247
+ )
248
+
249
+ def settled(state: dict[str, Any]) -> bool:
250
+ if errors_referencing(state, "orderId", order_id):
251
+ return True # rejected
252
+ if state.get("orderId") != order_id:
253
+ return False
254
+ return bool(blocking_errors(state)) or is_idle(state)
255
+
256
+ state = self._wait(settled, self._config.order_timeout_seconds)
257
+ if state is None:
258
+ self._cancel(order_id)
259
+ return _OrderOutcome(
260
+ False,
261
+ f"order_timeout: order {order_id} did not finish within "
262
+ f"{self._config.order_timeout_seconds:g}s; cancelOrder sent.",
263
+ None,
264
+ )
265
+ rejected = errors_referencing(state, "orderId", order_id)
266
+ if rejected and state.get("orderId") != order_id:
267
+ return _OrderOutcome(False, "order_rejected: " + "; ".join(describe_error(e) for e in rejected), state)
268
+ blocking = blocking_errors(state)
269
+ if blocking and not is_idle(state):
270
+ self._cancel(order_id)
271
+ return _OrderOutcome(
272
+ False, "vehicle_error: " + "; ".join(describe_error(e) for e in blocking) + "; cancelOrder sent.", state
273
+ )
274
+ for action in actions:
275
+ entry = action_status(state, action.action_id) or {}
276
+ if entry.get("actionStatus") != "FINISHED":
277
+ detail = entry.get("actionResult") or entry.get("actionStatus") or "not reported"
278
+ return _OrderOutcome(False, f"action_failed: {action.action_type} ({detail}).", state)
279
+ if state.get("lastNodeId") != goal_node_id:
280
+ return _OrderOutcome(
281
+ False,
282
+ f"goal_not_reached: order ended at node {state.get('lastNodeId')!r}, expected {goal_node_id!r}.",
283
+ state,
284
+ )
285
+ return _OrderOutcome(True, None, state)
286
+
287
+ def _cancel(self, order_id: str) -> None:
288
+ cancel = Action("cancelOrder", self._new_id("cancel"), "NONE", {"orderId": order_id})
289
+ self._publish("instantActions", self._factory.instant_actions([cancel]))
290
+
291
+ def _action_here(
292
+ self,
293
+ action_type: str,
294
+ parameters: dict[str, Any],
295
+ *,
296
+ at_station: bool = False,
297
+ expect_at: str | None = None,
298
+ ) -> tuple[_OrderOutcome, str | None]:
299
+ """Run one action at the node the vehicle stands on. Returns (outcome, location).
300
+
301
+ ``at_station`` adds the node's stationName / stationType (pick, drop).
302
+ ``expect_at`` refuses to act anywhere but that location.
303
+ """
304
+ if not self._config.supports(action_type):
305
+ return (
306
+ _OrderOutcome(
307
+ False,
308
+ f"action_not_supported_by_vehicle: {action_type!r} is not in supported_actions "
309
+ "(the vehicle factsheet's agvActions).",
310
+ None,
311
+ ),
312
+ None,
313
+ )
314
+ here, reason = self._preflight()
315
+ if here is None:
316
+ return _OrderOutcome(False, reason, None), None
317
+ if expect_at is not None and here != expect_at:
318
+ return (
319
+ _OrderOutcome(
320
+ False, f"location_mismatch: expected the vehicle at {expect_at!r}, it is at {here!r}.", None
321
+ ),
322
+ here,
323
+ )
324
+ params = dict(parameters)
325
+ if at_station:
326
+ node = self._config.nodes[here]
327
+ params.setdefault("stationName", node.station_name or here)
328
+ if node.station_type:
329
+ params.setdefault("stationType", node.station_type)
330
+ action = Action(action_type, self._new_id("action"), "HARD", params)
331
+ return self._run_order(start=here, route=[], actions=[action]), here
332
+
333
+ def _final_pose(self, state: dict[str, Any]) -> dict[str, float] | None:
334
+ position = state.get("mobileRobotPosition")
335
+ if not isinstance(position, dict):
336
+ return None
337
+ return {k: float(position[k]) for k in ("x", "y", "theta") if k in position}
338
+
339
+ # ------------------------------------------------------------------
340
+ # Supported
341
+ # ------------------------------------------------------------------
342
+
343
+ def send_navigation_goal(
344
+ self,
345
+ *,
346
+ location: str | None = None,
347
+ pose: dict[str, float] | None = None,
348
+ frame: str | None = None,
349
+ carrying: dict[str, Any] | None = None,
350
+ speed: float | None = None,
351
+ ) -> NavigationResult:
352
+ if location is None:
353
+ return NavigationResult(
354
+ success=False,
355
+ reason="vda5050_requires_named_location: VDA 5050 vehicles drive between route-graph "
356
+ "nodes; a raw pose goal has no node to send.",
357
+ )
358
+ if location not in self._config.nodes:
359
+ return NavigationResult(
360
+ success=False,
361
+ reason=f"location_not_configured: {location!r} is declared in the manifest but is not "
362
+ "a node in vda5050_adapter.yaml.",
363
+ )
364
+ here, reason = self._preflight()
365
+ if here is None:
366
+ return NavigationResult(success=False, reason=reason)
367
+ route = self._config.route(here, location)
368
+ if route is None:
369
+ return NavigationResult(
370
+ success=False, reason=f"no_route: no configured edges lead from {here!r} to {location!r}."
371
+ )
372
+ if not route:
373
+ state = self._fresh_state() or {}
374
+ return NavigationResult(success=True, final_pose=self._final_pose(state), frame=self._config.map_id)
375
+ outcome = self._run_order(start=here, route=route, speed=speed)
376
+ if not outcome.ok:
377
+ return NavigationResult(success=False, reason=outcome.reason)
378
+ return NavigationResult(success=True, final_pose=self._final_pose(outcome.state), frame=self._config.map_id)
379
+
380
+ def send_docking_goal(self, *, station: str, service: str, until: str | None = None) -> NavigationResult:
381
+ target = self._config.primary_dock if station == "primary" else station
382
+ if target is None or target not in self._config.nodes:
383
+ return NavigationResult(
384
+ success=False,
385
+ reason=f"station_not_configured: dock station {station!r} is not a node in "
386
+ "vda5050_adapter.yaml (set primary_dock for a dock without `at:`).",
387
+ )
388
+ if service not in self._config.dock_services:
389
+ return NavigationResult(
390
+ success=False,
391
+ reason=f"service_not_configured: dock service {service!r} has no entry in dock_services.",
392
+ )
393
+ action_type = self._config.dock_services[service]
394
+ if until is not None and not (until == "full" and action_type == "startCharging"):
395
+ return NavigationResult(
396
+ success=False,
397
+ reason=f"until_not_supported: this adapter supports `until: full` on a charging service "
398
+ f"only, not {until!r} on {service!r}.",
399
+ )
400
+ if action_type is not None and not self._config.supports(action_type):
401
+ return NavigationResult(
402
+ success=False,
403
+ reason=f"action_not_supported_by_vehicle: {action_type!r} is not in supported_actions.",
404
+ )
405
+ here, reason = self._preflight()
406
+ if here is None:
407
+ return NavigationResult(success=False, reason=reason)
408
+ route = self._config.route(here, target)
409
+ if route is None:
410
+ return NavigationResult(
411
+ success=False, reason=f"no_route: no configured edges lead from {here!r} to {target!r}."
412
+ )
413
+ actions = [Action(action_type, self._new_id("action"), "HARD")] if action_type else []
414
+ if not route and not actions:
415
+ state = self._fresh_state() or {}
416
+ return NavigationResult(success=True, final_pose=self._final_pose(state), frame=self._config.map_id)
417
+ outcome = self._run_order(start=here, route=route, actions=actions)
418
+ if not outcome.ok:
419
+ return NavigationResult(success=False, reason=outcome.reason)
420
+ if until == "full":
421
+ full = self._config.full_charge_percent
422
+
423
+ def charged(state: dict[str, Any]) -> bool:
424
+ power = state.get("powerSupply") or {}
425
+ return float(power.get("stateOfCharge", 0.0)) >= full or not power.get("charging", False)
426
+
427
+ charged_state = self._wait(charged, self._config.charge_timeout_seconds)
428
+ soc = float(((charged_state or {}).get("powerSupply") or {}).get("stateOfCharge", 0.0))
429
+ if charged_state is None or soc < full:
430
+ return NavigationResult(
431
+ success=False,
432
+ reason=f"charge_incomplete: charging ended or timed out at {soc:g}% (full is {full:g}%).",
433
+ )
434
+ return NavigationResult(success=True, final_pose=self._final_pose(outcome.state), frame=self._config.map_id)
435
+
436
+ def send_manipulation_goal(
437
+ self,
438
+ *,
439
+ action: Literal["grasp", "release"],
440
+ target: dict[str, Any] | None = None,
441
+ force_n: float | None = None,
442
+ approach: Literal["top", "side", "front", "auto"] = "auto",
443
+ release_mode: Literal["drop", "place", "hand_to_user"] | None = None,
444
+ release_at: dict[str, Any] | str | None = None,
445
+ arm: str | None = None,
446
+ grasp_type: str | None = None,
447
+ target_motion: str | None = None,
448
+ ) -> ManipulationResult:
449
+ if release_mode == "hand_to_user":
450
+ return ManipulationResult(success=False, reason=_NOT_SUPPORTED.format(capability="hand-over to a person"))
451
+ action_type = "pick" if action == "grasp" else "drop"
452
+ params: dict[str, Any] = {}
453
+ if isinstance(target, dict) and target.get("class"):
454
+ params["loadType"] = str(target["class"])
455
+ outcome, _ = self._action_here(action_type, params, at_station=True)
456
+ return ManipulationResult(success=outcome.ok, reason=outcome.reason)
457
+
458
+ def query_detection(
459
+ self,
460
+ *,
461
+ object_class: str,
462
+ attributes: dict[str, Any] | None = None,
463
+ where_near: str | None = None,
464
+ where_within: float | None = None,
465
+ ) -> DetectionResult:
466
+ if not self._config.supports("detectObject"):
467
+ return DetectionResult(
468
+ success=False,
469
+ reason="action_not_supported_by_vehicle: detection needs the detectObject action, which "
470
+ "this vehicle does not declare. pick_from composes detect + grasp, so it needs it too "
471
+ "(see SPEC-GAPS.md).",
472
+ )
473
+ outcome, here = self._action_here("detectObject", {"objectType": object_class}, expect_at=where_near)
474
+ if not outcome.ok:
475
+ return DetectionResult(success=False, reason=outcome.reason)
476
+ return DetectionResult(
477
+ success=True,
478
+ payload={
479
+ "class": object_class,
480
+ # detectObject reports no object pose; the vehicle's own pose at the station is the
481
+ # best location the interface gives. No confidence is reported either.
482
+ "pose": self._final_pose(outcome.state) or {},
483
+ "frame": self._config.map_id,
484
+ "attributes": attributes or {},
485
+ "confidence": None,
486
+ "station": here,
487
+ },
488
+ )
489
+
490
+ def take_measurement(self, *, what: str, target: str | None, sensor: str | None) -> MeasurementResult:
491
+ state = self._fresh_state()
492
+ if state is None:
493
+ return MeasurementResult(success=False, reason="vehicle_silent: no state message to read.")
494
+ power = state.get("powerSupply") or {}
495
+ readings: dict[str, tuple[Any, str]] = {
496
+ "battery": (power.get("stateOfCharge"), "percent"),
497
+ "state_of_charge": (power.get("stateOfCharge"), "percent"),
498
+ "voltage": (power.get("batteryVoltage"), "V"),
499
+ "current": (power.get("batteryCurrent"), "A"),
500
+ "position": (state.get("mobileRobotPosition"), self._config.map_id),
501
+ }
502
+ value, unit = readings.get(what, (None, ""))
503
+ if value is None:
504
+ return MeasurementResult(
505
+ success=False,
506
+ reason=f"measurement_not_reported: the vehicle state carries no {what!r} reading. "
507
+ f"Readable: {', '.join(readings)}.",
508
+ )
509
+ return MeasurementResult(
510
+ success=True, payload={"value": value, "unit": unit, "timestamp": state.get("timestamp"), "what": what}
511
+ )
512
+
513
+ def call_named_program(self, *, name: str, args: dict[str, Any] | None = None) -> ProgramCallResult:
514
+ """``call_program``: run a configured vendor action in place (RFC-0015).
515
+
516
+ VDA 5050 lets each manufacturer add actions beyond the predefined
517
+ set (section 6.2.3) and list them in the factsheet. A manifest-
518
+ declared program name resolves to one of those actions in
519
+ ``program_to_action``; ``call_program`` args are appended to its
520
+ fixed parameters. The action's ``actionResult`` is the payload.
521
+ """
522
+ spec = self._config.program_to_action.get(name)
523
+ if spec is None:
524
+ return ProgramCallResult(
525
+ success=False,
526
+ reason=f"program_not_configured: program {name!r} is not mapped to a vehicle action "
527
+ "in vda5050_adapter.yaml (program_to_action).",
528
+ )
529
+ outcome, _ = self._action_here(spec.action_type, {**spec.parameters, **(args or {})})
530
+ if not outcome.ok:
531
+ return ProgramCallResult(success=False, reason=outcome.reason)
532
+ result = None
533
+ for entry in outcome.state.get("actionStates", []):
534
+ if entry.get("actionType") == spec.action_type and entry.get("actionResult") is not None:
535
+ result = entry["actionResult"]
536
+ return ProgramCallResult(success=True, payload=None if result is None else {"value": result})
537
+
538
+ def wait_passively(self, *, duration_seconds: float) -> SubstrateResult:
539
+ # Between orders a VDA 5050 vehicle holds at its last node by itself.
540
+ if duration_seconds > 0:
541
+ self._sleep(duration_seconds)
542
+ return SubstrateResult(success=True)
543
+
544
+ def emit_report(
545
+ self,
546
+ *,
547
+ to: str,
548
+ facts: dict[str, Any],
549
+ attachments: list[str] | None,
550
+ status: Literal["success", "partial", "failure"],
551
+ severity: Literal["info", "notice", "warning", "error"],
552
+ ) -> SubstrateResult:
553
+ self._reports.append({"to": to, "status": status, "severity": severity, "facts": facts})
554
+ return SubstrateResult(success=True)
555
+
556
+ # ------------------------------------------------------------------
557
+ # Not supported by the vehicle interface
558
+ # ------------------------------------------------------------------
559
+
560
+ def wait_for_condition(
561
+ self,
562
+ *,
563
+ kind: Literal["event", "signal", "input", "sensor_threshold"],
564
+ name: str | None,
565
+ input_mode: str | None,
566
+ threshold: dict[str, Any] | None,
567
+ timeout_seconds: float | None,
568
+ ) -> WaitResult:
569
+ return WaitResult(
570
+ success=False,
571
+ reason=_NOT_SUPPORTED.format(capability=f"source for {kind} conditions")
572
+ + " A fleet-level runtime that sees the other robots can resolve wait_for events.",
573
+ )
574
+
575
+ def run_scan(
576
+ self,
577
+ *,
578
+ area: dict[str, Any],
579
+ pattern: Literal["serpentine", "spiral", "grid", "adaptive"],
580
+ overlap: float,
581
+ altitude: float | None,
582
+ media: Literal["photo", "video", "sensor_only"],
583
+ sensor: str | None,
584
+ ) -> ScanResult:
585
+ return ScanResult(success=False, reason=_NOT_SUPPORTED.format(capability="area-scan controller"))
586
+
587
+ def capture_media(
588
+ self,
589
+ *,
590
+ media: Literal["photo", "video"],
591
+ target: str | None,
592
+ duration_seconds: float | None,
593
+ attributes: dict[str, Any] | None,
594
+ camera: str | None = None,
595
+ ) -> CaptureResult:
596
+ return CaptureResult(success=False, reason=_NOT_SUPPORTED.format(capability="recordable camera"))
597
+
598
+ def emit_speech(
599
+ self,
600
+ *,
601
+ utterance: str,
602
+ locale: str | None,
603
+ style: Literal["notice", "warning", "conversational"],
604
+ interrupt: bool,
605
+ ) -> SubstrateResult:
606
+ return SubstrateResult(success=False, reason=_NOT_SUPPORTED.format(capability="speaker"))
607
+
608
+ def acquire_speech(
609
+ self,
610
+ *,
611
+ prompt: str | None,
612
+ locale: str | None,
613
+ timeout_seconds: float | None,
614
+ expected: Literal["free_form", "confirmation", "choice"],
615
+ choices: list[str] | None,
616
+ ) -> ListenResult:
617
+ return ListenResult(success=False, reason=_NOT_SUPPORTED.format(capability="microphone"))
618
+
619
+ def send_takeoff_goal(self, *, altitude: float, climb_rate: float | None = None) -> NavigationResult:
620
+ return NavigationResult(success=False, reason=_NOT_APPLICABLE.format(capability="take_off"))
621
+
622
+ def send_land_goal(
623
+ self,
624
+ *,
625
+ at: str | None = None,
626
+ precision: Literal["standard", "precise"] = "standard",
627
+ ) -> NavigationResult:
628
+ return NavigationResult(success=False, reason=_NOT_APPLICABLE.format(capability="land"))
629
+
630
+ def send_return_to_home_goal(
631
+ self,
632
+ *,
633
+ speed: float | None = None,
634
+ altitude: float | None = None,
635
+ ) -> NavigationResult:
636
+ return NavigationResult(success=False, reason=_NOT_APPLICABLE.format(capability="return_to_home"))