Master and Nodes

From Lofaro Lab Wiki
Jump to: navigation, search

One of the goal of the ros is to give us the ability to design our robot software as a collection of small, mostly independent programs called nodes. Nodes must communicate with each other to share data and ros master do the job. When you want to start some node you need to facilitate the communication using ros master. To start the ros master give the command

 roscore 

The important thing to remember is when you start a node it needs to be connected with master to communicate with other nodes. Therefore if you stop roscore in the middle of you program any nodes running at the time will be unable to maintain the connection, even if you restart roscore later.

Node

Once we have started roscore, we can run any program of ros. The program means generally the nodes. In the turtlesim example, we started two nodes namely turtlesim_node and turtlesim_teleop_key. To start a node

 rosrun package-name executable-name 

If you want to list the nodes running at a particular time, command

 rosnode list

If we do this command in our environment we will get three nodes running

 
/rosout
/teleop-key
/turtle_sim
  

The first node is started automatically when we give the command roscore.

If you want to inspect a node, command

 rosnode info node-name

The output will give a list of topics in which the node is a subscriber or publisher. To kill a node


 rosnode kill node-name


In the turtlesim example, it is clear that two nodes are running. One starts the simulation of turtlbot and other waits for specific key press to move in response with. So these two nodes are communicating with each other through something. The idea that a node want to share information will publish messages on the appropriate topic or topic, and the node that want to receive information will subscribe to the topic. In the following example turtle_telep_key is publishing messages in a topic and the turlesim_node is subscribed to that topic so that it gets the key press information and move according to that.


You can view the graph of work flow of nodes, topics and messages using the command

rqt_graph