在这部分中,笔者关心的是一个python文件 battery_simulator.py 、一个叫做node的东西、一个launch文件、一个叫做topic的东西和一个ros service,还有一个rqt。。
Nodes: A node is an executable that uses ROS to communicate with other nodes;
ROS nodes use a ROS client library to communicate with other nodes. Nodes canpublish or subscribe to a Topic. Nodes can also provide or use aService.
ROS client libraries allow nodes written in different programming languages to communicate:
- rospy = python client library
- roscpp = c++ client library
rosrun allows you to use the package name to directly run a node within apackage (without having to know the package path).
rosrun [package_name] [node_name]
通过上面对于node的介绍,笔者大概的将上面所说的几个内容联系起来,除了rqt...
笔者开始的理解:python定义了node用于执行的library,使用rosrun进行启动node执行,发送topic并且接收ros service,随后笔者发现根本没有书中没有使用rosrun而是launch 文件(理解错误),随后查看了关于launch文件的介绍 并看了源码中launch文件的定义
<span style="font-size:14px;"><launch>
<arg name="battery_runtime" default="60"/>
<node pkg="rbx2_utils" name="battery_simulator" type="battery_simulator.py" output="screen" clear_params="true">
<param name="rate" value="5" />
<param name="battery_runtime" value="$(arg battery_runtime)" />
</node>
</launch></span>
豁然开朗。。。但是在launch文件中看到了package name 随后便尝试一下使用rosrun的方式执行了一下(执行失败,此时已经执行roscore),
命令:rosrun rbx2_utils battery_simulator
结果:[rosrun] Couldn't find executable named battery_simulator,below /catkin_ws/src/rbx2/rbx2_utils
随后尝试执行battery_simulator.py
命令:rosrun rbx2_utils battery_simulator.py
结果:[INFO] [WallTime: 1445672174.183417] Publishing simulated battery level with a runtime of 30 seconds...成功,同时可打开另一个terminal查看topics信息。
结果:[INFO] [WallTime: 1445672174.183417] Publishing simulated battery level with a runtime of 30 seconds...成功,同时可打开另一个terminal查看topics信息。
使用launch文件的好处是,通过该文件,同一时间可以启动多个node
topics的工作原理和实现方式笔者略知一二,通过开源飞控项目PX4autopilot(笔者是一个开源爱好者),里面任务、进程间的通讯使用的就是类似于这种形式。
RQT_。是图形化界面的配置,但是笔者认为还是命令行终端输入指令比较炫酷,就像linux要比windows显得高端一样(个人理解)