TIAN-LEIDA-JIANCE/build_appimage.sh

318 lines
8.3 KiB
Bash
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.

#!/bin/bash
# 创建AppImage格式的Linux软件包
echo "🚀 创建AppImage格式的宇树雷达检测系统..."
# 检查环境
if [ ! -f "CMakeLists.txt" ]; then
echo "❌ 请在项目根目录运行此脚本"
exit 1
fi
# 变量设置
APP_NAME="YushuRadar"
APP_VERSION="1.0.0"
APP_DIR="${APP_NAME}.AppDir"
# 清理旧文件
rm -rf ${APP_DIR}
rm -f ${APP_NAME}-*.AppImage
echo "🔨 编译程序..."
# 编译程序
if [ ! -d "build" ]; then
mkdir build
fi
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr
make -j$(nproc) yushu_leida_fixed
cd ..
if [ ! -f "build/yushu_leida_fixed" ]; then
echo "❌ 编译失败"
exit 1
fi
echo "📁 创建AppDir结构..."
# 创建AppDir结构
mkdir -p ${APP_DIR}/usr/{bin,lib,share/{applications,pixmaps}}
mkdir -p ${APP_DIR}/usr/share/yushu-radar/{config,docs}
# 复制主程序
cp build/yushu_leida_fixed ${APP_DIR}/usr/bin/
# 复制配置文件
cp -r config/* ${APP_DIR}/usr/share/yushu-radar/config/
# 创建AppRun脚本
cat > ${APP_DIR}/AppRun << 'EOF'
#!/bin/bash
# AppImage启动脚本
# 获取AppImage目录
HERE="$(dirname "$(readlink -f "${0}")")"
# 设置环境变量
export LD_LIBRARY_PATH="${HERE}/usr/lib:${LD_LIBRARY_PATH}"
export PATH="${HERE}/usr/bin:${PATH}"
export YUSHU_RADAR_CONFIG="${HERE}/usr/share/yushu-radar/config"
# 检查设备权限
check_device() {
local devices=("/dev/ttyUSB0" "/dev/ttyUSB1" "/dev/ttyACM0")
local found=false
echo "🔍 检查雷达设备..."
for device in "${devices[@]}"; do
if [ -e "$device" ]; then
if [ -r "$device" ] && [ -w "$device" ]; then
echo "✅ 找到设备: $device"
found=true
break
else
echo "⚠️ 设备权限不足: $device"
echo "请运行: sudo chmod 666 $device"
fi
fi
done
if [ "$found" = false ]; then
echo "❌ 未找到可用的雷达设备"
echo "请检查设备连接,或运行以下命令查看设备:"
echo "ls -l /dev/ttyUSB* /dev/ttyACM*"
# 显示GUI对话框 (如果有zenity)
if command -v zenity >/dev/null 2>&1; then
zenity --warning --text="未找到雷达设备\n请检查设备连接和权限\n\n设备权限设置:\nsudo chmod 666 /dev/ttyUSB0\n\n或添加用户到dialout组:\nsudo usermod -a -G dialout \$USER" --width=400
fi
return 1
fi
return 0
}
# 检查依赖
check_dependencies() {
local missing=()
# 检查PCL
if ! ldconfig -p | grep -q libpcl; then
missing+=("PCL库")
fi
# 检查yaml-cpp
if ! ldconfig -p | grep -q libyaml-cpp; then
missing+=("yaml-cpp库")
fi
if [ ${#missing[@]} -gt 0 ]; then
echo "❌ 缺少依赖:"
printf '%s\n' "${missing[@]}"
if command -v zenity >/dev/null 2>&1; then
zenity --error --text="缺少系统依赖库\n\n请安装:\nsudo apt install libpcl-dev libyaml-cpp-dev espeak" --width=350
fi
return 1
fi
return 0
}
# 主函数
main() {
echo "🚀 启动宇树雷达检测系统 AppImage..."
# 切换到配置目录
cd "${HERE}/usr/share/yushu-radar"
# 检查依赖
if ! check_dependencies; then
exit 1
fi
# 检查设备
if ! check_device; then
exit 1
fi
# 启动程序
echo "🎯 启动主程序..."
exec "${HERE}/usr/bin/yushu_leida_fixed"
}
# 处理参数
case "$1" in
--check)
check_dependencies && check_device
;;
--help)
echo "宇树雷达检测系统 AppImage v${APP_VERSION}"
echo ""
echo "用法:"
echo " $0 启动程序"
echo " $0 --check 检查系统依赖"
echo " $0 --help 显示帮助"
;;
*)
main "$@"
;;
esac
EOF
chmod +x ${APP_DIR}/AppRun
# 创建桌面文件
cat > ${APP_DIR}/yushu-radar.desktop << 'EOF'
[Desktop Entry]
Type=Application
Name=宇树雷达检测系统
Name[en]=Unitree Radar Detection System
Comment=坡面裂缝和遮挡物检测系统
Comment[en]=Slope crack and occlusion detection system
Exec=yushu-radar
Icon=yushu-radar
Categories=Science;Engineering;Education;
Keywords=radar;lidar;detection;unitree;
Terminal=true
StartupNotify=true
EOF
# 复制桌面文件到标准位置
cp ${APP_DIR}/yushu-radar.desktop ${APP_DIR}/usr/share/applications/
# 创建图标
cat > ${APP_DIR}/yushu-radar.svg << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<svg width="128" height="128" viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">
<!-- 背景圆 -->
<circle cx="64" cy="64" r="60" fill="#1e3a8a" stroke="#3b82f6" stroke-width="4"/>
<!-- 雷达扫描圈 -->
<circle cx="64" cy="64" r="45" fill="none" stroke="#10b981" stroke-width="2" opacity="0.8"/>
<circle cx="64" cy="64" r="30" fill="none" stroke="#f59e0b" stroke-width="2" opacity="0.6"/>
<circle cx="64" cy="64" r="15" fill="none" stroke="#ef4444" stroke-width="2" opacity="0.4"/>
<!-- 中心点 -->
<circle cx="64" cy="64" r="4" fill="#ef4444"/>
<!-- 扫描线 -->
<line x1="64" y1="64" x2="64" y2="19" stroke="#10b981" stroke-width="2" opacity="0.8"/>
<line x1="64" y1="64" x2="95" y2="45" stroke="#10b981" stroke-width="1.5" opacity="0.6"/>
<!-- 检测点 -->
<circle cx="80" cy="40" r="2" fill="#f59e0b"/>
<circle cx="45" cy="50" r="2" fill="#f59e0b"/>
<circle cx="70" cy="85" r="2" fill="#ef4444"/>
<!-- 文字 -->
<text x="64" y="115" text-anchor="middle" fill="white" font-family="Arial, sans-serif" font-size="12" font-weight="bold">RADAR</text>
</svg>
EOF
# 复制图标
cp ${APP_DIR}/yushu-radar.svg ${APP_DIR}/usr/share/pixmaps/
ln -sf usr/share/pixmaps/yushu-radar.svg ${APP_DIR}/yushu-radar.svg
# 创建文档
mkdir -p ${APP_DIR}/usr/share/yushu-radar/docs
cat > ${APP_DIR}/usr/share/yushu-radar/docs/README.md << 'EOF'
# 宇树雷达检测系统 AppImage
## 关于AppImage
这是一个便携式的Linux应用程序无需安装即可运行。
## 系统要求
- Linux发行版 (Ubuntu 18.04+, CentOS 7+, 等)
- PCL库 (Point Cloud Library)
- yaml-cpp库
- espeak (可选,用于语音提示)
## 安装依赖
### Ubuntu/Debian:
```bash
sudo apt update
sudo apt install libpcl-dev libyaml-cpp-dev espeak
```
### CentOS/RHEL:
```bash
sudo yum install pcl-devel yaml-cpp-devel espeak
```
## 使用方法
1. 下载AppImage文件
2. 添加执行权限: `chmod +x YushuRadar-*.AppImage`
3. 运行: `./YushuRadar-*.AppImage`
## 设备权限
如果遇到设备权限问题:
```bash
# 临时解决
sudo chmod 666 /dev/ttyUSB0
# 永久解决
sudo usermod -a -G dialout $USER
# 然后重新登录
```
## 功能特点
- ✅ 实时3D点云显示
- ✅ 坐标轴和网格显示
- ✅ 遮挡物检测 (20厘米预警)
- ✅ 裂缝检测 (100米阈值)
- ✅ 声音预警系统
- ✅ 便携式,无需安装
## 故障排除
### 1. 找不到设备
- 检查USB连接
- 查看设备: `ls -l /dev/ttyUSB*`
- 检查权限: `./YushuRadar-*.AppImage --check`
### 2. 缺少依赖
- 安装系统依赖包
- 运行检查: `./YushuRadar-*.AppImage --check`
### 3. 图形界面问题
- 确保X11正常工作
- 远程连接时启用X11转发: `ssh -X user@host`
版本: 1.0.0
EOF
echo "📦 下载AppImage工具..."
# 下载appimagetool
if [ ! -f "appimagetool-x86_64.AppImage" ]; then
wget -q "https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage"
chmod +x appimagetool-x86_64.AppImage
fi
echo "🔧 构建AppImage..."
# 构建AppImage
./appimagetool-x86_64.AppImage ${APP_DIR} ${APP_NAME}-${APP_VERSION}-x86_64.AppImage
if [ -f "${APP_NAME}-${APP_VERSION}-x86_64.AppImage" ]; then
echo ""
echo "🎉 AppImage创建成功"
echo ""
echo "📁 文件: ${APP_NAME}-${APP_VERSION}-x86_64.AppImage"
echo "📊 大小: $(du -h ${APP_NAME}-${APP_VERSION}-x86_64.AppImage | cut -f1)"
echo ""
echo "📋 使用方法:"
echo "1. 添加执行权限: chmod +x ${APP_NAME}-${APP_VERSION}-x86_64.AppImage"
echo "2. 运行程序: ./${APP_NAME}-${APP_VERSION}-x86_64.AppImage"
echo "3. 检查系统: ./${APP_NAME}-${APP_VERSION}-x86_64.AppImage --check"
echo ""
echo "✅ 这个AppImage可以在任何Linux系统上运行无需安装"
echo ""
else
echo "❌ AppImage创建失败"
exit 1
fi