Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:ros:subscribepublish [2020/03/20 07:06] tomykalmen:ros:subscribepublish [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== ROS Concept ====== 
- 
 ===== ROS Packages ===== ===== ROS Packages =====
  
Line 9: Line 7:
 Install the package named //ros-tutorials//: Install the package named //ros-tutorials//:
  
-   $ sudo apt-get install ros-kinetic-ros-tutorials+   $ sudo apt-get install ros-melodic-ros-tutorials
  
 Once the package is successfully installed, the working environment must be recompiled: Once the package is successfully installed, the working environment must be recompiled:
Line 15: Line 13:
    $ catkin_make #compile the computing environment    $ catkin_make #compile the computing environment
  
-===== Roscore =====+===== Ros Master =====
  
-//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//.+ROS Master manages the communication between nodes. Every node registers at startup with the master. The //ros master// node must work. This node can be started with //roscore//.
  
 Open a new terminal window (Ctrl + Alt + T) and launch //roscore//: Open a new terminal window (Ctrl + Alt + T) and launch //roscore//:
Line 24: Line 22:
 If everything is set up correctly, something should appear on the terminal: 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 +  ... logging to /home/mohsen/.ros/log/83e74152-7a80-11eb/roslaunch-laptop-22969.log 
-   Checking log directory for disk usage. This may take awhile+  Checking log directory for disk usage. This may take a while
-   Press Ctrl-C to interrupt +  Press Ctrl-C to interrupt 
-   Done checking log file disk usage. Usage is <1GB. +  Done checking log file disk usage. Usage is <1GB. 
-    +   
-   started roslaunch server http: //machine_name33919+  started roslaunch server http://laptop:38393
-   ros_comm version 1.4.7 +  ros_comm version 1.14.6 
-    +   
-   SUMMARY +   
-   ====== +  SUMMARY 
-    +  ======== 
-    PARAMETERS +   
-    * /rosversion +  PARAMETERS 
-    * /rosdistro +   * /rosdistro: melodic 
-    +   * /rosversion: 1.14.6 
-   NODES +   
-    +  NODES 
-   auto-starting new master +   
-   process [master]: started with pid [13054+  auto-starting new master 
-   ROS_MASTER_URI = http: //machine_name:11311/ +  process[master]: started with pid [22980
-    +  ROS_MASTER_URI=http://laptop:11311/ 
-   setting /run_id to 9cf88ce4-b14d-11df-8a75-00251148e8cf +   
-   process [rosout-1]: started with pid [13067+  setting /run_id to 83e74152-7a80-11eb-b6ad-ccaf78b12fc1 
-   started core service [/rosout]+  process[rosout-1]: started with pid [22991
 +  started core service [/rosout] 
 +  
  
 Only one //roscore// can be run at a time. Now ROS nodes can communicate with each other. Only one //roscore// can be run at a time. Now ROS nodes can communicate with each other.
  
-===== Publisher and Subscriber =====+===== ROS Nodes ===== 
 +ROS nodes are actually programs that run on your PC. It's a single-purpose and executable program that can be compiled, run, and managed individually. Nodes are like building blocks of your program. Nodes are organized in packages. Each package may include several nodes. Each node should be registered with the ROS master: 
 + 
 +{{ :en:ros:screenshot_from_2021-03-08_10-43-56.png |}} 
 + 
 +To run a node: 
 +  $ rosrun package_name node_name 
 +To see the list of current active node: 
 +  $ rosnode list 
 +If you need to get some information about a specific node: 
 +  $ rosnode info node_name 
 + 
 +===== ROS Topics ===== 
 +Nodes communicate with each other through ROS topics. One node can publish and subscribes to topics. Actually, topics are a stream of messages. The figure below shows how a topic transfer message between two nodes while one is publishing and the other is subscribing to the topic. 
 + 
 +{{ :en:ros:screenshot_from_2021-03-08_11-03-36.png |}}
  
-The entire ROS system is built around nodes and topics. node is a program dedicated to a specific task. The nodes can communicate with each other through different topicsNodes 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.+To see the list of active topics: 
 +  $ rostopic list 
 +Subscribe and print the message inside a topic: 
 +  $ rostopic echo /topic_name 
 +To get the information about a topic such as a publisher and subscribers and the type of the message: 
 +  $ rostopic info /topic_name 
 +   
 +===== ROS Messages ===== 
 +Nodes publish messages over topics. Messages define the data structure of the information that flows from one node to the other. It includes simple data structures such as integers, floats, booleans, string, etc. They are defined in the *.msg file. You can see the message type inside a topic by running //rostopic info /topic_name//
 +To see the message structure of a specific type you need to run: 
 +  $ rosmsg show message_type 
 +for example : 
 +  $ rosmsg show geometry_msgs/Twist 
 +  geometry_msgs/Vector3 linear 
 +    float64 x 
 +    float64 y 
 +    float64 z 
 +  geometry_msgs/Vector3 angular 
 +    float64 x 
 +    float64 y 
 +    float64 z 
 +===== Sample Publisher and Subscriber ===== 
 +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. We use //rosrun// to execute the node.
Line 68: Line 105:
    [INFO] [WallTime: 1314931835.784853] hello world 1314931835.78    [INFO] [WallTime: 1314931835.784853] hello world 1314931835.78
    [INFO] [WallTime: 1314931836.788106] hello world 1314931836.79    [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 publisher goes and publishes messages to ///chatter//, now you need a subscriber who listens to those messages.
  
 The second node is called //listener// and subscribes to ///chatter// and starts displaying messages sent to that topic. The second node is called //listener// and subscribes to ///chatter// and starts displaying messages sent to that topic.
Line 77: Line 114:
 When messages sent by //talker// appear on the terminal, the node started successfully, ordered the ///chatter//, and the nodes now communicate successfully through ROS: 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: 1314931969.258941]/listener_17657_1314931968795I heard hello world  
-   [INFO] [WallTime: 1314931970.262246]/listener_17657_1314931968795I heard hello world 1314931970.26 +   1314931969.26 
-   [INFO] [WallTime: 1314931971.266348]/listener_17657_1314931968795I heard hello world 1314931971.26 +   [INFO] [WallTime: 1314931970.262246]/listener_17657_1314931968795I heard hello world  
-   [INFO] [WallTime: 1314931972.270429]/listener_17657_1314931968795I heard hello world 1314931972.27 +   1314931970.26 
-   [INFO] [WallTime: 1314931973.274382]/listener_17657_1314931968795I heard hello world 1314931973.27 +   [INFO] [WallTime: 1314931971.266348]/listener_17657_1314931968795I heard hello world  
-   [INFO] [WallTime: 1314931974.277694]/listener_17657_1314931968795I heard hello world 1314931974.28 +   1314931971.26 
-   [INFO] [WallTime: 1314931975.283708]/listener_17657_1314931968795I heard hello world 1314931975.28+   [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. 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.
- +==== Topics ====
-{{:et:ros:ros_pubsub_2_.png?700|}} +
- +
-===== 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: Entering the //rostopic// command shows all the ways you can use it:
  
    $rostopic    $rostopic
-   rostopic bw display bandwidth used by topic+   rostopic BW display bandwidth used by topic
    rostopic echo print messages to screen    rostopic echo print messages to screen
-   rostopic hz display publishing rate of topic+   rostopic Hz display publishing rate of topic
    rostopic list print information about active topics    rostopic list print information about active topics
-   rostopic pub publish data to topic+   rostopic pub publish data to topic
    rostopic type print topic type    rostopic type print topic type
-Make sure roscore, talker and listener work in the background.+Make sure roscore, talkerand listener work in the background.
  
 We will display all the topics currently in use: We will display all the topics currently in use:
Line 109: Line 148:
    /rosout    /rosout
    /rosout_agg    /rosout_agg
-///chatter// is the topic through which //talker// and //listener// interact+///chatter// is the topic through which //talker// and //listener// interact.
  
-we use the //rostopic info// command to display the necessary information about the topic:+We use the //rostopic info// command to display the necessary information about the topic:
  
    $ rostopic info/chatter    $ rostopic info/chatter
Line 129: Line 168:
    average rate: 10.005    average rate: 10.005
    min: 0.100s max: 0.100s std dev: 0.00017s window: 10    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 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: We use //echo// to display messages sent to the topic:
Line 147: Line 186:
  
    $ rostopic pub /chatter std_msgs /String "data: 'hello world'"    $ rostopic pub /chatter std_msgs /String "data: 'hello world'"
-   publishing and latching message. Press ctrl-C to terminate+   publishing and latching messages. Press "Ctrl + Cto terminate
 While listening to the subject at the same time, we see that the message we sent was published: While listening to the subject at the same time, we see that the message we sent was published:
  
Line 163: Line 202:
    ---    ---
    date: "hello world 1542817788.41"    date: "hello world 1542817788.41"
- +    
-====== Rqt_graph ====== +==== Nodes ====
-    +
-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 +
-{{:et:ros:rqt_graph.png|}} +
- +
-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: +
- +
-{{:et:ros:rqtslam.png?700|}} +
- +
-====== Rosnode ======+
  
 We use //rosnode list// to display all currently running nodes. We use //rosnode list// to display all currently running nodes.
Line 217: Line 239:
        * transport: TCPROS        * transport: TCPROS
 We can see which computer the node is running on and through which protocol it is connected to the ROS. 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