24小时热门版块排行榜    

查看: 513  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 333求调剂 +6 87639 2026-03-21 10/500 2026-03-23 10:41 by Iveryant
[考研] 070300,一志愿北航320求调剂 +3 Jerry0216 2026-03-22 5/250 2026-03-23 09:16 by 。。堂堂
[考研] 352求调剂 +3 大米饭! 2026-03-22 3/150 2026-03-22 23:28 by king123!
[考研] 一志愿华中农业071010,总分320求调剂 +5 困困困困坤坤 2026-03-20 6/300 2026-03-22 17:41 by hxsm
[考研] 308求调剂 +3 墨墨漠 2026-03-21 3/150 2026-03-22 16:54 by i_cooler
[考研] 293求调剂 +12 zjl的号 2026-03-16 17/850 2026-03-22 16:51 by i_cooler
[考研] 306求调剂 +5 来好运来来来 2026-03-22 5/250 2026-03-22 16:17 by BruceLiu320
[考研] 寻找调剂 +4 倔强芒? 2026-03-21 4/200 2026-03-22 16:14 by 木托莫露露
[考研] 一志愿 西北大学 ,070300化学学硕,总分287,双非一本,求调剂。 +3 晨昏线与星海 2026-03-20 3/150 2026-03-22 16:00 by ColorlessPI
[考研] 能源材料化学课题组招收硕士研究生8-10名 +5 脱颖而出 2026-03-16 17/850 2026-03-22 15:18 by 脱颖而出
[考研] 一志愿华中科技大学071000,求调剂 +4 沿岸有贝壳6 2026-03-21 4/200 2026-03-22 07:21 by ilovexiaobin
[考研] 求调剂 +3 13341 2026-03-20 3/150 2026-03-21 18:28 by 学员8dgXkO
[考研] 一志愿深大,0703化学,总分302,求调剂 +4 七月-七七 2026-03-21 4/200 2026-03-21 18:20 by 学员8dgXkO
[考研] 一志愿重庆大学085700资源与环境总分308求调剂 +7 墨墨漠 2026-03-20 7/350 2026-03-21 16:36 by barlinike
[考研] 265求调剂 +9 梁梁校校 2026-03-17 9/450 2026-03-21 02:17 by JourneyLucky
[考研] 华东师范大学-071000生物学-293分-求调剂 +3 研究生何瑶明 2026-03-18 3/150 2026-03-21 01:30 by JourneyLucky
[考研] 一志愿武理材料305分求调剂 +6 想上岸的鲤鱼 2026-03-18 7/350 2026-03-21 01:03 by JourneyLucky
[考研] 一志愿西南交通 专硕 材料355 本科双非 求调剂 +5 西南交通专材355 2026-03-19 5/250 2026-03-20 21:10 by JourneyLucky
[考研] 求调剂 +3 暗涌afhb 2026-03-16 3/150 2026-03-20 00:28 by 河南大学校友
[考研] 085601材料工程专硕求调剂 +10 慕寒mio 2026-03-16 10/500 2026-03-19 15:26 by 丁丁*
信息提示
请填处理意见