[Documentation] [TitleIndex] [WordIndex

Note: This tutorial assumes that you have completed the previous tutorials: building a ROS package.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Общие сведения о узлах в ROS

Description: Данное руководство знакомит с понятиями графа ROS и описывает использование инструментов командной строки: roscore, rosnode, и rosrun.

Tutorial Level: BEGINNER

Next Tutorial: Understanding ROS topics

Предварительные действия

Установите симулятор, будет использоваться в руководстве:

$ sudo apt-get install ros-<distro>-ros-tutorials

Replace '<distro>' with the name of your ROS distribution (e.g. hydro, groovy, electric, fuerte etc.)

Краткий обзор концепции


В системе ROS узел не сильно отличается от исполняемого файла. Узлы используют ROS для связи с другими узлами. Узлы могут публиковать сообщения в теме, а также подписаться на тему, для приема сообщений. Узлы могут быть сервисами.

Client Libraries

ROS client libraries allow nodes written in different programming languages to communicate:


roscore это первое, что вы должны запустить при использовании ROS.


$ roscore

Вы увидите что-то похожее на:

If roscore does not initialize, you probably have a network configuration issue. See Network Setup - Single Machine Configuration

If roscore does not initialize and sends a message about lack of permissions, probably the ~/.ros folder is owned by root, change recursively the ownership of that folder with:

$ sudo chown -R <your_username> ~/.ros

Использование rosnode

Open up a new terminal, and let's use rosnode to see what running roscore did...

Note: When opening a new terminal your environment is reset and your ~/.bashrc file is sourced. If you have trouble running commands like rosnode then you might need to add some environment setup files to your ~/.bashrc or manually re-source them.

rosnode displays information about the ROS nodes that are currently running. The rosnode list command lists these active nodes:

$ rosnode list

This showed us that there is only one node running: rosout. This is always running as it collects and logs nodes' debugging output.

The rosnode info command returns information about a specific node.

$ rosnode info /rosout

This gave us some more information about rosout, such as the fact that it publishes /rosout_agg.

Now, let's see some more nodes. For this, we're going to use rosrun to bring up another node.

Использование rosrun

rosrun allows you to use the package name to directly run a node within a package (without having to know the package path).


$ rosrun [package_name] [node_name]

So now we can run the turtlesim_node in the turtlesim package.

Then, in a new terminal:

$ rosrun turtlesim turtlesim_node

You will see the turtlesim window:

NOTE: The turtle may look different in your turtlesim window. Don't worry about it - there are many types of turtle and yours is a surprise!

In a new terminal:

$ rosnode list

You will see something similar to:

One powerful feature of ROS is that you can reassign Names from the command-line.

Close the turtlesim window to stop the node (or go back to the rosrun turtlesim terminal and use ctrl-C). Now let's re-run it, but this time use a Remapping Argument to change the node's name:

$ rosrun turtlesim turtlesim_node __name:=my_turtle

Now, if we go back and use rosnode list:

$ rosnode list

Note: If you still see /turtlesim in the list, it might mean that you stopped the node in the terminal using ctrl-C instead of closing the window, or that you don't have the $ROS_HOSTNAME environment variable defined as described in Network Setup - Single Machine Configuration. You can try cleaning the rosnode list with: $ rosnode cleanup

We see our new /my_turtle node. Let's use another rosnode command, ping, to test that it's up:

$ rosnode ping my_turtle


What was covered:

Now that you understand how ROS nodes work, let's look at how ROS topics work. Also, feel free to press Ctrl-C to stop turtlesim_node.

2020-01-18 13:09