< >
Home » ROS2版TurtleBot3入门教程_视频版 » TurtleBot3入门教程#ROS2版#-树莓派4安装

TurtleBot3入门教程#ROS2版#-树莓派4安装

文章说明

  • 本教程介绍如何在在树莓派4上安装对应的系统和软件

  • 系统与ROS版本对应关系:

    • Ubuntu Mate 20.04 - ROS1 Noetic and ROS2 Foxy
    • Ubuntu Mate 22.04 - ROS2 Humble
  • 若当前手上使用的是在创客智造采购的TB3则不需要进行以下的安装步骤

相关设备

安装步骤

系统安装
增加交换空间
  • [TurtleBot] 创建一个交换空间且赋予权限
$ sudo fallocate -l 1G /swapfile
$ sudo chmod 600 /swapfile
  • [TurtleBot] 使用mkswap命令设置Linux的交换空间
$ sudo mkswap /swapfile
  • [TurtleBot] 启用该交换空间
$ sudo swapon /swapfile
  • [TurtleBot] 设置开机挂载
$ sudo vim /etc/fstab
//将下面这句话添加到文件末
/swapfile swap swap defaults 0 0
  • [TurtleBot] 查看是否分配交换空间
$ sudo free -h
          total        used        free      shared  buff/cache   available
Mem:       912M         75M        254M        3.0M        582M        819M
Swap:      1.0G         35M        988M
ROS2安装
安装TurtleBot3及相关依赖包
  • [TurtleBot] 安装相关依赖包
$ sudo apt install -y python3-argcomplete python3-colcon-common-extensions python3-vcstool git

# 根据当前使用的ROS2版本来执行对应版本的命令
# foxy版
$ sudo apt-get install ros-foxy-gazebo-* ros-foxy-cartographer ros-foxy-cartographer-ros \
  ros-foxy-nav2-bringup ros-foxy-navigation2 ros-foxy-slam-toolbox

# humble版
$ sudo apt-get install ros-humble-gazebo-* ros-humble-cartographer ros-humble-cartographer-ros \
  ros-humble-nav2-bringup ros-humble-navigation2 ros-humble-slam-toolbox
  • [TurtleBot] 安装TurtleBot3包
$ sudo apt update
$ sudo apt install libudev-dev
$ mkdir -p ~/turtlebot3_ws2/src
$ cd ~/turtlebot3_ws2/src/

# 根据当前使用的ROS2版本来执行对应版本的命令
# foxy版
$ git clone -b foxy-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/DynamixelSDK.git
$ git clone -b foxy-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
$ git clone -b foxy-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/turtlebot3.git
$ git clone -b foxy-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/hls_lfcd_lds_driver.git
$ git clone -b ros2-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/ld08_driver.git

# humble版    
$ git clone -b humble-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/DynamixelSDK.git
$ git clone -b humble-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git
$ git clone -b humble-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/turtlebot3.git
$ git clone -b humble-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/hls_lfcd_lds_driver.git
$ git clone -b humble-devel https://ghproxy.com/https://github.com/ROBOTIS-GIT/ld08_driver.git

$ cd ~/turtlebot3_ws2
$ colcon build --symlink-install
$ echo 'source ~/turtlebot3_ws2/install/setup.bash' >> ~/.bashrc
$ source ~/.bashrc
  • [TurtleBot] 规则配置
$ colcon_cd turtlebot3_bringup
$ sudo cp script/99-turtlebot3-cdc.rules /etc/udev/rules.d/
$ sudo udevadm control --reload-rules
$ sudo udevadm trigger
  • [TurtleBot] 环境配置
$ echo 'export LDS_MODEL=LDS-02 #LDS-01 or LDS-02' >> ~/.bashrc
$ echo 'export ROS_DOMAIN_ID=30 #TURTLEBOT3' >> ~/.bashrc
$ echo "export TURTLEBOT3_MODEL=burger" >> ~/.bashrc
$ source ~/.bashrc

切换环境

  • 对于在创客智造上购买的foxy版系统的tb3是已经配置好系统,不需要重复安装配置

  • 若是创客智造上购买的默认是Noetic系统的tb3且想要切换到Foxy环境,则需要进行环境切换

  • 若在创客智造上购买的为humble版的TB3则忽略当前步骤

  • [TurtleBot] 若当前需要从Noetic切换到Foxy环境,需要将文档末端的两项环境变量全部注释,保存退出关闭此终端

$ vim ~/.bashrc
   
#source ~/tools/environment/noetic/setRosNoeticEnvironment.sh
#source ~/tools/environment/foxy/setRos2FoxyEnvironment.sh

$ exit
  • [TurtleBot] 打开新终端,将文档末端Foxy的环境变量的注释标志去掉,再保存退出
$ vim ~/.bashrc
   
#source ~/tools/environment/noetic/setRosNoeticEnvironment.sh
source ~/tools/environment/foxy/setRos2FoxyEnvironment.sh

$ source ~/.bashrc && rosversion -d
foxy

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: none