Félix Ingrand <firstname.lastname@example.org>
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.|
|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
pkg-config. You may move to
catkin if you feel like it, but do not ask me how
to do it ;-) I would not know…
The current setup contains 6 executable programs (the 2+2 mostly unmodified respective tutorial for both middlewares, plus 2 programs mixing them):
listenerare the regular ROS tutorial nodes with
chattertopic containing a string, and
listenerwhich 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 the
datafield. If you are not familiar with ROS, check the code and run the example to familiarize yourself with it.
greeter_serverare the regular gRPC tutorial client and server (synchronous version) which define the
Greeterservice which takes a string
HelloRequestas input and produces a string
HelloReplyas output (see the
helloworld.protofile which contains the ProtoBuf/gRPC definitions). Again, check the source and run the code to get an idea of how this works.
listener_greeter_bridgewhich mixes both middlewares tutorials. It is a ROS node/gRPC client which, acting as a ROS node, subscribes to the
chattertopic and, acting as a gRPC client, call synchronously the
Greeterservice with the string contained in
greeter_server, then runs the service and sends the reply back. The gRPC
Greeterservice call is made inside the ROS callback attached to the
greeter_talker_bridgewhich also mixes both middlewares. It is a ROS node/gRPC server which acts as a gRPC server which implements
Greeeter. It thus receives a string (in the
namefield )from a gRPC client and publish it in the
chattertopic 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
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
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:
talker(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 regular
greeter_client… you can even add another
talker(providing you change its node name).
greeter_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 a
if you run both
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_clientis a simple gRPC client using the service/protobuf defined in
AddTwoInts.proto. This ProtoBuf provides the definition for the service
Adderand its rpc
ATI, as well as the
add_two_ints_bridgeis 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 ...