当前位置:网站首页>Introduction to ros2 installation and basic knowledge
Introduction to ros2 installation and basic knowledge
2022-07-06 06:53:00 【Little white classic】
ros Introduce
ROS(Robot Operating System) Is an open source robot operating system ,ROS The system is composed of a large number of nodes , Any of these nodes can be published / Subscribe to communicate with other nodes . Take a chestnut , The radar unit in a position sensor on the robot can be used as ROS A node of , It can release the information obtained by radar in the form of information flow , The published information can be used by other nodes such as navigation units 、 Path planning unit, etc , The navigation and path planning unit itself is also a node , Similarly, the information obtained by each party is released in the form of information flow , For other nodes
ros2 install
This time it's in Ubuntu 22.04 Installation on system ros2 Of humble edition
Set the coding format of the terminal
sudo apt update && sudo apt install locales -y sudo locale-gen en_US en_US.UTF-8 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-8
Enable Universe The repository
sudo apt install software-properties-common sudo add-apt-repository universe
Add source
First update the software and download and install curl、gnupg and lsb-release
sudo apt update && sudo apt install curl gnupg lsb-release -y
Get the key of the source and save it to the specified directory , Only locally GPG Key to download and install ros2 Software for
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
An error is reported here
Failed to connect to raw.githubusercontent.com port 443 after 17 ms: Connection refused
, The solution is as follows :visit This website see raw.githubusercontent.com The domain name corresponds to IP Address , see DNS Resource Records Information in
Execute commands at the terminal
sudo vi /etc/hosts
, open hosts fileChoose one , take IP And domain name added to hosts In file , Such as :
185.199.108.133 raw.githubusercontent.com
If you execute the order again, you won't report a mistake
Add software source and update index
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(source /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
install ros2 package
Update the system software first
sudo apt update && sudo apt upgrade -y
install ros2, The version is humble The desktop version , This installation takes a long time , Please be patient , If there is an error, it is basically a network problem , Please check by yourself
sudo apt install ros-humble-desktop -y
Set up the environment
The purpose is to let the operating system know ros2 Where is it installed , Use
source
Order or.
command , Load environment informationsource /opt/ros/humble/setup.bash
or. /opt/ros/humble/setup.bash
This command can only take effect on the current terminal , Reopening the terminal requires another execution , You can add this command to
.bashrc
There is no need to execute every time in the file , The system can recognizeros2
commandecho "source /opt/ros/humble/setup.bash" >> ~/.bashrc
verification ros2 installation is complete
ros2 Provides C++ and python Of demo, Execute the following command at the terminal , As publisher
ros2 run demo_nodes_cpp talker
Open another terminal , As a listener, execute the following commands
ros2 run demo_nodes_py listener
listener
Can seetalker
Constant news , explain ros2 Installation successful
ros2 Core concept of
working space (Workspace): Project location
Function pack (Package): The storage place of each function module developed
node (Node): Working cells of robots , Used to create publishers 、 subscriber 、 Service etc.
topic of conversation (Topic): A bridge for transferring data between nodes
service (Service): Between nodes, you ask me and answer , It consists of a pair of messages ( Request and reply )
communication interface (Interface): Standard structure of data transmission
Parameters (Parameter): Global dictionary of robot system
action (Action): Process management of complete behavior
Distributed communication (Distributed Communication): Task allocation of multiple computing platforms
DDS(Data Distribution Service): Neural network of robot
turtlesim and rqt Installation and use
turtlesim and rqt Introduce
Turtlesim It's for learning ros2 Lightweight simulator for , It shows ros2 Work done at the basic level , In order to understand what can be done with real robots or robot simulations in the future
rqt yes ros2 Graphical interface of (GUI) Tools , What can be done on the command line rqt Can also do ,rpt Provides a more concise 、 In a more friendly way ros2 The elements of
turtlesim and rqt install
Perform the following installation turtlesim and rqt
sudo apt update sudo apt install ros-humble-turtlesim ~nros-humble-rqt* -y
start-up turrlesim
Executing the following command will bring up the simulator window , Randomly display a small turtle
ros2 run turtlesim turtlesim_node
Use turrlesim
Do not turn off the last terminal , Open a new terminal , Carry out orders
ros2 run turtlesim turtle_teleop_key
then , Click the direction key on the keyboard on this terminal to make the little turtle move
Do not close the above two terminals , Open a new terminal again , Now open 3 Terminals , Execute the following commands on the new terminal to view the currently used nodes 、 topic of conversation 、 Services and actions
ros2 node list # View the list of nodes ros2 topic list # Check the list of topics ros2 service list # View the list of services ros2 action list # View the action list
start-up rqt
The input terminal
rqt
, You can open rqt windowadopt rqt Post topic news
Select... In the menu bar Plugins → Topics → Message Publisher, call
/turtle1/cmd_vel
In servicegeometry_msgs/msg/Twist
type , Modify linear velocity and angular velocity , Then post the topic , The little turtle will move its position according to the set value , As shown in the figure belowIssue topic messages by command
Let the little turtle move using command line operation , The order is as follows ,rate Parameters can be understood as 1 Once per second , The default is 1 second , You can add parameters
--once
Only once , Otherwise, the command will be executed all the time , Keep drawing circlesros2 topic pub -r 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear:{x: 3.0,y: 0.0,z: 0.0},angular:{x: 0.0,y: 0.0,z: 2.2}}"
adopt rqt call
/spawn
Service creation Little TurtleSelect... In the menu bar Plugins → Services → Service Caller, call
/spawn
The service can create a new little turtle , Set the position where the little turtle appears 、 Angle and name , Click on 【Call】 stay turtlesim The window will show a new little turtle , As shown in the figure belowCall... By command
/spawn
Service creation Little TurtleYou can also use commands to operate , The order is as follows
ros2 service call /spawn turtlesim/srv/Spawn "{x: 3,y: 2,theta: 0.5,name: "test"}"
Turtle name can be empty , The default name of a little turtle is
turtle1
, If it is empty , The new name of the little turtle isturtle2
……
Clone sample project
Create workspace
mkdir -p ~/dev_ws/src && cd ~/dev_ws/src # Create and enter the workspace
Clone the little turtle project into the work area
sudo apt install git -y sudo git clone https://github.com/ros/ros_tutorials.git -b humble
Resolve dependencies
cd .. # Don't stop at src Under the table of contents , Go back to dev_ws Catalog sudo apt install python3-rosdep2 -y # install python3-rosdep2 rosdep update # initialization rosdep
Encounter newspaper
ERROR: unable to process source [https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml]
, It's still caused by the network , The solution is as follows :Connect phone hotspot
Execute commands at the terminal
sudo vim /etc/ros/rosdep/sources.list.d/20-default.list
In the original url with
https://ghproxy.com/
, As shown belowyaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx yaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml yaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml yaml https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml gbpdistro https://ghproxy.com/https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte
Then execute the following command to complete the initialization ! If it's still wrong , Please try other online methods by yourself
sudo apt-get update rosdep update
Finally, execute the command to solve the dependency
rosdep install -i --from-path src --rosdistro humble -y
appear
All required rosdeps installed successfully
It means completion
colcon structure
colcon Is a universal build tool ,ros Although the system is not recommended, the official documents still use this tool , Let's also demonstrate this , For more information about building tools, please check This article
install colcon
sudo apt install python3-colcon-common-extensions
Execute the following command to build all packages in the workspace
colcon build
Because automatic loading has been configured above ros2 Environmental information , Now we need to run this project , It is necessary to load the environment required by this project on this basis , After building , Open a new terminal , Execute the following command
source ~/dev_ws/install/local_setup.sh
At this time, execute the following command , What started is the local little turtle
ros2 run turtlesim turtlesim_node
It can be modified by setWindowTitle("TurtleSim")
Verify the window name in and execute the following command , Amendment No 52 Window name of the row
vim ~/dev_ws/src/ros_tutorials/turtlesim/src/turtle_frame.cpp
Then rebuild the package
colcon build
Execute the following command again to see that the window name has been modified
ros2 run turtlesim turtlesim_node
ros2 Common commands
About operation commands, you should use more tab Key automatic completion function and -h
View help documents , The following commands are not introduced about optional parameters , Check more help documents !
If there is no automatic completion function , It's the lack of python3-argcomplete
The installation package causes , Restart the terminal after executing the following commands
sudo apt-get install python3-argcomplete
meaning | command |
---|---|
Create Feature Pack | ros2 pkg create --build-type ament_python <package_name> |
View the function pack list | ros2 pkg list |
View the list of executable files in the package | ros2 pkg executables <package_name> |
Run the executable file in the package | ros2 run <package_name> <executable_name> |
View the list of currently active nodes | ros2 node list |
View node details | ros2 node info <node_name> |
List the currently available topics | ros2 topic list |
Check the message type of the topic | ros2 topic type <topic_name> |
List the currently available topics and types | ros2 topic list -t |
Check the topic message type 、 Number of publishers and subscribers | ros2 topic info <topic_name> |
Find relevant topics according to the message type | ros2 topic find <message_type> |
according to header The timestamp in calculates the message delay | ros2 topic delay <topic_name> |
Display the average publishing frequency of current topics in real time | ros2 topic hz <topic_name> |
Show the bandwidth of the current topic in real time | ros2 topic bw <topic_name> |
Display topic messages in real time on the console | ros2 topic echo <topic_name> |
Issue topic messages by command | ros2 topic pub <topic_name> <message_type> <message_content> |
See all the services | ros2 service list |
View service types | ros2 service type <service_name> |
Output all services and types | ros2 service list -t |
List all services of the specified type | ros2 service find <service_type> |
Call the service | ros2 service call <service_name> <service_type> |
View all actions | ros2 action list |
View action information | ros2 action info <action_name> |
View all actions and types | ros2 action list -t |
Launch action target | ros2 action send_goal <action_name> <action_type> <goal> |
View information about available plug-ins | ros2 bag list <plugin_type> |
Record the data of the specified topic | ros2 bag record <topic_name> |
Record data of multiple topics and customize file names | ros2 bag record -o <bag_file> <topic_name> <topic_name>…… |
View record information | ros2 bag info <bag_file> |
Playback recorded information | ros2 bag play <bag_file> |
View all parameters | ros2 param list |
View the value of the specified parameter | ros2 param get <node_name> <parameter_name> |
Set the value of the specified parameter | ros2 param set <node_name> <parameter_name> <value> |
See parameter details | ros2 param describe <node_name> <parameter_name> |
Transfer node parameters to yaml In file | ros2 param dump <node_name> --output-dir <dir_name> |
Load the parameter file of the node | ros2 param load <node_name> < parameter_file> |
Delete parameters | ros2 param delete <node_name> <parameter_name> |
Classification shows all interfaces | ros2 interface list |
View the list of packages that provide interfaces | ros2 interface packages |
Check the interface in the package | ros2 interface package <package_name> |
View the details of the specified interface | ros2 interface show <interface_name> |
View the specified interface prototype | ros2 interface proto <interface_name> |
adopt launch Files run multiple nodes at once | ros2 launch <package_name> <launch_arguments> |
For more functions and operations, please check Official documents Well !
边栏推荐
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
- pymongo获取一列数据
- Every API has its foundation when a building rises from the ground
- What is the difference between int (1) and int (10)? Senior developers can't tell!
- After working for 10 years, I changed to a programmer. Now I'm 35 + years old and I'm not anxious
- 19.段页结合的实际内存管理
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- 从autojs到冰狐智能辅助的心里历程
- UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
- librosa音频处理教程
猜你喜欢
万丈高楼平地起,每个API皆根基
Fedora/REHL 安装 semanage
[brush questions] how can we correctly meet the interview?
ROS learning_ Basics
After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.
[English] Grammar remodeling: the core framework of English Learning -- English rabbit learning notes (1)
Map of mL: Based on the adult census income two classification prediction data set (whether the predicted annual income exceeds 50K), use the map value to realize the interpretable case of xgboost mod
【每日一题】729. 我的日程安排表 I
机器学习植物叶片识别
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
随机推荐
Phishing & filename inversion & Office remote template
[Yu Yue education] Dunhuang Literature and art reference materials of Zhejiang Normal University
中青看点阅读新闻
[English] Grammar remodeling: the core framework of English Learning -- English rabbit learning notes (1)
一文读懂简单查询代价估算
C语言_双创建、前插,尾插,遍历,删除
简单描述 MySQL 中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
SQL Server Manager studio (SSMS) installation tutorial
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Monotonic stack
Apache dolphin scheduler source code analysis (super detailed)
UNIPRO Gantt chart "first experience": multi scene exploration behind attention to details
Chapter 7 - thread pool of shared model
How to do a good job in financial literature translation?
机器学习植物叶片识别
[advanced software testing step 1] basic knowledge of automated testing
The internationalization of domestic games is inseparable from professional translation companies
A method to measure the similarity of time series: from Euclidean distance to DTW and its variants
What are the commonly used English words and sentences about COVID-19?
(practice C language every day) reverse linked list II