24小时热门版块排行榜    

查看: 514  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 081700 调剂 267分 +5 迷人的哈哈 2026-03-23 5/250 2026-03-23 14:59 by lbsjt
[考研] 0854 考研调剂 招生了!AI 方向 +3 pk3725069 2026-03-19 14/700 2026-03-23 14:44 by Jack_333
[考研] 0854电子信息求调剂 +3 α____ 2026-03-22 3/150 2026-03-22 21:28 by zhq0425
[考研] 一志愿武理材料工程348求调剂 +5  ̄^ ̄゜汗 2026-03-19 7/350 2026-03-22 19:44 by 公瑾逍遥
[考研] 306求调剂 +5 来好运来来来 2026-03-22 5/250 2026-03-22 16:17 by BruceLiu320
[考研] 085600材料与化工306 +4 z1z2z3879 2026-03-21 4/200 2026-03-21 23:44 by ms629
[考研] 材料与化工(0856)304求 B区 调剂 +3 邱gl 2026-03-21 3/150 2026-03-21 13:47 by lature00
[考研] 一志愿山大07化学 332分 四六级已过 本科山东双非 求调剂! +3 不想理你 2026-03-16 3/150 2026-03-21 03:59 by JourneyLucky
[考研] 307求调剂 +3 wyyyqx 2026-03-17 3/150 2026-03-21 03:20 by JourneyLucky
[考研] 一志愿中国石油大学(华东) 本科齐鲁工业大学 +3 石能伟 2026-03-17 3/150 2026-03-21 02:22 by JourneyLucky
[考研] 华东师范大学-071000生物学-293分-求调剂 +3 研究生何瑶明 2026-03-18 3/150 2026-03-21 01:30 by JourneyLucky
[考研] 一志愿华中科技大学,080502,354分求调剂 +5 守候夕阳CF 2026-03-18 5/250 2026-03-21 01:06 by JourneyLucky
[考研] 一志愿重庆大学085700资源与环境专硕,总分308求调剂 +3 墨墨漠 2026-03-18 3/150 2026-03-21 00:39 by JourneyLucky
[考研] 321求调剂 +9 何润采123 2026-03-18 11/550 2026-03-20 23:19 by JourneyLucky
[考研] 330求调剂 +4 小材化本科 2026-03-18 4/200 2026-03-20 23:13 by JourneyLucky
[考研] 一志愿武汉理工材料工程专硕调剂 +9 Doleres 2026-03-19 9/450 2026-03-20 22:36 by JourneyLucky
[考研] A区线材料学调剂 +5 周周无极 2026-03-20 5/250 2026-03-20 21:33 by laoshidan
[考研] 一志愿西南交通 专硕 材料355 本科双非 求调剂 +5 西南交通专材355 2026-03-19 5/250 2026-03-20 21:10 by JourneyLucky
[考研] 材料工程专硕调剂 +5 204818@lcx 2026-03-17 6/300 2026-03-18 22:55 by 204818@lcx
[考研] [导师推荐]西南科技大学国防/材料导师推荐 +3 尖角小荷 2026-03-16 6/300 2026-03-16 23:21 by 尖角小荷
信息提示
请填处理意见