How matpomgit/alf-light-tracking works
1. Overall shape
- This is a single ROS2 Python package, g1_light_tracking, inside ros2_ws.
- The repo is organized around one runtime goal: detect a light spot, turn that into movement commands, and optionally bridge those commands either to a Unitree G1 robot or to a turtlesim simulator.
- The main architectural boundary is between perception (camera/CSV input to detection) and control/actuation (detection to /cmd_vel, then bridge to robot or simulation).
2. Primary runtime pipeline
- The preferred online path is: /camera/image_raw from a D435i camera node → light_spot_detector_node → /light_tracking/detection_json → g1_light_follower_node → /cmd_vel → a bridge node.
- The same follower layer is reused in simulation, where /cmd_vel is bridged to /turtle1/cmd_vel.
- The README emphasizes a fail-safe philosophy: prefer rejecting uncertain detections over publishing wrong motion.
3. Perception subsystem
- light_spot_detector_node.py is the main detector node.
- Supporting modules under vision/ define the detector abstraction, detection data types, and detector registry, which suggests the detector is pluggable rather than hard-wired.
- config/perception.yaml controls detection thresholds and can switch legacy_mode on, indicating two selection strategies: current filtered detection logic and older area-based selection.
- d435i_node.py likely provides the camera source integration for Intel RealSense D435i.
4. Control / follower subsystem
- g1_light_follower_node.py consumes detection_json and produces velocity commands on /cmd_vel.
- config/control.yaml contains follower tuning and speed limits, so the control loop is parameterized rather than embedded in code.
- This subsystem is intentionally downstream of perception; it does not appear to own camera logic or robot transport.
5. Actuation / bridge layer
- unitree_cmd_vel_bridge_node.py is the robot-facing transport layer for the Unitree G1 path.
- turtlesim_cmd_vel_bridge_node.py is the simulation bridge, mapping the same /cmd_vel stream to /turtle1/cmd_vel.
- config/bridge.yaml contains transport-specific settings for the Unitree bridge, keeping hardware details out of the follower.
6. Offline replay and testability
- csv_detection_replay_node.py turns CSV records into /light_tracking/detection_json, allowing the whole control stack to be tested without a camera.
- The turtlesim launch file wires this replay into the same follower logic, which makes the detection/control boundary easy to validate in isolation.
- This is a key architectural feature: the repo is designed so perception can be substituted with recorded data.
7. Arm skills as a separate capability
- arm_skill_bridge_node.py exposes simple services for /arm_skills/pick_box, /arm_skills/place_box, and /arm_skills/stop.
- The arm path is separate from the light-tracking pipeline and appears to be an action-oriented bridge to the Unitree arm SDK.
- Its inputs are service calls, not detection streams, which makes it a distinct subsystem in the diagram.
8. Launch orchestration
- launch/light_tracking_stack.launch.py assembles the full robot pipeline.
- launch/light_tracking_turtlesim.launch.py assembles the offline/simulation pipeline.
- Launch files are the main composition boundary in this repo: they decide which nodes run together and which config files are injected.
9. Calibration and tooling
- tools/calibrate_perception.py and the duplicate package-local version under g1_light_tracking/tools/ calibrate detection thresholds from a reference video.
- The calibration tool writes back to config/perception.yaml and produces a Markdown report in logs/.
- This makes perception tuning an explicit offline workflow rather than an ad hoc runtime tweak.
10. Configuration boundary
- config/perception.yaml, config/control.yaml, and config/bridge.yaml split the system into three tunable concerns: detection, motion behavior, and transport/hardware integration.
- That separation is important for diagramming because it shows which components are policy/config-driven versus code-driven.
- The presence of a logs/ folder with a sample run log and a calibration report indicates the repo supports diagnosis and validation alongside execution.
11. Runtime technologies and assumptions
- The codebase is ROS2-first and Python-based, built with colcon and packaged via setup.py / package.xml.
- The README assumes Ubuntu + ROS2 + Python 3.10+, which matters because all communication is via ROS topics/services and the node graph is the system boundary.
- External dependencies are mostly ROS message/service APIs plus whatever the Unitree and camera integrations require.
12. Reference material, not runtime logic
- docs/reference-links/ contains curated pointers for RT Linux, ROS2 real-time, logging, tf2, tracing, and bag recording.
- These files are support material for operating or tuning the system, not part of the runtime architecture.
- In a diagram, they belong outside the core data flow.
13. Recommended diagram emphasis
- The clearest architecture diagram would show three lanes: data sources (D435i, CSV replay), processing (light_spot_detector_node, g1_light_follower_node), and outputs (Unitree bridge, turtlesim bridge, arm services).
- A second axis should distinguish online robot mode from offline/simulation/calibration mode.
- The central interface between perception and control is /light_tracking/detection_json; the central actuation interface is /cmd_vel.
Main entry points: g1_light_follower_node.py Follower · light_spot_detector_node.py Light detector · light_tracking_stack.launch.py Robot launch · light_tracking_turtlesim.launch.py Turtlesim launch
Components 19
Inputs
Live and replayed data sources that enter the pipeline
- D435i node · Publishes camera frames from the Intel RealSense D435i
ros2_ws/g1_light_tracking/g1_light_tracking/d435i_node.py - CSV replay · Replays recorded detections into the live control pipeline
ros2_ws/g1_light_tracking/g1_light_tracking/csv_detection_replay_node.py
Perception
Camera ingestion and light-spot detection
- Light detector · Consumes images and publishes light spot detections as JSON
ros2_ws/g1_light_tracking/g1_light_tracking/light_spot_detector_node.py - Detector API · Detector interface and shared contracts
ros2_ws/g1_light_tracking/g1_light_tracking/vision/detector_interfaces.py - Detection types · Shared detection data structures
ros2_ws/g1_light_tracking/g1_light_tracking/vision/detection_types.py - Registry · Selects and registers detector implementations
ros2_ws/g1_light_tracking/g1_light_tracking/vision/detector_registry.py - Detectors · Concrete detector implementations used by the node
ros2_ws/g1_light_tracking/g1_light_tracking/vision/detectors.py
Control
Detection-to-motion follower logic
- Follower · Consumes detections and publishes velocity commands
ros2_ws/g1_light_tracking/g1_light_tracking/g1_light_follower_node.py
Actuation
Bridges from ROS velocity commands to robot or simulator
- Unitree bridge · Maps /cmd_vel to Unitree G1 actuation
ros2_ws/g1_light_tracking/g1_light_tracking/unitree_cmd_vel_bridge_node.py - Turtlesim bridge · Maps /cmd_vel to /turtle1/cmd_vel for simulation
ros2_ws/g1_light_tracking/g1_light_tracking/turtlesim_cmd_vel_bridge_node.py
Arm Skills
Separate service-based arm capability
- Arm bridge · Exposes pick, place, and stop services for arm control
ros2_ws/g1_light_tracking/g1_light_tracking/arm_skill_bridge_node.py - Arm controller · Implements arm skill execution logic
ros2_ws/g1_light_tracking/g1_light_tracking/arm_skill_controller.py
Launch & Tools
Composition, replay, and calibration entry points
- Robot launch · Composes the online robot pipeline
ros2_ws/g1_light_tracking/launch/light_tracking_stack.launch.py - Turtlesim launch · Composes the replay and simulation pipeline
ros2_ws/g1_light_tracking/launch/light_tracking_turtlesim.launch.py - Calibration tool · Derives perception thresholds from recorded video and writes back config
ros2_ws/g1_light_tracking/tools/calibrate_perception.py - Calibration report · Markdown output documenting threshold tuning results
ros2_ws/g1_light_tracking/config/perception_calibration_report.md
Configuration
Runtime tuning and transport settings
- Perception cfg · Detection thresholds and legacy selection mode
ros2_ws/g1_light_tracking/config/perception.yaml - Control cfg · Follower tuning and speed limits
ros2_ws/g1_light_tracking/config/control.yaml - Bridge cfg · Transport and hardware settings for the Unitree bridge
ros2_ws/g1_light_tracking/config/bridge.yaml
Connections 24
- D435i node → Light detector: /camera/image_raw · Live image stream into perception
- CSV replay → Follower: /light_tracking/detection_json · Offline detection input for control testing
- Light detector → Follower: /light_tracking/detection_json · Primary perception-to-control interface
- Follower → Unitree bridge: /cmd_vel · Velocity commands for robot actuation
- Follower → Turtlesim bridge: /cmd_vel · Velocity commands for simulation actuation
- Arm bridge → Arm controller: services · Service requests dispatched to arm skill logic
- Robot launch → D435i node: starts · Composes the live robot pipeline
- Robot launch → Light detector: starts · Launches perception node
- Robot launch → Follower: starts · Launches control node
- Robot launch → Unitree bridge: starts · Launches robot bridge
- Robot launch → Arm bridge: starts · Launches arm services
- Turtlesim launch → CSV replay: starts · Uses replay as perception substitute
- Turtlesim launch → Follower: starts · Reuses same control logic in simulation
- Turtlesim launch → Turtlesim bridge: starts · Launches simulator bridge
- Calibration tool → Perception cfg: writes · Updates detection thresholds
- Calibration tool → Calibration report: produces · Generates tuning report
- Perception cfg → Light detector: configures · Controls detector selection and thresholds
- Control cfg → Follower: configures · Sets follower tuning and limits
- Bridge cfg → Unitree bridge: configures · Sets transport and hardware parameters
- Detector API → Detectors: defines · Shared detector contract used by implementations
- Detection types → Light detector: defines · Shared detection payloads
- Registry → Light detector: selects · Chooses active detector implementation
- Detectors → Light detector: implements · Concrete detection algorithms used by the node
- Arm bridge → Robot launch: optional · Included in the full robot composition