Documentation for ROS ACUMOS bridge examples.
Félix Ingrand <felix@laas.fr>
This project contains a number of C++ examples on how to connect ROS nodes (using .msg, topics, publish/subscribe) and ACUMOS components (using ProtoBuf and gRPC client/server).
The credits for the code should do to the gRPC and ROS community/developers, as most of it is taken from their respective tutorials. |
These examples, should compile on any machine with ROS and gRPC installed (so install them first if needed). They are to be considered as starting points to be used for more ambitious projects.
Beware of inconsistent ProtoBuf/gRPC versions. I strongly advise you to install gRPC following the instruction on: https://grpc.io/docs/languages/cpp/quickstart/ This will install gRPC and ProtoBuf, minimizing the risk of version inconsistency. |
I am using regular Makefile
and pkg-config
. You may move to cmake
and catkin
if you feel like it, but do not ask me how
to do it ;-) I would not know…
Passing data from ROS/Topics to ACUMOS/ProtoBuf
The current setup contains 6 executable programs (the 2+2 mostly unmodified respective tutorial for both middlewares, plus 2 programs mixing them):
-
talker
andlistener
are the regular ROS tutorial nodes withtalker
publishing thechatter
topic containing a string, andlistener
which subscribes to this topic and prints it upon receiving i. The message description is trivial and standard:std_msgs/String.h
, where the string is in thedata
field. If you are not familiar with ROS, check the code and run the example to familiarize yourself with it. -
greeter_client
andgreeter_server
are the regular gRPC tutorial client and server (synchronous version) which define theGreeter
service which takes a stringHelloRequest
as input and produces a stringHelloReply
as output (see thehelloworld.proto
file which contains the ProtoBuf/gRPC definitions). Again, check the source and run the code to get an idea of how this works. -
listener_greeter_bridge
which mixes both middlewares tutorials. It is a ROS node/gRPC client which, acting as a ROS node, subscribes to thechatter
topic and, acting as a gRPC client, call synchronously theGreeter
service with the string contained inchatter
asHelloRequest
name
field.greeter_server
, then runs the service and sends the reply back. The gRPCGreeter
service call is made inside the ROS callback attached to thechatter
topic. -
greeter_talker_bridge
which also mixes both middlewares. It is a ROS node/gRPC server which acts as a gRPC server which implementsGreeeter
. It thus receives a string (in theHelloRequest
name
field )from a gRPC client and publish it in thechatter
topic and then reply to its client.
These two examples are the most "simple" setup one can think of to "get started". Still, note that in both setup, you do
not have to modify the nodes which publishes/subscibes to the topic (talker/listener
in our case), nor do you need to change the gRPC
server/client (greeter_server/greeter_client
in this setup). So existing ROS nodes and gRPC server/client do not need to be
modified, at the cost of an additional program which bridges the two middlewares.
Do not forget to start roscore before starting talker and listener
|
You can run all the programs at will, the most interesting combinations for connecting ROS nodes to ACUMOS components (without modifying any of theses) are:
The legend for the following figures is this one:
-
greeter_server
,listener_greeter_bridge
andtalker
(this combination can be used when you want a ROS node to send data to an ACUMOS component without changing any of these two). But nothing prevent you from adding the regularlistener
and orgreeter_client
… you can even add anothertalker
(providing you change its node name).
-
listener
,greeter_talker_bridge
andgreeter_client
(this combination can be used when you want an ACUMOS component to send data to a ROS node without changing any of these two). Here also you can add on the top of this atalker
or anothergreeter_client
.
if you run both greeter_talker_bridge and listener_greeter_bridge at the same time… and you feed them one
topic value… guess what? you will see how fast these middlewares can run and freeze your terminal… ;-)
|
Calling a ROS service from a gRPC client thru a gRPC(server)/ROS(client) bridge
This setup relies on the AddTwoInts ROS service descibed in the ROS tutorial, you need first to install it
Add Two Ints ROS Service, otherwise the executables
will not be compiled (the Makefile
is supposedly smart enough to not compile them). Two executables are provided:
add_two_ints_client
and add_two_ints_bridge
.
-
add_two_ints_client
is a simple gRPC client using the service/protobuf defined inAddTwoInts.proto
. This ProtoBuf provides the definition for the serviceAdder
and its rpcATI
, as well as theATIrequest
andATIreply
messages. -
add_two_ints_bridge
is a gRPC server/ROS Service client, which will call the ROS service defined in the Add Two Ints ROS Service tutorial.
The setup is illustrated in the following figure. You call the ROS Service server
rosrun beginner_tutorials add_two_ints_server
Then you start the add_two_ints_bridge
which will setup a bridge which will act as a gRPC server/ROS Service client, and then you can call the add_two_ints_client
with two integer as argument to illustrate the whole process.
add_two_ints_bridge & add_two_ints_client 4 7 ...
Enjoy!