24小时热门版块排行榜    

CyRhmU.jpeg
查看: 484  |  回复: 1

yadan33

新虫 (初入文坛)

[交流] ROS-service & parameter

这是一种单对单的形式,不用与之前的发布和订阅
rosservice list         print information about active services
rosservice call         call the service with the provided args
rosservice type         print service type
rosservice find         find services by service type
rosservice uri          print service ROSRPC uri

看看当前node的服务
$ rosservice list

查看类型rosservice type [service]
$ rosservice type clear
std_srvs/Empty
--表示当服务call时,没有任何参数(发送请求是没有数据,接受响应时也没有数据

调用
rosservice call [service] [args]
$ rosservice call /clear
清除了之前的轨迹

$ rosservice type spawn | rossrv show
--显示服务描述

$ rosservice call spawn 2 2 0.2 ""
---创建新的小海龟,给定参数x,y,theta,name(这里name为空)他自动返回name:
turtle2

参数
rosparam set            set parameter
rosparam get            get parameter
rosparam load           load parameters from file
rosparam dump           dump parameters to file
rosparam delete         delete parameter
rosparam list           list parameter names


rosparam set [param_name]
rosparam get [param_name]

$ rosparam get /
Here we write all the parameters to the file params.yaml

$ rosparam dump params.yaml
You can even load these yaml files into new namespaces, e.g. copy:

$ rosparam load params.yaml copy
$ rosparam get copy/background_b





Using rqt_console and roslaunch

如果没装rqt或者turtlesim
$ sudo apt-get install ros-<distro>-rqt ros-<distro>-rqt-common-plugins ros-<distro>-turtlesim

rxconsole 是连接ROS 日志文档,并将节点的这些信息显示在窗体内。
rxloggerlevel 可以显示运行中节点的DEBUG,WARN,INFO 和ERROR信息

用来显示进程运行过程中出现的错误警告之类
rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0,y: 0.0,z: 0.0}}'
会报错
日志(logger)层 信息包括:Fatal, Error, Warn, Info, Debug,他们设置依次从高到低,比如设置Warn,我们必须知道Info, Debug信息,我们可以做还在设置知道warnning



roslaunch

$ roslaunch [package] [filename.launch]

打开包
$ roscd beginner_tutorials
如果出现类似这种错误No such package/stack 'beginner_tutorials' ,要先source一下环境
$ cd ~/catkin_ws
$ source devel/setup.bash
$ roscd beginner_tutorials
再来建一个launch文件夹
$ mkdir launch
$ cd launch
其实也可以不用建,roslauch命令会自己去寻找.launch文件
建一个turtlemimic.launch文件,内容如下
   1 <launch>
   2
   3   <group ns="turtlesim1">
   4     <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
   5   </group>
   6
   7   <group ns="turtlesim2">
   8     <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
   9   </group>
  10
  11   <node pkg="turtlesim" name="mimic" type="mimic">
  12     <remap from="input" to="turtlesim1/turtle1"/>
  13     <remap from="output" to="turtlesim2/turtle1"/>
  14   </node>
  15
  16 </launch>

launch文件诠释:



1
<launch>----以launch作为launch文件开头


23
<group

ns="turtlesim1">
----以turlesim1为名的文件夹或者命名空间的节点

4
<node

pkg="turtlesim"

name="sim"

type="turtlesim_node"/>


5
</group>6


7
<group

ns="turtlesim2">----以turlesim2为名的文件夹或者命名空间的节点


8
<node

pkg="turtlesim"

name="sim"

type="turtlesim_node"/>


9
</group>



10



11
<node

pkg="turtlesim"

name="mimic"

type="mimic">---在主题上模仿节点的输入和输出,并重命名turlesim1,turlesim2,比如:turlesim1变成mimicturtlesim1


12
<remap

from="input"

to="turtlesim1/turtle1"/>


13
<remap

from="output"

to="turtlesim2/turtle1"/>



14
</node>



15



16
</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]'
两个乌龟一起画圆
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yadan33

新虫 (初入文坛)

Using rosed to edit files in ROS

$ rosed [package_name] [filename]
可以直接编辑包里面文件,不需要知道位置
$ rosed roscpp Logger.msg
This example demonstrates how you would edit the Logger.msg file within the roscpp package

学会用tab键,就不需要知道文件的名字
$ rosed [package_name] <tab><tab>
Example:

$ rosed roscpp <tab><tab>
会出来一堆
Empty.srv                   package.xml
GetLoggers.srv              roscpp-msg-extras.cmake
Logger.msg                  roscpp-msg-paths.cmake
SetLoggerLevel.srv          roscpp.cmake
genmsg_cpp.py               roscppConfig-version.cmake
gensrv_cpp.py               roscppConfig.cmake
msg_gen.py      

vim不是ros自带的,改默认编辑器为ros自带的nano
You can use it by editing your ~/.bashrc file to include:
export EDITOR='nano -w'
export EDITOR='emacs -nw'

NOTE: changes in .bashrc will only take effect for new terminals. Terminals that are already open will not see the new environmental variable


看一下改成没有
Open a new terminal and see if EDITOR is defined:


$ echo $EDITOR
nano -w
or
emacs -nw
2楼2016-08-10 17:44:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 yadan33 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见