-
Notifications
You must be signed in to change notification settings - Fork 0
3_ROS_Tips
A collection of useful commands and tips for working with ROS 2.
- Topics: Use for continuous data streams, like sensor readings or robot state.
- Services: Use for quick request/response communication, like triggering a calculation or changing a setting.
- Actions: Use for long-running tasks that have a clear beginning and end, and provide feedback along the way, like navigating to a goal.
ROS 2 uses DDS (Data Distribution Service) as its middleware. This provides:
- Reduced coupling between nodes
- Increased scalability
- Improved performance, reliability, security, and flexibility
To build a ROS 2 workspace, run the following command in the workspace folder:
colcon buildFor faster development, use --symlink-install to create symbolic links to your source files. This allows you to edit files without needing to rebuild.
colcon build --symlink-installQuickly change your directory to a specific package:
colcon_cd <some_ros_package>When you build your workspace, these folders are created automatically:
-
build: Temporary files used during the build process. -
install: The finished, ready-to-use parts of your software. -
log: Logs of the build process, useful for debugging.
To create a new Python package:
ros2 pkg create --build-type ament_python --license Apache-2.0 --node-name my_node my_package- It's best practice to create packages within a
srcfolder in your workspace.
Before building, check for and install any missing dependencies:
rosdep install -i --from-path src --rosdistro jazzy -yTo see all active nodes, topics, services, or actions:
ros2 node list
ros2 topic list
ros2 service list
ros2 action list-
Node Info: Get a list of a node's subscribers, publishers, services, and actions.
ros2 node info <node_name>
-
Topic Info: See the message type and number of publishers/subscribers for a topic.
ros2 topic info /turtle1/cmd_vel
-
Service Info: See the type of a service.
ros2 service info <service_name>
-
Action Info: Get details about an action.
ros2 action info /turtle1/rotate_absolute
-
RQT Graph: Visualize the connections between nodes and topics.
rqt_graph
-
RQT Console: A GUI for viewing and filtering log messages.
ros2 run rqt_console rqt_console
ros2 topic list -tros2 topic find geometry_msgs/msg/Twistros2 interface show geometry_msgs/msg/TwistPublish a message to a topic from the command line:
ros2 topic pub <topic_name> <msg_type> '<args>'Example:
ros2 topic pub /turtle1/cmd_vel geometry_msgs/msg/Twist "{linear: {x: 2.0}, angular: {z: 1.8}}"To publish a single message and then exit:
ros2 topic pub --once -w 2 /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}}"-
--once: Publish one message and exit. -
-w 2: Wait for two matching subscriptions before publishing.
-
Frequency: Check the rate at which messages are published.
ros2 topic hz /turtle1/pose
-
Bandwidth: Check the bandwidth used by a topic.
ros2 topic bw /turtle1/pose
To see the parameters for all active nodes:
ros2 param listros2 param get <node_name> <parameter_name>Example:
ros2 param get /turtlesim background_gros2 param set <node_name> <parameter_name> <value>Example:
ros2 param set /turtlesim background_r 150-
Save: Dump all of a node's parameters to a YAML file.
ros2 param dump <node_name> > <file_name>.yaml
-
Load: Load parameters from a file to a running node.
ros2 param load <node_name> <file_name>.yaml
-
Load on Startup: Start a node with parameters from a file.
ros2 run <package_name> <executable_name> --ros-args --params-file <file_name>.yaml
ros2 action list -tros2 interface show turtlesim/action/RotateAbsoluteWhich will return:
# The desired heading in radians
float32 theta
---
# The angular displacement in radians to the starting position
float32 delta
---
# The remaining rotation in radians
float32 remaining
ros2 action send_goal <action_name> <action_type> "<goal>"Example:
ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.57}"To get feedback while the goal is running:
ros2 action send_goal --feedback <action_name> <action_type> "<goal>"Record all data on a specific topic:
ros2 bag record <topic_name>To record services:
ros2 bag record --all-servicesros2 bag info <bag_file_name>ros2 bag play <bag_file_name>To replay service requests:
ros2 bag play --publish-service-requests <bag_file_name>-
XACRO to URDF:
xacro your_robot.xacro > your_robot.urdf -
URDF to SDF:
gz sdf -p your_model.urdf > your_model.sdf
-
Generate a PDF:
ros2 run tf2_tools view_frames
-
Use RQT:
ros2 run rqt_tf_tree rqt_tf_tree
Cassini Robotics