1. Часто используемые команды ROS2
Ubuntu 24.04 · colcon · topics · services · actions · parameters · launch · TF2 · bags · control · Gazebo
<p>Replace uppercase placeholders such as <code>PACKAGE</code>, <code>TOPIC</code>, and <code>NODE</code> with actual values.</p>
Environment
Source ROS 2
source /opt/ros/jazzy/setup.bash
Source a built workspace
source install/setup.bash
Inspect environment
printenv | grep -E '^(ROS|RMW|AMENT|COLCON)'
echo "$ROS_DISTRO"
echo "$ROS_DOMAIN_ID"
echo "$RMW_IMPLEMENTATION"
Set discovery domain and middleware
export ROS_DOMAIN_ID=42
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
Machines must normally use the same domain ID to discover each other.
Workspace and Build
Create a workspace
mkdir -p ~/ros2_ws/src
cd ~/ros2_ws
Resolve dependencies
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro jazzy -y
Build
colcon build --symlink-install
colcon build --symlink-install --packages-select PACKAGE
colcon build --packages-up-to PACKAGE
colcon build --cmake-clean-cache --packages-select PACKAGE
Test
colcon test
colcon test --packages-select PACKAGE --event-handlers console_direct+
colcon test-result --verbose
Run colcon build from the workspace root, not from its src directory.
Packages and Executables
Create packages
cd ~/ros2_ws/src
ros2 pkg create --build-type ament_python PACKAGE
ros2 pkg create --build-type ament_cmake PACKAGE
ros2 pkg create --build-type ament_python --dependencies rclpy std_msgs PACKAGE
Inspect packages
ros2 pkg list
ros2 pkg prefix PACKAGE
ros2 pkg prefix PACKAGE --share
ros2 pkg executables PACKAGE
ros2 pkg xml PACKAGE
Run an executable
ros2 run PACKAGE EXECUTABLE
ros2 run PACKAGE EXECUTABLE --ros-args --log-level debug
Nodes and Graph
ros2 node list
ros2 node list --include-hidden-nodes
ros2 node info /NODE
ros2 node info --include-hidden /NODE
Graphical inspection
rqt_graph
Stop a foreground process
Ctrl+C
Use fully qualified node names, including namespaces, when the short name is ambiguous.
Topics
Discover and inspect
ros2 topic list
ros2 topic list -t
ros2 topic info TOPIC
ros2 topic info TOPIC --verbose
ros2 topic type TOPIC
ros2 topic find MESSAGE_TYPE
Read data and rates
ros2 topic echo TOPIC
ros2 topic echo TOPIC --once
ros2 topic echo TOPIC --field FIELD
ros2 topic hz TOPIC
ros2 topic bw TOPIC
ros2 topic delay TOPIC
Publish
ros2 topic pub --once TOPIC std_msgs/msg/String "{data: hello}"
ros2 topic pub --rate 10 TOPIC geometry_msgs/msg/Twist \
"{linear: {x: 0.2}, angular: {z: 0.5}}"
QoS options
ros2 topic echo TOPIC --qos-reliability best_effort
ros2 topic pub TOPIC TYPE DATA --qos-durability transient_local
Services
ros2 service list
ros2 service list -t
ros2 service type SERVICE
ros2 service find SERVICE_TYPE
Call a service
ros2 service call SERVICE TYPE "{request_field: value}"
ros2 service call /spawn turtlesim/srv/Spawn \
"{x: 2.0, y: 3.0, theta: 0.0, name: turtle2}"
Actions
ros2 action list
ros2 action list -t
ros2 action info ACTION
ros2 action type ACTION
Send a goal
ros2 action send_goal ACTION TYPE "{goal_field: value}"
ros2 action send_goal ACTION TYPE "{goal_field: value}" --feedback
Messages and Interfaces
ros2 interface list
ros2 interface list --only-msgs
ros2 interface list --only-srvs
ros2 interface list --only-actions
ros2 interface show geometry_msgs/msg/Twist
ros2 interface package PACKAGE
ros2 interface packages
ros2 interface proto TYPE
Interface names use package/msg/Type, package/srv/Type, or package/action/Type.
Parameters
ros2 param list
ros2 param list /NODE
ros2 param get /NODE PARAMETER
ros2 param describe /NODE PARAMETER
ros2 param set /NODE PARAMETER VALUE
Save and load YAML
ros2 param dump /NODE
ros2 param dump /NODE --output-dir config
ros2 param load /NODE config/params.yaml
Pass parameters at startup
ros2 run PACKAGE EXECUTABLE --ros-args -p name:=value
ros2 run PACKAGE EXECUTABLE --ros-args --params-file config/params.yaml
Launch
ros2 launch PACKAGE FILE.launch.py
ros2 launch PACKAGE FILE.launch.py --show-args
ros2 launch PACKAGE FILE.launch.py argument:=value
ros2 launch PACKAGE FILE.launch.py --debug
Launch a file by path
ros2 launch path/to/FILE.launch.py
Names, Namespaces, and Remapping
ros2 run PACKAGE EXECUTABLE --ros-args -r __node:=NEW_NAME
ros2 run PACKAGE EXECUTABLE --ros-args -r __ns:=/NAMESPACE
ros2 run PACKAGE EXECUTABLE --ros-args -r OLD_TOPIC:=NEW_TOPIC
Combined example
ros2 run demo_nodes_cpp talker --ros-args \
-r __node:=course_talker \
-r __ns:=/group1 \
-r chatter:=status
rosbag2
Record
ros2 bag record TOPIC_A TOPIC_B
ros2 bag record --all
ros2 bag record --all --output course_run
ros2 bag record --regex '/camera/.*|/scan'
Inspect and replay
ros2 bag info BAG_DIRECTORY
ros2 bag play BAG_DIRECTORY
ros2 bag play BAG_DIRECTORY --rate 0.5
ros2 bag play BAG_DIRECTORY --loop
TF2, URDF, and Xacro
Inspect transforms
ros2 run tf2_ros tf2_echo SOURCE_FRAME TARGET_FRAME
ros2 run tf2_tools view_frames
ros2 run tf2_ros tf2_monitor
Publish a static transform
ros2 run tf2_ros static_transform_publisher \
--x 0 --y 0 --z 1 --roll 0 --pitch 0 --yaw 0 \
--frame-id parent --child-frame-id child
Validate robot descriptions
xacro robot_model.xacro > /tmp/robot_model.urdf
check_urdf /tmp/robot_model.urdf
xacro robot_model.xacro | check_urdf
Visualization
rviz2
ros2_control
ros2 control list_controllers
ros2 control list_controllers --verbose
ros2 control list_hardware_components
ros2 control list_hardware_interfaces
ros2 control list_controller_types
Controller lifecycle
ros2 control load_controller CONTROLLER
ros2 control configure_controller CONTROLLER
ros2 control set_controller_state CONTROLLER active
ros2 control switch_controllers --activate CONTROLLER_A --deactivate CONTROLLER_B
ros2 control unload_controller CONTROLLER
Spawner
ros2 run controller_manager spawner joint_state_broadcaster
ros2 run controller_manager spawner CONTROLLER
Gazebo Harmonic and ROS Bridge
Gazebo CLI
gz sim WORLD.sdf
gz sim -r WORLD.sdf
gz topic -l
gz topic -i -t GZ_TOPIC
gz topic -e -t GZ_TOPIC
Launch Gazebo through ROS 2
ros2 launch ros_gz_sim gz_sim.launch.py gz_args:="-r WORLD.sdf"
Spawn a model from robot_description
ros2 run ros_gz_sim create \
-name ROBOT_NAME -topic robot_description -x 0 -y 0 -z 0.2
Bridge one topic
ros2 run ros_gz_bridge parameter_bridge \
/clock@rosgraph_msgs/msg/Clock[gz.msgs.Clock
Bridge from a YAML configuration
ros2 run ros_gz_bridge parameter_bridge \
--ros-args -p config_file:=/absolute/path/bridge.yaml
Diagnostics and Troubleshooting
CLI help
ros2 --help
ros2 COMMAND --help
ros2 doctor
ros2 doctor --report
Discovery daemon
ros2 daemon status
ros2 daemon stop
ros2 daemon start
Common checks
ros2 node list
ros2 topic list -t
ros2 service list -t
ros2 action list -t
ros2 topic info TOPIC --verbose
Logging
ros2 run PACKAGE EXECUTABLE --ros-args --log-level debug
ros2 run PACKAGE EXECUTABLE --ros-args --log-level NODE:=debug
If a newly built package cannot be found, source both /opt/ros/jazzy/setup.bash and the workspace's install/setup.bash in the current terminal.
YouTube канал чтобы посмотреть видео по робототехнике & семинары
Аккаунт в Телеграмм чтобы следить за анонсами мероприятий & Исследованиями