Playing with ROS nodes

As we explained in the Nodes and nodelets section, nodes are executable programs and, once built, these executables can be found in the devel space. To practise and learn about nodes, we are going to use a typical package called turtlesim.

If you have installed the desktop installation, you will have the turtlesim package preinstalled; if not, install it with the following command:

    $ sudo apt-get install ros-kinetic-ros-tutorials  

Before starting this tutorial, it is important that you open a terminal and start roscore using the following command:

    $ roscore  

To get information on nodes, we have the rosnode tool. To see what parameters are provided, type the following command:

    $ rosnode  

You will obtain a list of accepted parameters, as shown in the following screenshot:

If you want a more detailed explanation of the use of these parameters, use the following command:

    $ rosnode <param> -h  

Now that roscore is running, we are going to get information about the nodes that are running, using the following command:

    $ rosnode list  

You will see that the only node running is /rosout. This is normal, as this node is usually launched with roscore.

We can get all the information about this node using the parameters provided by the rosnode tool. Try to use the following commands for more information:

    $ rosnode info
    $ rosnode ping
    $ rosnode machine
    $ rosnode kill
    $ rosnode cleanup  

Now we are going to start a new node with rosrun using the following command:

    $ rosrun turtlesim turtlesim_node  

We will then see a new window appear with a little turtle in the middle, as shown in the following screenshot:

If we see the node list now, we will see a new node with the name /turtlesim.
You can see information about the node using rosnode info nameNode.

You can see a lot of information that can be used to debug your programs, using the following command:

    $ rosnode info /turtlesim  

The preceding command line prints the following information:

In the information, we can see the Publications (topics), Subscriptions (topics), and Services (srv) that the node has and the unique name of each.

Now, let's see how you interact with the node using topics and services.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.70.21