古月居ROS入门21讲学习笔记——二 核心概念

2.1 安装ros系统

  • 安装步骤(网上很多教程,照着来就行)

  • https://www.ncnynl.com/archives/201801/2273.html

  • 安装目录默认在/opt/ros 路径下,功能包在lib/share里面

  • 测试:小海龟

    #启动ROS Master
    roscore
    #启动小海龟仿真器
    rosrun turtlesim turtlesim_node
    #启动海龟控制节点
    rosrun turtlesim turtle_teleop_key
    

2.2 ros是什么

  • ROS历史

    • 2007 诞生于斯坦福STAIR项目 Morgan Quigley
    • 2008 Willow Garage接手
    • 2010 ROS1.0发布
    • 2011 TurtleBot发布(Slam导航等)
    • 2012 第一届ROScon(ROS开发者大会)
    • 2013 OSRF接管ROS
    • 2014 ROS Indigo发布(第一个长期支持版)
    • 2016 ROS Kinetic发布
    • 2017 ROS 2.0 Ardent发布
    • 2018 ROS Melodic发布
  • ROS:通信机制+开发工具+应用功能+生态系统

    • 提高机器人研发中的软件复用率,加速机器人开发,减少重复造轮子的功能

    • 通讯机制:松耦合分布式通信

    • 开发工具:命令行&编译器,TF坐标变换,QT工具箱,Rviz,Gazebo

    • 应用功能:导航,建图,规划(拼接口)

    • 生态系统:发行版、软件源(Repository)、ROS wiki、邮件列表(Mailing list)、ROS Answers(咨询ROS相关问题的网站)、博客(http://www.ros.org/news)

      • ROS社区资源的组织形式

        ROS社区资源的组织形式

2.3 ros的核心概念

  • 包含很多node,每个node位置不一定一样(可以在不同电脑上),编程语言也不一定一样

    ROS节点示意图

2.3.1节点与节点管理器
  • 节点(Node)——执行单元

    • 执行具体任务的进程,独立运行的可执行文件
    • 不同节点可使用不同的编程语言,可分布式运行在不同的主机
    • 节点在系统中的名称必须式惟一的
  • 节点管理器(ROS Master)——控制中心(“婚介所”)

    • 为节点提供命名和注册服务

    • 跟踪和记录话题/服务通信,辅助节点相互查找,建立连接

    • 提供参数服务器,节点使用此服务器存储检索运行时的参数

    • 三个节点:Camera Node(摄像头驱动)、Image Processing Node(图像处理)、Image Display Node(远端接收图像处理结果节点)

      节点管理器

2.3.2通讯方式
  • 话题通讯

    • 话题(Topic)——异步式通信机制

      • 节点间用来传输数据的重要总线(通道)

      • 使用发布/订阅模型,数据由发布者传输到订阅者,同一个话题的订阅者和发布者可以不唯一

      • 话题模型(发布/订阅)

      话题模型

    • 消息(Message)——话题数据

      • 具有一定的类型和数据结构,包括ROS提供的标准类型和用户自定义类型
      • 使用编程语言无关的.msg文件定义,编译过程中生成对应的代码文件
      • 话题通信
  • 服务通讯

    • 服务(Service)——同步通信机制

      • 使用客户端/服务端(C/S)模型,客户端发送请求数据,服务器完成处理后返回应答数据

      • 使用编程无关的. srv文件定义请求和应答数据结构,编译过程中生成相应的代码文件

        服务模型
        服务通信例子

  • 话题和服务区别

    话题与服务区别

2.3.3参数
  • 参数(Parameter)——全局共享字典
    • 可通过网络访问的共享、多变量字典
    • 节点使用此服务器来存储和检索运行时的参数
    • 适合存储静态、非二进制的配置参数,不适合存储动态配置的数据

参数模型

2.3.4文件系统
  • 功能包(Package)

    • ROS软件中的基本单元,包含节点源码、配置文件、数据定义等
  • 功能包清单(Package manifest)

    • 记录功能包的基本信息,包含作者信息、许可信息、依赖选项、编译标志等
  • 元功能包(Mate Package)

    • 组织多个用于同一目的的功能包

文件系统

2.4 ros命令行工具的使用

  • 常用命令及所有命令

    ROS常用命令行

  • 以小海龟为例

    • 启动小海龟
    #启动ROS Master
    roscore
    #启动小海龟仿真器
    rosrun turtlesim turtlesim_node
    #启动海龟控制节点
    rosrun turtlesim turtle_teleop_key
    
  • rqt_graph工具

    #显示系统计算图的工具
    rqt_graph 
    

    图(Graph)是用于表示对象之间关联关系的一种抽象数据结构,使用顶点(Vertex)和边(Edge)进行描述:顶点表示对象,边表示对象之间的关系。可抽象成用图描述的数据即为图数据。图计算,便是以图作为数据模型来表达问题并予以解决的这一过程。以高效解决图计算问题为目标的系统软件称为图计算系统。

    计算图

    • rosnode

      #help
      yxq@yxq-ThinkPad-S2:~$ rosnode
      rosnode is a command-line tool for printing information about ROS Nodes.
      
      Commands:
      	rosnode ping	test connectivity to node
      	rosnode list	list active nodes
      	rosnode info	print information about node
      	rosnode machine	list nodes running on a particular machine or list machines
      	rosnode kill	kill a running node
      	rosnode cleanup	purge registration information of unreachable nodes
      
      Type rosnode <command> -h for more detailed usage, e.g. 'rosnode ping -h'
      
      #列出系统中所有节点
      yxq@yxq-ThinkPad-S2:~$ rosnode list
      /rosout			#(不关心)roscore启动后就会启动的默认话题,采集ros中所有节点的日志信息,用来提交给界面所显示
      /teleop_turtle	#键盘节点
      /turtlesim		#小乌龟仿真节点
      
      #查看某个节点的具体信息
      yxq@yxq-ThinkPad-S2:~$ rosnode info /turtlesim 
      --------------------------------------------------------------------------------
      Node [/turtlesim]
      Publications: 	#发布的话题
       * /rosout [rosgraph_msgs/Log]
       * /turtle1/color_sensor [turtlesim/Color]
       * /turtle1/pose [turtlesim/Pose]
      
      Subscriptions: 	#订阅的话题
       * /turtle1/cmd_vel [geometry_msgs/Twist]
      
      Services: 		#提供的服务
       * /clear
       * /kill
       * /reset
       * /spawn
       * /turtle1/set_pen
       * /turtle1/teleport_absolute
       * /turtle1/teleport_relative
       * /turtlesim/get_loggers
       * /turtlesim/set_logger_level
      
      
      contacting node http://yxq-ThinkPad-S2:40901/ ...	#主机号
      Pid: 24852	#Pid号
      Connections:
       * topic: /rosout
          * to: /rosout
          * direction: outbound
          * transport: TCPROS
       * topic: /turtle1/cmd_vel
          * to: /teleop_turtle (http://yxq-ThinkPad-S2:38073/)
          * direction: inbound
          * transport: TCPROS
      
      
      
    • rostopic

      #help
      yxq@yxq-ThinkPad-S2:~$ rostopic
      rostopic is a command-line tool for printing information about ROS Topics.
      
      Commands:
      	rostopic bw	display bandwidth used by topic
      	rostopic delay	display delay of topic from timestamp in header
      	rostopic echo	print messages to screen
      	rostopic find	find topics by type
      	rostopic hz	display publishing rate of topic    
      	rostopic info	print information about active topic
      	rostopic list	list active topics
      	rostopic pub	publish data to topic
      	rostopic type	print topic or field type
      
      Type rostopic <command> -h for more detailed usage, e.g. 'rostopic echo -h'
      
      #查看当前系统所有话题列表
      yxq@yxq-ThinkPad-S2:~$ rostopic list 
      /rosout
      /rosout_agg
      /turtle1/cmd_vel
      /turtle1/color_sensor
      /turtle1/pose
      
      #直接给topic发布数据给某个topic
      # -r 10:以10hz(10次/s)发布	/turtle1/cmd_vel:话题名	Twist:消息数据结构	“...”:消息中的具体数据
      yxq@yxq-ThinkPad-S2:~$ rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
        x: 1.0
        y: 0.0
        z: 0.0
      angular:
        x: 0.0
        y: 0.0
        z: 1.0" 
      
    • rosmsg

      #help
      yxq@yxq-ThinkPad-S2:~$ rosmsg
      rosmsg is a command-line tool for displaying information about ROS Message types.
      
      Commands:
      	rosmsg show	Show message description
      	rosmsg info	Alias for rosmsg show
      	rosmsg list	List all messages
      	rosmsg md5	Display message md5sum
      	rosmsg package	List messages in a package
      	rosmsg packages	List packages that contain messages
      
      Type rosmsg <command> -h for more detailed usage
      
      #显示某个消息的数据结构
      yxq@yxq-ThinkPad-S2:~$ rosmsg show geometry_msgs/Twist
      geometry_msgs/Vector3 linear
        float64 x
        float64 y
        float64 z
      geometry_msgs/Vector3 angular
        float64 x
        float64 y
        float64 z
      
    • rosserviece

      #help
      yxq@yxq-ThinkPad-S2:~$ rosservice
      Commands:
      	rosservice args	print service arguments
      	rosservice call	call the service with the provided args
      	rosservice find	find services by service type
      	rosservice info	print information about service
      	rosservice list	list active services
      	rosservice type	print service type
      	rosservice uri	print service ROSRPC uri
      
      Type rosservice <command> -h for more detailed usage, e.g. 'rosservice call -h'
      
      #显示当前所有服务,海龟中服务端都是海龟仿真器,终端都是作为客户端去请求某个服务
      yxq@yxq-ThinkPad-S2:~$ rosservice list
      /clear
      /kill
      /reset
      /rosout/get_loggers
      /rosout/set_logger_level
      /spawn	#产生新的海龟
      /teleop_turtle/get_loggers
      /teleop_turtle/set_logger_level
      /turtle1/set_pen
      /turtle1/teleport_absolute
      /turtle1/teleport_relative
      /turtlesim/get_loggers
      /turtlesim/set_logger_level
      
      #请求某个服务(例如/spawn)
      yxq@yxq-ThinkPad-S2:~$ rosservice call /spawn "x: 2.0
      y: 2.0
      theta: 0.0
      name: 'turtle2'" 
      name: "turtle2"	#service的反馈
      #用rostopic list 发现多了一个海龟的话题
      yxq@yxq-ThinkPad-S2:~$ rostopic list
      /rosout
      /rosout_agg
      /turtle1/cmd_vel
      /turtle1/color_sensor
      /turtle1/pose
      /turtle2/cmd_vel
      /turtle2/color_sensor
      /turtle2/pose
      #然后就可以用之前rostopic pub的指令来给海龟2话题发布数据内容
      yxq@yxq-ThinkPad-S2:~$ rostopic pub -r 10 /turtle2/cmd_vel geometry_msgs/Twist "linear:
        x: 1.0
        y: 0.0
        z: 0.0
      angular:
        x: 0.0
        y: 0.0
        z: 0.0" 
      
    • rosbag(采集数据并复现到仿真器中)

      #help
      yxq@yxq-ThinkPad-S2:~$ rosbag
      Usage: rosbag <subcommand> [options] [args]
      
      A bag is a file format in ROS for storing ROS message data. The rosbag command can record, replay and manipulate bags.
      
      Available subcommands:
         check  	Determine whether a bag is playable in the current system, or if it can be migrated.
         compress  	Compress one or more bag files.
         decompress  	Decompress one or more bag files.
         filter  	Filter the contents of the bag.
         fix  	Repair the messages in a bag file so that it can be played in the current system.
         help  
         info  	Summarize the contents of one or more bag files.
         play  	Play back the contents of one or more bag files in a time-synchronized fashion.
         record  	Record a bag file with the contents of specified topics.
         reindex  	Reindexes one or more bag files.
      
      For additional information, see http://wiki.ros.org/rosbag
      
      #记录数据并保存到压缩包中(压缩包保存在当前终端所处位置,例如例子里数据压缩包存在home中)
      # -a:所有数据	-O:保存到压缩包中
      yxq@yxq-ThinkPad-S2:~$ rosbag record -a -O cmd_record
      [ INFO] [1609578688.343089872]: Recording to cmd_record.bag.
      [ INFO] [1609578688.343491904]: Subscribing to /turtle1/color_sensor
      [ INFO] [1609578688.346475204]: Subscribing to /turtle2/color_sensor
      [ INFO] [1609578688.349480322]: Subscribing to /rosout
      [ INFO] [1609578688.352538254]: Subscribing to /turtle2/pose
      [ INFO] [1609578688.357086270]: Subscribing to /rosout_agg
      [ INFO] [1609578688.360927916]: Subscribing to /turtle1/cmd_vel
      [ INFO] [1609578688.363834265]: Subscribing to /turtle1/pose
      ^C#结束采集
      
      #复现数据(需要重启roscore、小海龟仿真节点,键盘节点直接关闭)
      yxq@yxq-ThinkPad-S2:~$ rosbag play cmd_record.bag 
      [ INFO] [1609578799.736674407]: Opening cmd_record.bag
      
      Waiting 0.2 seconds after advertising topics... done.
      
      Hit space to toggle paused, or 's' to step.
       [DELAYED]  Bag Time: 1609578688.367109   Duration: 0.000000 / 31.334983   Delay: 111.58 [RUNNING]  Bag Time: 1609578719.670937   Duration: 31.303828 / 31.334983               
      Done.
      
  • 47
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值