[learn ros] A fake battery simulator

在这部分中,笔者关心的是一个python文件 battery_simulator.py 、一个叫做node的东西、一个launch文件、一个叫做topic的东西和一个ros service,还有一个rqt。。

根据wiki对于node的介绍

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信息。

使用launch文件的好处是,通过该文件,同一时间可以启动多个node
topics的工作原理和实现方式笔者略知一二,通过开源飞控项目PX4autopilot(笔者是一个开源爱好者),里面任务、进程间的通讯使用的就是类似于这种形式。
RQT_。是图形化界面的配置,但是笔者认为还是命令行终端输入指令比较炫酷,就像linux要比windows显得高端一样(个人理解)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值