ROS 命令以及相关内容学习(二)
在上一节中我们已经学习了package node topic message 这些的运行方式,下面我们去理解service 的运行方式。
1.sevice
1 #命令 2 rosservice list print information about active services 3 rosservice call call the service with the provided args 4 rosservice type print service type 5 rosservice find find services by service type 6 rosservice uri print service ROSRPC uri 7 #例子 8 rosservice list 9 /clear 10 /kill 11 /reset 12 /rosout/get_loggers 13 /rosout/set_logger_level 14 /spawn 15 /teleop_turtle/get_loggers 16 /teleop_turtle/set_logger_level 17 /turtle1/set_pen 18 /turtle1/teleport_absolute 19 /turtle1/teleport_relative 20 /turtlesim/get_loggers 21 /turtlesim/set_logger_level 22 #另一个例子 23 rosservice type [service] 24 25 rosservice type /clear #你会发现这个命令是没有什么东西,
1.1 rosservice call [service] [args]
1 当你运行着一条的 2 $ rosservice call /clear 3 就可以清空小乌龟的轨迹哦。 4 运行着一条的时候 5 rosservice call /spawn 2 2 0.2 "" 6 你会发现另一只小乌龟出现啦!
2 rosparam list查看参数
1 rosparam set [param_name] #设置参数 2 rosparam get [param_name] #得到参数 3 rosparam set /background_r 150 #把参数设置成150 4 rosparam get /background_g #获得G的参数 5 rosparam get / #获得所有参数
2.1 rosparam dump and rosparam load
1 rosparam dump [file_name] [namespace] #将参数写进 。yaml文件中 2 rosparam load [file_name] [namespace] 3 4 rosparam dump params.yaml 5 6 rosparam load params.yaml copy 7 rosparam get /copy/background_b
3. Using rqt_console and roslaunch
rqt _console and rqt_logger_level 是调试的可视化界面。
roslaunch 是一次性打开多个 节点
1 rosrun rqt_console rqt_console 2 rosrun rqt_logger_level rqt_logger_level 3 4 http://wiki.ros.org/ROS/Tutorials/UsingRqtconsoleRoslaunch#CA-21ef414cf4c910bb1286ff2aedfe349a32a099b9_1
先打开这两个界面然后就,打开node 就可以调试啦!。不懂就去参考wik 吧。
创建一个roslaunch文件,你可以在 之前建的工作空间,src/beginner… 中建一个lanunch 文件(这个文件的名字其实是随便取的。反正要存放的你的lanunch文件)之后我们来写一个launch文吧。
1 cd ~/catkin_ws2 source devel/setup.bash3 roscd beginner_tutorials4 mkdir launch5 cd launch6 touch turtlemimic.launch 7 vi turtlemimic.launch 8 9 文件内容 10 <launch> #嘛 告诉你这是个lanunch 文件 11 12 <group ns="turtlesim1"> 13 <node pkg="turtlesim" name="sim" type="turtlesim_node"/> #嘛 定义以下这个节点的名字呀,sim ,类型呀。 14 </group> 15 16 <group ns="turtlesim2"> #第二个节点 17 <node pkg="turtlesim" name="sim" type="turtlesim_node"/> 18 </group> 19 20 <node pkg="turtlesim" name="mimic" type="mimic"> #第三个节点,命令文件,可以让小乌龟跑哦。 21 <remap from="input" to="turtlesim1/turtle1"/> 22 <remap from="output" to= "turtlesim2/turtle1"/> # 运行之后,你能想想到,节点之间是怎么 传递 订阅消息哦的吗? 23 </node> 24 25 </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]' 两只小乌龟就可以动啦!
4.rosed [package_name] [filename] ROS 里面的vim。
5.Creating a ROS msg and srv
$ roscd beginner_tutorials
$ mkdir msg
$ echo "int64 num" > msg/Num.msg #以上是创建msg 并且将int64 写入,也可以用其他方式写 in package.xlm make sure #以下是告诉package,xml 以及 camke 我们要创建msg <build_depend>message_generation</build_depend><run_depend>message_runtime</run_depend>
in CMakeLists.txt make sure
find_package(catkin REQUIRED COMPONENTSroscpprospystd_msgsmessage_generation
)
catkin_package(...CATKIN_DEPENDS message_runtime ......)
add_message_files(FILESNum.msg
)
generate_messages(DEPENDENCIESstd_msgs
)
查看一个信息。。rosmsg show XX
PS:roscp [package_name] [file_to_copy_path] [copy_path] ros 里买你的复制example:roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv
然后去 工作空间下catkin_make install 就可以ˊ啦。就会生成相应的 msg srv 源码。你可以在以下路径下查看,py 跟cpp
~/catkin_ws/devel/lib/python2.7/dist-packages/beginner_tutorials/msg.
~/catkin_ws/devel/share/common-lisp/ros/beginner_tutorials/msg/.
6.Writing the Publisher Node
$ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/talker.py $ chmod +x talker.py #将下载的东西弄成可执行
1 #!/usr/bin/env python
2 # license removed for brevity
3 import rospy
4 from std_msgs.msg import String
5
6 def talker():
7 pub = rospy.Publisher('chatter', String, queue_size=10) #节点发送了chatter topic 以 msg type string 的形式
8 rospy.init_node('talker', anonymous=True) # rospy.init_node(NAME) 是非常重要的,告诉了rospy 节点的名字,这样roscore 才可以管理
9 rate = rospy.Rate(10) # 10hz 一中非常好的方法,可以循环。因为是没有 十分之一秒的/
10 while not rospy.is_shutdown():
11 hello_str = "hello world %s" % rospy.get_time()
12 rospy.loginfo(hello_str)
13 pub.publish(hello_str)
14 rate.sleep() #这段loop 是为你没有crlt+c 的时候,你可以一直保持稳定的运行。
15
16 if __name__ == '__main__':
17 try:
18 talker()
19 except rospy.ROSInterruptException:
20 pass
6.Writing the Subscriber Node
$ roscd beginner_tutorials/scripts/ $ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/listener.py
#!/usr/bin/env python import rospy from std_msgs.msg import Stringdef callback(data):rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)def listener():# In ROS, nodes are uniquely named. If two nodes with the same# node are launched, the previous one is kicked off. The# anonymous=True flag means that rospy will choose a unique# name for our 'listener' node so that multiple listeners can# run simultaneously.rospy.init_node('listener', anonymous=True)rospy.Subscriber("chatter", String, callback)# spin() simply keeps python from exiting until this node is stopped rospy.spin()if __name__ == '__main__':listener()
注意: 其实写 订阅以及 发送也是一个节点, 可以直接运行,你去运行试试吧。
7.Writing a Service Node
1 # Create the scripts/add_two_ints_server.py file within the beginner_tutorials package and paste the following inside it: 2 3 #!/usr/bin/env python 4 5 from beginner_tutorials.srv import * 6 import rospy 7 8 def handle_add_two_ints(req): 9 print "Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b)) 10 return AddTwoIntsResponse(req.a + req.b) #表示加法的 11 #实现发布 service 12 def add_two_ints_server(): 13 rospy.init_node('add_two_ints_server') 14 s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints) 15 print "Ready to add two ints." 16 rospy.spin() # 确保在没有结束这段程序之前,他就一直运行。 17 18 if __name__ == "__main__": 19 add_two_ints_server()
上面的 发布的,我们来写一个客户
1 #!/usr/bin/env python 2 3 import sys 4 import rospy 5 from beginner_tutorials.srv import * 6 7 def add_two_ints_client(x, y): 8 rospy.wait_for_service('add_two_ints') #等待 服务。 9 try: 10 add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts) 11 resp1 = add_two_ints(x, y) 12 return resp1.sum 13 except rospy.ServiceException, e: 14 print "Service call failed: %s"%e 15 16 def usage(): 17 return "%s [x y]"%sys.argv[0] 18 19 if __name__ == "__main__": 20 if len(sys.argv) == 3: 21 x = int(sys.argv[1]) 22 y = int(sys.argv[2]) 23 else: 24 print usage() 25 sys.exit(1) 26 print "Requesting %s+%s"%(x, y) 27 print "%s + %s = %s"%(x, y, add_two_ints_client(x, y))
转载于:https://www.cnblogs.com/xialuobo/p/6082877.html
ROS 命令以及相关内容学习(二)相关推荐
- Gazebo相关内容学习
什么是Gazebo和ros,以及二者的关系? Gazebo是一个不错的仿真工具,它使用物理引擎模拟真实的世界,使得我们可以通过仿真的方式从原理上验证算法,计算负载和受力情况,进而指引我们做结构和算法的 ...
- 音频处理相关内容学习——自动编码器——变分自动编码器——频谱图
文章目录 概述 一.Approaches And Challenges 生成的声音是什么类型 训练模型使用的是什么特征 原始音频Raw Audio 频谱图Spectrograms 声音生成模型常用的结 ...
- Maven相关内容学习笔记一:基本配置和使用
首先必须推荐的这本书<Maven实战> 许晓斌,机械工业出版社 Maven简介 其实使用Maven也有很久时间了,大部分都是别人建好了工程我使用一下,实际上并没有非常详细的使用经验,这次到 ...
- Android屏幕保护KeyguardManager相关内容学习
前阵子收到客户要求,要做一款安卓手机和平板上使用的屏保,其实蛮奇怪的,电脑用屏保倒是见得多了,可是手机不使用的时候关掉屏幕不就OK了吗?话说现在的智能手机电池都不耐用的可怜,还装屏保岂不是很费电.原来 ...
- DNS相关内容学习笔记1
记录dns协议学习中的一些内容,全程无图. 目录 DNS简介 DNS查询过程 DNS缓存 DNS劫持 DoH基本原理 Firefox开启DoH DNS报文格式 DNS几个关键字段 DNS类型字段 DN ...
- C++ const相关内容学习
const 作用 修饰变量,说明变量不可以被修改 修饰指针,分为指向常量的指针(pointer to const)和自身是常量的指针(常量指针,const pointer) 修饰引用,指向常量的引用( ...
- Android studio根据文本提取出的关键词在sqlite数据库中查找相关内容
Android studio根据文本提取出的关键词在sqlite数据库中查找相关内容 一.介绍 二.Android studio连接.操作和查看sqlite数据库 三.在数据库中查找相关内容 四.运行 ...
- nuxt3.0学习-二、nuxt3.0的请求相关内容、状态管理(useState/Pinia)、cookie管理(useCookie)、token续期
请求相关内容 nuxt3.0提供的多种数据访问 API 上一次是nuxt3.0的安装和约定式的使用 接下来就是使用请求调整,Nuxt3 中提供的多种数据访问 API: $fetch: 使用时机: 首屏 ...
- 【ROS入门学习01| ROS命令行工具的使用】
ROS命令行工具的使用 -----------------可以配合古月居的ROS入门教程来学习实践. 文章目录 ROS命令行工具的使用 一.roscore 二.rosrun 三.rqt_graph 四 ...
最新文章
- 因退休太无聊,Python创始人加入微软!
- python中安装一个第三方库的命令格式是-无法使用pip命令安装python第三方库的彻底解决方案...
- openGL第四讲——像素格式管理
- javascript(js)自动刷新页面的实现方法总结
- svg defs 进行定义 引用
- fitbit手表中文说明书_我如何分析FitBit中的数据以改善整体健康状况
- MySQL DATE_ADD() 函数
- Django:ORM基本操作-CRUD,管理器对象objects,----->查询1(all,values,values_list,order_by)
- 【BZOJ1417】Pku3156 Interconnect
- 必应暗藏戏精模式,拿捏名人说话语气口头禅!官方还自推三种个性供挑选
- Qgis教程07:矢量数据属性编辑
- JAVA_Android客户端_基础知识点总结
- ai条码插件免安装_ai cs6条码插件 支持Illustrator cs6的条码生成脚本
- 小白的靶机VulnHub-Stapler
- 联力L216装机心得
- ESP32学习11:PWM
- 系统中IDE硬盘与SCSI硬盘的区别
- arduino模拟类传感器编程方法
- Vue.config.productionTip = false 是什麽意思?
- [易飞]9.0新增账套
热门文章
- v8学习笔记(五) 编译过程
- [转]个人开发者做一款Android App需要知道的事情
- JVM学习笔记之-StringTable String的基本特性,内存分配,基本操作,拼接操作,intern()的使用,垃圾回收 ,G1中的String去重操作
- H3C 使用命令视图
- ARP(Address Resolution Protocol)地址解析协议初识
- C++笔记(2017/2/9)
- Apk打包-签名过程
- ASP.NET Core - Razor页面之Handlers处理方法
- Cacti监控一台Webserver上多个Tomcatport的实现
- [迷宫中的算法实践]迷宫生成算法——Prim算法