Skip to content

Quick Start

creeper5820 edited this page Dec 19, 2025 · 10 revisions

环境依赖:任意能够运行 Docker 的发行版,UbuntuArchLinuxDebainWSL 皆可

配置开发环境

安装 Docker

  1. 各平台 Docker 安装指南
  2. 不使用 Root 使用 Docker

随后确认 Docker 是否成功安装:

docker ps

它应该输出如下输出:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
......

不出意料的,Docker Pull 会无法从 Docker Hub 拉取任何镜像,我们需要配置代理:

# 请自行把 http://127.0.0.1:7890 改为合适的代理地址。
sudo mkdir -p /etc/systemd/system/docker.service.d &&
sudo tee /etc/systemd/system/docker.service.d/proxy.conf << EOF
[Service]
Environment="HTTP_PROXY=http://127.0.0.1:7890/"
Environment="HTTPS_PROXY=http://127.0.0.1:7890/"
EOF
sudo systemctl daemon-reload &&
sudo systemctl restart docker

这时候就可以拉取镜像了,我们可以先拉取一个 hello-world 测试:

docker pull hello-world
输出如下(点击展开)

⋊> ~/w/a/o/RMCS on release/tunnel-omni-infantry  docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
17eec7bbc9d7: Pull complete 
ea52d2000f90: Download complete 
Digest: sha256:d4aaab6242e0cace87e2ec17a2ed3d779d18fbfd03042ea58f2995626396a274
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest

最后运行这个镜像:

docker run --rm hello-world:latest

如果输出下面的输出,则代表配置完全成功,可以开始拉取团队镜像了

输出如下(点击展开)

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/

For more examples and ideas, visit: https://docs.docker.com/get-started/

开拉,大概 1.6G

docker pull qzhhhi/rmcs-develop:latest

进入 RMCS 开发环境

寻找一个地方,开始克隆仓库:

git clone --recurse-submodules https://github.com/Alliance-Algorithm/RMCS.git

标准工作流是使用 vscodeDev Containers 插件进行开发,所以我们需要下载 vscode 后安装相关插件,随后在 vscode 打开 RMCS 根目录

在 vscode 中新建终端,键入下面的指令,同步配置文件:

cp .vscode/settings.default.json .vscode/settings.json

这会应用我们推荐的 VSCode 配置文件,你也可以按需自行修改配置文件

在拓展列表中,可以看到我们推荐使用的拓展正在安装,你也可以按需自行删减拓展

Ctrl+Shift+P,在弹出的菜单中选择 Dev Containers: Reopen in Container

vscode 将拉起一个 Docker 容器,容器中已配置好完整开发环境,之后所有工作将在容器内进行

执行这一步之前,需先在VScode内安装 Dev Containers 扩展

如果 Dev Containers 在启动时卡住很长一段时间,可以尝试 这个解决方案

编译项目

完成上述步骤后,左下角应该会显示类似的文字,表示你正在一个 Docker 容器中工作

图片

此时新建一个终端。使用如下指令构建项目

# RMCS 为开发者预先准备好了丰富的开发脚本,具体在 .script/ 目录下
build-rmcs

在 Windows WSL 开发的用户需要注意,全核编译 ROS2 包需要大量内存,由于 WSL 的局限性,一部分开发者可能会在编译时卡死,需要在 WSl 设置界面调整内存和线程分配,分配更多的内存并减少逻辑处理数量

08a0f0f03e52d2408b3ae7aaf8e7bd3a

开发与热更新构建产物

在本机简单测试,我们可以使用如下方式:

ros2 launch rmcs_bringup rmcs.launch.py robot:=robot-name

这里的 robot-name 对应着 rmcs_bringup/config/ 下面的一份 .yaml 文件,使用如下指令可以查看存在的配置文件

ls ${RMCS_PATH}/rmcs_ws/src/rmcs_bringup/config/
比如这个例子(点击展开)

# 没有插入下位机,所以会报错,这是正常现象 
ubuntu@creeper [22:04:31] [~] 
-> % ros2 launch rmcs_bringup rmcs.launch.py robot:=tunnel-omni-infantry
[INFO] [launch]: All log files can be found below /home/ubuntu/.ros/log/2025-12-10-22-04-32-405335-creeper-131324
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [launch.user]: Starting RMCS on robot 'tunnel-omni-infantry' -> tunnel-omni-infantry.yaml
[INFO] [rmcs_executor-1]: process started with pid [131327]
[rmcs_executor-1] [WARN] [1765375472.469565984] [rcl]: ROS_LOCALHOST_ONLY is deprecated but still honored if it is enabled. Use ROS_AUTOMATIC_DISCOVERY_RANGE and ROS_STATIC_PEERS instead.
[rmcs_executor-1] [WARN] [1765375472.469576704] [rcl]: 'localhost_only' is enabled, 'automatic_discovery_range' and 'static_peers' will be ignored.
[rmcs_executor-1] [ERROR] [1765375472.490965871] [librmcs]: No devices found with vendor id: 0xa11c
[rmcs_executor-1] terminate called after throwing an instance of 'std::runtime_error'
[rmcs_executor-1]   what():  Failed to init usb transfer for cboard, see log for detail.

对于远程设备(运行着 rmcs-runtime),我们需要先知道其 IP 地址,然后设置为 remote

有以下几个办法可以获得机器人的 IP:

  1. 使用有线连接,物理网口或者外置网口转 USB 都可以,此时机器人使用固定 IP 169.254.233.233,我们只需要将自己电脑的 IP 设置成同一网段即可,比如 169.254.233.1,一个外置网卡 50 元上下,提供 USB 到网口的转换,调试必备,建议买一个,(爱国者牌子的质感最好,推之),不建议购买 typec 接口,容易坏,可以买一个 A 口加 A 转 C 的头

  2. 使用 IP 扫描,需要确保机器人连上了同一 Wifi,处于同一个局域网

# 下载扫描工具
sudo apt-get install nmap -y

# 然后扫描对应网段(1,2,3 这几个子网都扫扫,如果用 192.168.0.0/16 那时间将会非常长,一般只扫几个常用的子网)
# 2022 端口是 docker 开放的 ssh 端口,用于连接开发容器,可以作为特征
sudo nmap -p 2022 --open 192.168.1.0/24
sudo nmap -p 2022 --open 192.168.2.0/24

# 会有类似的输出,登录上去看看 hostname 即可
# 「一般来说」,机器人本机的用户名是 alliance,密码也是
Nmap scan report for 192.168.1.246
Host is up (0.16s latency).

PORT     STATE SERVICE
2022/tcp open  down
MAC Address: 50:2F:9B:15:AB:C6 (Intel Corporate)
  1. 插屏幕或者采集卡(最后的手段) + 键盘,视频采集卡提供 HDMI 转 USB 的接口,可以接到手机上,使用「USB 摄像头」之类的软件查看,或者在电脑使用 OBS 捕获,不需要像屏幕一样外置电源,比较方便,一个差不多 100 上下,推荐购买一个以备不时之需

然后开始调试:

# 手动设置 IP
set-remote 192.168.1.246

# 使用广播寻找 IP,后缀是 local 的会自动调用寻找逻辑,但这个功能在复杂的网络环境中并不是很灵光
# 在 2025 赛季我们开发了一个机器人心跳端用于同步数据,这样可以使用网页来查看在线机器人的相关信息
# 后续应该会有更好的解决方案
set-remote hostname.local

# 进入目标机器人的 rmcs-runtime 容器中
ssh-remote

# 同步构建产物至目标机器人的容器中
sync-remote

# 进入 RMCS 的终端会话中(托管在 `screen` 上)
attach-remote [-r 重启程序]

配置运行时环境(机器人上)

我们队伍目前所使用的是:ubuntu-server:24.04,之所以是 server 版本,是因为 RMCS 的所有工作流都是基于终端,且无 GUI 版本的系统可以为程序节省更多性能与空间

ssh 为核心手段的调试工作流也避免了需要携带便携屏和外置键盘的窘迫境地,只需要一台轻薄本和一根网线,或者是一个 USB 转网口,即可愉快调试,而可视化调试则使用 ROS2 Visualization Topic 和视频推流,远比传统的远程桌面流畅

建议装机并配置好网络后立刻切换到 ssh 会话进行下一步的配置,后续有大段脚本的输入需求

网络配置

  • 设置 Hostname:

    sudo hostnamectl set-hostname 一个有意义的名字
    
  • 配置 netplan

    # 获取网卡信息
    ip ad

    将下面指令中的 <有线网卡名><无线网卡名> 修改为上面步骤获得的信息,比如 eno1wlan0

    然后修改 wifis 配置中的 access-points,放进终端中执行

    # 创建文件
    sudo tee /etc/netplan/99-rmcs-config.yaml > /dev/null <<'EOF'
    network:
      version: 2
      ethernets:
        <有线网卡名>:
          optional: true
          dhcp4: true
          dhcp6: true
          addresses:
            - 169.254.233.233/16
        usb-net:
          match:
            name: "enx*"
          optional: true
          dhcp4: true
          dhcp6: true
          addresses:
            - 169.254.233.233/16
      wifis:
        <无线网卡名>:
          optional: true
          access-points:
            AllianceTeam5.2G:
              password: rm-alliance.icu
          dhcp4: true
          dhcp6: true
    EOF
    
    # 修正权限
    sudo chmod 600 /etc/netplan/99-rmcs-config.yaml
    
    # 应用配置
    sudo netplan apply

杂项配置

  • 阻止在开机时阻塞 A start job is running for wait for network to be configured.

    相关链接:askubuntu.com/a/979493

    通常,将 interface 设为 optional: true (上面的配置文件中) 可以有效防止启动卡住,但为了以防万一,把下面的服务也禁用

    sudo systemctl disable systemd-networkd-wait-online.service &&
    sudo systemctl mask systemd-networkd-wait-online.service

依赖安装

在确保有网络的情况下,执行下面的脚本用于安装

# Docker 相关组件安装
sudo apt-get update &&
sudo apt-get -y install ca-certificates curl &&
sudo install -m 0755 -d /etc/apt/keyrings &&
sudo curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc &&
sudo chmod a+r /etc/apt/keyrings/docker.asc &&
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null &&
sudo apt-get update &&
sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin &&
sudo usermod -aG docker $USER

# 基础工具安装
sudo apt install -y net-tools zsh &&
curl -fsSL https://gitee.com/pocmon/ohmyzsh/raw/master/tools/install.sh | sh &&
sed -i 's/ZSH_THEME=\"[a-z0-9\-]*\"/ZSH_THEME="af-magic"/g' .zshrc &&
chsh -s $(which zsh)

导入 Docker 镜像

如果非常幸运能够直连 Docker Hub,或者配置好了代理环境,可以直接拉取:

docker pull qzhhhi/rmcs-runtime:latest

没有上述条件时,只能通过开发机的代理环境下载好 rmcs-runtime,然后手动导出,再导入

# 在开发机上导出镜像
docker pull qzhhhi/rmcs-runtime:latest
docker save -o rmcs-runtime.rar qzhhhi/rmcs-runtime:latest

# 通过 U 盘或者 `scp` 拷贝到机器人的环境中

# 在机器人的环境中导入镜像
docker load -i rmcs-runtime.tar

最后启动 rmcs-runtime

docker run -d --restart=always --privileged --network=host -v /dev:/dev qzhhhi/rmcs-runtime

至此 rmcs-runtime 安装完毕

Clone this wiki locally