叭遭段 发表于 2025-6-9 09:36:26

【ROS教程】ROS文件系统和基础架构

@
目录

[*]1.工作空间目录

[*]1.1 package.xml

[*]2.启动节点的方式

[*]2.1 一次启动一个
[*]2.2 一次启动多个

[*]3.ROS常用命令

[*]3.1 增
[*]3.2 查
[*]3.3 执行

[*]3.3.1 加载环境变量
[*]3.3.2 运行节点

[*]3.4 查看计算图

[*]4.创建功能包

[*]4.1 选择工作目录
[*]4.2 创建功能包目录
[*]4.3 建立功能包


1.工作空间目录


WorkSpace --- 自定义的工作空间

    |--- build:编译空间,用于存放CMake和catkin的缓存信息、配置信息和其他中间文件。

    |--- devel:开发空间,用于存放编译后生成的目标文件,包括头文件、动态&静态链接库、可执行文件等。

    |--- src:源码

      |-- package:功能包(ROS基本单元)包含多个节点、库与配置文件,包名所有字母小写,只能由字母、数字与下划线组成

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- CMakeLists.txt:配置编译规则,比如源文件、依赖项、目标文件

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- package.xml:包信息,比如:包名、版本、作者、依赖项...(以前版本是 manifest.xml)

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- scripts:存储python文件

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- src:存储C++源文件

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- include:头文件

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- msg:消息通信格式文件

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- srv:服务通信格式文件

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- action:动作格式文件

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- launch:可一次性运行多个节点

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- config:配置信息

<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>|-- CMakeLists.txt:编译的基本配置1.1 package.xml


[*]固定格式
<?xml version="1.0"?>

<package format="2">

<name><the name of package></name>

<version>0.0.0</version>

<description>The <the name of package> package</description>





<maintainer email="*">XXX</maintainer>






<license>TODO</license>



































<buildtool_depend>catkin</buildtool_depend>


<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>


<build_export_depend>roscpp</build_export_depend>
<build_export_depend>rospy</build_export_depend>
<build_export_depend>std_msgs</build_export_depend>

   
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>



<export>
   

</export>
</package>2.启动节点的方式

2.1 一次启动一个

rosrun <the name of package> <the name of executable file>

[*]executable file:对于C语言,这个文件就是CMakeLists.txt中用add_executable生成的可执行文件;对于python,这个文件就是CMakeLists.txt中用catkin_install_python指向的文件
对应语法:
add_executable(<the name of executable file>
<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>   src/<the name of the source>.cpp
<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>)
catkin_install_python(PROGRAMS scripts/<the name of the source>.py
<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>          DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>         )2.2 一次启动多个

如果想要一次性启动一个包里的多个节点,而不是一行行地输入rosrun指令...

[*]我们需要一个launch文件,它的固定格式是这样的:
<launch>
    <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
    <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
    <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>

[*]node:包含的某个节点
[*]pkg:功能包
[*]type:被运行的节点文件
[*]name:为节点命名
[*]output:设置日志的输出目标
然后,在终端输入:
roslaunch <the name of package> <the name of launch file>3.ROS常用命令

3.1 增

创建新的ROS功能包:
catkin_create_pkg 自定义包名 依赖包3.2 查

列出所有功能包:
rospack list查找某个功能包是否存在,如果存在返回安装路径:
rospack find 包名3.3 执行

3.3.1 加载环境变量

先进入工作目录,然后:
source ./devel/setup.bash3.3.2 运行节点

roscore:ROS的系统先决条件节点和程序的集合,必须运行 roscore 才能使 ROS 节点进行通信。新开一个终端并输入:
roscore #用法一
roscore -p xxxx #用法二,指定端口号roscore 将启动:

[*]ros master
[*]ros 参数服务器
[*]rosout 日志节点
3.4 查看计算图

在节点正在运行的情况下,终端输入:
rosrun rqt_graph rqt_graph
4.创建功能包

4.1 选择工作目录

首先,选择一个路径作为工作目录。这里我选择了如下路径作为工作目录

4.2 创建功能包目录

mkdir src然后,在工作空间目录下:
catkin_makesrc目录下会多出一个锁定的CMakeLists.txt文件,不用管它。
4.3 建立功能包

先进入src目录
cd src然后使用ROS提供的指令直接创建功能包即可:
catkin_create_pkg <the name of your package> roscpp rospy std_msgs message_generatioroscpp、rospy、std_msgs、message_generatio是你所需要的依赖,你可以自由决定想要哪些依赖
本文由博客一文多发平台 OpenWrite 发布!

来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: 【ROS教程】ROS文件系统和基础架构