Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ versioning: [Semantic Versioning 2.0.0](https://semver.org/) (policy in `docs/33
- Dashboard polish (T-113a/b, T-115): Spaces list with YAML view and validation,
Workbench worker table, Settings (session token, theme, number locale, SSE reconnect),
report export with sandboxed preview route, and global keyboard shortcuts dialog.
- Jazzy command relay (T-093d) applies FIFO velocity delays on the simulation clock and
publishes observed delay for the episode recorder.
- Web production image (T-116): read-only nginx-unprivileged SPA, runtime `/config.json`,
CSP and security headers, and a Compose `app` profile that starts the authenticated API,
workers and dashboard with same-origin SSE.
Expand Down
6 changes: 6 additions & 0 deletions docs/10-simulator-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ Give the sensor-data topics `scan_raw` and `scan` separate resolved names to pre
The node publishes cumulative `count` (processed beams) and `dropped` (new `+inf` returns)
as JSON in `std_msgs/msg/String` once per second on `/roboprobe/perturber_stats`.

The `cmd_delay` node reads `cmd_delay_ms` and the Nav2 controller's `rate_hz` from
`perturb_params.yaml`. It keeps messages in order on the simulation clock and publishes the
observed latency in **seconds** as `std_msgs/msg/Float64` on `/roboprobe/cmd_delay_actual`.
The `stamped_cmd_vel` flag in `topics.yaml` selects the ROS message type. Zero delay forwards
the message in its subscription callback with a reported latency of zero.

Friction and lighting are world properties ⇒ a fresh world load per run (no warm reset in MVP; see §8).

**SUT profiles** (`configs/sut_profiles/<id>.yaml`, schema `schemas/sut_profile.schema.json`, loader
Expand Down
5 changes: 5 additions & 0 deletions docs/28-traceability-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ and ETags; `test_uow_lifecycle.py` covers transaction entry/exit. Shared factory
`tests/unit/runner/test_campaign_factory.py`; SQL filter/keyset checks and PostgreSQL pagination
are in `tests/unit/store/test_run_queries.py` and `tests/integration/store/test_run_queries.py`.

Gazebo velocity relay verification (T-093d, #195, FR-SIM-003):
`ros_ws/src/roboprobe_ros/test/test_cmd_delay.py` launches installed Jazzy relays
against a fake simulation clock and verifies both velocity message types, FIFO ordering,
reported latency, zero-delay delivery and process shutdown.

Trace transport verification (T-081e, #150; FR-DSH-005, FR-STO-002, NFR-SEC-003):
`tests/api/test_trace_artifacts.py` covers clearance minima, flag transitions, rate caps, column
selection, Parquet/attachment headers, unknown ids, and malicious stored paths (TM-04).
Expand Down
2 changes: 2 additions & 0 deletions ros_ws/src/roboprobe_ros/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<exec_depend>sensor_msgs_py</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>geometry_msgs</exec_depend>
<exec_depend>std_msgs</exec_depend>
<exec_depend>nav_msgs</exec_depend>
<exec_depend>nav2_msgs</exec_depend>
<exec_depend>python3-numpy</exec_depend>
Expand All @@ -20,6 +21,7 @@
<test_depend>python3-pytest</test_depend>
<test_depend>launch_ros</test_depend>
<test_depend>launch_testing</test_depend>
<test_depend>rosgraph_msgs</test_depend>
<export>
<build_type>ament_python</build_type>
</export>
Expand Down
12 changes: 11 additions & 1 deletion ros_ws/src/roboprobe_ros/roboprobe_ros/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def _read_yaml(path: Path) -> dict[str, object]:
return _mapping(yaml.safe_load(stream), str(path))


def _stamped_cmd_vel(config: dict[str, object]) -> bool:
stamped = config.get("stamped_cmd_vel", False)
if not isinstance(stamped, bool):
msg = "stamped_cmd_vel must be a boolean"
raise TypeError(msg)
return stamped


class RoboProbeNode(Node):
"""Load generated episode data and expose deterministic node utilities."""

Expand All @@ -55,7 +63,9 @@ def __init__(
seed = self.declare_parameter("seed", 0)
topics_path = Path(topic_file.get_parameter_value().string_value)
perturb_path = perturb_file.get_parameter_value().string_value
self._topics = _mapping(_read_yaml(topics_path).get("topics"), "topics")
topic_config = _read_yaml(topics_path)
self._topics = _mapping(topic_config.get("topics"), "topics")
self.stamped_cmd_vel = _stamped_cmd_vel(topic_config)
self.perturbation = _read_yaml(Path(perturb_path)) if perturb_path else {}
self.rng = Generator(PCG64(seed.get_parameter_value().integer_value))
except Exception:
Expand Down
123 changes: 123 additions & 0 deletions ros_ws/src/roboprobe_ros/roboprobe_ros/cmd_delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""Sim-time command latency relay for Jazzy Nav2 (T-093d, FR-SIM-003)."""

from __future__ import annotations

import math
from typing import TYPE_CHECKING, Final

import rclpy
from geometry_msgs.msg import Twist, TwistStamped
from rclpy.clock import JumpThreshold
from rclpy.duration import Duration
from rclpy.executors import ExternalShutdownException
from rclpy.parameter import Parameter
from std_msgs.msg import Float64

from roboprobe_ros._vendor.perturbation.delay import CommandDelayBuffer
from roboprobe_ros.base import RoboProbeNode

if TYPE_CHECKING:
from rclpy.clock import TimeJump
from rclpy.context import Context

__all__ = ["CommandDelay", "main"]

_DELAY_ACTUAL_TOPIC: Final = "/roboprobe/cmd_delay_actual"
_MS_PER_S: Final = 1000
_NS_PER_S: Final = 1_000_000_000

type Command = Twist | TwistStamped


def _number(values: dict[str, object], key: str) -> float:
value = values.get(key)
if isinstance(value, bool) or not isinstance(value, int | float):
msg = f"perturb_params.yaml must specify numeric {key}"
raise TypeError(msg)
if not math.isfinite(value):
msg = f"{key} must be finite"
raise ValueError(msg)
return float(value)


class CommandDelay(RoboProbeNode):
"""Apply the shared FIFO model on the same clock as the simulation."""

def __init__(
self,
*,
context: Context | None = None,
parameter_overrides: list[Parameter] | None = None,
) -> None:
"""Enable simulation time and configure the episode relay."""
overrides = [*(parameter_overrides or ()), Parameter("use_sim_time", value=True)]
super().__init__("cmd_delay", context=context, parameter_overrides=overrides)
try:
self._configure()
except Exception:
self.destroy_node()
raise

def _configure(self) -> None:
self._delay_s = _number(self.perturbation, "cmd_delay_ms") / _MS_PER_S
rate_hz = _number(self.perturbation, "rate_hz")
if rate_hz <= 0.0:
msg = "rate_hz must be positive"
raise ValueError(msg)
self._queue = CommandDelayBuffer[tuple[float, Command]](self._delay_s)
raw = self.topic("cmd_vel_nav")
output = self.topic("cmd_vel")
if self.resolve_topic_name(raw) == self.resolve_topic_name(output):
msg = "cmd_vel_nav and cmd_vel must resolve to distinct topics"
raise ValueError(msg)

message_type = TwistStamped if self.stamped_cmd_vel else Twist
output_qos = self.qos("cmd_vel")
self._command = self.create_publisher(message_type, output, output_qos)
self._latency = self.create_publisher(Float64, _DELAY_ACTUAL_TOPIC, output_qos)
self.create_subscription(message_type, raw, self._receive, self.qos("cmd_vel_nav"))
if self._delay_s > 0.0:
self.create_timer(1.0 / rate_hz, self._release)
self._jump_handler = self.get_clock().create_jump_callback(
JumpThreshold(
min_forward=None, min_backward=Duration(nanoseconds=-1), on_clock_change=True
),
post_callback=self._reset_queue,
)

def _reset_queue(self, _jump: TimeJump) -> None:
# The shared FIFO disallows clock regressions, so a new timeline gets a new FIFO.
self._queue = CommandDelayBuffer[tuple[float, Command]](self._delay_s)

def _receive(self, command: Command) -> None:
if self._delay_s == 0.0:
self._send(command, 0.0)
return
now = self.get_clock().now().nanoseconds / _NS_PER_S
# ROS reports zero until the first simulation clock sample arrives.
if now > 0.0:
self._queue.push(now, (now, command))

def _release(self) -> None:
now = self.get_clock().now().nanoseconds / _NS_PER_S
for enqueued, command in self._queue.pop_due(now):
self._send(command, now - enqueued)

def _send(self, command: Command, actual_s: float) -> None:
self._command.publish(command)
self._latency.publish(Float64(data=actual_s))


def main(args: list[str] | None = None) -> None:
"""Start the relay and release its resources on ROS shutdown."""
rclpy.init(args=args)
try:
node = CommandDelay()
try:
rclpy.spin(node)
finally:
node.destroy_node()
except (KeyboardInterrupt, ExternalShutdownException):
pass
finally:
rclpy.try_shutdown()
5 changes: 4 additions & 1 deletion ros_ws/src/roboprobe_ros/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
install_requires=["setuptools"],
extras_require={"recorder": ["pyarrow>=17"]},
entry_points={
"console_scripts": ["sensor_perturber = roboprobe_ros.sensor_perturber:main"],
"console_scripts": [
"cmd_delay = roboprobe_ros.cmd_delay:main",
"sensor_perturber = roboprobe_ros.sensor_perturber:main",
],
},
zip_safe=False,
maintainer="CodewithJha",
Expand Down
Loading
Loading