[vc_row][vc_column][vc_column_text]
This tutorial covers the toolchain to build a package.
[/vc_column_text][vc_tour interval=”0″][vc_tab title=”Prerequisites” tab_id=”1394605844-1-1″][vc_column_text][/vc_column_text][vc_column_text]For this tutorial we will use a lightweight simulator, please install it using
$ sudo apt-get install ros-<distro>-ros-tutorials
Replace ‘<distro>’ with the name of your ROS distribution (e.g. hydro, groovy, electric, fuerte etc.)[/vc_column_text][/vc_tab][vc_tab title=”Quick Overview of Graph Concepts” tab_id=”1394605844-2-63″][vc_column_text]
- Nodes: A node is an executable that uses ROS to communicate with other nodes.
- Messages: ROS data type used when subscribing or publishing to a topic.
- Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
- Master: Name service for ROS (i.e. helps nodes find each other)
- rosout: ROS equivalent of stdout/stderr
- roscore: Master + rosout + parameter server (parameter server will be introduced later)
[/vc_column_text][/vc_tab][vc_tab title=”Nodes” tab_id=”1394606195229-2-4″][vc_column_text]A node really isn’t much more than an executable file within a ROS package. ROS nodes use a ROS client library to communicate with other nodes. Nodes can publish or subscribe to a Topic. Nodes can also provide or use a Service.[/vc_column_text][/vc_tab][vc_tab title=”Client Libraries” tab_id=”1394606196452-3-2″][vc_column_text]ROS client libraries allow nodes written in different programming languages to communicate:
- rospy = python client library
- roscpp = c++ client library
[/vc_column_text][/vc_tab][vc_tab title=”Roscore” tab_id=”1394607183584-4-0″][vc_column_text]roscore is the first thing you should run when using ROS.
Please run:
$ roscore You will see something similar to:
… logging to ~/.ros/log/9cf88ce4-b14d-11df-8a75-00251148e8cf/roslaunch-machine_name-13039.log Checking log directory for disk usage. This may take awhile. Press Ctrl-C to interrupt Done checking log file disk usage. Usage is <1GB. started roslaunch server http://machine_name:33919/ ros_comm version 1.4.7 SUMMARY ======== PARAMETERS * /rosversion * /rosdistro NODES auto-starting new master process[master]: started with pid [13054] ROS_MASTER_URI=http://machine_name:11311/ setting /run_id to 9cf88ce4-b14d-11df-8a75-00251148e8cf process[rosout-1]: started with pid [13067] started core service [/rosout]
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
[/vc_column_text][/vc_tab][vc_tab title=”Using rosnode” tab_id=”1394607184691-5-4″][vc_column_text][/vc_column_text][vc_column_text]rosrun allows you to use the package name to directly run a node within a package (without having to know the package path).
Usage:
$ 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:
-
/rosout /turtlesim
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
- You will see something similar to:
-
/rosout /my_turtle
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
-
rosnode: node is [/my_turtle] pinging /my_turtle with a timeout of 3.0s xmlrpc reply from http://aqy:42235/ time=1.152992ms xmlrpc reply from http://aqy:42235/ time=1.120090ms xmlrpc reply from http://aqy:42235/ time=1.700878ms xmlrpc reply from http://aqy:42235/ time=1.127958ms
[/vc_column_text][/vc_tab][vc_tab title=”Using rosrun” tab_id=”1394607254525-6-10″][vc_column_text]rosrun allows you to use the package name to directly run a node within a package (without having to know the package path).
Usage:
$ 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:
-
/rosout /turtlesim
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
- You will see something similar to:
-
/rosout /my_turtle
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
-
rosnode: node is [/my_turtle] pinging /my_turtle with a timeout of 3.0s xmlrpc reply from http://aqy:42235/ time=1.152992ms xmlrpc reply from http://aqy:42235/ time=1.120090ms xmlrpc reply from http://aqy:42235/ time=1.700878ms xmlrpc reply from http://aqy:42235/ time=1.127958ms
[/vc_column_text][/vc_tab][vc_tab title=”Review” tab_id=”1394607255980-7-1″][vc_column_text]
What was covered:
- roscore = ros+core : master (provides name service for ROS) + rosout (stdout/stderr) + parameter server (parameter server will be introduced later)
- rosnode = ros+node : ROS tool to get information about a node.
- rosrun = ros+run : runs a node from a given package.
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.
This post is from Wiki: ROS/Tutorials/UnderstandingNodes
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.