# ROS Day2
# ROS Topic
可以通过双击tab来检查可执行的命令 如输入rostopic后双击tab,会列出可执行的子命令
到rqt_plot章节 运行命令rosrun rqt_plot rqt_plot报和rqt_graph相同的错误,Segmentation fault(core dumped) 应该是Qt的问题。 与rqt_graph相同的解决方案,直接运行命令rqt_plot 即可
通过命令
rostopic echo [topic]
来监听节点上关于话题[topic]的指令
通过命令
rostopic list -v
其中v代表verbose(唠叨) 能够打印所有的话题(Published)以及被订阅的话题(Subscribed)
话题的通讯是通过节点之间发送ROS消息实现的。 例如控制?移动的例子,turtle_teleop_key通过键盘控制就是话题的发布者,turtlulesim_node(图形界面)就是话题的订阅者。 发布者和订阅者必须发送和接受相同类型(type)的消息,通过rostopic type [topic]可以查看发布在话题上的消息类型。 还可以通过pub子命令来发布消息。
rostopic pub [话题名称] [消息类型] -- [参数]
例如
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -- '[2,0,0]' '[0,0,1.8]'
就与turtle_teleop_key控制乌龟一样了
rostopic hz [topic]
可以查看数据发布速度
# ROS Service
# rosservice list 可以列出所有可用的服务 可以通过rosservice type [service] 来查看某个服务的类型,想要获得具体的信息可以添加字段 rosservice type [service] | rossrv show 例如服务/spawn rosservice type /spawn | rossrv show float32 x float32 y float32 theta string name
# string name 意思是有x,y,theta,name四个参数,其中name可省略 而服务/clear只输出
意思是无需参数,其类型为std_srvs/Empty
可以通过 rosservice call [service] [args] 来调用服务
服务类似于话题,也是节点的通信方式
例如乌龟例子就有/clear,/reset等服务 rosservice call /clear 就能清空已绘制的画面。
通过rosparam get / 来获得所有的参数值 也可以通过rosparam dump xxx.yaml来存储所有参数 读取通过rosparam load xxx.yaml copyturtle 其中copyturtle为一个新的namespace
roslaunch用来启动定义在launch文件中的节点 如果理解?每个包(package)都有一个launch目录(并不一定命名为launch,但通常都这么做),roslaunch会自动查找包中的可启动文件
roslaunch [package] [filename.launch] 例如beginner_tutorial
cd ~/catkin_ws
source devel/setup.bash
roscd beginner_tutorials
创建launch目录
mkdir launch
cd launch
在目录下创建tutlemimic.launch文件 并写入下面的内容
<launch>
<group ns="turtlesim1">
<node pkg="turtlesim" name="sim" type="turtlesim_node">
</group>
<group ns="turtlesim1">
<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>
使用roslaunch beginner_tutorials turtlemimic.launch 会启动launch文件中的三个节点
turtlesim1/sim
turtlesim2/sim
mimic
mimic节点会将turtlesim1/turtle1的所有信息发送给turtlesim2/turtle1
