ROS_launch("let's create a launch file called turtlemimic.launch")

ROS中可以把很多的命令以描述的形式写成launch文件,然后用 roslaunch命令执行launch文件。 它的使用方法如下:
roslaunch [package] [filename.launch]

比如:我们切换到 beginner_tutorials文件下:
roscd beginner_tutorials  

注:如果提示找不到文件或文件夹,就参照前面把环境变量设置一下。执行:
cd ~/catkin_ws/devel/


source setup.bash

在beginner_tutorials文件夹下, 创建launch文件夹,切换到该文件夹下:
mkdir launch


cd launch

输入:
gedit turtlemimic.launch   

用ubuntu默认的编辑器gedit创建一个launch文件。
然后在打开的的launch文件中复制入下面的内容:
[C]  纯文本查看  复制代码
?
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
<launch>
 
   <group ns= "turtlesim1" >
     <node pkg= "turtlesim" name= "sim" type= "turtlesim_node" />
   </group>
 
   <group ns= "turtlesim2" >
     <node pkg= "turtlesim" name= "sim" type= "turtlesim_node" />
   </group>
 
   <node pkg= "turtlesim" name= "mimic" type= "mimic" >
     <remap from= "input" to= "turtlesim1/turtle1" />
     <remap from= "output" to= "turtlesim2/turtle1" />
   </node>
 
</launch>

保存退出就可以了。

     现在使用如下命令载入刚才创建的launch文件:


roslaunch beginner_tutorials turtlemimic.launch  


就可以看到新打开两个乌龟节点。

新打开一个终端,输入命令

rostopic pub /turtlesim1/turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'


使乌龟运动起来。就可以看到两只乌龟都在运动。

输入命令:
rosnode list

就可以看到启动了两个节点 /turtlesim1/sim和 /turtlesim2/sim。如图:
 


下面来解析一下launch文件的标签的意思:
<lanuch>

<lanuch>标签用来识别这是一个launch文件。


<group ns="turtlesim1">  
  <node pkg="turtlesim" name="sim" type="turtlesim_node"/>  
</group>  
  
<group ns="turtlesim2">  
  <node pkg="turtlesim" name="sim" type="turtlesim_node"/>  
</group>  

上面的内容表示我们启动了两只乌龟。分别名为turtlesim1和turtlesim2.


<node pkg="turtlesim" name="mimic" type="mimic">  
  <remap from="input" to="turtlesim1/turtle1"/>  
  <remap from="output" to="turtlesim2/turtle1"/>  
</node>  

上面的内容使turtlesim2模仿turtlesim1。所以虽然我们只向turtlesim1发布了话题,turtlesim2也做出了反应。


转载说明:http://www.arduino.cn/thread-12413-1-1.htmlhttp://www.arduino.cn/thread-12413-1-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值