update : make_deb.sh

This commit is contained in:
Alvin-lyq 2025-09-16 13:16:03 +08:00
parent 1a10e5649f
commit f2b0359a44
3 changed files with 87 additions and 17 deletions

3
.gitignore vendored
View File

@ -2,5 +2,4 @@ build
install
log
.vscode
deb_build
*.deb
deb_build

View File

@ -81,12 +81,12 @@ sudo dpkg -r controller
| 字段类型 | 字段名称 | 取值范围 / 说明 | 功能描述 |
| -------- | ------------------------------- | ----------------------------------------------- | ------------------------------------------------------------ |
| uint8 | brake | 0、1 | 电磁刹控制0 表示解除电磁刹1 表示激活电磁刹 |
| uint8 | brake | 0不刹、1 | 电磁刹控制0 表示解除电磁刹1 表示激活电磁刹 |
| uint8 | gear | 0空挡、1后退、2前进、3保留 | 车辆挡位控制3 为预留挡位暂未使用 |
| uint8 | rpm | 0-6000 | 电机转速指令数值直接对应实际电机转速rpm |
| float32 | angle | \[-66.0, 66.0](分辨率 0.2°,建议适当缩减范围) | 轮端转向角度控制,单位为度(°) |
| uint8 | rpm | 0-4000 | 电机转速指令数值直接对应实际电机转速rpm |
| float32 | angle | \[-40.0, 40.0] | 轮端转向角度控制,单位为度(°)[-左、+右] |
| uint16 | angle\_speed | 120-1500 | 转向角速度控制,单位为 rpm |
| bool | sweep | true:清扫 false:不清扫 | 清扫 |
| bool | sweep | true清扫、false不清扫 | 清扫 |
#### 对应 Topic
@ -128,3 +128,5 @@ sudo dpkg -r controller
| 版本 | 更新日期 | 更新内容 | 开发者 |
| ---- | -------- | ------------------------------------------------------------ | ------------------ |
| V1.0 | 2025-09-02 | 初始版本,定义`McCtrl.msg`和`Rtk.msg`结构,明确 Topic | \[zxwl] |
| V1.1 | 2025-09-16 | controller.deb的安装、启动与卸载 | \[zxwl] |

View File

@ -10,10 +10,12 @@ INSTALL_DIR="/opt/${PKG_NAME}"
WORKDIR="$(pwd)/deb_build"
INSTALL_SRC="$(pwd)/install"
# 清理工作目录
rm -rf "${WORKDIR}"
mkdir -p "${WORKDIR}/${INSTALL_DIR}"
mkdir -p "${WORKDIR}/DEBIAN"
# 复制 ROS2 install 文件
cp -a "${INSTALL_SRC}/." "${WORKDIR}/${INSTALL_DIR}/"
# control 文件
@ -29,7 +31,44 @@ Depends: ros-humble-ros-base, libc6 (>= 2.34)
Description: ${DESCRIPTION}
EOF
# 创建 start_all.sh
# ============================
# 创建 can.sh (root 执行)
# ============================
cat > "${WORKDIR}/${INSTALL_DIR}/can.sh" <<'EOF'
#!/bin/bash
# Script: can.sh
# Description: Configures CAN interface can0 on startup
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
if ip link show can0 &> /dev/null; then
ip link set can0 down
fi
modprobe can
modprobe can_raw
modprobe mttcan
ip link set can0 type can bitrate 500000
ip link set up can0
if [[ $? -ne 0 ]]; then
echo "Error configuring CAN interface can0"
exit 1
fi
echo "CAN interface can0 configured successfully"
exit 0
EOF
chmod +x "${WORKDIR}/${INSTALL_DIR}/can.sh"
# ============================
# 创建 start_all.sh (nvidia 用户执行)
# ============================
cat > "${WORKDIR}/${INSTALL_DIR}/start_all.sh" <<EOF
#!/bin/bash
set -e
@ -44,24 +83,45 @@ source ${INSTALL_DIR}/local_setup.bash
ros2 run radio_ctrl radio_ctrl_node &
ros2 run mc mc_node &
ros2 run ctrl_arbiter ctrl_arbiter_node &
ros2 run mqtt_report mqtt_report_node &
ros2 run rtk rtk_node &
ros2 run pub_gps pub_gps_node &
# ros2 run mqtt_report mqtt_report_node &
# ros2 run rtk rtk_node &
# ros2 run pub_gps pub_gps_node &
wait
EOF
chmod +x "${WORKDIR}/${INSTALL_DIR}/start_all.sh"
# systemd 服务文件
# ============================
# systemd 服务目录
# ============================
mkdir -p "${WORKDIR}/etc/systemd/system"
cat > "${WORKDIR}/etc/systemd/system/${PKG_NAME}.service" <<EOF
# CAN 配置服务 (root 执行)
cat > "${WORKDIR}/etc/systemd/system/${PKG_NAME}-can.service" <<EOF
[Unit]
Description=Remote Controller Nodes
Description=Configure CAN interface can0
After=network.target
[Service]
Type=simple
Type=oneshot
ExecStart=${INSTALL_DIR}/can.sh
RemainAfterExit=yes
User=root
[Install]
WantedBy=multi-user.target
EOF
# ROS2 节点服务 (nvidia 用户执行,依赖 CAN 配置)
cat > "${WORKDIR}/etc/systemd/system/${PKG_NAME}.service" <<EOF
[Unit]
Description=Remote Controller Nodes
After=network.target ${PKG_NAME}-can.service
Requires=${PKG_NAME}-can.service
[Service]
Type=simple
User=nvidia
Environment="ROS_DISTRO=humble"
ExecStart=${INSTALL_DIR}/start_all.sh
Restart=on-failure
@ -71,32 +131,41 @@ RestartSec=2
WantedBy=multi-user.target
EOF
# postinst 脚本(安装后执行)
# ============================
# postinst 启用服务
# ============================
cat > "${WORKDIR}/DEBIAN/postinst" <<EOF
#!/bin/bash
set -e
systemctl daemon-reload
systemctl enable ${PKG_NAME}-can.service
systemctl enable ${PKG_NAME}.service
exit 0
EOF
chmod 755 "${WORKDIR}/DEBIAN/postinst"
# postrm 脚本(卸载时执行)
# ============================
# postrm 停用服务
# ============================
cat > "${WORKDIR}/DEBIAN/postrm" <<EOF
#!/bin/bash
set -e
systemctl stop ${PKG_NAME}.service || true
systemctl disable ${PKG_NAME}.service || true
systemctl stop ${PKG_NAME}-can.service || true
systemctl disable ${PKG_NAME}-can.service || true
systemctl daemon-reload
exit 0
EOF
chmod 755 "${WORKDIR}/DEBIAN/postrm"
# 打包
# ============================
# 构建 deb 包
# ============================
dpkg-deb --build "${WORKDIR}" "${PKG_NAME}_${PKG_VERSION}_${ARCH}.deb"
echo "生成 ${PKG_NAME}_${PKG_VERSION}_${ARCH}.deb"