This is an old revision of the document!


ROS Concept

ROS Packages

ROS has software for organized packages. The package may contain ROS nodes, data sets, configuration files, third-party software, or any other program needed to run the program. The purpose of libraries is to provide useful functions that can be easily used for different purposes.

The libraries can be installed using the Linux package manager apt-get or placed in the src directory of your workspace. The package called ros-tutorials contains packages that demonstrate the capabilities of ROS and are necessary to follow this tutorial.

Install the package named ros-tutorials:

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

Once the package is successfully installed, the working environment must be recompiled:

 $ catkin_make #compile the computing environment

Roscore

Roscore is a collection of nodes and programs that are prerequisites for a ROS-based system. In order for ROS nodes to communicate with each other, the ros master node must work. This node can be started with roscore.

Open a new terminal window (Ctrl + Alt + T) and launch roscore:

 $ roscore

If everything is set up correctly, something should appear on the terminal:

 ... 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]

Only one roscore can be run at a time. Now ROS nodes can communicate with each other.

Publisher and Subscriber

The entire ROS system is built around nodes and topics. A node is a program dedicated to a specific task. The nodes can communicate with each other through different topics. Nodes can publish messages to topics and subscribe to topics to read messages from them. Above you installed a package called ros-tutorials. This package contains two nodes. The first node is called talker, which publishes the text “hello world” into the /chatter topic.

We use rosrun to execute the node.

Open a new terminal window (Ctrl + Alt + T) and run a node called talker there:

 $ rosrun rospy_tutorials talker

Make sure roscore is running, you can't start a node without it. If the node is successfully started, the terminal should appear:

 [INFO] [WallTime: 1314931831.774057] hello world 1314931831.77
 [INFO] [WallTime: 1314931832.775497] hello world 1314931832.77
 [INFO] [WallTime: 1314931833.778937] hello world 1314931833.78
 [INFO] [WallTime: 1314931834.782059] hello world 1314931834.78
 [INFO] [WallTime: 1314931835.784853] hello world 1314931835.78
 [INFO] [WallTime: 1314931836.788106] hello world 1314931836.79

The publisher goes and publishes messages to /chatter, now you need a subscriber who reads those messages.

The second node is called listener and subscribes to /chatter and starts displaying messages sent to that topic.

Open a new terminal window (Ctrl + Alt + T) and execute a subscriber named listener:

 $ rosrun rospy_tutorials listener

When messages sent by talker appear on the terminal, the node started successfully, ordered the /chatter, and the nodes now communicate successfully through ROS:

 [INFO] [WallTime: 1314931969.258941]/listener_17657_1314931968795I heard hello world 1314931969.26
 [INFO] [WallTime: 1314931970.262246]/listener_17657_1314931968795I heard hello world 1314931970.26
 [INFO] [WallTime: 1314931971.266348]/listener_17657_1314931968795I heard hello world 1314931971.26
 [INFO] [WallTime: 1314931972.270429]/listener_17657_1314931968795I heard hello world 1314931972.27
 [INFO] [WallTime: 1314931973.274382]/listener_17657_1314931968795I heard hello world 1314931973.27
 [INFO] [WallTime: 1314931974.277694]/listener_17657_1314931968795I heard hello world 1314931974.28
 [INFO] [WallTime: 1314931975.283708]/listener_17657_1314931968795I heard hello world 1314931975.28

ROS-based robots usually have a large number of nodes, each with its own specific function. Nodes can be located on different computers and communicate through different protocols. But now we're getting to know the tools that come with ROS, which allow us to track and manage nodes and topics.

Rostopic

The first tool we look at is rostopic. Rostopic is a tool to monitor and manage ROS topics.

Entering the rostopic command shows all the ways you can use it:

 $rostopic
 rostopic bw display bandwidth used by topic
 rostopic echo print messages to screen
 rostopic hz display publishing rate of topic
 rostopic list print information about active topics
 rostopic pub publish data to topic
 rostopic type print topic type

Make sure roscore, talker and listener work in the background.

We will display all the topics currently in use:

 $rostopic list
 /chatter
 /rosout
 /rosout_agg

/chatter is the topic through which talker and listener interact

we use the rostopic info command to display the necessary information about the topic:

 $ rostopic info/chatter
 Type: std_msgs/String
 
 Publishers:
  * /talker_12621_1542817185271 (http://rage-HP-EliteBook:45495/)
 
 Subscribers:
  * /listener_12836_1542817212996 (http://rage-HP-EliteBook:34711/)

You will see which nodes have subscribed to the topic and which ones are publishing to the topic, as well as the message type, which is std_msgs/String.

We use rostopic hz to see the frequency of messages:

 $ rostopic hz/chatter
 subscribed to [/chatter]
 average rate: 10.005
 min: 0.100s max: 0.100s std dev: 0.00017s window: 10

We see that the average frequency of messages is about 10 Hz. (Ctrl + C aborts the process)

We use echo to display messages sent to the topic:

 $ rostopic echo /chatter
 date: "hello world 1542817743.91"
 ---
 date: "hello world 1542817744.01"
 ---
 date: "hello world 1542817744.11"
 ---
 date: "hello world 1542817744.21"
 ---
 date: "hello world 1542817744.31"
 ---

We use pub to post a message to:

 $ rostopic pub /chatter std_msgs /String "data: 'hello world'"
 publishing and latching message. Press ctrl-C to terminate

While listening to the subject at the same time, we see that the message we sent was published:

 date: "hello world 1542817787.91"
 ---
 date: "hello world 1542817788.01"
 ---
 date: "hello world 1542817788.11"
 ---
 data: "hello world"
 ---
 date: "hello world 1542817788.21"
 ---
 date: "hello world 1542817788.31"
 ---
 date: "hello world 1542817788.41"

Rqt_graph

    ROS also comes with some graphical tools. Rqt_graph graphically shows which nodes communicate with each other. It is also possible to filter nodes and topics differently. rqt_graph allows you to save the graph in pdf format.

run rqt_graph:

 $ rqt_graph

When the command is executed, the graphical user interface opens. We see that talker publishes messages to /chatter and listener listens to them.

Robots with more complex tasks usually have many different nodes working on them that interact with a variety of topics. It is difficult to see the big picture from the command line and this is done using the rqt_graph program.

Example of a graph on a more complex robot:

Rosnode

We use rosnode list to display all currently running nodes.

 $ rosnode list
 /listener_12836_1542817212996
 /rosout
 /talker_12621_1542817185271

We use rosnode info to display the necessary information about the node:

 $ rosnode info /talker_12621_1542817185271
 -------------------------------------------------- ------------------------------
 Node [/talker_12621_1542817185271]
 Publications:
  * /chatter [std_msgs /String]
  * /rosout [rosgraph_msgs /Log]
 
 Subscriptions: None
 
 Services:
   * /talker_12621_1542817185271/get_loggers
  * /talker_12621_1542817185271/set_logger_level
 
 
 contacting node http://rage-HP-EliteBook:45495/...
 Hold: 12,621
 Connections:
  * topic: /chatter
     * to: /listener_12836_1542817212996
     * direction: outbound
     * transport: TCPROS
  * topic: /rosout
     * to: /rosout
     * direction: outbound
     * transport: TCPROS

We can see which computer the node is running on and through which protocol it is connected to the ROS.

en/ros/subscribepublish.1584688018.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0