ROS2入门之开发环境搭建
本文展示的方法是基于docker搭建开发环境,相对于宿主机搭建更加方便快捷,首先需要在宿主机安装docker:https://docs.docker.com/engine/install/ubuntu/
1.拉取镜像
docker pull osrf/ros:humble-desktop-full
2.创建容器
docker run -it -v ~/workspace:/home/sunwenqi/workspace osrf/ros:humble-desktop-full /bin/bash
3.VS Code安装 Docker 与 Remote-Container 插件
4.选中docker->containers,找到刚刚创建的容器,右键弹出如上图的菜单,选择Attach VS Code
左下角的显示即说明我们已经在容器中了,选择打开文件夹,打开刚刚挂载的目录即可开始工作。
5.ROS2初体验
配置环境变量
source /opt/ros/humble/setup.bash
运行demo节点
ros2 run demo_nodes_cpp talker
新建一个终端,依次输入以下指令
source /opt/ros/humble/setup.bash
ros2 topic list
ros2 topic echo /chatter
回车可以看到输出信息
附录:VS Code配置
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/**",
"/opt/ros/humble/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}