This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:ros:subscribepublish [2020/03/20 07:06] – tomykalm | en: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 // | Install the package named // | ||
- | $ 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 | + | ROS Master manages the communication between |
Open a new terminal window (Ctrl + Alt + T) and launch // | Open a new terminal window (Ctrl + Alt + T) and launch // | ||
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 | + | |
- | | + | Checking log directory for disk usage. This may take a while. |
- | | + | Press Ctrl-C to interrupt |
- | | + | Done checking log file disk usage. Usage is <1GB. |
- | | + | |
- | | + | started roslaunch server http://laptop:38393/ |
- | | + | ros_comm version 1.14.6 |
- | | + | |
- | | + | |
- | | + | |
- | | + | ======== |
- | PARAMETERS | + | |
- | * /rosversion | + | PARAMETERS |
- | * /rosdistro | + | |
- | | + | |
- | | + | |
- | | + | NODES |
- | | + | |
- | | + | auto-starting new master |
- | | + | process[master]: |
- | | + | ROS_MASTER_URI=http:// |
- | | + | |
- | | + | setting /run_id to 83e74152-7a80-11eb-b6ad-ccaf78b12fc1 |
- | | + | process[rosout-1]: |
+ | 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 | + | ===== ROS Nodes ===== |
+ | ROS nodes are actually programs that run on your PC. It's a single-purpose | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | 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. | ||
+ | |||
+ | {{ : | ||
- | The entire ROS system is built around nodes and topics. | + | To see the list of active topics: |
+ | $ rostopic list | ||
+ | Subscribe | ||
+ | $ rostopic echo / | ||
+ | To get the information about a topic such as a publisher and subscribers and the type of the message: | ||
+ | $ rostopic info / | ||
+ | |||
+ | ===== ROS Messages ===== | ||
+ | Nodes publish messages over topics. | ||
+ | To see the message structure of a specific type you need to run: | ||
+ | $ rosmsg show message_type | ||
+ | for example : | ||
+ | $ rosmsg show geometry_msgs/ | ||
+ | geometry_msgs/ | ||
+ | float64 x | ||
+ | float64 y | ||
+ | float64 z | ||
+ | geometry_msgs/ | ||
+ | float64 x | ||
+ | float64 y | ||
+ | float64 z | ||
+ | ===== Sample Publisher | ||
+ | Above you installed a package called // | ||
We use //rosrun// to execute the node. | We use //rosrun// to execute the node. | ||
Line 68: | Line 105: | ||
| | ||
| | ||
- | The publisher goes and publishes messages to /// | + | The publisher goes and publishes messages to /// |
The second node is called // | The second node is called // | ||
Line 77: | Line 114: | ||
When messages sent by //talker// appear on the terminal, the node started successfully, | When messages sent by //talker// appear on the terminal, the node started successfully, | ||
- | | + | |
- | | + | 1314931969.26 |
- | | + | |
- | | + | 1314931970.26 |
- | | + | |
- | | + | 1314931971.26 |
- | | + | |
+ | 1314931972.27 | ||
+ | | ||
+ | 1314931973.27 | ||
+ | | ||
+ | 1314931974.28 | ||
+ | | ||
+ | 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 | |
- | {{: | + | |
- | + | ||
- | ===== Rostopic | + | |
- | + | ||
- | The first tool we look at is // | + | |
Entering the // | Entering the // | ||
| | ||
- | | + | |
| | ||
- | | + | |
| | ||
- | | + | |
| | ||
- | Make sure roscore, talker and listener work in the background. | + | Make sure roscore, talker, and 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: | ||
/ | / | ||
/ | / | ||
- | /// | + | /// |
- | 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/ | $ rostopic info/ | ||
Line 129: | Line 168: | ||
| | ||
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'" | ||
- | | + | |
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. // | + | |
- | + | ||
- | run // | + | |
- | + | ||
- | $ rqt_graph | + | |
- | {{: | + | |
- | + | ||
- | When the command is executed, the graphical user interface opens. We see that //talker// publishes messages to /// | + | |
- | + | ||
- | 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 // | + | |
- | + | ||
- | Example of a graph on a more complex robot: | + | |
- | + | ||
- | {{: | + | |
- | + | ||
- | ====== 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: | ||
| | ||
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. | ||
+ | |||
+ |