ROS Efficient Introduction Chapter 2--Basic concepts and common command learning, based on the sample of the little turtle

1 data

This section mainly refers to the following materials:
(1) "Analysis of Robot Operating System (ROS)" [US] Jason M. O'Kane, translated by Xiao Junhao
(2) "ROS Robot Development Practice" Hu Chunxu
(3) ros Tutorials primary tutorial Sections 1~9: http://wiki.ros.org/cn/ROS/Tutorials
(4) If you like videos, you can also watch:
https://www.bilibili.com/video/av59458869/Guyue
ROS Introduction 21 Lecture | The first 9 sections of the ROS robot introductory tutorial that you can learn

2 Organize the output

2.1 ros version selection and environment construction

(1) Release history of ros: http://wiki.ros.org/Distributions
(2) Recommended ros version: ROS Noetic Ninjemys, LTS to 2025.5, use ubuntu20.04
Supplement: It is recommended to use Virtual Box, build ubuntu20 The .04 virtual machine has the lowest cost and the highest efficiency!
(3) The first installation method (very convenient and fast, recommended!):
wget http://fishros.com/install -O fishros && sudo ./fishros
related blog:
https://blog.csdn.net/KIK9973/ article/details/118755045
(4) The second installation method (official website): http://wiki.ros.org/cn/Installation/Ubuntu
(5) After installation, verify the ros version and check whether the installation is successful:

printenv | grep ROS

cat ~/.bashrc

2.2 Example of running little turtle

(1) The little turtle is a synonym for robots. For the story, you can read the first chapter of my ROS Efficient Introduction – ROS History and Current Status
(2) ROS comes with a little turtle simulation program: turtlesim. Using this example, you can use the concepts related to ros And command, learn it quickly!
In ubuntu with ros installed, open three terminals and execute them respectively:

roscore
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key

When moving the little turtle, the cursor must be placed in the turtle_teleop_key window!
insert image description here

2.3 ROS Packages software package

(1) In ros, all software is organized into software packages, each package has a manifest file package.xml, describing the package, and a CMakeLists.txt, used to build the package.
Therefore, a package can be defined as a directory that ROS can find and contain package.xml.
(2) For a detailed explanation of package.xml, see
http://wiki.ros.org/cn/ROS/Tutorials/CreatingPackage
(3) The software package of the little turtle sample is turtlesim, which contains two executable programs, turtlesim_node and turtle_teleop_key
( 4) Commands of the ROS operation package:

//  创建,构建软件包并使能
cd ~/catkin_ws
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
catkin_make
source ~/catkin_ws/devel/setup.bash  // 将工作空间添加到ROS环境中

rospack list
rospack find turtlesim
rosls turtlesim
roscd turtlesim
rospack depends turtlesim

(5) See the explanation and complex usage of catkin_make:
http://wiki.ros.org/cn/ROS/Tutorials/BuildingPackages
http://wiki.ros.org/catkin/commands/catkin_make
catkin_make source code:
https:// github.com/ros/catkin/blob/kinetic-devel/bin/catkin_make

2.4 ROS Node Manager and Nodes

(1) ROS architecture diagram
insert image description here
(2) Node manager Master, responsible for managing each node and realizing distributed communication.
Start command:

roscore

(3) The running instance of the ROS program is called the node (node)
startup command:

rosrun package-name executable-name
// 例如2.2节的
rosrun turtlesim turtlesim_node
rosrun turtlesim turtle_teleop_key
// 节点重命名
rosrun turtlesim turtlesim_node __name:=my_turtle

Node debugging command:

rosnode list
rosnode info node-name
rosnode kill node-name
rosnode cleanup

2.5 Topic and message msg

(1) Topic communication mechanism
insert image description here
In ROS, msg is stored in the topic topic in an organized manner. The idea of ​​message passing is:
when a node wants to share information, it will publish (publish) the message to one or more corresponding topics; when a node wants to receive information, it will subscribe (subscribe) One or more topics required.
Nodes are loosely coupled, and each node does not need to explicitly know the existence of other nodes.
The ROS node manager is responsible for ensuring that publishing and subscribing nodes can find each other.
Moreover, the message is directly delivered from the publishing node to the subscribing node, without being forwarded by the node manager in the middle.
(2) Visually view nodes and topics

rosrun rqt_graph rqt_graph
rosrun rqt_plot rqt_plot

insert image description here
insert image description here

(3) Message and topic debugging commands

rostopic list
rostopic echo topic-name
rostopic hz topic-name
rostopic bw topic-name
rostopic info topic-name

rostopic type topic-name
rosmsg show message-type-name

// 手动发送消息
rostopic pub –r rate-in-hz topic-name message-type message-content
// 例如
rostopic pub –r 1 /turtle1/cmd_vel geometry_msgs/Twist ’[2,0,0]’ ’[0,0,0]’

// 对整个拓扑体检
roswtf

(4) Naming method of message type
insert image description here

2.6 Service service

(1) Service is a communication mechanism with response (request and reply), it is C/S mode, it is synchronous communication, it is one-to-one, and the topic is asynchronous communication, it is broadcast communication.
insert image description here
insert image description here
(2) Service debugging parameters

rosservice list
rosservice type [service]
rosservice call [service] [args]
rosservice info [service]

rosservice type /spawn | rossrv show
rossrv show service-data-type-name

rosservice call  [service] request-content
rosservice call /spawn 3 3 0 Mikey

2.7 parameterparam

(1) Parameters are similar to global variables in ROS and are managed by ROS Master (parameter server). By allowing nodes to actively query the values ​​of parameters they are interested in, they are suitable for configuring information that does not change frequently over time.
The parameter server can store data types such as integer, float, boolean, dictionaries, and lists. rosparam uses the syntax of the YAML markup language.
insert image description here
(2) Debug command

rosparam list

rosparam set [param_name]
rosparam get [param_name]

//修改turtlesim背景颜色为黄色,参数值修改后,需要调用服务/clear才能生效
rosparam set /turtlesim/background_r 255
rosparam set /turtlesim/background_g 255
rosparam set /turtlesim/background_b 0
rosservice call /clear

//获取所有参数
rosparam get /

// 命名空间不是必须
rosparam dump [file_name] [namespace]
rosparam load [file_name] [namespace]

2.8 ROS log and rqt_console

(1) ROS has developed a log system that supports programming calls and visual viewing. Here we mainly focus on the latter. Divided into the following levels,

Fatal (致命)
Error (错误)
Warn  (警告)
Info  (信息)
Debug (调试)

(2) In the little turtle sample, there is a /rosout node, which is responsible for receiving the /rosout topic sent by each node, and
aggregates the topic, and sends it out as the /rosout_agg topic. rqt_console, as a node, subscribes to the log aggregation topic.

rosrun rqt_console rqt_console

Set the log level (after clicking refresh, enable):

rosrun rqt_logger_level rqt_logger_level

Let the little turtle hit the wall, you can see the warn log, as follows
insert image description here

2.9 launch file and roslaunch

(1) The little turtle samples above are all started manually with roscore and rosrun, which takes up a lot of windows and is troublesome. A real system is generally started with a launch file. This startup method does not need to start the node manager separately, and can pull up multiple nodes at once.
(2) The launch file is described in XML and the suffix is ​​.launch. Generally, a launch directory is created in the root directory of a software package to store the startup files

cd ~/catkin_ws
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
source devel/setup.bash

roscd beginner_tutorials
mkdir launch
cd launch
touch turtlemimic.launch

Rough explanation of the contents of turtlemimic.launch:

<launch>

// 此处我们创建了两个分组,并以命名空间(namespace)标签来区分,
// 其中一个名为turtulesim1,另一个名为turtlesim2,两个分组中都有相同的名为sim的turtlesim节点。
  <group ns="turtlesim1">
    <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
  </group>

  <group ns="turtlesim2">
    <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
  </group>

// 启动模仿节点,话题的输入和输出分别重命名为turtlesim1和turtlesim2,这样就可以让turtlesim2模仿turtlesim1了
  <node pkg="turtlesim" name="mimic" type="mimic">
    <remap from="input" to="turtlesim1/turtle1"/>
    <remap from="output" to="turtlesim2/turtle1"/>
  </node>

</launch>

Start and test

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]'

(3) For more specific grammatical rules about roslaunch files, see Chapter 6 of "Analysis of Robot Operating System (ROS)"

Summarize

Use the little turtle example to operate all of these, and write down these concepts to lay the foundation for more in-depth ROS programming later.

Guess you like

Origin blog.csdn.net/cy1641395022/article/details/130205195