ROS 学习笔记(一)

简介

ROS (The Robot Operating System) 是一个灵活的机器人研发的框架。
机器人运行逻辑:Computer Vision + Sensor Fusion -> Localization -> Path Planning -> Control

优点

  1. Modularity: 每个功能都可以作为单独的程序运行。
  2. Distributed: programs can run on multiple computers across different networks
  3. Reproducible: 软件复用率高
  4. 很多机器人功能都是开源
  5. 提供 interface/API for both Python and C++

ROS Workspace

folders to host, modify, and update all the components of a robotic system in one place. 形式如下:

workspace_folder/            -- WORKSPACE
	src/                     -- SOURCE SPACE
		CMakeLists.txt
		package_1/
			CMakeLists.txt
			package.xml
			...
		package_n/
			CATKIN_IGNORE    -- optional empty file to exclude package_n from being processed
			CMakeLists.txt
			package.xml
	build/                   -- BUILD SPACE
	devel/                   -- DEVELOPMENT SPACE
	install/                 -- INSTALL SPACE

创建 ROS 工作空间

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/
$ catkin build
$ source devel/setup.bash

Remember to source the workspace every time when you start to use ROS

ROS Packages

A package might contain ROS nodes, a ROS independent library, a dataset, configuration files, …
软件包必须包含

workspace_folder/
	src/
		package/
			CMakeLists.txt
			package.xml       -- dependency to build a package
			src/
			scripts/
			launch/
			plans/
			test/
			include/
			config/

创建 ROS

$ cd ~/catkin_ws/src
$ catkin_create_pkg <pkg_name> std_msgs rospy roscpp [more_depends]
$ catkin build
$ source devel/setup.bash

Navigating ROS Filesystem

rospack: get information about packages.

$ rospack fine [package_name]

roscd: change directory directly to a package or a stack.

$ roscd <package> [/subdir]

rosls: list directly in a package by name rather than by absolute path.

$ rosls [package_name]

ROS Communication Graph

一个process (pkg1) 调用摄像头,另一个process (pkg2) 识别人,ROS通过 graph-like structure 管理各个processes之间的通信。

Basic ROS Graph Components:

  • Nodes
  • Topics
  • Messages
  • Services
  • Bags
  • Parameter Server
  • Master

Nodes

定义:Nodes are the executables that take care of computation

Nodes can interact with each other, and they are implemented by ROS client libraries like roscpp or rospy

run a node use rosrun

Topics

named routes over which nodes exchange messages. Each route have a specific topic name associated with it.

Msg

Nodes communicate with each other by publishing messages to topics.

A message is a simple data structure comprising typed fields

geometry_msgs/Point.msg

float64 x
float64 y
float64 z

Publisher and Subscriber

Publisher (Pub): a node that publishes a specific type of message over a given topic.

Subscriber (Sub): a node that subscribes a specific type of message over a given topic and invokes a callback function to process received message.

Pub/Sub is a form of asynchronous communication

Parameter Server

a shared dictionary used by nodes to store and retrieve parameters at runtime

rosparam list                # list all parameters' name 
rosparam get <param-name>    # get parameter's value
rosparam set <param-name>    # set parameter to a value
rosparam delete <param-name> # delete a parameter

Master

Responsible for communication between the nodes and maintain registries for nodes and helps them find each other

roscore: command to start the master, and create the communication for ROS nodes.

Remember to run roscore first! The master should always be running when using ROS

Bags

recording from and playing back to ROS topics

rosbag record [TOPIC NAME]
rosbag play [bagfile]
rosbag play --clock [bagfile]
上一篇:S1雷达ROS包更新指南


下一篇:在ROS中实现多Realscene D455数据的读取并发布