ROS 2 architecture: a proposal, a guard, and an observer
Documentation and local logic checks: 3 December 2026

SCOPE AND VALIDATION
This is original MIT-licensed teaching code. It supplies no actuator interface,
robot driver, e-stop, lifecycle manager, TF broadcaster or safety certification.
It targets ROS 2 Jazzy on Ubuntu 24.04 with system Python 3.12 and Fast DDS
(rmw_fastrtps_cpp). All nodes run on one host with use_sim_time=false.

The local authoring environment had Python 3.13.5 but no ros2, colcon or rclpy.
Executed: 15 standard-library policy tests, four static package/launch checks,
and the deterministic scenarios below. ROS import, DDS communication, colcon
build and launch were NOT executed. Static checks do not establish ROS runtime
compatibility. No robot, latency benchmark or hardware test was performed.

Package maintainer: Thomas THELLIEZ. The metadata uses the author's GitHub
noreply address; it is not a technical-support inbox.

CONTENTS
  ros2_architecture_demo/policy.py     Pure admission/state logic, no ROS imports
  ros2_architecture_demo/nodes.py      Three rclpy node adapters
  ros2_architecture_demo/scenarios.py  Deterministic local observations
  launch/demo.launch.py               Three separate process actions
  package.xml, setup.py, setup.cfg    ament_python package/install metadata
  resource/ros2_architecture_demo     ament index marker
  test/                              Logic and static structure checks
  LICENSE                            MIT license for the original example code
  interface-contract.json            Timing, units, QoS and ownership contract
  architecture.svg                    Annotated diagram
  expected-policy-results.json        Recorded local deterministic observations

RUN THE CHECKS WITHOUT ROS
Extract ros2-architecture-demo.zip into an empty working directory, then:
  cd ros2_architecture_demo
  PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s test -v
  PYTHONDONTWRITEBYTECODE=1 python3 -m ros2_architecture_demo.scenarios

The scenario emits, in order:
  waiting_for_input   linear_x=0.0  angular_z=0.0
  accepted           linear_x=0.2  angular_z=0.1
  stale_input        linear_x=0.0  angular_z=0.0
  accepted           linear_x=0.2  angular_z=0.1
  input_timeout      linear_x=0.0  angular_z=0.0
  accepted           linear_x=0.2  angular_z=0.1
This is direct policy evaluation with synthetic timestamps, not ROS output.

ROS PROCEDURE TO TRY (NOT EXECUTED IN THE AUTHORING ENVIRONMENT)
Prerequisite: follow the official ROS 2 Jazzy installation for Ubuntu 24.04.
The following apt commands assume those ROS apt repositories are already set up:
  sudo apt update
  sudo apt install python3-colcon-common-extensions ros-jazzy-rclpy ros-jazzy-geometry-msgs ros-jazzy-std-msgs ros-jazzy-launch-ros ros-jazzy-rmw-fastrtps-cpp

Use a new workspace. With the downloaded ZIP in ~/Downloads:
  mkdir -p ~/ros2_architecture_ws/src
  unzip ~/Downloads/ros2-architecture-demo.zip -d ~/ros2_architecture_ws/src
  cd ~/ros2_architecture_ws
  source /opt/ros/jazzy/setup.bash
  colcon build --packages-select ros2_architecture_demo --symlink-install
  source install/setup.bash
  export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
  export ROS_DOMAIN_ID=73
  export ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
  unset ROS_STATIC_PEERS
  ros2 launch ros2_architecture_demo demo.launch.py mode:=timeline

Choose another unused domain ID if 73 is already in use locally. Domain ID and
discovery scope reduce accidental interference; neither authenticates a sender.
Do not change use_sim_time at runtime; simulated-time replay is outside scope.

EXPECTED ROS OBSERVATIONS (TO VERIFY ON YOUR MACHINE)
The source's monotonic clock drives this approximate sequence:
  0-2 s: fresh proposals, accepted output (0.2 m/s, 0.1 rad/s)
  2-4 s: proposals stamped one second old, stale_input and zero output
  4-6 s: no publications; input_timeout after over 300 ms of receipt silence
  6-8 s: fresh proposals resume, accepted output again
  after 8 s: source stays silent; input_timeout, zero output
Discovery and executor scheduling affect when observers see these transitions.
The first waiting_for_input log can be missed while DDS discovery completes.
Ctrl-C stops the launch. The silent source process remains alive intentionally.

In a second terminal, source both environments and set the same discovery vars:
  source /opt/ros/jazzy/setup.bash
  source ~/ros2_architecture_ws/install/setup.bash
  export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
  export ROS_DOMAIN_ID=73
  export ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
  unset ROS_STATIC_PEERS
  ros2 node list
  ros2 topic info /demo/proposal --verbose
  ros2 topic echo /demo/guard_status
Use Ctrl-C to leave echo, then inspect the output separately:
  ros2 topic echo /demo/accepted_twist

For continuous input, restart the launch with mode:=normal. To explore a real
source-process exit, run each executable in its own terminal instead of launch:
  ros2 run ros2_architecture_demo proposal_source --ros-args -r __ns:=/demo -p mode:=normal
  ros2 run ros2_architecture_demo proposal_guard --ros-args -r __ns:=/demo
  ros2 run ros2_architecture_demo decision_observer --ros-args -r __ns:=/demo
Each terminal needs the environment above. Stop only the source with Ctrl-C;
the guard should report input_timeout on a subsequent timer callback. This is
an expected experiment, not a result observed by the author. Do not run these
alongside the launch: multiple publishers violate the one-source assumption.

CONTRACT AND FAILURE SEMANTICS
/demo/proposal is geometry_msgs/msg/TwistStamped at a nominal 10 Hz. Its stamp
means proposal creation time in the shared ROS/system clock, frame is base_link,
linear.x is in m/s, angular.z in rad/s, and the other four twist axes must be zero.
Limits are illustrative: |linear.x| <= 0.5 and |angular.z| <= 1.0. All numbers must
be finite. Input age must be <=500 ms, and a stamp more than 50 ms ahead is refused.
Accepted stamps must strictly increase; old or duplicate packets revoke output.
There is no TF transformation, source identity check or publisher arbitration.

The source and guard input both use best-effort, keep-last 1, volatile QoS.
The guard's two outputs use reliable, keep-last 1, volatile QoS. Compatibility
permits delivery; it does not prove freshness or authorization. The JSON status
uses std_msgs/String to avoid custom interface generation; a production system
should define a typed status interface and appropriate diagnostic metadata.

Receipt silence is measured with time.monotonic in the guard, separately from
input stamp age. The guard timer uses rclpy STEADY_TIME and requests a 50 ms period.
Callbacks run in a SingleThreadedExecutor in each process. Zero output appears
on the next timer callback after a refusal/expiry; 50 ms is NOT a proven upper
bound. CPU contention, a blocked executor or blocked publication can delay it.
Do not insert blocking work in these callbacks and infer that the timer is safe.

Invalid input discards the previous proposal; it never keeps a last nonzero
output as a fallback. Fresh valid data automatically resumes output. This is
not a latched safety reset. Backwards observed clock changes invalidate state;
a forward clock jump can expire the proposal. This does not synchronize clocks.

/demo/accepted_twist contains the guard's output timestamp, not the original
input's creation timestamp. No example subscribes it to motor hardware. The
observer logs /demo/guard_status changes, not physical motion. If the guard
itself dies, it cannot publish zero. A real downstream controller would need its
own validity/timeout policy and independent hardware safety mechanisms.

PRIMARY REFERENCES (checked 2026-12-03; upstream content is not bundled)
Jazzy Ubuntu installation:
https://docs.ros.org/en/jazzy/Installation/Ubuntu-Install-Debs.html
Jazzy ament_python package structure:
https://docs.ros.org/en/jazzy/Tutorials/Beginner-Client-Libraries/Creating-Your-First-ROS2-Package.html
Jazzy Python launch:
https://docs.ros.org/en/jazzy/Tutorials/Intermediate/Launch/Creating-Launch-Files.html
Jazzy QoS compatibility:
https://docs.ros.org/en/jazzy/Concepts/Intermediate/About-Quality-of-Service-Settings.html
ROS clock design:
https://design.ros2.org/articles/clock_and_time.html
Jazzy discovery scope:
https://docs.ros.org/en/jazzy/Tutorials/Advanced/Improved-Dynamic-Discovery.html
The official ros2/ros2_documentation jazzy-branch RST sources and rclpy jazzy
source were inspected when docs.ros.org returned an access challenge.
