TEXT 8
Yarp.txt Guest on 6th April 2021 09:30:47 AM
  1. YARP
  2. ====
  3.  
  4. The YARP middleware provides a simple method to share data across components in
  5. different computers. It is based on the concept of *ports*, which are
  6. registered in a *name server* to differentiate between separate channels of
  7. communication.
  8.  
  9. Data is shared in the format of bottles, which are nested data structures of
  10. various data types.
  11.  
  12. .. note:: Port names used in MORSE have the following format:
  13.   ``/morse/component_name/[direction]``. The term [direction]
  14.   is either ``in`` or ``out``, depending on the type of component being actuator
  15.   or sensor, respectively.
  16.  
  17. Files
  18. -----
  19.  
  20. - Python: ``$MORSE_ROOT/src/morse/middleware/yarp_datastream.py``
  21.  
  22. .. _yarp_ds_configuration:
  23.  
  24. Configuration specificities
  25. ---------------------------
  26.  
  27. When configuring a component to export its data through YARP, you can pass
  28. several options to tune the behaviour of the {ex, im}porter.
  29.  
  30. The option ``port`` allows to select the explicit name of the port exported by
  31. YARP, instead of the default name. If existing, the option``topic`` will tell
  32. the component to connect automatically to the named topic.
  33.  
  34. .. code-block :: python
  35.  
  36.     foo.add_stream('yarp', port = '/foo/bar', topic = '/this/interesting/topic')
  37.  
  38.  
  39. Service interface
  40. -----------------
  41.  
  42. MORSE components providing :doc:`services <../../dev/services>` can expose this interface using YARP ports.
  43.  
  44. .. note:: Services handled with YARP will create two ports, named:
  45.   ``/ors/services/[component_name]/[service_name]/request`` and
  46.   ``/ors/services/[component_name]/[service_name]/reply``.
  47.   Where [service_name] is a string consisting of ``[component_name]#[service_method]``.
  48.  
  49. The (ASCII) protocol of the requests is simple::
  50.  
  51.   id component service "[parameters]"
  52.  
  53. - ``id`` is a freely chosen request id. It is mainly useful to identify answers
  54.   from asynchronous services.  
  55. - ``component`` is the name of the component you want to invoke the service on.
  56.  
  57. .. note::
  58.   Services that control the whole simulator belong to the special component ``simulation``.
  59.  
  60. - ``service``: the name of the request to invoke.
  61. - ``parameters`` (can be omitted if the request takes no argument): request
  62.   arguments. Arguments must be enclosed in brackets, and surrounded by quotes.
  63.  
  64. MORSE answer follows this model::
  65.  
  66.   id status [result]
  67.  
  68. - ``id`` the same id the client used to send the request,
  69. - ``status``: one of the :py:mod:`morse.core.status` constants
  70. - ``result``: a JSON-like result (actually, the representation of the Python
  71.   result object), if any.
  72.  
  73. Example (sending request on terminal 1)::
  74.  
  75.   $ yarp write /request /ors/services/Motion_Controller/Motion_Controller#goto/request
  76.   yarp: Port /request active at tcp://140.93.0.93:10173
  77.   yarp: Sending output from /request to /ors/services/Motion_Controller/Motion_Controller#goto/request using tcp
  78.   req1 Motion_Controller goto "[5.0, 4.0, 0.0]"
  79.  
  80. Example (receiving reply on terminal 2)::
  81.  
  82.   $ yarp read /reply /ors/services/Motion_Controller/Motion_Controller#goto/reply
  83.   yarp: Port /reply listening at tcp://140.93.0.93:10174
  84.   yarp: Receiving input from /ors/services/Motion_Controller/Motion_Controller#goto/reply to /reply using tcp
  85.   "0 SUCCESS Stop"
  86.  
  87.  
  88. The YARP service interface is implemented in :py:mod:`morse.middleware.yarp_request_manager`.
  89.  
  90.  
  91.  
  92. Known problems
  93. --------------
  94.  
  95. Some blender files will start the simulation fine the first time after opening the
  96. file, but stopping the simulation and starting it again will give this error::
  97.  
  98.     def open(self, *args): return _yarp.Contactable_open(self, *args)
  99.     NotImplementedError: Wrong number of arguments for overloaded function 'Contactable_open'.
  100.  
  101. To correct this, it is necessary to open the Blender file, then on a Text
  102. Editor window, select the file ``load_yarp.py``. To the right of the file name,
  103. there is a checkbox named ``Register``. Check this checkbox, save the file, and
  104. open it again. This will ensure that the script ``load_yarp.py`` is read every
  105. time the file is opened, so that yarp is correctly setup before launching the simulation.

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.