This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:ros:subscribepublish [2021/03/01 09:48] – [ROS Concept] momala | en:ros:subscribepublish [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== ROS Concept ====== | ||
| - | |||
| - | The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms. The below figure shows four different elements of ROS. | ||
| - | {{ : | ||
| - | **Plumbing: | ||
| - | |||
| - | **Tools:** ROS has many basic tools which are important when you are working with robots such as, simulation, visualization, | ||
| - | |||
| - | **Capabilities: | ||
| - | |||
| - | **Ecosystem: | ||
| - | |||
| ===== ROS Packages ===== | ===== ROS Packages ===== | ||
| Line 19: | 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 25: | 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 34: | 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 | + | PARAMETERS |
| - | * /rosversion | + | |
| - | * /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 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: | ||
| - | The entire ROS system is built around nodes and topics. A node is a program dedicated | + | {{ : |
| + | |||
| + | 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 | ||
| + | $ rosnode info node_name | ||
| + | |||
| + | ===== ROS Topics ===== | ||
| + | Nodes communicate with each other through | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | To see the list of active | ||
| + | $ rostopic list | ||
| + | Subscribe and print the message inside a topic: | ||
| + | $ 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 | ||
| + | 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 and Subscriber ===== | ||
| + | Above you installed a package called // | ||
| We use //rosrun// to execute the node. | We use //rosrun// to execute the node. | ||
| Line 79: | 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 103: | Line 129: | ||
| | | ||
| 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 127: | 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 147: | 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 165: | 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 181: | 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 235: | 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. | ||
| + | |||
| + | |||