当前位置:网站首页>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

  1. 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
    
  2. Enable Universe The repository

    sudo apt install software-properties-common
    sudo add-apt-repository universe
    
  3. 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 :

    1. visit This website see raw.githubusercontent.com The domain name corresponds to IP Address , see DNS Resource Records Information in

    2. Execute commands at the terminal sudo vi /etc/hosts, open hosts file

    3. Choose 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

  4. 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
    
  5. 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
    
  6. 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 information

    source /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 recognize ros2 command

    echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
    
  7. 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 see talker 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 window

  • adopt rqt Post topic news

    Select... In the menu bar Plugins → Topics → Message Publisher, call /turtle1/cmd_vel In service geometry_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 below

  • Issue 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 circles

    ros2 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 Turtle

    Select... 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 below

  • Call... By command /spawn Service creation Little Turtle

    You 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 is turtle2……

Clone sample project

  1. Create workspace

    mkdir -p ~/dev_ws/src && cd ~/dev_ws/src #  Create and enter the workspace 
    
  2. 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
    
  3. 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 :

    1. Connect phone hotspot

    2. Execute commands at the terminal

      sudo vim /etc/ros/rosdep/sources.list.d/20-default.list
      
    3. In the original url with https://ghproxy.com/, As shown below

      yaml 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
      
    4. 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 !

原网站

版权声明
本文为[Little white classic]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060635471638.html