ROS2机器人应用简明教程4工区

本文详细介绍了ROS2工作区的概念及其配置过程,包括如何设置系统和局部工作区,自定义机器人软件程序的步骤,以及如何解决包重名问题。通过实例演示了从创建到编译自定义工作区的全过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工区/工作区/工作空间(workspace简写为ws)是机器人操作系统核心概念之一。

工作空间是包含ROS 2软件的文件夹。在使用ROS 2之前,必须在正在使用的终端中配置ROS 2工作区(包括系统和局部),使ROS 2的软件包可在此终端中使用。

如上图所示,foxy/noetic分别为ros2和ros1的系统工作区,使用如下命令可以顺利加载配置:

  • source /opt/ros/foxy/setup.bash

如上文件夹下都是使用apt安装在系统目录下的软件包。

如果自定义机器人软件程序,通常在home文件夹下,新建诸如ros_ws/src文件夹,然后编写代码,编译生成可执行文件使用。

以博客中之前讲解过的mobot为例,此案例正在dashing/eloquent/foxy进行测试。

如果需要编译工区源码,需要使用如下命令安装所需功能包:

  • rosdep install -i --from-path src --rosdistro foxy -y

接着使用colcon build:

  • colcon build

这样就完成了一个自定义工区的编译,使用如下命令加载环境:

  • source install/setup.bash 

install:

如果没有正确加载的话,此工区的功能包是无法发现和使用的!

其他注意事项:

  1. You also have the option of sourcing an “overlay” – a secondary workspace where you can add new packages without interfering with the existing ROS 2 workspace that you’re extending, or “underlay”. Your underlay must contain the dependencies of all the packages in your overlay. Packages in your overlay will override packages in the underlay. It’s also possible to have several layers of underlays and overlays, with each successive overlay using the packages of its parent underlays.
  2. Sourcing the local_setup of the overlay will only add the packages available in the overlay to your environment. setup sources the overlay as well as the underlay it was created in, allowing you to utilize both workspaces.So, sourcing your main ROS 2 installation’s setup and then the dev_ws overlay’s local_setup, like you just did, is the same as just sourcing dev_ws’s setup, because that includes the environment of the underlay it was created in.

如果自定义包和系统包重名,或者下载了系统包源码自定义,请掌握环境配置方法,确保启动的是需要的节点和应用,而非系统默认的应用。

参考视频教程链接如下:


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zhangrelay

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值