ROS - RoBorregos/robocup-home GitHub Wiki
ROS
For the competition the Robotics Operating System is being used. Specifically, ROS1 (because we started with it and most packages are in this one) at version Melodic. Here is a brief explanation of it features, how is used, and references for it.
Features
ROS is a "layer" above the OS that enables developing "for robots" where you can have several process talking to each other. Even that was not originally designed for "production", it is used by several organizations.
- Several programs and utilities ready for very task-specific algorithms, advanced sensors, motors, even complete comercial robots organized in packages.
- Offers the concept of nodes that is an executable that interact with other nodes written in different languages.
- Officially three supported languages: C++, Python, Lisp; others unofficials like Java and Go.
- Originally, not designed for real-time systems.
- Offers three ways of making nodes interact (by using TCP/IP under the hood) between them:
- Topics: A node publishes data that anyone listening can read.
- Services: A node can be requested by another node with a petition and reply. Like the so called microservices.
- Actions: With a defined types of topics, offers "async" services where a task, that can take long time or even fail, is requested to a node.
- At ROS1, offers a special CMake, catkin, to easily use ROS. Other tools like rosrun, roslaunch, rostopic, etc.
- Allows nodes to be running in different machines.
Interfaces
A main component of ROS is that enables to send, hear, and receive data from other nodes. For this, a listening and pooling method exists: spin
, another one useful is rate.sleep()
. In the team, we have only used the C++ and Python ROS interfaces.
ROScpp
This is the privileged (and reference) interface for using ROS, then, offers access to all the APIs and is the most powerful interface. Done to have options to have the best performance.
- Offers several APIs that can be used with threads: spins, publishing, etc.
- Not so c++11, boost is used extensively.
- A compliant implementation of "listening" for topics, that always in the background correctly collects and keeps the latest messages from subscribed topics.
- The callbacks of the subscriptions are triggered only when doing
spin()
,callOnce()
, etc. as aspected. - Killing the node instantly stops any executing callback and correctly only leaves the blocking by
spin()
and others. - Different ways of pooling topics:
spin()
,spinOnce()
,_aCallbackQueue_.callOnce()
,WaitForMessage()
, etc.
ROSpy
This interface is presented as a fast way for "prototyping" in ROS. It lacks options in several APIs and sometimes isn't very compliant with the reference, but it is indeed pythonic and nice to use.
- The receiving and pooling of subscribed topics "are" the same thing and automatically without any notice even without using
spin()
: is almost always receiving in the background and it interrupts the code for executing the callbacks.spin()
is relegated to only block and avoid the code ends; it isn't required to trigger the pending callbacks.- The callbacks interrupt the "main" code including
rate.sleep()
, except another executing callback.
- There is not support for threads.
- Because the receiving (/pooling) of messages is done in the background except when a callback is being executed, the messages won't be the most recent ones but the last ones received before executing the callback. An example of the received data in the callbacks with a
queue_size=3
could be: 1,2,3,9,8,10,15,16,17,... This is common when queue size is big and the callbacks take long. - Killing the node stops any executing callback and the block by
spin()
.
References
- Official wiki for ROS1 and tutorials page.
- Guide to create packages and understanding nodes.
- Tutorials for topics: c++, python and services: c++, python.
- Actions official tutorial.
By the team:
Other Wikis
- Run ROS nodes across multiple computers, wiki.