@@ -6,40 +6,206 @@ sidebar_position: 7
66
77# 项目管理(XRobot)
88
9- 本章简要介绍 XRobot 在嵌入式项目中的基本用法,包括模块拉取、配置和主函数生成等。详细的命令说明将在后续页面中分模块展开 。
9+ XRobot 是一套面向嵌入式系统(如 STM32)的自动化代码生成工具,配合模块化硬件抽象层 LibXR 使用。它支持模块仓库管理、参数配置和主函数自动生成等工作,极大提高嵌入式项目的工程组织和开发效率 。
1010
11- ## 使用前提
11+ 本章介绍 XRobot 的安装、目录结构、主要功能、命令行工具用法,以及完整的快速上手流程。
1212
13- 确保已通过 pip 或 pipx 安装 ` xrobot ` 工具:
13+ ---
1414
15- ``` bash
16- pip install xrobot
17- # 或使用 pipx
15+ ## 安装
16+
17+ 推荐通过 pipx 安装(支持隔离环境):
18+
19+ ** Windows:**
20+ ``` ps
21+ python -m pip install --user pipx
22+ python -m pipx ensurepath
1823pipx install xrobot
24+ # 重启终端
1925```
2026
21- ## 基本目录结构
27+ ** Linux:**
28+ ``` bash
29+ sudo apt install pipx
30+ pipx install xrobot
31+ pipx ensurepath
32+ # 重启终端
33+ ```
2234
23- XRobot 使用约定的目录布局进行模块管理和代码生成:
35+ ** 或者使用 pip 安装:**
36+ ``` bash
37+ pip install xrobot
38+ ```
2439
40+ ** 源码安装:**
2541``` bash
42+ git clone https://github.com/xrobot-org/XRobot.git
43+ cd XRobot
44+ pip install .
45+ ```
46+
47+ ---
48+
49+ ## 目录结构约定
50+
51+ XRobot 推荐如下目录布局进行模块管理和代码生成:
52+
53+ ``` text
2654YourProject/
2755├── Modules/ # 存放模块仓库
2856│ └── modules.yaml # 仓库列表
57+ │ └── sources.yaml # (可选)模块源索引
2958├── User/ # 用户配置与生成输出
3059│ ├── xrobot.yaml # 构造参数配置
3160│ └── xrobot_main.hpp # 自动生成主函数
3261```
3362
34- ## 工具说明
63+ ---
64+
65+ ## 功能总览
66+
67+ - ** 模块仓库拉取与同步**
68+ 自动拉取、同步和递归解析模块仓库,保证依赖与版本一致性。
69+ - ** 参数自动提取与配置**
70+ 自动解析模块头文件参数,生成和管理 YAML 配置文件。
71+ - ** 自动主函数生成**
72+ 根据配置自动生成 C++ 入口函数 ` XRobotMain() ` ,支持多模块、实例和嵌套结构。
73+ - ** manifest 解析**
74+ 解析并格式化模块头文件清单(manifest)。
75+ - ** 模块模板快速生成**
76+ 一键生成包含 CI 的标准化模块目录。
77+ - ** 多源模块管理**
78+ 支持本地/远程 YAML 配置和多模块源索引管理。
79+
80+ ---
81+
82+ ## 命令行工具一览
83+
84+ | 命令 Command | 说明 | Description |
85+ | ------------------- | -------------------------------- | -------------------------------------------------- |
86+ | ` xrobot_gen_main ` | 自动生成 C++ 主函数 | Generate main C++ entry source file |
87+ | ` xrobot_mod_parser ` | 解析模块并打印 manifest 信息 | Parse and show module manifest |
88+ | ` xrobot_create_mod ` | 快速创建标准化模块目录 | Create a new module folder & header |
89+ | ` xrobot_init_mod ` | 拉取并递归同步所有模块仓库 | Clone and recursively sync all module repos |
90+ | ` xrobot_setup ` | 一键初始化工作区和生成主函数 | One-click workspace setup & main function generate |
91+ | ` xrobot_add_mod ` | 添加模块仓库或追加模块实例到配置 | Add repo or append module instance config |
92+ | ` xrobot_src_man ` | 多源模块仓库管理与索引工具 | Multi-source module repository management utility |
93+
94+ 详细参数和用法见后续章节。
95+
96+ ---
97+
98+ ## 快速上手(推荐流程)
99+
100+ ``` bash
101+ # 1. 一键初始化环境、拉取模块、生成主函数(推荐)
102+ # 1. One-click initialize workspace, fetch modules, and generate main function (recommended)
103+ $ xrobot_setup
104+ Starting XRobot auto-configuration...
105+ [INFO] Created default Modules/modules.yaml
106+ Please edit this file; each line should be a full module name like:
107+ - xrobot-org/BlinkLED
108+ - your-namespace/YourModule@dev
109+ [INFO] Created default Modules/sources.yaml
110+ Please configure sources index.yaml for official or custom/private mirrors.
111+ Default official source already included.
112+
113+ $ xrobot_setup
114+ Starting XRobot auto-configuration...
115+ [EXEC] xrobot_init_mod --config Modules/modules.yaml --directory Modules --sources Modules/sources.yaml
116+ [INFO] Cloning new module: xrobot-org/BlinkLED
117+ Cloning into ' Modules/BlinkLED' ...
118+ remote: Enumerating objects: 31, done.
119+ remote: Counting objects: 100% (31/31), done.
120+ remote: Compressing objects: 100% (21/21), done.
121+ remote: Total 31 (delta 10), reused 31 (delta 10), pack-reused 0 (from 0)
122+ Receiving objects: 100% (31/31), 4.43 KiB | 2.22 MiB/s, done.
123+ Resolving deltas: 100% (10/10), done.
124+ [SUCCESS] All modules and their dependencies processed.
125+ [INFO] Created default Modules/CMakeLists.txt: Modules/CMakeLists.txt
126+ [EXEC] xrobot_gen_main --output User/xrobot_main.hpp
127+ Discovered modules: BlinkLED
128+ [INFO] Successfully parsed manifest for BlinkLED
129+ [INFO] Writing configuration to User/xrobot.yaml
130+ [SUCCESS] Generated entry file: User/xrobot_main.hpp
131+
132+ All done! Main function generated at: User/xrobot_main.hpp
133+
134+ # 2. 单独拉取/同步模块仓库(可选)
135+ # 2. Pull or sync module repositories separately (optional)
136+ $ xrobot_init_mod --config Modules/modules.yaml --directory Modules
137+ [INFO] Updating module: xrobot-org/BlinkLED
138+ Already up to date.
139+ Already on ' master'
140+ Your branch is up to date with ' origin/master' .
141+ [SUCCESS] All modules and their dependencies processed.
35142
36- XRobot 工具集包括以下命令,具体用法见后续子页面:
143+ # 3. 创建模块
144+ # 3. Create a module
145+ $ xrobot_create_mod MySensor --desc " IMU interface module" --hw i2c1
146+ [OK] Module MySensor generated at Modules/MySensor
37147
38- - ` xrobot_add_mod ` :添加模块仓库或模块实例
39- - ` xrobot_init_mod ` :拉取/更新模块仓库
40- - ` xrobot_gen_main ` :生成主函数代码
41- - ` xrobot_create_mod ` :创建模块模板
42- - ` xrobot_mod_parser ` :解析模块头文件中的构造参数
43- - ` xrobot_setup ` :一键生成入口文件和配置
148+ # 4. 查看模块信息
149+ # 4. View module information
150+ $ xrobot_mod_parser --path ./Modules/MySensor/
44151
45- 后续页面将逐个介绍这些命令的详细用法与参数。
152+ === Module: MySensor.hpp ===
153+ Description : IMU interface module
154+
155+ Constructor Args :
156+ Required Hardware : i2c1
157+ Depends : None
158+
159+ # 5. 添加模块仓库(如需自定义来源)
160+ # 5. Add a module repository (custom source, optional)
161+ $ xrobot_add_mod your-namespace/YourModule@main
162+ [SUCCESS] Added repo module ' your-namespace/YourModule@main' to Modules/modules.yaml
163+
164+ # 6. 添加模块实例
165+ # 6. Add a module instance
166+ $ xrobot_add_mod MySensor
167+ [SUCCESS] Appended module instance ' MySensor' as id ' MySensor_0' to User/xrobot.yaml
168+
169+ # 7. 查看模块实例
170+ # 7. View module instances
171+ $ cat ./User/xrobot.yaml
172+ global_settings:
173+ monitor_sleep_ms: 1000
174+ modules:
175+ - name: BlinkLED
176+ constructor_args:
177+ blink_cycle: 250
178+ - id: MySensor_0
179+ name: MySensor
180+ constructor_args: {}
181+
182+ # 8. 重新生成主函数(支持自动扫描和配置)
183+ # 8. Regenerate main function (auto scan & config supported)
184+ $ xrobot_gen_main --output User/xrobot_main.hpp
185+ Discovered modules: BlinkLED, MySensor
186+ [SUCCESS] Generated entry file: User/xrobot_main.hpp
187+
188+ # 9. 查看主函数
189+ # 9. View main function
190+ $ cat ./User/xrobot_main.hpp
191+ # include "app_framework.hpp"
192+ # include "libxr.hpp"
193+
194+ // Module headers
195+ # include "BlinkLED.hpp"
196+ # include "MySensor.hpp"
197+
198+ static void XRobotMain(LibXR::HardwareContainer & hw) {
199+ using namespace LibXR;
200+ ApplicationManager appmgr;
201+
202+ // Auto-generated module instantiations
203+ static BlinkLED blinkled(hw, appmgr, 250);
204+ static MySensor MySensor_0(hw, appmgr);
205+
206+ while (true) {
207+ appmgr.MonitorAll ();
208+ Thread::Sleep(1000);
209+ }
210+ }
211+ ` ` `
0 commit comments