# yuanqizhiti/hongtu architecture

> Architecture diagram of the GitHub repository yuanqizhiti/hongtu, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuanqizhiti/hongtu
- Repository: https://github.com/yuanqizhiti/hongtu

## Overview

1. **Repository shape**
   This repo is really three systems side by side:
   - `G1Nav2D`: a ROS1 Catkin workspace for 2D SLAM/navigation on a Unitree robot.
   - `PythonProject/py-xiaozhi-main`: a separate Python voice-assistant application with MCP tool integration.
   - `unitree_sdk2_python`: a vendored Unitree SDK used for robot control and state access.

2. **Main robotics stack boundary: ROS1 navigation**
   `G1Nav2D` is the core autonomy stack. It assumes:
   - a Livox LiDAR publishes point clouds,
   - localization/mapping nodes build or match against a map,
   - `move_base` plans navigation goals,
   - a separate control program sends motion commands to the robot.

3. **Sensor ingestion layer**
   `src/livox_ros_driver2-master` is the LiDAR driver layer. Its job is to turn Livox hardware input into ROS topics. Configuration is device-specific (`MID360_config.json`, `HAP_config.json`, mixed configs), and launch files select ROS1/ROS2 publish modes. This is the upstream data source for SLAM.

4. **SLAM and localization**
   `src/fastlio2` is the mapping/localization subsystem. It contains:
   - LiDAR-IMU odometry and map building logic,
   - IMU processing (`lio_builder/imu_processor`),
   - ICP-based localization (`localizer/icp_localizer`),
   - k-d tree map indexing (`ikd-Tree`),
   - IKFoM/ESEKF math utilities for state estimation.
   
   Its launch/config split indicates two modes:
   - mapping (`mapping.launch`, `mapping.yaml`)
   - localization (`localize.yaml`, `navigation.launch` with loaded map)

5. **Navigation and planning**
   `src/movebase` is the path planning layer. It packages:
   - `move_base` / Move Base Flex parameters,
   - global and local costmaps,
   - planner configs such as DWA and TEB,
   - SBPL motion primitives and recovery behavior settings.
   
   In the architecture, this sits downstream of localization and upstream of the robot motion interface.

6. **Map artifact management**
   Maps are treated as persistent assets, not just runtime outputs:
   - `fastlio2/PCD` stores point-cloud maps.
   - `ros_map_edit/maps` stores occupancy map bundles (`.pgm`, `.yaml`, `.json`).
   - `path/key_poses.txt` and `tool/path/teaching_paths.txt` store navigation/path history.
   
   This means the system has both 3D mapping artifacts and 2D occupancy-grid artifacts.

7. **Interactive map editing and publishing**
   `src/ros_map_edit` is a GUI/utility subsystem for editing occupancy maps. It provides:
   - RViz plugins/tools for erasing, regions, and virtual walls,
   - map file management,
   - launch files for map server + editor.
   
   This is a human-in-the-loop boundary: maps are generated by SLAM, then edited before being consumed by navigation.

8. **Point-cloud and frame conversion tools**
   `src/tool` and `src/pointcloud_to_laserscan` are support layers:
   - point-cloud frame transforms,
   - downsampling,
   - LiDAR-to-vehicle/odometry transformations,
   - point-cloud-to-2D-scan conversion for navigation compatibility,
   - path/waypoint utilities and teaching-path replay.
   
   These nodes bridge raw sensor geometry into formats expected by the planner and map stack.

9. **Robot control boundary**
   The actual robot actuation is not implemented inside `G1Nav2D`; it is delegated to `unitree_sdk2_python`.
   That SDK exposes DDS/RPC-based APIs for:
   - sport/high-level motion control,
   - low-level state and command access,
   - audio/video and other robot services.
   
   The README’s `g1_control.py` usage shows the navigation stack depends on an external control process that talks over the robot network interface.

10. **Voice interaction and task orchestration**
   `PythonProject/py-xiaozhi-main` is a separate AI voice assistant application. Its architecture includes:
   - audio processing and wake-word/VAD modules,
   - MQTT/WebSocket protocol clients,
   - GUI/CLI front ends,
   - a large `mcp` tool registry for actions like search, timer, camera, system control, and custom navigation tasks.
   
   The custom `daohang_*` modules and scripts are the bridge into robot navigation.

11. **Voice-to-navigation data flow**
   The README shows the main integration path:
   - user speaks a destination keyword,
   - `py-xiaozhi-main` recognizes intent,
   - MCP service resolves it to a custom navigation tool,
   - the tool launches a Python script in `PythonProject/daohang` or `point_nav`,
   - that script triggers navigation to a preconfigured point in the ROS system.
   
   So voice control does not directly drive the robot; it dispatches a prewired navigation task into the ROS navigation stack.

12. **Runtime orchestration**
   Most behavior is wired through launch files rather than a single monolith:
   - ROS launch files start sensing, SLAM, mapping, navigation, map server, and RViz.
   - Python entrypoints start the voice assistant and its MCP services.
   - Separate shell/scripts are used for build, activation, and startup on Linux.
   
   For an architecture diagram, the critical boundaries are:
   - hardware sensors → ROS driver → SLAM/localization → planner → Unitree control SDK,
   - voice assistant → MCP tools/scripts → ROS navigation stack,
   - map generation/editing as a persisted asset pipeline between SLAM and planning.

Main entry points: [`G1Nav2D/src/fastlio2`](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2) (FAST-LIO2), [`G1Nav2D/src/movebase`](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/movebase) (Move Base), [`PythonProject/py-xiaozhi-main`](https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main) (Voice app), [`G1Nav2D/src/ros_map_edit/maps`](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/ros_map_edit/maps) (Map assets)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_g_ros["G1Nav2D ROS stack"]
  node_n_livox["Livox driver<br/>ROS sensor driver"]
  node_n_fastlio["FAST-LIO2<br/>SLAM/localization"]
  node_n_imu["IMU fusion<br/>estimation core"]
  node_n_icp["ICP localizer<br/>localization module"]
  node_n_ikd["ikd tree<br/>map index"]
  node_n_movebase["Move Base<br/>navigation planner"]
  node_n_costmaps["Costmaps<br/>planning maps"]
  node_n_mapedit["Map editor<br/>human map tooling"]
  node_n_mapfiles["Map assets<br/>persisted maps"]
  node_n_tools["Geometry tools<br/>transform utilities"]
  node_n_pc2scan["Scan bridge<br/>sensor adapter"]
  node_n_vsmooth["Vel smoother<br/>motion filter"]
end

subgraph group_g_voice["Voice assistant"]
  node_n_voiceapp["Voice app<br/>Python assistant"]
  node_n_audio["Audio pipeline<br/>speech front-end"]
  node_n_mcp["MCP server<br/>tool dispatch"]
  node_n_navtools["Nav tools<br/>robot task tools"]
  node_n_scripts["Nav scripts<br/>task runners"]
end

subgraph group_g_sdk["Unitree SDK"]
  node_n_sdkcore["Robot SDK<br/>DDS/RPC SDK"]
  node_n_g1ctrl["G1 control<br/>motion client<br/>[g1_control.py]"]
end

node_n_livox -->|"point clouds"| node_n_fastlio
node_n_fastlio -->|"estimates"| node_n_imu
node_n_fastlio -->|"localize"| node_n_icp
node_n_fastlio -->|"indexes map"| node_n_ikd
node_n_fastlio -->|"writes maps"| node_n_mapfiles
node_n_mapedit -->|"edits maps"| node_n_mapfiles
node_n_mapfiles -->|"loaded by"| node_n_movebase
node_n_pc2scan -->|"scan input"| node_n_movebase
node_n_tools -->|"converts"| node_n_pc2scan
node_n_fastlio -->|"poses"| node_n_tools
node_n_movebase -->|"cmd vel"| node_n_vsmooth
node_n_vsmooth -->|"motion cmd"| node_n_g1ctrl
node_n_voiceapp -->|"listens"| node_n_audio
node_n_voiceapp -->|"dispatches"| node_n_mcp
node_n_mcp -->|"navigation tools"| node_n_navtools
node_n_navtools -->|"launches"| node_n_scripts
node_n_scripts -->|"goal request"| node_n_movebase
node_n_g1ctrl -->|"SDK calls"| node_n_sdkcore
node_n_voiceapp -.->|"optional services"| node_n_sdkcore
node_n_movebase -.->|"requires actuation"| node_n_g1ctrl

click node_n_livox "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/livox_ros_driver2-master"
click node_n_fastlio "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2"
click node_n_imu "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2/include/lio_builder"
click node_n_icp "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2/include/localizer"
click node_n_ikd "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2/include/ikd-Tree"
click node_n_movebase "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/movebase"
click node_n_costmaps "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/movebase/param"
click node_n_mapedit "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/ros_map_edit"
click node_n_mapfiles "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/ros_map_edit/maps"
click node_n_tools "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/tool"
click node_n_pc2scan "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/pointcloud_to_laserscan"
click node_n_vsmooth "https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/velocity_smoother_ema"
click node_n_voiceapp "https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main"
click node_n_audio "https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main/src/audio_processing"
click node_n_mcp "https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main/src/mcp"
click node_n_navtools "https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main/src/mcp/tools/daohang_dianti"
click node_n_scripts "https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/daohang"
click node_n_sdkcore "https://github.com/yuanqizhiti/hongtu/tree/main/unitree_sdk2_python/unitree_sdk2py"
click node_n_g1ctrl "https://github.com/yuanqizhiti/hongtu/blob/main/unitree_sdk2_python/example/g1/high_level/g1_control.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_livox,node_n_fastlio,node_n_imu,node_n_icp,node_n_ikd,node_n_movebase,node_n_costmaps,node_n_mapedit,node_n_mapfiles,node_n_tools,node_n_pc2scan,node_n_vsmooth toneBlue
class node_n_voiceapp,node_n_audio,node_n_mcp,node_n_navtools,node_n_scripts toneAmber
class node_n_sdkcore,node_n_g1ctrl toneMint
```

## Components

### G1Nav2D ROS stack

ROS1 catkin workspace for sensing, SLAM, map editing, planning, and motion support.

- [Livox driver](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/livox_ros_driver2-master): ROS sensor driver · Turns Livox LiDAR hardware input into ROS point-cloud topics in ROS1/ROS2 modes. · `G1Nav2D/src/livox_ros_driver2-master`
- [FAST-LIO2](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2): SLAM/localization · LiDAR-IMU odometry, map building, and ICP-based localization subsystem. · `G1Nav2D/src/fastlio2`
- [IMU fusion](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2/include/lio_builder): estimation core · IMU processing and LiDAR-IMU state estimation path. · `G1Nav2D/src/fastlio2/include/lio_builder`
- [ICP localizer](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2/include/localizer): localization module · Map matching and localization against a prebuilt map. · `G1Nav2D/src/fastlio2/include/localizer`
- [ikd tree](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/fastlio2/include/ikd-Tree): map index · Spatial index used for efficient point-cloud map querying and updates. · `G1Nav2D/src/fastlio2/include/ikd-Tree`
- [Move Base](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/movebase): navigation planner · Global/local planning, costmaps, recovery behavior, and planner parameterization. · `G1Nav2D/src/movebase`
- [Costmaps](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/movebase/param): planning maps · Global and local obstacle maps plus converter and planner parameters. · `G1Nav2D/src/movebase/param`
- [Map editor](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/ros_map_edit): human map tooling · GUI tools for editing occupancy maps, regions, and virtual walls before navigation consumes them. · `G1Nav2D/src/ros_map_edit`
- [Map assets](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/ros_map_edit/maps): persisted maps · Occupancy-grid bundles and region metadata stored as map artifacts. · `G1Nav2D/src/ros_map_edit/maps`
- [Geometry tools](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/tool): transform utilities · Point-cloud transforms, downsampling, frame conversion, and teaching-path helpers. · `G1Nav2D/src/tool`
- [Scan bridge](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/pointcloud_to_laserscan): sensor adapter · Converts point clouds into laser-scan-compatible data for navigation components. · `G1Nav2D/src/pointcloud_to_laserscan`
- [Vel smoother](https://github.com/yuanqizhiti/hongtu/tree/main/G1Nav2D/src/velocity_smoother_ema): motion filter · Velocity smoothing layer used between planning and robot command output. · `G1Nav2D/src/velocity_smoother_ema`

### Voice assistant

Separate Python assistant with MCP tools and navigation dispatch.

- [Voice app](https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main): Python assistant · Main voice-assistant application with audio, protocols, GUI/CLI, and task orchestration. · `PythonProject/py-xiaozhi-main`
- [Audio pipeline](https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main/src/audio_processing): speech front-end · Wake-word detection, VAD, and audio codec/processing modules. · `PythonProject/py-xiaozhi-main/src/audio_processing`
- [MCP server](https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main/src/mcp): tool dispatch · Registers and routes assistant actions to tool managers and scripts. · `PythonProject/py-xiaozhi-main/src/mcp`
- [Nav tools](https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/py-xiaozhi-main/src/mcp/tools/daohang_dianti): robot task tools · Custom daohang and point-navigation tools that launch prewired robot destinations. · `PythonProject/py-xiaozhi-main/src/mcp/tools/daohang_dianti`
- [Nav scripts](https://github.com/yuanqizhiti/hongtu/tree/main/PythonProject/daohang): task runners · Script entrypoints for destination-specific navigation actions. · `PythonProject/daohang`

### Unitree SDK

Vendored robot control and state-access SDK.

- [Robot SDK](https://github.com/yuanqizhiti/hongtu/tree/main/unitree_sdk2_python/unitree_sdk2py): DDS/RPC SDK · Core Unitree SDK layer for sport, state, video, audio, and RPC access. · `unitree_sdk2_python/unitree_sdk2py`
- [G1 control](https://github.com/yuanqizhiti/hongtu/blob/main/unitree_sdk2_python/example/g1/high_level/g1_control.py): motion client · Example high-level control client showing how external code commands the robot. · `unitree_sdk2_python/example/g1/high_level/g1_control.py`

## Connections

- Livox driver → FAST-LIO2: point clouds · LiDAR data feeds SLAM and localization.
- FAST-LIO2 → IMU fusion: estimates · LiDAR-IMU odometry uses IMU processing and fusion.
- FAST-LIO2 → ICP localizer: localize · Loads a map and matches against it for localization mode.
- FAST-LIO2 → ikd tree: indexes map · Uses the k-d tree structure for efficient map operations.
- FAST-LIO2 → Map assets: writes maps · Produces persistent point-cloud map artifacts.
- Map editor → Map assets: edits maps · Human-in-the-loop map editing and saving.
- Map assets → Move Base: loaded by · Edited occupancy maps are consumed by navigation.
- Scan bridge → Move Base: scan input · Provides 2D scan-compatible sensing to planner components.
- Geometry tools → Scan bridge: converts · Transforms point clouds and frames into navigation-friendly geometry.
- FAST-LIO2 → Geometry tools: poses · Supplies map/local frame transformations and path history.
- Move Base → Vel smoother: cmd vel · Planner output is smoothed before actuation.
- Vel smoother → G1 control: motion cmd · Smoothed velocity commands reach the external robot control process.
- Voice app → Audio pipeline: listens · Assistant starts from speech capture and recognition.
- Voice app → MCP server: dispatches · Assistant hands intents to MCP tool routing.
- MCP server → Nav tools: navigation tools · Custom MCP tools expose robot-destination actions.
- Nav tools → Nav scripts: launches · Tools invoke Python navigation scripts for specific destinations.
- Nav scripts → Move Base: goal request · Navigation scripts trigger ROS navigation goals.
- G1 control → Robot SDK: SDK calls · External control clients use the Unitree SDK APIs.
- Voice app → Robot SDK: optional services · Assistant ecosystem can access device and service capabilities through the SDK.
- Move Base → G1 control: requires actuation · Planner depends on an external process to actually drive the robot.
