ROS2 介绍
Rolling Ridley (rolling) — ROS 2 Documentation: Humble 文档
官方二进制和源码安装教程
英文:docs.ros.org/en/rolling/… 中文: fishros.org/doc/ros2/hu…
Windows 二进展安装 ROS
包依赖管理工具 Choco
安装 Chocolatey 是 Windows 的软件包管理器,请按照他们的安装说明进行安装:
您将使用 Chocolatey 安装其他一些开发工具
Chocolatey is a software management solution unlike any you’ve ever experienced on Windows. Think of it like this - you create a software deployment package using a little PowerShell, then you can deploy it anywhere you have Windows with everything (like Puppet, SCCM, Altiris, Connectwise Automate, etc).
Write your deployment once for any software, then deploy it with any solution everywhere you have Windows.
You know those massively complicated, complex, and expensive software management solutions where you typically need to buy more machines and hire consultants to help you configure/maintain them? Yeah, that’s not us. We believe in simple solutions to complex problems. Software on Windows is already complex enough, we’ve designed our tools to be able to be simple to use, extremely powerful, flexible to fit nearly any situation, to work with your existing infrastructure, and for scale. And the best part is you can take advantage of Chocolatey without any cost (yes, even internally for an organization)!
- Install with cmd.exe
Run the following command:
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
2. Install with PowerShell.exe
With PowerShell, there is an additional step. You must ensure Get-ExecutionPolicy is not Restricted. We suggest using Bypass
to bypass the policy to get things installed or AllSigned
for quite a bit more security.
- Run
Get-ExecutionPolicy
. If it returnsRestricted
, then runSet-ExecutionPolicy AllSigned
orSet-ExecutionPolicy Bypass -Scope Process
. - Now run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
安装 Python
打开命令提示符并输入以下命令通过 Chocolatey 安装 Python:
choco install -y python --version 3.8.3
Visual C++ Redistributables
打开命令提示符并输入以下命令通过 Chocolatey 安装它们:
choco install -y vcredist2013 vcredist140
安装 OpenSSL
从 此页面 下载 Win64 OpenSSL v1.1.1n OpenSSL 安装程序。滚动到页面底部下载 Win64 OpenSSL v1.1.1t。不要下载 Win32 或 Light 版本,也不要下载 v3.X.Y 安装程序。
使用默认参数运行安装程序,因为下面的命令假设你使用了默认安装目录。
此命令设置一个在会话间持久存在的环境变量:
setx /m OPENSSL_CONF "C:\Program Files\OpenSSL-Win64\bin\openssl.cfg"
您需要将OpenSSL-Win64 bin文件夹添加到您的PATH中。您可以通过点击Windows图标,输入"环境变量",然后点击"编辑系统环境变量"来实现这一点。在弹出的对话框中,点击"环境变量",然后点击底部窗格上的"Path",最后点击"编辑"并添加下面的路径。
C:\Program Files\OpenSSL-Win64\bin
QT
Index of /archive/qt/5.12/5.12.12 Index of /archive/qt/5.15/5.15.16/single
Linux 手动按安装(fishros.com/d2lros2/#/h…)
2.1Ctrl+Alt+T打开终端
2.2 添加源
echo "deb [arch=$(dpkg --print-architecture)] https://repo.huaweicloud.com/ros2/ubuntu/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/nullCopy to clipboardErrorCopied
2.3 添加源对应的秘钥
sudo apt install curl gnupg2 -y
curl -s https://gitee.com/ohhuo/rosdistro/raw/master/ros.asc | sudo apt-key add -Copy to clipboardErrorCopied
2.4 更新
sudo apt update Copy to clipboardErrorCopied
2.5 安装ROS2
上面步骤完成后,安装就变得非常的简单了,一行指令搞定;
sudo apt install ros-humble-desktopCopy to clipboardErrorCopied
然后等着就行:
2.6 安装额外依赖
sudo apt install python3-argcomplete -yCopy to clipboardErrorCopied
2.7 配置环境变量
大家此时再打开一个终端,输入ros2,看看会有什么神奇的事情发生吧。
很不幸,你可能会看到到:
不要怕,跟着小鱼输入一句话:
source /opt/ros/humble/setup.bashCopy to clipboardErrorCopied
再尝试一下,就可以了。
这是为什么呢?
因为虽然安装好了ros2,但ros2并没有加入到系统默认的环境中来。每次想用还需要进行source.有什么办法可以一劳永逸呢?
有的,把ros2加入bashrc中。就是每次启动终端都让它自动的输入这句话。
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrcCopy to clipboardErrorCopied
3.出现问题可以这样卸载
别的教程肯定不会写这个,不过这招有时候还挺好用,就是麻烦一些哈。
sudo apt remove ros-humble-*
sudo apt autoremoveCopy to clipboardErrorCopied
4.ROS2到底装哪里了
在Windows安装过软件的小伙伴都知道安装软件都会选择一个安装目录,但是安装ROS时候并没有让你选择,ROS安装的默认目录在/opt/ros/下,根据版本的名字进行区分。
我们本节安装的是humble版本的ROS,所以安装目录在/opt/ros/humble下。
cd /opt/ros/humble/
lsCopy to clipboardErrorCopied
参考链接:
- ROS2 镜像使用帮助:mirrors.tuna.tsinghua.edu.cn/help/ros2/
- ROS2官方文档:docs.ros.org/en/humble/i…
OSX M1+ conda + python
Hello fellow robotics enthusiasts!
If you’re excited about diving into the world of robotics with your shiny new Apple Silicon Mac, you’re in the right place! Whether you’re using an M1 or M2 chip, you can leverage its power to run ROS2 Humble Hawksbill natively. This guide will walk you through the process step-by-step, making it as simple as possible.
Why ROS2 on Apple Silicon?
Because you bought one, of course! 😇😇 And it’s awesome! So, let’s get this party started!
Let’s Start!!!
Installing ROS2
We’ll be using the amazing RoboStack repository on GitHub as a reference. However, I’ve made some adjustments to ensure you get a complete setup, including essential tools like Gazebo, RViz, and more.
Let’s dive in and get your environment up and running smoothly.
First, check your Python version by running python --version
. If it’s not 3.9, you'll need to install Python 3.9 from the official website.
Next, install Miniconda3 for macOS Apple M1 ARM 64-bit from this link. Make sure to choose the Python 3.9 version.
Then copy-paste the following commands one by one into your terminal.
# if you don't have mamba yet, install it first in the base environment (not needed when using mambaforge):
conda install mamba -c conda-forge
# now create a new environment , here ros2 is the name of your ROS working environment you can name it whatever you want
conda create -n ros2conda activate ros2conda config --env --add channels conda-forgeconda config --env --add channels robostack-stagingconda config --env --remove channels defaultsconda install ros-humble-desktop-fullconda install compilers cmake pkg-config make ninja colcon-common-extensions catkin_tools rosdep
# Restart the Environment
conda deactivate
conda activate ros2
# Testing
rviz2
# Rviz will be deployed if the installation was successful
Installing Gazebo
To install Gazebo, you’ll need to exit the Conda environment completely:
- Exit the Conda Environment: First, make sure you’re out of the Conda environment. If you see
(base)
before your computer name in the Terminal, run:
conda deactivate
# to get out of the conda env
# if you are in your ros env type the same command twice
- Install Gazebo: Now, you can install Gazebo by running:
curl -ssL http://get.gazebosim.org | sh # to start the gazebo installation process
Conclusion
Congratulations! You’ve successfully set up ROS2 Humble Hawksbill on your Apple Silicon Mac. With everything installed and running, you’re now ready to start exploring the exciting possibilities of robotics.
Your new setup will leverage the full power of your M1 or M2 chip, making your robotics projects smoother and more efficient. If you run into any issues or have questions, feel free to reach out. Enjoy your journey into robotics and happy coding!
查看环境变量
(base) ➜ fishbot_description printenv
ROS_DISTRO=humble
ROS_LOCALHOST_ONLY=0
ROS_PYTHON_VERSION=3
ROS_VERSION=2
ROS_OS_OVERRIDE=conda:osx
ROS_ETC_DIR=/Users/xxxxx/miniconda3/etc/ros
安装 joint-state-publisher-gui
(base) ➜ fishbot_description conda install ros-$ROS_DISTRO-joint-state-publisher-gui
小鱼安装脚本
一行代码-解决人生烦恼
- 推荐语:一行代码搭建机器人开发环境(ROS/ROS2/ROSDEP)
- 开源地址:github.com/fishros/ins… GitHub - fishros/fishbot: 动手学ROS2第二阶段课程源码|机器人建模仿真fishbot
一键安装指令
wget http://fishros.com/install -O fishros && . fishros
常用教程
Docker
ROS 生态中的部分工具只支持 linux 系统平台。使用 Docker 之类的 Container 技术可以方便在不同步系统平台上使用 ROS ,实现跨平台的诉求。
安装
- 首先在你使用的系统上安装 Docker ,可以参考 juejin.cn/editor/draf… Docker 是一个容器平台,可以在宿主系统上运行其他操作系统实例,与虚拟机类似。
-
拉取 ROS2 的 Docker 镜像 Docker 镜像是一系列软件打包在一起,构成一个可以运行和部署的标准单元。包含了应用代码,运行时库,配置,系统工具,依赖包,
在 Docker hub 中选择合适的 ros 镜像进行拉取。
docker pull ros:jazzy-ros-core
运行
- 自定义镜像,增加依赖包 在工作目录下新建 Dockerfile ,输入一下内容。
FROM ros:jazzy-ros-core
RUN apt-get update && apt-get install -y \
ros-jazzy-demo-nodes-cpp \
ros-jazzy-foxglove-bridge \
ros-jazzy-tf2-ros
保存后,执行一下命令
docker build -t rosdemo .
- 使用 docker 运行镜像 -it 表示保持一个可交互的 bash ,-rm 表示容器停止后释放磁盘空间。
docker run --rm -it rosdemo bash
3. 使用 docker-compose 运行镜像,增加磁盘路径的映射
- 新增一个 Dockerfile, 增加一个 bash 命令执行。
FROM rosdemo
CMD ["bash"]
- 创建 docker-compose.yml 文件, tty: true 可以使容器不会立即停止,保持长期运行。
# yaml 配置实例
version: '3'
services:
rosdemo:
image: rosdemo
volumes:
- /host/path:/container/path
tty: true
- 加载镜像,运行容器, -d 表示后台运行
docker-compose up -d
- 在运行容器中生成可交换的 bash
docker exec -it learn-rosdemo-1 /bin/bash
- 加载 ros2 环境
source ros_entrypoint.sh
小乌龟 turtlesim
安装
对于绝大部分 ros package,其在 ubuntu 软件库中的名字很有规律,都是 ros-版本-package。例如要在 ros kinetic 版本中安装 turtlesim package,对应的 ubuntu 软件库中的名字就是 ros-kinetic-turtlesim;在 ros indigo 版本中安装游戏手柄驱动包 joy,对应的名字就是 ros-indigo-joy。
sudo apt install ros-xxxx-turtlesim
检查是否安装了该软件包:
ros2 pkg executables turtlesim
上述命令应返回turtlesim的可执行文件列表:
turtlesim draw_square
turtlesim mimic
turtlesim turtle_teleop_key
turtlesim turtlesim_node
启动 turtlesim
要启动turtlesim,请在终端中输入以下命令:
ros2 run turtlesim turtlesim_node
模拟器窗口应出现,并在中心显示一个随机的乌龟。
ROS2 使用
使用 turtlesim 、 ros2 和 rqt — ROS 2 Documentation: Humble 文档
创建一个功能包
目录结构