当前位置:网站首页>[1] Basic knowledge of ros2 - summary version of operation commands

[1] Basic knowledge of ros2 - summary version of operation commands

2022-07-07 13:31:00 Plum fruit tea


This article is mainly about the previously used ROS2 Instructions are summarized , Convenient for subsequent reference . It mainly includes : Function pack 、 node 、 topic of conversation 、 service 、 action 、 Parameters 、launch、ros2 bag Wait for the operation order .

1. Function pack

# 1. Create a workspace 
mkdir -p test_ws/src 
cd test_ws/src
# 2. Create Feature Pack 
ros2 pkg create <package-name> --build-type {
    cmake,ament_cmake,ament_python} --dependencies < Rely on names >
# 3. Compile function packs 
colcon build --packages-select <package-name>

# 4. List all feature packs 
ros2 pkg list
# 5. List the executable files under the function package 
ros2 pkg executables turtlesim
# 6. List the path of the Feature Pack 
ros2 pkg prefix turtlesim
# 7. List the description file of the function package 
ros2 pkg xml turtlesim

Detailed link :[3] ROS2 How to use the function pack

2. node

# ros2 run  Function pack name   Executable name  
ros2 run <package_name> <executable_name>

#  View all node names 
ros2 node list
#  View node information 
ros2 node info /turtlesim
#  Node remapping 
ros2 run turtlesim turtlesim_node --ros-args --remap __node:=my_turtle

Detailed link :[4] ROS2 How to use the node of preliminary exploration

3. topic of conversation

# 1. Check the list of topics 
ros2 topic list  
# 2. View a list of topics with type attribute suffixes 
ros2 topic list -t
# 3. Check the topic content  ros2 topic echo <topic_name>
ros2 topic echo /turtle1/cmd_vel
# 4. Check the topic info
ros2 topic info /turtle1/cmd_vel
# 5. View the data structure of the topic message , coordination  ros2 topic list -t Use 
ros2 interface show /geometry_msgs/msg/Twist
# 6. Check the frequency of topic Publishing 
ros2 topic hz /turtle1/cmd_vel
# 7. Post topic news ros2 topic pub <topic_name> <msg_type> '<args>'
ros2 topic pub --once /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
ros2 topic pub --rate 1 /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0, y: 0.0, z: 0.0}, angular: {x: 0.0, y: 0.0, z: 1.8}}"
#  Use the plug-in to view the relationship between topics 
rqt_graph

Detailed link :[5] ROS2 A preliminary study of communication mechanism ( topic of conversation )

4. service

# 1. View the list of services 
ros2 service list
# 2. Check the service interface type 
ros2 service type /add_two_ints
# 3. Find a service that uses an interface 
ros2 service find example_interfaces/srv/AddTwoInts
# 4. Call service interface 
ros2 service call /add_two_ints example_interfaces/srv/AddTwoInts "{a: 5,b: 10}"

Detailed link :[7] ROS2 A preliminary study of communication mechanism ( service )

5. action

# 1.  see Action list 
ros2 action list
# 2.  see Action list +Action type 
ros2 action list -t
# 3.  Check the interface information 
ros2 interface show [Action type ]
# 4.  see Action Information 
ros2 action info [Action name ]
# Action Request the server to send data 
ros2 action send_goals [Action name ] [Action type ] [valus] --feedback

Detailed link :[10] ROS2 A preliminary study of communication mechanism ( action )

6. Parameters

# 1.  View the parameter list of all nodes 
ros2 param list
# 2.  View the details of a parameter 
ros2 param describe <node_name> <param_name>
# 3.  Get the direct of the parameter 
ros2 param get <node_name> <param_name>
# 4.  Set the value of the parameter ( Temporary modification )
ros2 param set <node_name> <parameter_name> <value>
# 5.  First set Set the parameter value , Again dump Save parameter file (yaml Format )
ros2 param dump <node_name>
# 6.  Load the call parameter file 
ros2 param load <node_name> <file_name>
# 7.  Load the call parameter file when starting the node 
ros2 run <package_name> <executable_name> --ros-args --params-file <file_name> 

Detailed link :[12] ROS2 A preliminary study of communication mechanism ( Parameters )

7. launch Templates

#  stay ROS2 in , commonly launch The file suffix format is name_launch.py perhaps name.launch.py
touch my_script_launch.py
gedit my_script_launch.py
from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    return LaunchDescription([
        Node(
            package='turtlesim',
            namespace='turtlesim1',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            namespace='turtlesim2',
            executable='turtlesim_node',
            name='sim'
        ),
        Node(
            package='turtlesim',
            executable='mimic',
            name='mimic',
            remappings=[
                ('/input/pose', '/turtlesim1/turtle1/pose'),
                ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
            ]
        )
    ])

Detailed link :[14] ROS2 Probe into node management tools launch file

8. ros2 bag

# 1. Record topic messages 
ros2 bag record <topic_name>
# 2. Record multiple topic messages 
ros2 bag record -o <file_dir_name> <topic_name_1> <topic_name_2>...<topic_name_n>
# 3. Record all topic messages 
ros2 bag record -a
# 4. View the topic data record file information ( For example, the time of topic recording , size , type , Number )
ros2 bag info <file_dir_name>
# 5. Play the recorded topic data 
ros2 bag play <file_dir_name>
# 6. Loop through the recorded topic data 
ros2 bag play <file_dir_name> -l
# 7. Speed up (2 Double speed )
ros2 bag play <file_dir_name> -r 2
# 8. Play the data of the specified topic 
ros2 bag play <file_dir_name> --topic <topic_name>

Detailed link :[15] ROS2 The data of recording topics ros2 bag

原网站

版权声明
本文为[Plum fruit tea]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071128218656.html