当前位置:网站首页>ROS learning notes - tutorial on the use of ROS

ROS learning notes - tutorial on the use of ROS

2022-04-23 20:59:00 YOULANSHENGMENG

One , What is knot ROS System

       ROS(Robot Operating System) Robot operating system actually provides multi node cooperation mechanism , Use the topic 、 service 、 Parameter server 、action And so on , meanwhile ROS It also provides Gazebo、rviz、rqt、rosbag Tools such as , The essence of these tools is also the sending and receiving of communication messages .
      ROS Itself provides a point-to-point network , Working together on data , Its basic concepts include nodes 、 Master node 、 Parameter server 、 news 、 service 、 topic of conversation 、 Bags, etc .

1.1、ROS The main characteristics of

(1) Distributed architecture ( Each work process is regarded as a node , Use the node manager to manage ),

(2) Multilingual support ( Such as C++、Python etc. ),

(3) Good scalability ( You can write a node , It can also be done through roslaunch Organize many nodes into a larger project ),

(4) Open source code (ROS follow BSD agreement , Free of charge for individual and commercial applications and modifications ).

1.2 ROS Common commands


rospack- Get information about the package : View package dependencies ,
roscd- Switch to package directory
rosls- View the files contained in the package
rosnode- see ros Node related information : View the list of nodes , View node message properties
rosrun- The software package runs - Function of a node :rqt-graph
rostopic- Get information about the topic
rosservice- Get service related information
rosparam- Get parameter related information
roslaunch- start-up launch file
rosmsg- View information about the message

have access to Tab The completion code

Two 、ROS Calculation diagram level in

Figure conceptual description

· Nodes: node , A node is an executable file , It can go through ROS Communicate with other nodes .
· Messages: news , News is a kind of ROS data type , Used to subscribe to or publish to a topic .
· Topics: topic of conversation , Nodes can publish messages to topics , You can also subscribe to topics to receive messages .
· Master: Node manager ,ROS The name of the service ( For example, help nodes find each other ).
· rosout: ROS Equivalent to stdout/stderr.
· roscore: host + rosout + Parameter server ( The parameter server will be introduced later )

2.1 node

      Node is the main computing execution process .ROS It is composed of many nodes . A node is just ROS An executable file in the package .ROS Nodes can use ROS The customer library communicates with other nodes . Nodes can publish or receive a topic . Nodes can also provide or use certain services .

( Node is ros A very important concept in , To help beginners understand this concept , Here is a popular example :

for example , We have a robot , And a remote control , So when the robot and the remote control start working , Just two nodes . The remote control plays the role of giving directions The role of orders ; The robot is responsible for monitoring the instructions given by the remote control , Complete the action . From here we can see that , A node is a task that can perform a specific job Work unit of business , And can communicate with each other , So as to realize the overall function of a robot system . Here, we simply define the remote controller and robot as two nodes , In fact, in the robot, according to the controller 、 sensor 、 Actuator and other different modules , It can also be further subdivided into more nodes , This is defined according to the program written by the user .)

The method of starting a node , Take the tortoise tutorial as an example :

roscore
rosrun turtlesim turtlesim_node
// If you want to view the graph of nodes , Execute the following command 
rqt_graph

ROS Command line tools rosnode

rosnode command effect
rosnode list Query all currently running nodes
rosnode info node_name Display the details of this node
rosnode kill node_name End a node
rosnode ping Test whether the node survives
rosnode machine Lists the nodes running on a particular machine or list of machines
rosnode cleanup Clear the registration information of non runnable nodes

  When developing and debugging, you often need to check the current node as well as node Information , So remember these common commands . If I can't remember , It can also be done through rosnode help Check it out. rosnode command reference .

2.2. news

Nodes pass through news Realize each other's Logical connection and data exchange .

ROS Command line tools rosmsg

rosmsg command effect
rosmsg show Display a message field
rosmsg list List all messages
rosmsg package List all Feature Pack messages
rosmsg packages List all feature packs with this message
rosmsg md5 Display a message MD5 Test value

2.3 topic of conversation  

Topic is a kind of message transmission ( Release / subscribe ) The way . Every message should be posted on the corresponding topic , Every topic is strongly typed .

ROS Topic messages can use TCP/IP or UDP transmission ,ROS The default transmission mode is TCP/IP. be based on TCP Transmission becomes TCPROS, It's a long connection ; be based on UDP Transmission becomes UDPROS, It's a low latency 、 Efficient transmission mode , But it's easy to lose data , Suitable for remote operation .

rostopic command effect
rostopic bw /topic Displays the bandwidth used by the topic
rostopic echo /topic Output the message corresponding to the topic to the screen
rostopic find message_type Find topics by type
rostopic hz /topic Displays how often the topic is published
rostopic info /topic Output information about the topic
rostopic list Output a list of active topics
rostopic pub /topic type args Publish data to topics
rostopic type /topic Output topic type

2.4 service  

    The service is used for the request response model , It must also have a unique name . When a node provides a service , All nodes can be accessed by using ROS The code written by the client communicates with it .

rosservice command effect
rosservice args /service Display service parameters
rosservice call /service Request the service with the input parameters
rosservice find /service Find topics by type
rosservice info /service Displays information about the specified service
rosservice list Display active service information
rosservice uri /service Show ROSRPC URI service
rosservice type /service Displays the service type

2.5 Message logging package  

Message recording package is a kind of package for saving and playback ROS File format of message data , Save in .bag In file . Is an important mechanism for storing data .

rosbag command effect
check Determine whether a package can be carried out in the current system , Or whether it can be migrated .
decompress Compress one or more package files .
filter Decompress one or more package files .
fix Fix the message in the package file , In order to play in the current system .
help Get relevant command guidance and help information .
info Summarize the contents of one or more packages .
play Replay the contents of one or more package files in a time synchronized manner .
record Record a package file with the content of the specified topic .
reindex Re index one or more package files .

2.6  Parameter server

The parameter server is a shared multivariable dictionary accessible through the network , Stored on the node manager by keyword .

ROS Command line tools rosparam: 

rosparam command effect
rosparam delete parameter Delete parameters
rosparam dump file Write the parameters in the parameter server to the file
rosparam get parameter Get the parameter value
rosparam list List the parameters in the parameter server
rosparam load file Load parameters from file to parameter server
rosparam set parameter value Set parameters

 2.7 Node manager (Master)

      The node manager is used for topics 、 Registration and search of service name . Throughout ROS If there is no node manager in the system , There will be no communication between nodes .

3, Create a virtual machine based on ros Project files for

3.1 Project file structure

ROS File structure , Not every folder is required , Design according to business requirements .

After turning on the virtual machine , Sometimes it indicates that the network activation fails , Refer to the following link for repair methods :

VMware In the virtual machine Ubuntu18.04 The solution to being unable to connect to the network - Baidu library https://wenku.baidu.com/view/6eacf52775c66137ee06eff9aef8941ea76e4bd6.html

3.2、 working space

A workspace is managing and organizing ROS Place of project documents , The intuitive description is a warehouse , It's loaded with ROS Various project works , It is convenient for system organization and management to call . In the visual graphical interface is a folder . We wrote it ourselves ROS The code is usually placed in the workspace . There are four primary directories under it :

  • src: Source space ;ROS Of catkin software package ( Source code package )
  • build: Compilation space ;catkin(CMake) Cache information and intermediate files
  • devel: Development space ; Generated target file ( Including header files , Dynamic link library , Static link library , Executable documents, etc )、 environment variable
  • install: Installation space

The top workspace ( Can be named as you like ) and src ( It has to be for src) Folders need to be created by yourself ;

  • build and devel Folder by catkin_make Command automatic creation ;
  • install Folder by catkin_make install Command automatic creation , Hardly used , Generally do not create .

  Be careful : Use catkin_make Be sure to return to the top workspace before compiling . Under the same workspace , A feature pack with the same name is not allowed ; In different workspaces , Feature packs with the same name are allowed .

mkdir -p ~/catkin_ws/src  #  establish 
cd catkin_ws/             #  Enter the workspace 
catkin_make               #  compile 
source devel/setup.bash   #  Update workspace environment 

3.3、package Function pack

package It is a specific combination of file structure and folder . Usually, the program code that implements the same specific function is put into one package in . Only CMakeLists.txt and package.xml yes 【 must 】 Of , The rest of the path depends on whether the software package needs to be .

Create Feature Pack

cd ~/catkin_ws/src
catkin_create_pkg my_pkg rospy rosmsg roscpp

 

【rospy】、【rosmsg】、【roscpp】 It's a dependency Library , Can be added according to business requirements , You can also add other , When you add it when you create it, you don't need to configure , Forget to add. You need to configure it yourself . 

  File structure :

|-- CMakeLists.txt  # ( must ) At present package The Compilation Rules of . It usually needs to be c++ Add compile time dependencies to the code , To perform, etc .
|—— package.xml     # ( must )package Description information of . Usually add some ros Library support .
|—— include Folder     #  Deposit c++  Of the header file 
|—— config Folder      #  Store parameter configuration files 
|—— launch Folder      #  Deposit launch file (.launch or .xml)
|—— meshes Folder      #  Storage of robots or simulation scenes 3D Model (.sda, .stl, .dae etc. ) ;
|—— urdf Folder        #  Model description of storage robot (.urdf or .xacro) ;
|—— rviz Folder        # rviz file 
|—— src Folder         # c++ Source code 
|—— scripts Folder     #  Executable script ; for example shell Script (.sh)、Python Script (.py) ;
|—— srv Folder         #  Customize service
|—— msg Folder         #  Customize topic
|—— action Folder      #  Customize action

 

3.4、CMakeLists.txt Introduce

CMakeLists.txt It was Cmake Compile the rules file of the system , and Catkin The compiling system basically follows CMake Compilation style , Just for ROS The project has added some macro definitions . So in terms of writing ,catkin Of CMakeLists.txt And CMake Basically the same .

This document directly stipulates this package What to rely on package, Which targets to compile , How to compile and so on . therefore CMakeLists.txt It's very important , It specifies the rules from the source code to the target file ,catkin When the compiling system works, it will first find each package Under the CMakeLists.txt, Then compile and build according to the rules .

CMakeLists.txt The basic grammar of is still in accordance with CMake, and Catkin Add a few macros to it , The overall structure is as follows :

cmake_minimum_required() #  what is needed CMake edition  
project()                #  Package name  
find_package()           #  Find other... Needed for compilation CMake/Catkin package
catkin_python_setup()    #  Enable Python Module support 
add_message_files()      # message generator 
add_service_files()      # service generator 
add_action_files()       # action generator 
generate_message()       #  Generate different language versions of msg/srv/action Interface 
catkin_package()         #  Generate current package Of cmake To configure , For other software packages that depend on this package 
add_library()            #  Used to specify the library generated by compilation . default catkin Compile to generate shared library .
add_executable()         #  Generate executable binaries 
add_dependencies()       #  The definition target file depends on other target files , Ensure that other goals have been built 
target_link_libraries()  #  Specifies the library to which the executable is linked . This should be used in add_executable() Back .
catkin_add_gtest()       #  Test build 
install()                #  Install to this machine 

After following the above steps , Generated CMakeLists.txt The contents of the file are :

cmake_minimum_required(VERSION 3.0.2)
project(my_pkg)

## Compile as C++11, supported in ROS Kinetic and newer
# add_compile_options(-std=c++11)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rosmsg
  rospy
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)


## Uncomment this if the package has a setup.py. This macro ensures
## modules and global scripts declared therein get installed
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
# catkin_python_setup()

################################################
## Declare ROS messages, services and actions ##
################################################

## To declare and build messages, services or actions from within this
## package, follow these steps:
## * Let MSG_DEP_SET be the set of packages whose message types you use in
##   your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
## * In the file package.xml:
##   * add a build_depend tag for "message_generation"
##   * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
##   * If MSG_DEP_SET isn't empty the following dependency has been pulled in
##     but can be declared for certainty nonetheless:
##     * add a exec_depend tag for "message_runtime"
## * In this file (CMakeLists.txt):
##   * add "message_generation" and every package in MSG_DEP_SET to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * add "message_runtime" and every package in MSG_DEP_SET to
##     catkin_package(CATKIN_DEPENDS ...)
##   * uncomment the add_*_files sections below as needed
##     and list every .msg/.srv/.action file to be processed
##   * uncomment the generate_messages entry below
##   * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
#   FILES
#   Message1.msg
#   Message2.msg
# )

## Generate services in the 'srv' folder
# add_service_files(
#   FILES
#   Service1.srv
#   Service2.srv
# )

## Generate actions in the 'action' folder
# add_action_files(
#   FILES
#   Action1.action
#   Action2.action
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
#   DEPENDENCIES
#   std_msgs  # Or other packages containing msgs
# )

################################################
## Declare ROS dynamic reconfigure parameters ##
################################################

## To declare and build dynamic reconfigure parameters within this
## package, follow these steps:
## * In the file package.xml:
##   * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
## * In this file (CMakeLists.txt):
##   * add "dynamic_reconfigure" to
##     find_package(catkin REQUIRED COMPONENTS ...)
##   * uncomment the "generate_dynamic_reconfigure_options" section below
##     and list every .cfg file to be processed

## Generate dynamic reconfigure parameters in the 'cfg' folder
# generate_dynamic_reconfigure_options(
#   cfg/DynReconf1.cfg
#   cfg/DynReconf2.cfg
# )

###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## LIBRARIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES my_pkg
#  CATKIN_DEPENDS roscpp rosmsg rospy
#  DEPENDS system_lib
)

###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)

## Declare a C++ library
# add_library(${PROJECT_NAME}
#   src/${PROJECT_NAME}/my_pkg.cpp
# )

## Add cmake target dependencies of the library
## as an example, code may need to be generated before libraries
## either from message generation or dynamic reconfigure
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
# add_executable(${PROJECT_NAME}_node src/my_pkg_node.cpp)

## Rename C++ executable without prefix
## The above recommended prefix causes long target names, the following renames the
## target back to the shorter version for ease of user use
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")

## Add cmake target dependencies of the executable
## same as for the library above
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

## Specify libraries to link a library or executable target against
# target_link_libraries(${PROJECT_NAME}_node
#   ${catkin_LIBRARIES}
# )

#############
## Install ##
#############

# all install targets should use catkin DESTINATION variables
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html

## Mark executable scripts (Python etc.) for installation
## in contrast to setup.py, you can choose the destination
# catkin_install_python(PROGRAMS
#   scripts/my_python_script
#   DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark executables for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
# install(TARGETS ${PROJECT_NAME}_node
#   RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
# )

## Mark libraries for installation
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
# install(TARGETS ${PROJECT_NAME}
#   ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
#   RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
# )

## Mark cpp header files for installation
# install(DIRECTORY include/${PROJECT_NAME}/
#   DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
#   FILES_MATCHING PATTERN "*.h"
#   PATTERN ".svn" EXCLUDE
# )

## Mark other files for installation (e.g. launch and bag files, etc.)
# install(FILES
#   # myfile1
#   # myfile2
#   DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
# )

#############
## Testing ##
#############

## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test test/test_my_pkg.cpp)
# if(TARGET ${PROJECT_NAME}-test)
#   target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
# endif()

## Add folders to be run by python nosetests
# catkin_add_nosetests(test)

  Important syntax instructions :

1)catkin_package()

catkin_package() It's a catkin Provided CMake macro . This is specified for the build system catkin Necessary for specific information , The latter is used to generate pkg-config and CMake file .

In the use of add_library() or add_executable() Before declaring any goals , Must call This function . This function is 5 individual Optional Parameters :

  • INCLUDE_DIRS - The export of the package contains the path
  • LIBRARIES - Library exported from project
  • CATKIN_DEPENDS - The project relies on other catkin project
  • DEPENDS - The project relies on non catkin CMake project .
  • CFG_EXTRAS - Other configuration options

 3.5 、package.xml Introduce

The package list is a XML The file named package.xml Must include the root folder of any compatible package .package.xml Also a catkin Of package Necessary documents , It is the description file of the software package , In the earlier ROS edition (rosbuild Compiling system ) in , This document is called manifest.xml, Used to describe pacakge Basic information of . If you see something on the Internet ROS The project contains manifest.xml, Then it's mostly hydro Projects before version .pacakge.xml Contains package The name of 、 Version number 、 Content description 、 maintenance staff 、 Software license 、 Compile build tools 、 Compile dependencies 、 Operation dependency and other information .

package.xml file build_depend Must contain message_generation,run_depend Must contain message_runtime.

<pacakge>               #  Root tag file   
<name>                  #  Package name   
<version>               #  Version number   
<description>           #  Content description   
<maintainer>            #  Maintainer  
<license>               #  software license   
<buildtool_depend>      #  Compile build tools , Usually it is catkin    
<depend>                #  Specifies that the dependency is compiled 、 export 、 Run the required dependencies , The most commonly used 
<build_depend>          #  Compile dependencies   
<build_export_depend>   #  Export dependencies 
<exec_depend>           #  Run dependency 
<test_depend>           #  Test case dependencies   
<doc_depend>            #  Document dependencies 

版权声明
本文为[YOULANSHENGMENG]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232049111523.html