本文主要是介绍[rk3588 ubuntu20.04]移植ROS2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
1 使用命令行安装ROS2
1.1设置语言
1.2添加源
1.3安装ROS2
1.4设置环境变量
2 在编译源码阶段安装ROS2
2.1调整roofts.img大小
2.2 安装ROS2
3 ROS2功能测试
1 使用命令行安装ROS2
1.1设置语言
设置语言为UTF-8。
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
1.2添加源
使能代码库。
sudo apt install software-properties-common -y
sudo add-apt-repository universe
添加ROS2秘钥,第三步命令添加秘钥可能会超时,多次执行该命令直到添加成功即可。
sudo apt update
sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
将ROS2储存库添加到源列表中。
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
1.3安装ROS2
设置存储库后,更新apt存储库缓存。
sudo apt update
sudo apt upgrade -y
安装aptitude工具,为的是能正常安装ros-foxy-rviz2和ros-foxy-joy。如果使用apt来安装ros-foxy-rviz2和ros-foxy-joy会安装失败。
sudo apt install aptitude -y
安装ros-foxy-desktop的依赖包ros-foxy-rviz2,执行该命令时会要求输入Y/n/q,依次输入n、Y、Y即可。
sudo aptitude install ros-foxy-rviz2
安装ros-foxy-desktop的依赖包ros-foxy-joy,执行该命令时会要求输入Y/n/q,依次输入n、Y、Y即可。
sudo aptitude install ros-foxy-joy
安装ros-foxy-desktop,ROS2桌面版。
sudo apt install ros-foxy-desktop -y
sudo apt install python3-argcomplete
若在安装ros-foxy-desktop时没有预先使用aptitude工具安装ros-foxy-rviz2和ros-foxy-joy,则会报错,报错如下所示。
root@ubuntu:/home/rockchip# sudo apt install ros-noetic-desktop-full
Reading package lists... Done
Building dependency tree
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:The following packages have unmet dependencies:ros-noetic-desktop-full : Depends: ros-noetic-desktop but it is not going to be installedDepends: ros-noetic-perception but it is not going to be installedDepends: ros-noetic-simulators but it is not going to be installedDepends: ros-noetic-urdf-sim-tutorial but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
安装编译器和其他构建ROS包的工具。
sudo apt install ros-dev-tools -y
1.4设置环境变量
设置环境变量后,在任意终端都能使用ROS2。
echo "source /opt/ros/foxy/setup.bash " >> /home/rockchip/.bashrc
source /home/rockchip/.bashrc
2 在编译源码阶段安装ROS2
2.1调整roofts.img大小
安装的ROS2空间大小比较大,若不调整roofts.img,后面会因rootfs.img空间不足无法安装ROS,如下所示。
/usr/bin/mandb: can't write to /var/cache/man/31302: No space left on device
/usr/bin/mandb: can't create index cache /var/cache/man/31302: No space left on device
将rootfs.img调整为8000M,修改的代码如下所示。
diff --git a/build/python3/build.py b/build/python3/build.py
index 1cfa376e6..248168a50 100755
--- a/build/python3/build.py
+++ b/build/python3/build.py
@@ -675,7 +675,7 @@ class Build:sys.exit(1)if rootfs_size == "auto":
- cmd = '%s/build/scripts/resize.sh %s/rootfs.img 5000M' % (root_path, out_path)
+ cmd = '%s/build/scripts/resize.sh %s/rootfs.img 8000M' % (root_path, out_path)else:cmd = '%s/build/scripts/resize.sh %s/rootfs.img %dM' % (root_path, out_path, int(rootfs_size))if edge_cmd(cmd, None) != 0:
2.2 安装ROS2
在vendor/common/pre-install/目录下增加ROS2的安装脚本,并添加可执行权限。
touch vendor/common/pre-install/ros_foxy_desktop_install.sh
chmod +x vendor/common/pre-install/ros_foxy_desktop_install.sh
ros_foxy_desktop_install.sh脚本的内容如下所示。之所以sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg会重复三次,是因为执行该命令时有可能会因网络不好超时,所以多执行几次避免没发添加秘钥成功。
#!/bin/bashsudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
export LANG=en_US.UTF-8
sudo apt install software-properties-common -y
sudo add-apt-repository universe
sudo apt update
echo "-------------- install curl -y ----------------------"
sudo apt install curl -y
echo "-------------- add key ----------------------"
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
echo "-------------- apt update ----------------------"
sudo apt update
echo "-------------- apt upgrade ----------------------"
sudo apt upgrade -y
sudo apt install aptitude -y
echo "-------------- install ros-foxy-rviz2 ----------------------"
sudo aptitude install ros-foxy-rviz2
echo "-------------- install ros-foxy-joy ----------------------"
sudo aptitude install ros-foxy-joy
echo "-------------- install ros-foxy-desktop ----------------------"
sudo apt install ros-foxy-desktop -y
echo "-------------- install python3-argcomplete ----------------------"
sudo apt install python3-argcomplete
echo "-------------- install ros-dev-tools ----------------------"
sudo apt install ros-dev-tools -y
echo "-------------- source /opt/ros/foxy/setup.bash ----------------------"
echo "source /opt/ros/foxy/setup.bash " >> /home/rockchip/.bashrc
source /home/rockchip/.bashrc
./edge build -r生成根文件系统时会执行build/scripts/rootfs-install.sh脚本,修改build/scripts/rootfs-install.sh脚本,使其在执行时能执行ros_foxy_desktop_install.sh脚本从而安装ROS2环境,修改的内容如下所示。
diff --git a/build/scripts/rootfs-install.sh b/build/scripts/rootfs-install.sh
index 853a125df..d64dab498 100755
--- a/build/scripts/rootfs-install.sh
+++ b/build/scripts/rootfs-install.sh
@@ -19,6 +19,7 @@ function post_install()pre_installsudo chroot rootfs /pre-install/install.sh $*
+sudo chroot rootfs /pre-install/ros_foxy_desktop_install.shret=$?sleep 1post_install
执行./edge build -r编译命令生成根文件系统时,在执行到ros_foxy_desktop_install.sh脚本中的sudo aptitude install ros-foxy-rviz2命令时,执行该命令时会要求输入Y/n/q,依次输入n、Y、Y即可。在执行到ros_foxy_desktop_install.sh脚本中的sudo aptitude install ros-foxy-joy命令时执行该命令时会要求输入Y/n/q,依次输入n、Y、Y即可。等待./edge build -r执行成功完成后,ROS2的环境即已经预安装成功在roofts.img里面。
3 ROS2功能测试
#测试小乌龟功能包
#一个终端执行该命令
ros2 run turtlesim turtlesim_node
#另一个终端执行该命令
ros2 run turtlesim turtle_teleop_key#测试cpp与py的demo功能包
#一个终端执行该命令
ros2 run demo_nodes_cpp talker
#另一个终端执行该命令
ros2 run demo_nodes_py listener
这篇关于[rk3588 ubuntu20.04]移植ROS2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!