Understanding ROS Nodes
Understanding ROS Nodes
1) First, please install this simulator:
sudo apt-get install ros-hydro-ros-tutorials
Terminology:
- 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)
2) To use ROS, start by running the core:
roscore
It will display a summary. If it fails to initialize, try changing the ownership of the root:
sudo chown -R <your_username> ~/.ros
Then attempt to bring up roscore again.
3) In a new terminal (we will call this terminal 2) see what nodes are running:
rosnode list
Likely, you will only see one called /rosout.
4) In terminal 2 try seeing more information about each node:
rosnode info /rosout
This gives you information about the currently running nodes.
5) In a new terminal (terminal 3) we will initialize a new node.
To run a node, use rosrun [package_name] [node_name]:
rosrun turtlesim turtlesim_node
A new window with a turtle will show up.
6) In terminal 2 (where we used rosnode list) run rosnode again:
rosnode list
The nodes /rosout and /turtlesim now appear.
7) Close the turtle sim. In terminal 3 (where we had started the turtle sim) we will restart it again, but give the node a name:
rosrun turtlesim turtlesim_node __name:=my_turtle
8) In terminal 2, look at the nodes again:
rosnode list
You will see /rosout and /my_turtle. If not, try cleaning up the rosnode list:
rosnode cleanup
Then try running the rosnode list command again.
9) In terminal 2, let us ping our simulation:
rosnode ping my_turtle
This tests the simulation to see if it is in fact running. You will see time of replies printed to the command.