Files

97 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# AGV 智能巡检系统 — 脚本说明
## 目录结构
```
scripts/
├── start_all.sh ← 生产环境完整启动(ROS2 + Nav2 + Flask
├── stop_all.sh ← 生产环境完整停止
├── start_flask.sh ← 仅重启 Flask(修改代码后快速部署)
├── restart_flask.sh ← 语法检查 + 清缓存 + 重启 Flask + 验证
└── dev_start.sh ← 本地开发用(前台运行,不启动 ROS2)
```
## 使用场景
### 0. 初始化 Python 环境
项目使用 `uv` 统一管理 Python 虚拟环境,依赖声明在仓库根目录 `pyproject.toml`,锁定版本在 `uv.lock`
```bash
# 如系统尚未安装 uv,先安装 uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# 在仓库根目录执行
cd ~/work/smart-inspection
uv sync
```
`uv sync` 会按 `.python-version` 创建 Python 3.10 虚拟环境到 `.venv`。ROS2 Humble 仍使用系统环境 `/opt/ros/humble`,不要把 ROS2 系统包写入 `pyproject.toml`
系统依赖仍需通过系统包管理器安装:
```bash
sudo apt install -y ffmpeg libzbar0
```
### 1. 首次开机 / 完整重启
```bash
# 在 AGV 上执行
cd ~/work/smart-inspection
./scripts/stop_all.sh # 先彻底清理
./scripts/start_all.sh # 完整启动
```
### 2. 修改代码后快速部署
```bash
# 部署文件到 AGV 后
ssh elephant@192.168.60.80 'bash -s' < scripts/restart_flask.sh
```
### 3. 本地开发调试(不连硬件)
```bash
# 在本机执行,仅启动 Flask
./scripts/dev_start.sh
# 访问 http://127.0.0.1:5000
```
### 4. 远程轻量重启(ROS2 已运行)
```bash
ssh elephant@192.168.60.80 'bash -s' < scripts/start_flask.sh
```
## 环境变量
所有脚本支持通过环境变量覆盖默认路径:
| 变量 | 默认值 | 说明 |
|------|--------|------|
| `AGV_PROJECT_DIR` | `/home/elephant/work/smart-inspection` | 仓库根目录 |
| `AGV_APP_DIR` | `$AGV_PROJECT_DIR/agv_app` | Flask 应用目录 |
| `AGV_ROS2_DIR` | `/home/elephant/agv_pro_ros2` | ROS2 工作空间 |
| `SCAN_FIXER_DIR` | `/home/elephant/work/scan_fixer` | 时间戳修正工具目录 |
| `FIXER_SCRIPT` | `fix_scan_timestamp_v6.py` | fixer 脚本名 |
## 日志位置(AGV 上)
| 组件 | 日志 |
|------|------|
| bringup (激光雷达) | `/tmp/ros2_bringup.log` |
| Nav2 导航 | `/tmp/ros2_nav2.log` |
| scan fixer | `/tmp/scan_fixer.log` |
| Flask | `/tmp/agv_flask.log` |
## 机械臂端
机械臂 (Pi) 的启动由 systemd 托管,在 Pi 上执行:
```bash
cd ~/work/smart-inspection
uv sync
sudo systemctl start arm_server # 启动
sudo systemctl status arm_server # 查看状态
sudo systemctl enable arm_server # 开机自启
```
配置见 `arm_server/arm_server.service`