学习记录,在Ubuntu23.10操作系统下,使用docker运行ros:noetic,搭建Mobile Aloha的运行环境,同时给容器添加N卡gpu支持。(注意:笔者进行环境搭建时全程处于魔法状态,非魔法可能导致网络受限;NVIDIA显卡驱动安装的是metapackage from nvidia-driver-535版本;CPU是x86_x64架构)
1 基本环境搭建
1.1 安装docker
安装依赖
sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release
注册Docker的GPG密钥圈
sudo mkdir -p /etc/apt/trusted.gpg.d
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/docker.gpg
sudo chmod a+r /etc/apt/trusted.gpg.d/docker.gpg
将docker包的源码加入系统
sudo echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/trusted.gpg.d/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
安装docker
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io
测试docker
sudo docker run hello-world
安装成功则屏幕打印如下
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.
1.2 安装NVIDIA显卡支持
启用CUDA仓库(由于官方还未更新支持Ubuntu23.10的版本,这里使用最新的22.04版本经测试可行)
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /"
安装nvidia-container-toolkit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker
2 配置docker容器
2.1 在docker下安装ros:noetic版本
输入以下指令,镜像有4G左右,可能需要较长时间进行下载(此处引用的是fishros大佬打包好的ros镜像,亲测好用)
sudo docker run -dit --gpus all --name=ros-noetic -v /tmp/.X11-unix:/tmp/.X11-unix --device=/dev/dri/renderD128 -v /dev/dri:/dev/dri --device=/dev/snd -e DISPLAY=unix$DISPLAY -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all -w /root fishros2/ros:noetic-desktop-full
镜像下载完毕后,终端将自动创建、启动、进入容器,在容器内输入以下指令测试gpu支持
nvidia-smi
终端打印如下信息则说明docker容器已支持访问gpu
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.146.02 Driver Version: 535.146.02 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+======================+======================|
| 0 NVIDIA GeForce GTX 1650 Off | 00000000:01:00.0 Off | N/A |
| N/A 52C P8 3W / 50W | 5MiB / 4096MiB | 0% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
+---------------------------------------------------------------------------------------+
此镜像仅包含最基础的ros功能,无法满足我们运行Mobile Aloha的环境要求,而且机械臂是通过ttyUSB与上位机进行通讯的,因此docker容器内的硬件条件也暂时不能得到满足,接下来将进行X-Series Arms机械臂的环境搭建并生成新的docker镜像。
2.2 在docker下安装X-Series Arms机械臂支持
输入以下指令一键安装
sudo apt install curl
curl 'https://raw.githubusercontent.com/Interbotix/interbotix_ros_manipulators/main/interbotix_ros_xsarms/install/amd64/xsarm_amd64_install.sh' > xsarm_amd64_install.sh
chmod +x xsarm_amd64_install.sh
./xsarm_amd64_install.sh -d noetic
全部选择yes(MATLAB-ROS可选no,不过笔者选择安装)
安装成功后打印如下
3 配置Mobile Aloha硬件代码
在容器内输入以下指令,进入X-Series Arms支持包的源码部分
cd ~/interbotix_ws/src
输入以下指令,安装ros机器视觉相关依赖
source /opt/ros/noetic/setup.sh && source ~/interbotix_ws/devel/setup.sh
apt-get install ros-noetic-usb-cam && apt-get install ros-noetic-cv-bridge
输入以下指令,下载Mobile Aloha硬件代码
git clone https://github.com/MarkFzp/mobile-aloha.git
回到~/interbotix_ws目录,对整个X-Series Arms支持包进行编译
cd ~/interbotix_ws
catkin_make
修改InterbotixArmXSInterface类中的publish_positions函数,将self.T_sb = mr.FKinSpace(self.robot_des.M, self.robot_des.Slist, self.joint_commands)改为self.T_sb = None,防止每一步都计算FK导致响应时间变长
apt-get install vim
vim ~/interbotix_ws/src/interbotix_ros_toolboxes/interbotix_xs_toolbox/interbotix_xs_modules/src/interbotix_xs_modules/arm.py
至此,Mobile Aloha的环境搭建完毕,可以将此容器保存为镜像,方便在不同平台上进行快速移植
sudo docker commit ros-noetic wangml71/mobile-aloha:noetic
通过docker images命令可查看生成好的镜像文件,后续进行Mobile Aloha部署时可直接使用