mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 18:05:17 +02:00
Compare commits
72
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c258692a7 | ||
|
|
b4350945ec | ||
|
|
6feb61e801 | ||
|
|
91461248d2 | ||
|
|
beac621a94 | ||
|
|
9ededdbfe7 | ||
|
|
f43d2ecb0a | ||
|
|
055d213294 | ||
|
|
af007872b0 | ||
|
|
e8dc4deda2 | ||
|
|
29aab24f8a | ||
|
|
dc4a428a75 | ||
|
|
7f0af6b953 | ||
|
|
7372bbe5bd | ||
|
|
a88be1bbbb | ||
|
|
92b7343d1a | ||
|
|
e6b928b1e1 | ||
|
|
4c98e4f9f5 | ||
|
|
964b0aec1a | ||
|
|
03946126dd | ||
|
|
0142528a73 | ||
|
|
53ff7d409d | ||
|
|
9e9167b0d7 | ||
|
|
93aa9e6a73 | ||
|
|
e62154a1cf | ||
|
|
495733690c | ||
|
|
179ae80b94 | ||
|
|
5ad09cec70 | ||
|
|
dfd6966cd1 | ||
|
|
d91c98ab6e | ||
|
|
9ed4bb3c15 | ||
|
|
489dbddced | ||
|
|
ed0402c2dd | ||
|
|
5780038fcc | ||
|
|
57bdfc5463 | ||
|
|
1f1b5842c6 | ||
|
|
6d2d47490a | ||
|
|
61b1e6fc8c | ||
|
|
d7dab5c671 | ||
|
|
e85eccb7c0 | ||
|
|
ac9f09b656 | ||
|
|
7ffd5f0bb6 | ||
|
|
ceb1a1436c | ||
|
|
c98705319f | ||
|
|
d149bb7018 | ||
|
|
646ca52aab | ||
|
|
95fecd77ae | ||
|
|
69f17c28a8 | ||
|
|
f6a2aa3b60 | ||
|
|
a623308505 | ||
|
|
e133754746 | ||
|
|
a3fe4aa376 | ||
|
|
003cb38ef2 | ||
|
|
99b3d98430 | ||
|
|
0220dd6feb | ||
|
|
fc57709ead | ||
|
|
0009366a62 | ||
|
|
df9202ea8c | ||
|
|
837d8718bf | ||
|
|
4df06bcfaa | ||
|
|
e9330bf974 | ||
|
|
602976b45f | ||
|
|
23bcea8efb | ||
|
|
dce3c25a33 | ||
|
|
8bbe143d11 | ||
|
|
81316109d9 | ||
|
|
b7406c4b34 | ||
|
|
85ef5321f8 | ||
|
|
f0effec782 | ||
|
|
85ec50d441 | ||
|
|
f377b7a727 | ||
|
|
b47de612e6 |
@@ -0,0 +1,30 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Create a report to help us improve
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
Steps to reproduce the behaviour:
|
||||||
|
1. Clone repo '...'
|
||||||
|
2. Add these lines '...'
|
||||||
|
3. Run the script '....'
|
||||||
|
4. See error
|
||||||
|
Code or shell commands ready to be copy-pasted are welcome.
|
||||||
|
|
||||||
|
**Expected behaviour**
|
||||||
|
A clear and concise description of what you expected to happen.
|
||||||
|
|
||||||
|
**System information (please complete the following information):**
|
||||||
|
- OS: [e.g. WIndows 10, Ubuntu 16.04, ...]
|
||||||
|
- ROS 2 [e.g. Dashing, Foxy, ...]
|
||||||
|
- Version [e.g. commit hash, tag, ...]
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context about the problem here.
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
name: General issue
|
||||||
|
about: General issue template for micro-ROS
|
||||||
|
title: ''
|
||||||
|
labels: ''
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Issue template
|
||||||
|
|
||||||
|
- Hardware description: <!-- hardware where you are using micro-ROS -->
|
||||||
|
- RTOS: <!-- RTOS where you are using micro-ROS -->
|
||||||
|
- Installation type: <!-- micro_ros_setup, modules, etc -->
|
||||||
|
- Version or commit hash: <!-- version of micro-ROS used: foxy, rolling -->
|
||||||
|
|
||||||
|
#### Steps to reproduce the issue
|
||||||
|
<!-- Detailed instructions on how to reliably reproduce this issue http://sscce.org/-->
|
||||||
|
|
||||||
|
#### Expected behavior
|
||||||
|
|
||||||
|
#### Actual behavior
|
||||||
|
|
||||||
|
#### Additional information
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
name: CI micro-ROS Agent
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- 'jazzy'
|
||||||
|
schedule:
|
||||||
|
- cron: '33 6 * * *'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
microros_agent_ci:
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [ ubuntu-latest ]
|
||||||
|
ros_distribution: [ jazzy ]
|
||||||
|
include:
|
||||||
|
- docker_image: ubuntu:24.04
|
||||||
|
ros_distribution: jazzy
|
||||||
|
container:
|
||||||
|
image: ${{ matrix.docker_image }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: ros-tooling/setup-ros@0.7.13
|
||||||
|
with:
|
||||||
|
use-ros2-testing: false
|
||||||
|
required-ros-distributions: ${{ matrix.ros_distribution }}
|
||||||
|
- name : Download and install dependencies
|
||||||
|
run: |
|
||||||
|
apt-get install ros-${{ matrix.ros_distribution }}-micro-ros-msgs
|
||||||
|
apt-get install ros-${{ matrix.ros_distribution }}-rmw-fastrtps-cpp
|
||||||
|
- uses : ros-tooling/action-ros-ci@0.4.3
|
||||||
|
with:
|
||||||
|
package-name: "micro_ros_agent"
|
||||||
|
target-ros2-distro: ${{ matrix.ros_distribution }}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
Third Party Licenses
|
||||||
|
====================
|
||||||
|
|
||||||
|
This repository does not directly contain 3rd party source code.
|
||||||
+107
@@ -0,0 +1,107 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
Want to contribute? Great! You can do so through the standard GitHub pull
|
||||||
|
request model. For large contributions we do encourage you to file a ticket in
|
||||||
|
the GitHub issues tracking system prior to any code development to coordinate
|
||||||
|
with the system_modes development team early in the process. Coordinating up
|
||||||
|
front helps to avoid frustration later on.
|
||||||
|
|
||||||
|
Your contribution must be licensed under the Apache-2.0 license, the license
|
||||||
|
used by this project.
|
||||||
|
|
||||||
|
## Add / retain copyright notices
|
||||||
|
|
||||||
|
Include a copyright notice and license in each new file to be contributed,
|
||||||
|
consistent with the style used by this project. If your contribution contains
|
||||||
|
code under the copyright of a third party, document its origin, license, and
|
||||||
|
copyright holders.
|
||||||
|
|
||||||
|
## Sign your work
|
||||||
|
|
||||||
|
This project tracks patch provenance and licensing using a modified Developer
|
||||||
|
Certificate of Origin (DCO; from [OSDL][DCO]) and Signed-off-by tags initially
|
||||||
|
developed by the Linux kernel project.
|
||||||
|
|
||||||
|
```
|
||||||
|
system_modes Developer's Certificate of Origin. Version 1.0
|
||||||
|
|
||||||
|
By making a contribution to this project, I certify that:
|
||||||
|
|
||||||
|
(a) The contribution was created in whole or in part by me and I
|
||||||
|
have the right to submit it under the "Apache License, Version 2.0"
|
||||||
|
("Apache-2.0"); or
|
||||||
|
|
||||||
|
(b) The contribution is based upon previous work that is covered by
|
||||||
|
an appropriate open source license and I have the right under
|
||||||
|
that license to submit that work with modifications, whether
|
||||||
|
created in whole or in part by me, under the Apache-2.0 license;
|
||||||
|
or
|
||||||
|
|
||||||
|
(c) The contribution was provided directly to me by some other
|
||||||
|
person who certified (a) or (b) and I have not modified it.
|
||||||
|
|
||||||
|
(d) I understand and agree that this project and the contribution
|
||||||
|
are public and that a record of the contribution (including all
|
||||||
|
metadata and personal information I submit with it, including my
|
||||||
|
sign-off) is maintained indefinitely and may be redistributed
|
||||||
|
consistent with this project and the requirements of the Apache-2.0
|
||||||
|
license or any open source license(s) involved, where they are
|
||||||
|
relevant.
|
||||||
|
|
||||||
|
(e) I am granting the contribution to this project under the terms of
|
||||||
|
Apache-2.0.
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
```
|
||||||
|
|
||||||
|
With the sign-off in a commit message you certify that you authored the patch
|
||||||
|
or otherwise have the right to submit it under an open source license. The
|
||||||
|
procedure is simple: To certify above system_modes Developer's Certificate of
|
||||||
|
Origin 1.0 for your contribution just append a line
|
||||||
|
|
||||||
|
Signed-off-by: Random J Developer <random@developer.example.org>
|
||||||
|
|
||||||
|
to every commit message using your real name or your pseudonym and a valid
|
||||||
|
email address.
|
||||||
|
|
||||||
|
If you have set your `user.name` and `user.email` git configs you can
|
||||||
|
automatically sign the commit by running the git-commit command with the `-s`
|
||||||
|
option. There may be multiple sign-offs if more than one developer was
|
||||||
|
involved in authoring the contribution.
|
||||||
|
|
||||||
|
For a more detailed description of this procedure, please see
|
||||||
|
[SubmittingPatches][] which was extracted from the Linux kernel project, and
|
||||||
|
which is stored in an external repository.
|
||||||
|
|
||||||
|
### Individual vs. Corporate Contributors
|
||||||
|
|
||||||
|
Often employers or academic institution have ownership over code that is
|
||||||
|
written in certain circumstances, so please do due diligence to ensure that
|
||||||
|
you have the right to submit the code.
|
||||||
|
|
||||||
|
If you are a developer who is authorized to contribute to system_modes on
|
||||||
|
behalf of your employer, then please use your corporate email address in the
|
||||||
|
Signed-off-by tag. Otherwise please use a personal email address.
|
||||||
|
|
||||||
|
## Maintain Copyright holder / Contributor list
|
||||||
|
|
||||||
|
Each contributor is responsible for identifying themselves in the
|
||||||
|
[NOTICE](NOTICE) file, the project's list of copyright holders and authors.
|
||||||
|
Please add the respective information corresponding to the Signed-off-by tag
|
||||||
|
as part of your first pull request.
|
||||||
|
|
||||||
|
If you are a developer who is authorized to contribute to system_modes on
|
||||||
|
behalf of your employer, then add your company / organization to the list of
|
||||||
|
copyright holders in the [NOTICE](NOTICE) file. As author of a corporate
|
||||||
|
contribution you can also add your name and corporate email address as in the
|
||||||
|
Signed-off-by tag.
|
||||||
|
|
||||||
|
If your contribution is covered by this project's DCO's clause "(c) The
|
||||||
|
contribution was provided directly to me by some other person who certified
|
||||||
|
(a) or (b) and I have not modified it", please add the appropriate copyright
|
||||||
|
holder(s) to the [NOTICE](NOTICE) file as part of your contribution.
|
||||||
|
|
||||||
|
|
||||||
|
[DCO]: http://web.archive.org/web/20070306195036/http://osdlab.org/newsroom/press_releases/2004/2004_05_24_dco.html
|
||||||
|
|
||||||
|
[SubmittingPatches]: https://github.com/wking/signed-off-by/blob/7d71be37194df05c349157a2161c7534feaf86a4/Documentation/SubmittingPatches
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
|
||||||
|
# This is the official list of copyright holders and authors.
|
||||||
|
#
|
||||||
|
# Often employers or academic institutions have ownership over code that is
|
||||||
|
# written in certain circumstances, so please do due diligence to ensure that
|
||||||
|
# you have the right to submit the code.
|
||||||
|
#
|
||||||
|
# When adding J Random Contributor's name to this file, either J's name on its
|
||||||
|
# own or J's name associated with J's organization's name should be added,
|
||||||
|
# depending on whether J's employer (or academic institution) has ownership
|
||||||
|
# over code that is written for this project.
|
||||||
|
#
|
||||||
|
# How to add names to this file:
|
||||||
|
# Individual's name <submission email address>.
|
||||||
|
#
|
||||||
|
# If Individual's organization is copyright holder of her contributions add the
|
||||||
|
# organization's name, optionally also the contributor's name:
|
||||||
|
#
|
||||||
|
# Organization's name
|
||||||
|
# Individual's name <submission corporate email address>
|
||||||
|
#
|
||||||
|
# Please keep the list sorted.
|
||||||
|
|
||||||
|
eProsima
|
||||||
|
Jose Antonio Moral <joseantoniomoralparras@eprosima.com>
|
||||||
|
Pablo Garrido <pablogarrido@eprosima.com>
|
||||||
|
|
||||||
@@ -1,7 +1,58 @@
|
|||||||
# micro-ROS-Agent
|
# micro-ROS Agent
|
||||||
|
|
||||||
[](https://github.com/microROS/micro-ROS-Agent)
|
[](https://github.com/microROS/micro-ROS-Agent)
|
||||||
[](https://github.com/microROS/micro-ROS-Agent/releases)
|
[](https://github.com/microROS/micro-ROS-Agent/releases)
|
||||||
|
|
||||||
ROS 2 package using Micro XRCE-DDS Agent.
|
ROS 2 package using Micro XRCE-DDS Agent.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
This repository contains the Micro-ROS Agent package.
|
||||||
|
Micro-ROS Agent is a ROS 2 node that wraps the Micro XRCE-DDS Agent.
|
||||||
|
For further information about Micro XRCE-DDS Agent click [here](https://github.com/eProsima/Micro-XRCE-DDS-Agent)
|
||||||
|
This package is a part of the Micro-ROS project stack.
|
||||||
|
For more information about Micro-ROS project click [here](https://micro-ros.github.io/).
|
||||||
|
|
||||||
|
The node acts as a server between DDS Network and Micro-ROS nodes inside MCU.
|
||||||
|
It receives and send messages from Micro-ROS nodes, and keep track of the Micro-ROS nodes exposing them to the ROS 2 network.
|
||||||
|
The node interacts with DDS Global Data Space on behalf of the Micro-ROS nodes.
|
||||||
|
|
||||||
|
## Package features
|
||||||
|
|
||||||
|
### XML generation
|
||||||
|
|
||||||
|
During the build process, the package looks for all ROS 2 messages to generate an initial list of XML profiles.
|
||||||
|
These profiles can are referenced in the Agent-Client communication to avoid sending the full XML content.
|
||||||
|
This reference mechanism can be switched on and off from the Micro XRCE-DDS middleware layer.
|
||||||
|
|
||||||
|
### Agent-Client communication mechanism
|
||||||
|
|
||||||
|
Communication between the Micro-ROS Agent and the Micro-ROS nodes supports two types of transport:
|
||||||
|
|
||||||
|
- UDP and TCP over IPv4 and IPv6.
|
||||||
|
- Serial Port transports.
|
||||||
|
|
||||||
|
All available configurations are supported directly by the Micro XRCE-DDS agent.
|
||||||
|
|
||||||
|
## Purpose of the Project
|
||||||
|
|
||||||
|
This software is not ready for production use. It has neither been developed nor
|
||||||
|
tested for a specific use case. However, the license conditions of the
|
||||||
|
applicable Open Source licenses allow you to adapt the software to your needs.
|
||||||
|
Before using it in a safety relevant setting, make sure that the software
|
||||||
|
fulfills your requirements and adjust it according to any applicable safety
|
||||||
|
standards, e.g., ISO 26262.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This repository is open-sourced under the Apache-2.0 license. See the [LICENSE](LICENSE) file for details.
|
||||||
|
|
||||||
|
For a list of other open-source components included in this repository,
|
||||||
|
see the file [3rd-party-licenses.txt](3rd-party-licenses.txt).
|
||||||
|
|
||||||
|
## Known Issues/Limitations
|
||||||
|
|
||||||
|
Please notice the following issues/limitations:
|
||||||
|
|
||||||
|
* There is an unknown issue when dealing with serial ports shared with the micro-ROS agent running inside a Docker. Sometimes it works with a remarkable packet loss.
|
||||||
|
* There is an known issues with serial port communication on micro-ros-agent snap version. It is recommended to use the dockerized version or build it from source.
|
||||||
@@ -2,6 +2,64 @@
|
|||||||
Changelog for package micro-ros_agent
|
Changelog for package micro-ros_agent
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
5.0.20 (2024-10-14)
|
||||||
|
-------------------
|
||||||
|
* Bump micro-ROS-Agent to Fast DDS v3.0.1 (`#237 <https://github.com/micro-ROS/micro-ROS-Agent/issues/237>`_)
|
||||||
|
|
||||||
|
5.0.2 (2024-05-31)
|
||||||
|
------------------
|
||||||
|
* Jazzy Release
|
||||||
|
* Bump Micro XRCE-DDS Agent (`#226 <https://github.com/micro-ROS/micro-ROS-Agent/issues/226>`_)
|
||||||
|
|
||||||
|
5.0.1 (2024-01-29)
|
||||||
|
------------------
|
||||||
|
* Fix thread include (`#216 <https://github.com/micro-ROS/micro-ROS-Agent/issues/216>`_) (`#218 <https://github.com/micro-ROS/micro-ROS-Agent/issues/218>`_)
|
||||||
|
|
||||||
|
5.0.0 (2023-06-06)
|
||||||
|
------------------
|
||||||
|
* Add empty type key hash to GraphCache (`#189 <https://github.com/micro-ROS/micro-ROS-Agent/issues/189>`_)
|
||||||
|
* Contributors: Antonio Cuadros
|
||||||
|
|
||||||
|
4.0.2 (2022-09-28)
|
||||||
|
------------------
|
||||||
|
* Fix Datawriter destruction (`#169 <https://github.com/micro-ROS/micro-ROS-Agent/issues/169>`_) (`#170 <https://github.com/micro-ROS/micro-ROS-Agent/issues/170>`_)
|
||||||
|
* Synchronise predicate (`#160 <https://github.com/micro-ROS/micro-ROS-Agent/issues/160>`_) (`#165 <https://github.com/micro-ROS/micro-ROS-Agent/issues/165>`_)
|
||||||
|
|
||||||
|
4.0.1 (2022-06-13)
|
||||||
|
------------------
|
||||||
|
* Fix memory leak in graph manager (`#147 <https://github.com/micro-ROS/micro-ROS-Agent/issues/147>`_) (`#148 <https://github.com/micro-ROS/micro-ROS-Agent/issues/148>`_)
|
||||||
|
|
||||||
|
4.0.0 (2022-05-25)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
3.0.1 (2022-03-25)
|
||||||
|
------------------
|
||||||
|
* Add services to graph manager (`#127 <https://github.com/micro-ROS/micro-ROS-Agent/issues/127>`_) (`#129 <https://github.com/micro-ROS/micro-ROS-Agent/issues/129>`_)
|
||||||
|
* Add used missing includes (`#116 <https://github.com/micro-ROS/micro-ROS-Agent/issues/116>`_) (`#124 <https://github.com/micro-ROS/micro-ROS-Agent/issues/124>`_)
|
||||||
|
* Add system logger flag (`#118 <https://github.com/micro-ROS/micro-ROS-Agent/issues/118>`_) (`#119 <https://github.com/micro-ROS/micro-ROS-Agent/issues/119>`_)
|
||||||
|
* Add condition variable include (`#113 <https://github.com/micro-ROS/micro-ROS-Agent/issues/113>`_) (`#114 <https://github.com/micro-ROS/micro-ROS-Agent/issues/114>`_)
|
||||||
|
* pass system name to xrceagent (`#110 <https://github.com/micro-ROS/micro-ROS-Agent/issues/110>`_) (`#112 <https://github.com/micro-ROS/micro-ROS-Agent/issues/112>`_)
|
||||||
|
* Fix memory leak in FastDDS datawriter (`#107 <https://github.com/micro-ROS/micro-ROS-Agent/issues/107>`_) (`#109 <https://github.com/micro-ROS/micro-ROS-Agent/issues/109>`_)
|
||||||
|
|
||||||
|
3.0.0 (2021-09-13)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
1.0.1 (2021-09-13)
|
||||||
|
------------------
|
||||||
|
* Remove XRCE dependency and add superbuild (`#97 <https://github.com/micro-ROS/micro-ROS-Agent/issues/97>`_)
|
||||||
|
* Fixed launch file by using a list for arguments. Ensures order of items is kept. (`#93 <https://github.com/micro-ROS/micro-ROS-Agent/issues/93>`_) (`#94 <https://github.com/micro-ROS/micro-ROS-Agent/issues/94>`_)
|
||||||
|
* Modify argument type (`#91 <https://github.com/micro-ROS/micro-ROS-Agent/issues/91>`_)
|
||||||
|
* Fix graph manager datawriters behaviour (`#84 <https://github.com/micro-ROS/micro-ROS-Agent/issues/84>`_)
|
||||||
|
* Graph manager: Fix participant mask for listener callbacks (`#81 <https://github.com/micro-ROS/micro-ROS-Agent/issues/81>`_)
|
||||||
|
* Fix agent launch (`#78 <https://github.com/micro-ROS/micro-ROS-Agent/issues/78>`_)
|
||||||
|
* Fix graph manager node namespaces (`#75 <https://github.com/micro-ROS/micro-ROS-Agent/issues/75>`_)
|
||||||
|
* Fix Rolling agent (`#61 <https://github.com/micro-ROS/micro-ROS-Agent/issues/61>`_)
|
||||||
|
* Add multi domain graph manager (`#69 <https://github.com/micro-ROS/micro-ROS-Agent/issues/69>`_)
|
||||||
|
* Add ros2 launch capabilities and example launch file (`#47 <https://github.com/micro-ROS/micro-ROS-Agent/issues/47>`_)
|
||||||
|
* Snap build for the micro-ROS-Agent (`#43 <https://github.com/micro-ROS/micro-ROS-Agent/issues/43>`_)
|
||||||
|
* Create graph manager after checking passed CLI arguments and launch xrce-dds server (`#41 <https://github.com/micro-ROS/micro-ROS-Agent/issues/41>`_)
|
||||||
|
* Contributors: Antonio Cuadros, Jose Antonio Moral, Pablo Garrido, mergify[bot]
|
||||||
|
|
||||||
0.0.1 (2019-04-24)
|
0.0.1 (2019-04-24)
|
||||||
-----------------
|
-----------------
|
||||||
* Initial release
|
* Initial release
|
||||||
|
|||||||
+170
-159
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
# Copyright 2018-present Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@@ -12,162 +12,229 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.11)
|
||||||
|
|
||||||
# Set CMake version
|
option(UROSAGENT_GENERATE_PROFILE
|
||||||
cmake_minimum_required(VERSION 3.5)
|
"Generates agent.refs according to the .msgs provided in the .repos" OFF
|
||||||
|
)
|
||||||
# Set proyect name
|
|
||||||
project(micro_ros_agent)
|
|
||||||
|
|
||||||
|
|
||||||
set(CMAKE_C_CLANG_TIDY clang-tidy -checks=*)
|
set(CMAKE_C_CLANG_TIDY clang-tidy -checks=*)
|
||||||
|
|
||||||
# Default to C++14
|
option(MICROROSAGENT_SUPERBUILD "Enable superbuild compilation." ON)
|
||||||
if(NOT CMAKE_CXX_STANDARD)
|
option(UAGENT_USE_SYSTEM_LOGGER "Force use of system installed spdlog logger on superbuild." OFF)
|
||||||
set(CMAKE_CXX_STANDARD 14)
|
|
||||||
|
if(NOT MICROROSAGENT_SUPERBUILD)
|
||||||
|
project(micro_ros_agent LANGUAGES CXX)
|
||||||
|
else()
|
||||||
|
project(uagent_superbuild NONE)
|
||||||
|
include(${PROJECT_SOURCE_DIR}/cmake/SuperBuild.cmake)
|
||||||
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
||||||
add_compile_options(-Wall -Wextra -Wpedantic)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
# Find packages depencences
|
|
||||||
find_package(rosidl_cmake REQUIRED)
|
|
||||||
find_package(ament_cmake REQUIRED)
|
find_package(ament_cmake REQUIRED)
|
||||||
find_package(fastcdr REQUIRED CONFIG)
|
find_package(microxrcedds_agent REQUIRED)
|
||||||
find_package(fastrtps REQUIRED CONFIG)
|
find_package(rosidl_cmake REQUIRED)
|
||||||
find_package(microxrcedds_agent REQUIRED CONFIG)
|
find_package(fastcdr REQUIRED)
|
||||||
find_package(ament_cmake_python REQUIRED)
|
find_package(fastdds REQUIRED)
|
||||||
|
find_package(fastrtps_cmake_module REQUIRED)
|
||||||
|
find_package(rmw_dds_common REQUIRED)
|
||||||
|
find_package(rmw REQUIRED)
|
||||||
|
find_package(rcutils REQUIRED)
|
||||||
|
find_package(rmw_fastrtps_shared_cpp REQUIRED)
|
||||||
|
|
||||||
|
find_package(ament_lint_auto REQUIRED)
|
||||||
|
|
||||||
|
find_package(rosidl_typesupport_fastrtps_cpp REQUIRED)
|
||||||
|
find_package(rosidl_runtime_cpp REQUIRED)
|
||||||
|
find_package(rosidl_typesupport_cpp REQUIRED)
|
||||||
|
find_package(ament_cmake_gtest REQUIRED)
|
||||||
|
|
||||||
|
find_package(micro_ros_msgs REQUIRED)
|
||||||
|
|
||||||
|
add_executable(${PROJECT_NAME}
|
||||||
|
src/main.cpp
|
||||||
|
src/agent/Agent.cpp
|
||||||
|
src/agent/graph_manager/graph_manager.cpp
|
||||||
|
src/agent/graph_manager/graph_typesupport.cpp
|
||||||
|
src/agent/utils/demangle.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
include
|
||||||
|
)
|
||||||
|
|
||||||
|
ament_target_dependencies(${PROJECT_NAME}
|
||||||
|
rosidl_typesupport_fastrtps_cpp
|
||||||
|
rosidl_runtime_cpp
|
||||||
|
rosidl_typesupport_cpp
|
||||||
|
fastcdr
|
||||||
|
fastdds
|
||||||
|
rmw_dds_common
|
||||||
|
rmw
|
||||||
|
rmw_fastrtps_shared_cpp
|
||||||
|
micro_ros_msgs
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
microxrcedds_agent
|
||||||
|
fastcdr
|
||||||
|
fastdds
|
||||||
|
$<$<BOOL:$<PLATFORM_ID:Linux>>:rt>
|
||||||
|
$<$<BOOL:$<PLATFORM_ID:Linux>>:dl>
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
$<$<C_COMPILER_ID:GNU>:-Wall>
|
||||||
|
$<$<C_COMPILER_ID:GNU>:-Wextra>
|
||||||
|
$<$<C_COMPILER_ID:GNU>:-pedantic>
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
CXX_STANDARD
|
||||||
|
14
|
||||||
|
CXX_STANDARD_REQUIRED
|
||||||
|
YES
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||||
|
CXX_STANDARD
|
||||||
|
14
|
||||||
|
CXX_STANDARD_REQUIRED
|
||||||
|
YES
|
||||||
|
)
|
||||||
|
|
||||||
|
target_compile_options(${PROJECT_NAME}
|
||||||
|
PRIVATE
|
||||||
|
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall>
|
||||||
|
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wextra>
|
||||||
|
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wpedantic>
|
||||||
|
)
|
||||||
|
|
||||||
# Export dependencies to downstream packages
|
|
||||||
ament_export_dependencies(fastcdr)
|
|
||||||
ament_export_dependencies(fastrtps)
|
|
||||||
ament_export_dependencies(microxrcedds_agent)
|
ament_export_dependencies(microxrcedds_agent)
|
||||||
|
|
||||||
|
ament_package()
|
||||||
|
|
||||||
# Set variables
|
install(
|
||||||
set(_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/python")
|
TARGETS
|
||||||
|
${PROJECT_NAME}
|
||||||
|
DESTINATION
|
||||||
|
lib/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
set(_XML_INTERFACE_GEN_BIN "${_OUTPUT_PATH}/bin/Xml_interface_gen.py")
|
install(
|
||||||
normalize_path(_XML_INTERFACE_GEN_BIN "${_XML_INTERFACE_GEN_BIN}")
|
DIRECTORY
|
||||||
|
launch
|
||||||
|
DESTINATION
|
||||||
|
share/${PROJECT_NAME}
|
||||||
|
)
|
||||||
|
|
||||||
set(_XML_DEFAULT_READ_BIN "${_OUTPUT_PATH}/bin/Xml_read_default_profiles.py")
|
if(UROSAGENT_GENERATE_PROFILE)
|
||||||
normalize_path(_XML_DEFAULT_READ_BIN "${_XML_DEFAULT_READ_BIN}")
|
set(_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/python")
|
||||||
|
|
||||||
set(_PYTHON_PKG_TOOL ${PROJECT_NAME})
|
set(_XML_INTERFACE_GEN_BIN "${_OUTPUT_PATH}/bin/Xml_interface_gen.py")
|
||||||
|
normalize_path(_XML_INTERFACE_GEN_BIN "${_XML_INTERFACE_GEN_BIN}")
|
||||||
|
|
||||||
set(_RESOURCE_DIR "${_OUTPUT_PATH}/resource")
|
set(_XML_DEFAULT_READ_BIN "${_OUTPUT_PATH}/bin/Xml_read_default_profiles.py")
|
||||||
normalize_path(_RESOURCE_DIR "${_RESOURCE_DIR}")
|
normalize_path(_XML_DEFAULT_READ_BIN "${_XML_DEFAULT_READ_BIN}")
|
||||||
|
|
||||||
|
set(_PYTHON_PKG_TOOL utils)
|
||||||
|
|
||||||
set(_DEFAULT_FASTRTPS_PROFILES_PATH "${_OUTPUT_PATH}/gen/DEFAULT_FASTRTPS_PROFILES.xml")
|
set(_RESOURCE_DIR "${_OUTPUT_PATH}/resource")
|
||||||
normalize_path(_DEFAULT_FASTRTPS_PROFILES_PATH "${_DEFAULT_FASTRTPS_PROFILES_PATH}")
|
normalize_path(_RESOURCE_DIR "${_RESOURCE_DIR}")
|
||||||
|
|
||||||
|
set(_DEFAULT_FASTRTPS_PROFILES_PATH "${_OUTPUT_PATH}/gen/DEFAULT_FASTRTPS_PROFILES.xml")
|
||||||
|
normalize_path(_DEFAULT_FASTRTPS_PROFILES_PATH "${_DEFAULT_FASTRTPS_PROFILES_PATH}")
|
||||||
|
|
||||||
# Get colcon call dir
|
get_filename_component(_COLCON_CALL_DIR "${PROJECT_BINARY_DIR}" DIRECTORY)
|
||||||
get_filename_component(_COLCON_CALL_DIR "${PROJECT_BINARY_DIR}" DIRECTORY)
|
get_filename_component(_COLCON_CALL_DIR "${_COLCON_CALL_DIR}" DIRECTORY)
|
||||||
get_filename_component(_COLCON_CALL_DIR "${_COLCON_CALL_DIR}" DIRECTORY)
|
|
||||||
|
|
||||||
|
set(_PYTHON_SCRIPT_HEAD
|
||||||
# Generate python header
|
"import os
|
||||||
set(
|
import sys
|
||||||
_PYTHON_SCRIPT_HEAD
|
sys.path.append('${_OUTPUT_PATH}')
|
||||||
|
from ${_PYTHON_PKG_TOOL} import *
|
||||||
"
|
"
|
||||||
import os\n
|
)
|
||||||
import sys\n
|
|
||||||
sys.path.append('${_OUTPUT_PATH}')\n
|
|
||||||
from ${_PYTHON_PKG_TOOL} import *\n
|
|
||||||
"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
file(
|
||||||
|
COPY
|
||||||
|
"bin" "${_PYTHON_PKG_TOOL}" "resource"
|
||||||
|
DESTINATION
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/python"
|
||||||
|
)
|
||||||
|
|
||||||
# Copy pyton files
|
execute_process(
|
||||||
file(COPY "bin" "${_PYTHON_PKG_TOOL}" "resource" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/python")
|
|
||||||
|
|
||||||
|
|
||||||
# Extract all packages and manifiest paths
|
|
||||||
execute_process(
|
|
||||||
COMMAND
|
COMMAND
|
||||||
"${PYTHON_EXECUTABLE}"
|
"${PYTHON_EXECUTABLE}"
|
||||||
"-c"
|
"-c"
|
||||||
"${_PYTHON_SCRIPT_HEAD}for package in GetInterfacePackages(GetPackageList('${_COLCON_CALL_DIR}')): print ('%s,%s' % (package, GetPackageName(package)))"
|
"${_PYTHON_SCRIPT_HEAD}for package in GetInterfacePackages(GetPackageList('${_COLCON_CALL_DIR}')): print ('%s,%s' % (package, GetPackageName(package)))"
|
||||||
OUTPUT_VARIABLE _packages
|
OUTPUT_VARIABLE
|
||||||
RESULT_VARIABLE _result
|
_packages
|
||||||
|
RESULT_VARIABLE
|
||||||
|
_result
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
)
|
)
|
||||||
if(NOT _result EQUAL 0)
|
|
||||||
message(FATAL_ERROR "Error finding xml packages")
|
|
||||||
endif()
|
|
||||||
message("Packages in '${_COLCON_CALL_DIR}: ${_packages}")
|
|
||||||
|
|
||||||
|
if(NOT _result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Error finding XML packages")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Convert output to list
|
string(REPLACE "\n" ";" _packages ${_packages})
|
||||||
string(REPLACE "\n" ";" _packages ${_packages})
|
|
||||||
|
|
||||||
|
set(ALL_MSG_FILES "")
|
||||||
|
foreach(package ${_packages})
|
||||||
|
|
||||||
# Extract all msg from each package (stored in ${package}_MSG_FILES)
|
|
||||||
set(ALL_MSG_FILES "")
|
|
||||||
foreach(package ${_packages})
|
|
||||||
|
|
||||||
# Extract info
|
|
||||||
string(REPLACE "," ";" package ${package})
|
string(REPLACE "," ";" package ${package})
|
||||||
list(GET package 0 package_file)
|
list(GET package 0 package_file)
|
||||||
list(GET package 1 package)
|
list(GET package 1 package)
|
||||||
|
|
||||||
|
|
||||||
# Get all msg files
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND
|
COMMAND
|
||||||
"${PYTHON_EXECUTABLE}"
|
"${PYTHON_EXECUTABLE}"
|
||||||
"-c"
|
"-c"
|
||||||
"${_PYTHON_SCRIPT_HEAD}for msg in GetInterfacePackageMsgs('${package_file}'): print ('%s' % msg)"
|
"${_PYTHON_SCRIPT_HEAD}for msg in GetInterfacePackageMsgs('${package_file}'): print ('%s' % msg)"
|
||||||
OUTPUT_VARIABLE ${package}_MSG_FILES
|
OUTPUT_VARIABLE
|
||||||
RESULT_VARIABLE _result
|
${package}_MSG_FILES
|
||||||
|
RESULT_VARIABLE
|
||||||
|
_result
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT _result EQUAL 0)
|
if(NOT _result EQUAL 0)
|
||||||
message(FATAL_ERROR "Error finding .msg files")
|
message(FATAL_ERROR "Error finding .msg files")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Skip if there are no msgs to create
|
|
||||||
if(${package}_MSG_FILES STREQUAL "")
|
if(${package}_MSG_FILES STREQUAL "")
|
||||||
continue()
|
continue()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Generate list
|
|
||||||
string(REPLACE "\n" ";" ${package}_MSG_FILES ${${package}_MSG_FILES})
|
string(REPLACE "\n" ";" ${package}_MSG_FILES ${${package}_MSG_FILES})
|
||||||
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
execute_process(
|
||||||
# Append defaul xml profiles
|
COMMAND
|
||||||
execute_process(
|
"${PYTHON_EXECUTABLE}" "${_XML_DEFAULT_READ_BIN}" "--default-xml-path" "${_RESOURCE_DIR}"
|
||||||
COMMAND "${PYTHON_EXECUTABLE}" "${_XML_DEFAULT_READ_BIN}" "--default-xml-path" "${_RESOURCE_DIR}"
|
OUTPUT_VARIABLE
|
||||||
OUTPUT_VARIABLE _XmlDoc
|
_XmlDoc
|
||||||
RESULT_VARIABLE _result
|
RESULT_VARIABLE
|
||||||
|
_result
|
||||||
)
|
)
|
||||||
if(NOT _result EQUAL 0)
|
|
||||||
message(FATAL_ERROR "Error in typesuppor generation")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
if(NOT _result EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Error in typesupport generation")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Create one xml for each message
|
foreach(package ${_packages})
|
||||||
foreach(package ${_packages})
|
|
||||||
string(REPLACE "," ";" package ${package})
|
string(REPLACE "," ";" package ${package})
|
||||||
list(GET package 0 package_file)
|
list(GET package 0 package_file)
|
||||||
list(GET package 1 package)
|
list(GET package 1 package)
|
||||||
|
|
||||||
|
|
||||||
# Skip this generation if there are no msgs to process
|
|
||||||
if(${package}_MSG_FILES STREQUAL "")
|
if(${package}_MSG_FILES STREQUAL "")
|
||||||
continue()
|
continue()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# generate script argument file
|
|
||||||
set(generator_arguments_file "${_OUTPUT_PATH}/XML_ArgFiles/${package}_Args.json")
|
set(generator_arguments_file "${_OUTPUT_PATH}/XML_ArgFiles/${package}_Args.json")
|
||||||
rosidl_write_generator_arguments(
|
rosidl_write_generator_arguments(
|
||||||
"${generator_arguments_file}"
|
"${generator_arguments_file}"
|
||||||
@@ -180,80 +247,24 @@ foreach(package ${_packages})
|
|||||||
ADDITIONAL_FILES ""
|
ADDITIONAL_FILES ""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# execute python script
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND "${PYTHON_EXECUTABLE}" "${_XML_INTERFACE_GEN_BIN}" --generator-arguments-file "${generator_arguments_file}"
|
COMMAND
|
||||||
OUTPUT_VARIABLE _XmlGen
|
"${PYTHON_EXECUTABLE}" "${_XML_INTERFACE_GEN_BIN}" --generator-arguments-file "${generator_arguments_file}"
|
||||||
RESULT_VARIABLE _result
|
OUTPUT_VARIABLE
|
||||||
|
_XmlGen
|
||||||
|
RESULT_VARIABLE
|
||||||
|
_result
|
||||||
)
|
)
|
||||||
|
|
||||||
if(NOT _result EQUAL 0)
|
if(NOT _result EQUAL 0)
|
||||||
message(FATAL_ERROR "Error in typesuppor generation")
|
message(FATAL_ERROR "Error in typesupport generation")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
# Strore xml
|
|
||||||
set(_XmlDoc "${_XmlDoc}${_XmlGen}")
|
set(_XmlDoc "${_XmlDoc}${_XmlGen}")
|
||||||
|
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
|
set (_XmlDoc "<profiles>\n${_XmlDoc}</profiles>\n")
|
||||||
|
|
||||||
# Close profile
|
file(WRITE "${_DEFAULT_FASTRTPS_PROFILES_PATH}" "${_XmlDoc}")
|
||||||
set (_XmlDoc "<profiles>\n${_XmlDoc}</profiles>\n")
|
|
||||||
|
|
||||||
|
|
||||||
# Save
|
|
||||||
file(WRITE "${_DEFAULT_FASTRTPS_PROFILES_PATH}" "${_XmlDoc}")
|
|
||||||
|
|
||||||
|
|
||||||
# Only compile uROS agent if rclcpp is found
|
|
||||||
find_package(rclcpp QUIET)
|
|
||||||
if (rclcpp_FOUND)
|
|
||||||
find_package(microxrcedds_agent_cmake_module REQUIRED)
|
|
||||||
find_package(MicroXRCEDDS_Agent REQUIRED MODULE)
|
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME} src/main.cpp)
|
|
||||||
ament_target_dependencies(
|
|
||||||
${PROJECT_NAME}
|
|
||||||
rclcpp
|
|
||||||
microxrcedds_agent
|
|
||||||
)
|
|
||||||
|
|
||||||
# TODO(Javier) Temporal until thread error is solver
|
|
||||||
target_link_libraries(
|
|
||||||
${PROJECT_NAME}
|
|
||||||
microxrcedds_agent
|
|
||||||
)
|
|
||||||
|
|
||||||
else()
|
|
||||||
message("uROS agent node will be not build")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Install the package.xml file, and generate code for ``find_package`` so that other packages can get information about this package.
|
|
||||||
ament_package()
|
|
||||||
|
|
||||||
|
|
||||||
# Only install if uROS_Agent is comiled
|
|
||||||
if (rclcpp_FOUND)
|
|
||||||
install(TARGETS
|
|
||||||
${PROJECT_NAME}
|
|
||||||
DESTINATION lib/${PROJECT_NAME}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
#Install
|
|
||||||
install(
|
|
||||||
FILES "${_DEFAULT_FASTRTPS_PROFILES_PATH}"
|
|
||||||
DESTINATION lib/${PROJECT_NAME}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Install package
|
|
||||||
#install(
|
|
||||||
# DIRECTORY cmake resource
|
|
||||||
# DESTINATION share/${PROJECT_NAME}
|
|
||||||
#)
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import sys
|
|||||||
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),'..'))
|
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),'..'))
|
||||||
|
|
||||||
from rosidl_cmake import read_generator_arguments
|
from rosidl_cmake import read_generator_arguments
|
||||||
from rosidl_parser import UnknownMessageType
|
from rosidl_adapter.parser import UnknownMessageType
|
||||||
from micro_ros_agent import generate_XML
|
from micro_ros_agent import generate_XML
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
# Copyright 2019 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
|
||||||
|
unset(_deps)
|
||||||
|
|
||||||
|
enable_language(C)
|
||||||
|
enable_language(CXX)
|
||||||
|
|
||||||
|
unset(xrceagent_DIR CACHE)
|
||||||
|
find_package(xrceagent 3 EXACT QUIET)
|
||||||
|
if(NOT xrceagent_FOUND)
|
||||||
|
ExternalProject_Add(xrceagent
|
||||||
|
GIT_REPOSITORY
|
||||||
|
https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
|
||||||
|
GIT_TAG
|
||||||
|
v3.0.1
|
||||||
|
PREFIX
|
||||||
|
${PROJECT_BINARY_DIR}/agent
|
||||||
|
INSTALL_DIR
|
||||||
|
${CMAKE_INSTALL_PREFIX}
|
||||||
|
CMAKE_CACHE_ARGS
|
||||||
|
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
|
||||||
|
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
|
||||||
|
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||||
|
-DCMAKE_C_FLAGS:STRING=${CMAKE_C_FLAGS}
|
||||||
|
-DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
|
||||||
|
-DCMAKE_EXE_LINKER_FLAGS:STRING=${CMAKE_EXE_LINKER_FLAGS}
|
||||||
|
-DCMAKE_SHARED_LINKER_FLAGS:STRING=${CMAKE_SHARED_LINKER_FLAGS}
|
||||||
|
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
|
||||||
|
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
|
||||||
|
-DCMAKE_PREFIX_PATH:PATH=<INSTALL_DIR>
|
||||||
|
-DCMAKE_SYSTEM_NAME:STRING=${CMAKE_SYSTEM_NAME}
|
||||||
|
-DUAGENT_USE_SYSTEM_FASTDDS:BOOL=ON
|
||||||
|
-DUAGENT_USE_SYSTEM_FASTCDR:BOOL=ON
|
||||||
|
-DUAGENT_USE_SYSTEM_LOGGER:BOOL=${UAGENT_USE_SYSTEM_LOGGER}
|
||||||
|
-DUAGENT_CED_PROFILE:BOOL=OFF
|
||||||
|
-DUAGENT_P2P_PROFILE:BOOL=OFF
|
||||||
|
-DUAGENT_BUILD_EXECUTABLE:BOOL=OFF
|
||||||
|
-DUAGENT_ISOLATED_INSTALL:BOOL=OFF
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Main project.
|
||||||
|
ExternalProject_Add(micro_ros_agent
|
||||||
|
SOURCE_DIR
|
||||||
|
${PROJECT_SOURCE_DIR}
|
||||||
|
BINARY_DIR
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
CMAKE_CACHE_ARGS
|
||||||
|
-DMICROROSAGENT_SUPERBUILD:BOOL=OFF
|
||||||
|
INSTALL_COMMAND
|
||||||
|
""
|
||||||
|
DEPENDS
|
||||||
|
xrceagent
|
||||||
|
)
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef _UROS_AGENT_AGENT_HPP
|
||||||
|
#define _UROS_AGENT_AGENT_HPP
|
||||||
|
|
||||||
|
#include <uxr/agent/AgentInstance.hpp>
|
||||||
|
#include <uxr/agent/middleware/Middleware.hpp>
|
||||||
|
#include <uxr/agent/middleware/utils/Callbacks.hpp>
|
||||||
|
|
||||||
|
#include <agent/graph_manager/graph_manager.hpp>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
// TODO(jamoralp): class Documentation
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
|
||||||
|
class Agent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
Agent();
|
||||||
|
|
||||||
|
~Agent() = default;
|
||||||
|
|
||||||
|
bool create(
|
||||||
|
int argc,
|
||||||
|
char** argv);
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
eprosima::uxr::AgentInstance& xrce_dds_agent_instance_;
|
||||||
|
std::map<eprosima::fastdds::dds::DomainId_t, std::shared_ptr<graph_manager::GraphManager>> graph_manager_map_;
|
||||||
|
|
||||||
|
std::shared_ptr<graph_manager::GraphManager> find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
#endif // _UROS_AGENT_AGENT_HPP
|
||||||
@@ -0,0 +1,321 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef _UROS_AGENT_GRAPH_MANAGER_HPP
|
||||||
|
#define _UROS_AGENT_GRAPH_MANAGER_HPP
|
||||||
|
|
||||||
|
#include "fastdds/dds/topic/TopicDataType.hpp"
|
||||||
|
#include "fastdds/rtps/attributes/RTPSParticipantAttributes.hpp"
|
||||||
|
#include "fastdds/rtps/participant/RTPSParticipant.hpp"
|
||||||
|
#include "fastdds/rtps/participant/RTPSParticipantListener.hpp"
|
||||||
|
#include "fastdds/rtps/RTPSDomain.hpp"
|
||||||
|
#include <fastdds/dds/domain/DomainParticipant.hpp>
|
||||||
|
#include <fastdds/dds/domain/DomainParticipantFactory.hpp>
|
||||||
|
#include <fastdds/dds/domain/DomainParticipantListener.hpp>
|
||||||
|
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
|
||||||
|
#include <fastdds/dds/publisher/DataWriter.hpp>
|
||||||
|
#include <fastdds/dds/publisher/Publisher.hpp>
|
||||||
|
#include <fastdds/dds/publisher/PublisherListener.hpp>
|
||||||
|
#include <fastdds/dds/publisher/qos/DataWriterQos.hpp>
|
||||||
|
#include <fastdds/dds/subscriber/DataReader.hpp>
|
||||||
|
#include <fastdds/dds/subscriber/DataReaderListener.hpp>
|
||||||
|
#include <fastdds/dds/subscriber/qos/DataReaderQos.hpp>
|
||||||
|
#include <fastdds/dds/subscriber/SampleInfo.hpp>
|
||||||
|
#include <fastdds/dds/subscriber/Subscriber.hpp>
|
||||||
|
#include <fastdds/rtps/common/MatchingInfo.hpp>
|
||||||
|
|
||||||
|
#include "rmw/types.h"
|
||||||
|
#include "rmw/names_and_types.h"
|
||||||
|
#include "rmw/impl/cpp/key_value.hpp"
|
||||||
|
#include "rmw_dds_common/graph_cache.hpp"
|
||||||
|
#include "rmw_fastrtps_shared_cpp/create_rmw_gid.hpp"
|
||||||
|
#include "rmw_fastrtps_shared_cpp/qos.hpp"
|
||||||
|
|
||||||
|
#include "rcutils/types.h"
|
||||||
|
#include "rcutils/types/string_array.h"
|
||||||
|
|
||||||
|
#include "rosidl_typesupport_cpp/message_type_support.hpp"
|
||||||
|
#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h"
|
||||||
|
|
||||||
|
#include "rmw_dds_common/msg/participant_entities_info.hpp"
|
||||||
|
#include "micro_ros_msgs/msg/graph.hpp"
|
||||||
|
#include "micro_ros_msgs/msg/node.hpp"
|
||||||
|
#include "micro_ros_msgs/msg/entity.hpp"
|
||||||
|
|
||||||
|
#include <uxr/agent/types/XRCETypes.hpp>
|
||||||
|
|
||||||
|
#include <agent/graph_manager/graph_typesupport.hpp>
|
||||||
|
#include <agent/utils/demangle.hpp>
|
||||||
|
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
#include <map>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
namespace graph_manager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Class that keeps track of the existing entities in the ROS 2 world,
|
||||||
|
* both coming from micro-ROS or from external ROS 2 applications.
|
||||||
|
*/
|
||||||
|
class GraphManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Default constructor.
|
||||||
|
*/
|
||||||
|
GraphManager(eprosima::fastdds::dds::DomainId_t domain_id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default destructor.
|
||||||
|
*/
|
||||||
|
~GraphManager() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Implementation of the notification logic that updates the micro-ROS graph.
|
||||||
|
*/
|
||||||
|
void publish_microros_graph();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a DDS participant to the graph tree.
|
||||||
|
* @param participant eprosima::fastdds::dds::DomainParticipant to be added.
|
||||||
|
* @param from_microros if this participant has been added from micro-ROS.
|
||||||
|
* @param enclave ROS 2 enclave.
|
||||||
|
*/
|
||||||
|
void add_participant(
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
bool from_microros = true,
|
||||||
|
const std::string& enclave = "/");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes a DDS participant from the graph tree.
|
||||||
|
* @param participant eprosima::fastdds::dds::DomainParticipant to be removed.
|
||||||
|
*/
|
||||||
|
void remove_participant(
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
bool from_microros = true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Getter for the graph cache.
|
||||||
|
* @return Reference to inner graph cache
|
||||||
|
*/
|
||||||
|
rmw_dds_common::GraphCache& get_graph_cache() { return graphCache_; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a DDS datawriter to the graph tree.
|
||||||
|
* @param datawriter_guid rtps::GUID_t of the datawriter to be added.
|
||||||
|
* @param participant Pointer to the participant which owns this datawriter.
|
||||||
|
* @param datawriter Pointer to the datawriter to be added.
|
||||||
|
*/
|
||||||
|
void add_datawriter(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datawriter_guid,
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a DDS datawriter to the graph tree.
|
||||||
|
* @param datawriter_guid rtps::GUID_t of the datawriter to be added.
|
||||||
|
* @param topic_name Name of the topic to which the datawriter sends information to.
|
||||||
|
* @param type_name Type name of the sent topic.
|
||||||
|
* @param participant_guid rtps::GUID_t of the participant which owns this datawriter.
|
||||||
|
* @param writer_qos QOS of the datawriter to be included into the graph tree.
|
||||||
|
*/
|
||||||
|
void add_datawriter(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datawriter_guid,
|
||||||
|
const std::string& topic_name,
|
||||||
|
const std::string& type_name,
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& participant_guid,
|
||||||
|
const eprosima::fastdds::dds::DataWriterQos& writer_qos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes a DDS datawriter from the graph tree.
|
||||||
|
* @param datawriter_guid rtps::GUID_t of the datawriter to be removed.
|
||||||
|
*/
|
||||||
|
void remove_datawriter(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datawriter_guid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a DDS datareader to the graph tree.
|
||||||
|
* @param datareader_guid rtps::GUID_t of the datareader to be added.
|
||||||
|
* @param participant Pointer to the participant which owns this datareader.
|
||||||
|
* @param datareader Pointer to the datareader to be added.
|
||||||
|
*/
|
||||||
|
void add_datareader(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datareader_guid,
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataReader* datareader);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Adds a DDS datareader to the graph tree.
|
||||||
|
* @param datareader_guid rtps::GUID_t of the datareader to be added.
|
||||||
|
* @param topic_name Name of the topic to which the datareader sends information to.
|
||||||
|
* @param type_name Type name of the sent topic.
|
||||||
|
* @param participant_guid rtps::GUID_t of the participant which owns this datareader.
|
||||||
|
* @param reader_qos QOS of the datareader to be included into the graph tree.
|
||||||
|
*/
|
||||||
|
void add_datareader(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datareader_guid,
|
||||||
|
const std::string& topic_name,
|
||||||
|
const std::string& type_name,
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& participant_guid,
|
||||||
|
const eprosima::fastdds::dds::DataReaderQos& reader_qos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Removes a DDS datareader from the graph tree.
|
||||||
|
* @param datareader_guid rtps::GUID_t of the datareader to be removed.
|
||||||
|
*/
|
||||||
|
void remove_datareader(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datareader_guid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Associates a certain DDS entity with a provided participant.
|
||||||
|
* @param guid rtps::GUID_t identifier of the entity.
|
||||||
|
* @param participant Participant to be associated with.
|
||||||
|
* @param entity_kind Kind of the DDS entity.
|
||||||
|
*/
|
||||||
|
void associate_entity(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& entity_guid,
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const dds::xrce::ObjectKind& entity_kind);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Implementation of FastDDS' DomainParticipantListener abstract class.
|
||||||
|
*/
|
||||||
|
class ParticipantListener : public eprosima::fastdds::dds::DomainParticipantListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor.
|
||||||
|
* @param graph_manager Pointer to the GraphManager object which owns this ParticipantListener.
|
||||||
|
*/
|
||||||
|
ParticipantListener(
|
||||||
|
GraphManager* graph_manager);
|
||||||
|
private:
|
||||||
|
|
||||||
|
template <typename DiscoveryStatus, typename Info>
|
||||||
|
void process_discovery_info(
|
||||||
|
DiscoveryStatus reason,
|
||||||
|
const Info& proxyData);
|
||||||
|
|
||||||
|
void on_participant_discovery(
|
||||||
|
eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
eprosima::fastdds::rtps::ParticipantDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::dds::ParticipantBuiltinTopicData& info,
|
||||||
|
bool& should_be_ignored) override;
|
||||||
|
|
||||||
|
void on_data_reader_discovery(
|
||||||
|
eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
eprosima::fastdds::rtps::ReaderDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::dds::SubscriptionBuiltinTopicData& info,
|
||||||
|
bool& should_be_ignored) override;
|
||||||
|
|
||||||
|
void on_data_writer_discovery(
|
||||||
|
eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
eprosima::fastdds::rtps::WriterDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::dds::PublicationBuiltinTopicData& info,
|
||||||
|
bool& should_be_ignored) override;
|
||||||
|
|
||||||
|
GraphManager* graphManager_from_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Implementation of FastDDS' DomainReaderListener abstract class.
|
||||||
|
*/
|
||||||
|
class DatareaderListener : public eprosima::fastdds::dds::DataReaderListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor.
|
||||||
|
* @param graph_manager Pointer to the GraphManager object which owns this DataReaderListener.
|
||||||
|
*/
|
||||||
|
DatareaderListener(
|
||||||
|
GraphManager* graph_manager);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
void on_data_available(
|
||||||
|
eprosima::fastdds::dds::DataReader* /*sub*/) override;
|
||||||
|
|
||||||
|
GraphManager* graphManager_from_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Convert FastDDS QOS object instance to RMW instance.
|
||||||
|
* @param fastdds_qos QOS instance to be converted.
|
||||||
|
* @returns RMW object representation of the given FastDDS QOS.
|
||||||
|
*/
|
||||||
|
template <typename FastDDSQos>
|
||||||
|
const rmw_qos_profile_t fastdds_qos_to_rmw_qos(
|
||||||
|
const FastDDSQos& fastdds_qos);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Update micro-ROS graph information upon new data
|
||||||
|
* received in the 'ros_discovery_info' topic.
|
||||||
|
*/
|
||||||
|
void update_node_entities_info();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Retrieves node name and namespace from
|
||||||
|
* participant.
|
||||||
|
* @param participant_name DDS participant name.
|
||||||
|
* @param node_name ROS2 Node name.
|
||||||
|
* @param namespace ROS2 Node namespace.
|
||||||
|
*/
|
||||||
|
void get_name_and_namespace(
|
||||||
|
std::string participant_name,
|
||||||
|
std::string& node_name,
|
||||||
|
std::string& node_namespace);
|
||||||
|
|
||||||
|
eprosima::fastdds::dds::DomainId_t domain_id_;
|
||||||
|
bool graph_changed_;
|
||||||
|
bool display_on_change_;
|
||||||
|
std::thread microros_graph_publisher_;
|
||||||
|
std::mutex mtx_;
|
||||||
|
std::condition_variable cv_;
|
||||||
|
|
||||||
|
eprosima::fastdds::dds::DataWriterQos datawriter_qos_;
|
||||||
|
|
||||||
|
rmw_dds_common::GraphCache graphCache_;
|
||||||
|
std::unique_ptr<ParticipantListener> participant_listener_;
|
||||||
|
std::unique_ptr<DatareaderListener> datareader_listener_;
|
||||||
|
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::TypeSupport> participant_info_typesupport_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::TypeSupport> microros_graph_info_typesupport_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::DomainParticipant> participant_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::Publisher> publisher_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::Subscriber> subscriber_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::Topic> ros_discovery_topic_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::Topic> ros_to_microros_graph_topic_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::DataWriter> ros_to_microros_graph_datawriter_;
|
||||||
|
std::unique_ptr<eprosima::fastdds::dds::DataReader> ros_discovery_datareader_;
|
||||||
|
|
||||||
|
// Store a auxiliary publishers and datawriter for each participant created in micro-ROS
|
||||||
|
std::map<
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant*,
|
||||||
|
eprosima::fastdds::dds::DataWriter*
|
||||||
|
> micro_ros_graph_datawriters_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace graph_manager
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
|
||||||
|
#endif // _UROS_AGENT_GRAPH_MANAGER_HPP
|
||||||
@@ -0,0 +1,139 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_HPP_
|
||||||
|
#define UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_HPP_
|
||||||
|
|
||||||
|
#include "fastdds/dds/publisher/Publisher.hpp"
|
||||||
|
#include "fastdds/dds/topic/TopicDataType.hpp"
|
||||||
|
#include "fastdds/rtps/attributes/RTPSParticipantAttributes.hpp"
|
||||||
|
#include "fastdds/rtps/participant/RTPSParticipant.hpp"
|
||||||
|
#include "fastdds/rtps/participant/RTPSParticipantListener.hpp"
|
||||||
|
#include "fastdds/rtps/RTPSDomain.hpp"
|
||||||
|
#include <fastdds/dds/domain/DomainParticipant.hpp>
|
||||||
|
#include <fastdds/dds/domain/qos/DomainParticipantQos.hpp>
|
||||||
|
#include <fastdds/dds/publisher/PublisherListener.hpp>
|
||||||
|
#include <fastdds/rtps/common/MatchingInfo.hpp>
|
||||||
|
|
||||||
|
#include "rmw/types.h"
|
||||||
|
#include "rmw/impl/cpp/key_value.hpp"
|
||||||
|
#include "rmw_dds_common/graph_cache.hpp"
|
||||||
|
#include "rmw_fastrtps_shared_cpp/create_rmw_gid.hpp"
|
||||||
|
#include "rmw_fastrtps_shared_cpp/qos.hpp"
|
||||||
|
|
||||||
|
#include "rcutils/types.h"
|
||||||
|
|
||||||
|
#include "rosidl_typesupport_cpp/message_type_support.hpp"
|
||||||
|
#include "rosidl_typesupport_fastrtps_cpp/message_type_support.h"
|
||||||
|
|
||||||
|
#include "rmw_dds_common/msg/participant_entities_info.hpp"
|
||||||
|
|
||||||
|
#include "micro_ros_msgs/msg/graph.hpp"
|
||||||
|
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
namespace graph_manager {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Implementation of virtual class eprosima::fastdds::dds::TopicDataType.
|
||||||
|
* Is used to gather and send information about the entities present within a DDS domain,
|
||||||
|
* in the Agent's context.
|
||||||
|
*/
|
||||||
|
class ParticipantEntitiesInfoTypeSupport : public eprosima::fastdds::dds::TopicDataType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
ParticipantEntitiesInfoTypeSupport();
|
||||||
|
|
||||||
|
virtual bool serialize(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
|
||||||
|
|
||||||
|
virtual bool deserialize(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
void* data) override;
|
||||||
|
|
||||||
|
virtual uint32_t calculate_serialized_size(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
|
||||||
|
|
||||||
|
virtual void* create_data() override;
|
||||||
|
|
||||||
|
virtual void delete_data(void* data) override;
|
||||||
|
|
||||||
|
virtual bool compute_key(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
|
||||||
|
bool force_md5 = false) override;
|
||||||
|
|
||||||
|
virtual bool compute_key(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
|
||||||
|
bool force_md5 = false) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
const message_type_support_callbacks_t* callbacks_;
|
||||||
|
const rosidl_message_type_support_t* type_support_;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Implementation of virtual class eprosima::fastdds::dds::TopicDataType.
|
||||||
|
* Is used to send graph information to Micro-ROS.
|
||||||
|
*/
|
||||||
|
class MicrorosGraphInfoTypeSupport : public eprosima::fastdds::dds::TopicDataType
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
MicrorosGraphInfoTypeSupport();
|
||||||
|
|
||||||
|
virtual bool serialize(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
|
||||||
|
|
||||||
|
virtual bool deserialize(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
void* data) override;
|
||||||
|
|
||||||
|
virtual uint32_t calculate_serialized_size(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation) override;
|
||||||
|
|
||||||
|
virtual void* create_data() override;
|
||||||
|
|
||||||
|
virtual void delete_data(void* data) override;
|
||||||
|
|
||||||
|
virtual bool compute_key(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
|
||||||
|
bool force_md5 = false) override;
|
||||||
|
|
||||||
|
virtual bool compute_key(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
|
||||||
|
bool force_md5 = false) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
const message_type_support_callbacks_t* callbacks_;
|
||||||
|
const rosidl_message_type_support_t* type_support_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace graph_manager
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
|
||||||
|
#endif // UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_HPP_
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef UROS_AGENT_UTILS_DEMANGLE_HPP_
|
||||||
|
#define UROS_AGENT_UTILS_DEMANGLE_HPP_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
class Demangle
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Default constructor. Creating instances of this class is not allowed.
|
||||||
|
*/
|
||||||
|
Demangle() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Default destructor.
|
||||||
|
*/
|
||||||
|
~Demangle() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Demangle service name for a given topic, prefix and service suffix,
|
||||||
|
* if the topic is part of a service; otherwise, return blank.
|
||||||
|
* @param prefix The ROS service prefix.
|
||||||
|
* @param topic_name Topic to be demangled.
|
||||||
|
* @param suffix The ROS service suffix.
|
||||||
|
* @returns The demangled service name.
|
||||||
|
*/
|
||||||
|
static std::string _demangle_service_from_topic(
|
||||||
|
const std::string& prefix,
|
||||||
|
const std::string& topic_name,
|
||||||
|
const std::string& suffix);
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Demangle if passed topic is a ROS topic; otherwise, keep it intact.
|
||||||
|
* @param topic_name Topic to be demangled.
|
||||||
|
* @returns The demangled topic.
|
||||||
|
*/
|
||||||
|
static std::string demangle_if_ros_topic(
|
||||||
|
const std::string& topic_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Demangle if passed type is a ROS type; otherwise, keep it intact.
|
||||||
|
* @param dds_type_string Type to be demangled.
|
||||||
|
* @returns The demangled type.
|
||||||
|
*/
|
||||||
|
static std::string demangle_if_ros_type(
|
||||||
|
const std::string& dds_type_string);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Demangle topic name for a given topic if it is part of one;
|
||||||
|
* otherwise, return empty.
|
||||||
|
* @param topic_name Topic to be demangled.
|
||||||
|
* @returns The demangled topic name.
|
||||||
|
*/
|
||||||
|
static std::string demangle_ros_topic_from_topic(
|
||||||
|
const std::string& topic_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Demangle the service name for a given topic if it is part of a service;
|
||||||
|
* otherwise, return empty.
|
||||||
|
* @param topic_name Topic to be demangled.
|
||||||
|
* @returns The demangled service name.
|
||||||
|
*/
|
||||||
|
|
||||||
|
static std::string demangle_service_from_topic(
|
||||||
|
const std::string& topic_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Demangle the service name for a given topic if it is part
|
||||||
|
* of a service request; otherwise, return empty.
|
||||||
|
* @param topic_name Topic to be demangled.
|
||||||
|
* @returns The demangled service request name.
|
||||||
|
*/
|
||||||
|
static std::string demangle_service_request_from_topic(
|
||||||
|
const std::string& topic_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Demangle the service name for a given topic if it is part
|
||||||
|
* of a service reply; otherwise, return empty.
|
||||||
|
* @param topic_name Topic to be demangled.
|
||||||
|
* @returns The demangled service reply name.
|
||||||
|
*/
|
||||||
|
static std::string demangle_service_reply_from_topic(
|
||||||
|
const std::string& topic_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Demangle the service type name if it is a ROS srv type; otherwise, return empty.
|
||||||
|
* @param dds_type_name Type to be demangled.
|
||||||
|
* @returns The demangled service type.
|
||||||
|
*/
|
||||||
|
static std::string demangle_service_type_only(
|
||||||
|
const std::string& dds_type_name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generic demangle function, used when ROS names are not mangled.
|
||||||
|
* @param name Generic name to be demangled.
|
||||||
|
* @returns The demangled name.
|
||||||
|
*/
|
||||||
|
static std::string identity_demangle(
|
||||||
|
const std::string& name);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
|
||||||
|
#endif // UROS_AGENT_UTILS_DEMANGLE_HPP_
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
from launch import LaunchDescription
|
||||||
|
from launch_ros.actions import Node
|
||||||
|
|
||||||
|
def generate_launch_description():
|
||||||
|
return LaunchDescription([
|
||||||
|
Node(
|
||||||
|
package='micro_ros_agent',
|
||||||
|
executable='micro_ros_agent',
|
||||||
|
name='micro_ros_agent',
|
||||||
|
arguments=["udp4", "-p", "8888", "-v6"]
|
||||||
|
)
|
||||||
|
])
|
||||||
+14
-15
@@ -2,29 +2,28 @@
|
|||||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
||||||
<package format="3">
|
<package format="3">
|
||||||
<name>micro_ros_agent</name>
|
<name>micro_ros_agent</name>
|
||||||
<version>0.0.1</version>
|
<version>5.0.20</version>
|
||||||
<description>DDS-XCRE agent implementation </description>
|
<description>micro-ROS Agent package</description>
|
||||||
<maintainer email="borjaouterelo@eprosima.com">Borja Outerelo</maintainer>
|
<maintainer email="pablogarrido@eprosima.com">Pablo Garrido</maintainer>
|
||||||
|
<maintainer email="antoniocuadros@eprosima.com">Antonio Cuadros</maintainer>
|
||||||
<license>Apache License 2.0</license>
|
<license>Apache License 2.0</license>
|
||||||
|
|
||||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
<buildtool_depend>ament_cmake</buildtool_depend>
|
||||||
<buildtool_export_depend>ament_cmake</buildtool_export_depend>
|
|
||||||
|
|
||||||
<exec_depend>rosidl_parser</exec_depend>
|
<test_depend>rosidl_default_generators</test_depend>
|
||||||
|
|
||||||
<depend>fastcdr</depend>
|
|
||||||
<depend>fastrtps</depend>
|
|
||||||
<depend>microxrcedds_agent_cmake_module</depend>
|
|
||||||
<depend>rosidl_cmake</depend>
|
|
||||||
|
|
||||||
<build_depend>rclcpp</build_depend>
|
|
||||||
|
|
||||||
<exec_depend>rclcpp</exec_depend>
|
|
||||||
|
|
||||||
<test_depend>ament_lint_auto</test_depend>
|
<test_depend>ament_lint_auto</test_depend>
|
||||||
<test_depend>ament_lint_common</test_depend>
|
<test_depend>ament_lint_common</test_depend>
|
||||||
|
|
||||||
<group_depend>rosidl_interface_packages</group_depend>
|
<depend>rmw</depend>
|
||||||
|
<depend>rcutils</depend>
|
||||||
|
<depend>rmw_fastrtps_shared_cpp</depend>
|
||||||
|
<depend>rmw_dds_common</depend>
|
||||||
|
<depend>micro_ros_msgs</depend>
|
||||||
|
|
||||||
|
<test_depend>rosidl_typesupport_fastrtps_cpp</test_depend>
|
||||||
|
<test_depend>ament_cmake_gtest</test_depend>
|
||||||
|
<test_depend>builtin_interfaces</test_depend>
|
||||||
|
|
||||||
<export>
|
<export>
|
||||||
<build_type>ament_cmake</build_type>
|
<build_type>ament_cmake</build_type>
|
||||||
|
|||||||
@@ -0,0 +1,313 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef _UROS_AGENT_AGENT_CPP
|
||||||
|
#define _UROS_AGENT_AGENT_CPP
|
||||||
|
|
||||||
|
#include <agent/Agent.hpp>
|
||||||
|
|
||||||
|
#include <utility>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
|
||||||
|
Agent::Agent()
|
||||||
|
: xrce_dds_agent_instance_(xrce_dds_agent_instance_.getInstance())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Agent::create(
|
||||||
|
int argc,
|
||||||
|
char** argv)
|
||||||
|
{
|
||||||
|
bool result = xrce_dds_agent_instance_.create(argc, argv);
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Add CREATE_PARTICIPANT callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *)> on_create_participant
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
graph_manager_->add_participant(participant);
|
||||||
|
});
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::CREATE_PARTICIPANT,
|
||||||
|
std::move(on_create_participant));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add REMOVE_PARTICIPANT callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *)> on_delete_participant
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
graph_manager_->remove_participant(participant);
|
||||||
|
});
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::DELETE_PARTICIPANT,
|
||||||
|
std::move(on_delete_participant));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add CREATE_DATAWRITER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataWriter *)> on_create_datawriter
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
graph_manager_->add_datawriter(datawriter->guid(), participant, datawriter);
|
||||||
|
graph_manager_->associate_entity(
|
||||||
|
datawriter->guid(), participant, dds::xrce::OBJK_DATAWRITER);
|
||||||
|
});
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::CREATE_DATAWRITER,
|
||||||
|
std::move(on_create_datawriter));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add DELETE_DATAWRITER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataWriter *)> on_delete_datawriter
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter) -> void
|
||||||
|
{
|
||||||
|
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
graph_manager_->remove_datawriter(datawriter->guid());
|
||||||
|
});
|
||||||
|
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::DELETE_DATAWRITER,
|
||||||
|
std::move(on_delete_datawriter));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add CREATE_DATAREADER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataReader*)> on_create_datareader
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataReader* datareader) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||||
|
const eprosima::fastdds::rtps::InstanceHandle_t instance_handle =
|
||||||
|
datareader->get_instance_handle();
|
||||||
|
const eprosima::fastdds::rtps::GUID_t datareader_guid =
|
||||||
|
eprosima::fastdds::rtps::iHandle2GUID(instance_handle);
|
||||||
|
graph_manager_->add_datareader(datareader_guid, participant, datareader);
|
||||||
|
graph_manager_->associate_entity(
|
||||||
|
datareader_guid, participant, dds::xrce::OBJK_DATAREADER);
|
||||||
|
});
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::CREATE_DATAREADER,
|
||||||
|
std::move(on_create_datareader));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add DELETE_DATAREADER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataReader *)> on_delete_datareader
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataReader* datareader) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
// TODO(jamoralp): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||||
|
const eprosima::fastdds::rtps::InstanceHandle_t instance_handle =
|
||||||
|
datareader->get_instance_handle();
|
||||||
|
const eprosima::fastdds::rtps::GUID_t datareader_guid =
|
||||||
|
eprosima::fastdds::rtps::iHandle2GUID(instance_handle);
|
||||||
|
graph_manager_->remove_datareader(datareader_guid);
|
||||||
|
});
|
||||||
|
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::DELETE_DATAREADER,
|
||||||
|
std::move(on_delete_datareader));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add CREATE_REQUESTER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataWriter *,
|
||||||
|
const eprosima::fastdds::dds::DataReader *)> on_create_requester
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter,
|
||||||
|
const eprosima::fastdds::dds::DataReader * datareader) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
graph_manager_->add_datawriter(datawriter->guid(), participant, datawriter);
|
||||||
|
graph_manager_->associate_entity(
|
||||||
|
datawriter->guid(), participant, dds::xrce::OBJK_DATAWRITER);
|
||||||
|
|
||||||
|
// TODO(pablogs): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||||
|
const eprosima::fastdds::rtps::InstanceHandle_t instance_handle =
|
||||||
|
datareader->get_instance_handle();
|
||||||
|
const eprosima::fastdds::rtps::GUID_t datareader_guid =
|
||||||
|
eprosima::fastdds::rtps::iHandle2GUID(instance_handle);
|
||||||
|
graph_manager_->add_datareader(datareader_guid, participant, datareader);
|
||||||
|
graph_manager_->associate_entity(
|
||||||
|
datareader_guid, participant, dds::xrce::OBJK_DATAREADER);
|
||||||
|
});
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::CREATE_REQUESTER,
|
||||||
|
std::move(on_create_requester));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add DELETE_REQUESTER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataWriter *,
|
||||||
|
const eprosima::fastdds::dds::DataReader *)> on_delete_requester
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter,
|
||||||
|
const eprosima::fastdds::dds::DataReader * datareader) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
graph_manager_->remove_datawriter(datawriter->guid());
|
||||||
|
|
||||||
|
// TODO(pablogs): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||||
|
const eprosima::fastdds::rtps::InstanceHandle_t instance_handle =
|
||||||
|
datareader->get_instance_handle();
|
||||||
|
const eprosima::fastdds::rtps::GUID_t datareader_guid =
|
||||||
|
eprosima::fastdds::rtps::iHandle2GUID(instance_handle);
|
||||||
|
graph_manager_->remove_datareader(datareader_guid);
|
||||||
|
});
|
||||||
|
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::DELETE_REQUESTER,
|
||||||
|
std::move(on_delete_requester));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add CREATE_REPLIER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataWriter *,
|
||||||
|
const eprosima::fastdds::dds::DataReader *)> on_create_replier
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter,
|
||||||
|
const eprosima::fastdds::dds::DataReader * datareader) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
graph_manager_->add_datawriter(datawriter->guid(), participant, datawriter);
|
||||||
|
graph_manager_->associate_entity(
|
||||||
|
datawriter->guid(), participant, dds::xrce::OBJK_DATAWRITER);
|
||||||
|
|
||||||
|
// TODO(pablogs): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||||
|
const eprosima::fastdds::rtps::InstanceHandle_t instance_handle =
|
||||||
|
datareader->get_instance_handle();
|
||||||
|
const eprosima::fastdds::rtps::GUID_t datareader_guid =
|
||||||
|
eprosima::fastdds::rtps::iHandle2GUID(instance_handle);
|
||||||
|
graph_manager_->add_datareader(datareader_guid, participant, datareader);
|
||||||
|
graph_manager_->associate_entity(
|
||||||
|
datareader_guid, participant, dds::xrce::OBJK_DATAREADER);
|
||||||
|
});
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::CREATE_REPLIER,
|
||||||
|
std::move(on_create_replier));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add DELETE_REPLIER callback.
|
||||||
|
*/
|
||||||
|
std::function<void (
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant *,
|
||||||
|
const eprosima::fastdds::dds::DataWriter *,
|
||||||
|
const eprosima::fastdds::dds::DataReader *)> on_delete_replier
|
||||||
|
([&](
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter,
|
||||||
|
const eprosima::fastdds::dds::DataReader * datareader) -> void
|
||||||
|
{
|
||||||
|
auto graph_manager_ = find_or_create_graph_manager(participant->get_domain_id());
|
||||||
|
|
||||||
|
graph_manager_->remove_datawriter(datawriter->guid());
|
||||||
|
|
||||||
|
// TODO(pablogs): Workaround for Fast-DDS bug #9977. Remove when fixed
|
||||||
|
const eprosima::fastdds::rtps::InstanceHandle_t instance_handle =
|
||||||
|
datareader->get_instance_handle();
|
||||||
|
const eprosima::fastdds::rtps::GUID_t datareader_guid =
|
||||||
|
eprosima::fastdds::rtps::iHandle2GUID(instance_handle);
|
||||||
|
graph_manager_->remove_datareader(datareader_guid);
|
||||||
|
});
|
||||||
|
|
||||||
|
xrce_dds_agent_instance_.add_middleware_callback(
|
||||||
|
eprosima::uxr::Middleware::Kind::FASTDDS,
|
||||||
|
eprosima::uxr::middleware::CallbackKind::DELETE_REPLIER,
|
||||||
|
std::move(on_delete_replier));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Agent::run()
|
||||||
|
{
|
||||||
|
return xrce_dds_agent_instance_.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<graph_manager::GraphManager> Agent::find_or_create_graph_manager(eprosima::fastdds::dds::DomainId_t domain_id)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto it = graph_manager_map_.find(domain_id);
|
||||||
|
|
||||||
|
if (it != graph_manager_map_.end()) {
|
||||||
|
return it->second;
|
||||||
|
}else{
|
||||||
|
return graph_manager_map_.insert(
|
||||||
|
std::make_pair(
|
||||||
|
domain_id,
|
||||||
|
std::make_shared<graph_manager::GraphManager>(domain_id)
|
||||||
|
)
|
||||||
|
).first->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
#endif // _UROS_AGENT_AGENT_CPP
|
||||||
@@ -0,0 +1,797 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef _UROS_AGENT_GRAPH_MANAGER_CPP
|
||||||
|
#define _UROS_AGENT_GRAPH_MANAGER_CPP
|
||||||
|
|
||||||
|
#include <agent/graph_manager/graph_manager.hpp>
|
||||||
|
#include <fastdds/dds/core/detail/DDSReturnCode.hpp>
|
||||||
|
#include <fastdds/rtps/participant/ParticipantDiscoveryInfo.hpp>
|
||||||
|
#include <fastdds/rtps/reader/ReaderDiscoveryStatus.hpp>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
namespace graph_manager {
|
||||||
|
|
||||||
|
GraphManager::GraphManager(eprosima::fastdds::dds::DomainId_t domain_id)
|
||||||
|
: domain_id_(domain_id)
|
||||||
|
, graph_changed_(false)
|
||||||
|
, display_on_change_(false)
|
||||||
|
, mtx_()
|
||||||
|
, cv_()
|
||||||
|
, graphCache_()
|
||||||
|
, participant_listener_(std::make_unique<ParticipantListener>(this))
|
||||||
|
, datareader_listener_(std::make_unique<DatareaderListener>(this))
|
||||||
|
, participant_info_typesupport_(std::make_unique<
|
||||||
|
eprosima::fastdds::dds::TypeSupport>(new graph_manager::ParticipantEntitiesInfoTypeSupport()))
|
||||||
|
, microros_graph_info_typesupport_(std::make_unique<
|
||||||
|
eprosima::fastdds::dds::TypeSupport>(new graph_manager::MicrorosGraphInfoTypeSupport()))
|
||||||
|
{
|
||||||
|
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->load_profiles();
|
||||||
|
|
||||||
|
// Create DomainParticipant
|
||||||
|
eprosima::fastdds::dds::DomainParticipantQos participant_qos =
|
||||||
|
eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->get_default_participant_qos();
|
||||||
|
|
||||||
|
const char * enclave = "/";
|
||||||
|
size_t length = snprintf(nullptr, 0, "enclave=%s;", enclave) + 1;
|
||||||
|
participant_qos.user_data().resize(length);
|
||||||
|
snprintf(reinterpret_cast<char *>(participant_qos.user_data().data_vec().data()),
|
||||||
|
length, "enclave=%s;", enclave);
|
||||||
|
|
||||||
|
participant_qos.name(enclave);
|
||||||
|
participant_qos.wire_protocol().builtin.readerHistoryMemoryPolicy =
|
||||||
|
eprosima::fastdds::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
|
||||||
|
participant_qos.wire_protocol().builtin.writerHistoryMemoryPolicy =
|
||||||
|
eprosima::fastdds::rtps::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
|
||||||
|
|
||||||
|
eprosima::fastdds::dds::StatusMask par_mask = eprosima::fastdds::dds::StatusMask::none();
|
||||||
|
participant_.reset(eprosima::fastdds::dds::DomainParticipantFactory::get_instance()->
|
||||||
|
create_participant(domain_id_, participant_qos, participant_listener_.get(), par_mask));
|
||||||
|
|
||||||
|
// Register participant within typesupport
|
||||||
|
participant_->register_type(*participant_info_typesupport_);
|
||||||
|
participant_->register_type(*microros_graph_info_typesupport_);
|
||||||
|
|
||||||
|
// Create publisher
|
||||||
|
publisher_.reset(participant_->create_publisher(
|
||||||
|
eprosima::fastdds::dds::PUBLISHER_QOS_DEFAULT));
|
||||||
|
|
||||||
|
// Create subscriber
|
||||||
|
subscriber_.reset(participant_->create_subscriber(
|
||||||
|
eprosima::fastdds::dds::SUBSCRIBER_QOS_DEFAULT));
|
||||||
|
|
||||||
|
// Create topics
|
||||||
|
ros_discovery_topic_.reset(participant_->create_topic("ros_discovery_info",
|
||||||
|
participant_info_typesupport_->get_type_name(),
|
||||||
|
eprosima::fastdds::dds::TOPIC_QOS_DEFAULT));
|
||||||
|
|
||||||
|
ros_to_microros_graph_topic_.reset(participant_->create_topic("ros_to_microros_graph",
|
||||||
|
microros_graph_info_typesupport_->get_type_name(),
|
||||||
|
eprosima::fastdds::dds::TOPIC_QOS_DEFAULT));
|
||||||
|
|
||||||
|
// Create datawriters
|
||||||
|
datawriter_qos_ =
|
||||||
|
eprosima::fastdds::dds::DATAWRITER_QOS_DEFAULT;
|
||||||
|
|
||||||
|
datawriter_qos_.history().kind =
|
||||||
|
eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
|
||||||
|
datawriter_qos_.history().depth = 1;
|
||||||
|
datawriter_qos_.endpoint().history_memory_policy =
|
||||||
|
eprosima::fastdds::rtps::MemoryManagementPolicy::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
|
||||||
|
datawriter_qos_.publish_mode().kind =
|
||||||
|
eprosima::fastdds::dds::PublishModeQosPolicyKind::ASYNCHRONOUS_PUBLISH_MODE;
|
||||||
|
datawriter_qos_.reliability().kind =
|
||||||
|
eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
|
||||||
|
datawriter_qos_.durability().kind =
|
||||||
|
eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
|
||||||
|
|
||||||
|
eprosima::fastdds::dds::DataWriterQos ros_to_microros_datawriter_qos_ = datawriter_qos_;
|
||||||
|
ros_to_microros_datawriter_qos_.history().kind =
|
||||||
|
eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
|
||||||
|
ros_to_microros_graph_datawriter_.reset(
|
||||||
|
publisher_->create_datawriter(ros_to_microros_graph_topic_.get(), ros_to_microros_datawriter_qos_));
|
||||||
|
|
||||||
|
// Create datareaders
|
||||||
|
|
||||||
|
eprosima::fastdds::dds::DataReaderQos datareader_qos =
|
||||||
|
eprosima::fastdds::dds::DATAREADER_QOS_DEFAULT;
|
||||||
|
datareader_qos.history().kind =
|
||||||
|
eprosima::fastdds::dds::HistoryQosPolicyKind::KEEP_LAST_HISTORY_QOS;
|
||||||
|
datareader_qos.history().depth = 1;
|
||||||
|
datareader_qos.endpoint().history_memory_policy =
|
||||||
|
eprosima::fastdds::rtps::MemoryManagementPolicy::PREALLOCATED_WITH_REALLOC_MEMORY_MODE;
|
||||||
|
datareader_qos.reliability().kind =
|
||||||
|
eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS;
|
||||||
|
datareader_qos.durability().kind =
|
||||||
|
eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS;
|
||||||
|
|
||||||
|
ros_discovery_datareader_.reset(
|
||||||
|
subscriber_->create_datareader(ros_discovery_topic_.get(),
|
||||||
|
datareader_qos, datareader_listener_.get()));
|
||||||
|
|
||||||
|
// Set graph cache on change callback function
|
||||||
|
graphCache_.set_on_change_callback([this]()
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(this->mtx_);
|
||||||
|
this->graph_changed_ = true;
|
||||||
|
}
|
||||||
|
this->cv_.notify_one();
|
||||||
|
});
|
||||||
|
|
||||||
|
microros_graph_publisher_ = std::thread(&GraphManager::publish_microros_graph, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void GraphManager::publish_microros_graph()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lock(mtx_);
|
||||||
|
cv_.wait(lock, [this]()
|
||||||
|
{
|
||||||
|
return this->graph_changed_;
|
||||||
|
});
|
||||||
|
graph_changed_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (display_on_change_)
|
||||||
|
{
|
||||||
|
std::cout << "Updated uros Graph: graph changed" << std::endl;
|
||||||
|
std::cout << graphCache_ << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
micro_ros_msgs::msg::Graph graph_message;
|
||||||
|
|
||||||
|
rcutils_string_array_t node_names = rcutils_get_zero_initialized_string_array();
|
||||||
|
rcutils_string_array_t node_namespaces = rcutils_get_zero_initialized_string_array();
|
||||||
|
rcutils_allocator_t allocator = rcutils_get_default_allocator();
|
||||||
|
|
||||||
|
graphCache_.get_node_names(&node_names, &node_namespaces, nullptr, &allocator);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < node_names.size; ++i)
|
||||||
|
{
|
||||||
|
const std::string node_name(node_names.data[i]);
|
||||||
|
const std::string node_namespace(node_namespaces.data[i]);
|
||||||
|
|
||||||
|
micro_ros_msgs::msg::Node node_message;
|
||||||
|
node_message.node_namespace = std::move(node_namespace);
|
||||||
|
node_message.node_name = std::move(node_name);
|
||||||
|
|
||||||
|
// Get publishers info
|
||||||
|
rmw_names_and_types_t writer_names_and_types =
|
||||||
|
rmw_get_zero_initialized_names_and_types();
|
||||||
|
if (RMW_RET_OK != graphCache_.get_writer_names_and_types_by_node(node_name, node_namespace,
|
||||||
|
uros::agent::utils::Demangle::demangle_ros_topic_from_topic,
|
||||||
|
uros::agent::utils::Demangle::demangle_if_ros_type,
|
||||||
|
&allocator, &writer_names_and_types))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < writer_names_and_types.names.size; ++i)
|
||||||
|
{
|
||||||
|
micro_ros_msgs::msg::Entity entity_message;
|
||||||
|
entity_message.entity_type = micro_ros_msgs::msg::Entity::PUBLISHER;
|
||||||
|
entity_message.name = std::move(std::string(writer_names_and_types.names.data[i]));
|
||||||
|
|
||||||
|
for (size_t j = 0; j < writer_names_and_types.types[i].size; ++j)
|
||||||
|
{
|
||||||
|
entity_message.types.emplace_back(writer_names_and_types.types[i].data[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
node_message.entities.emplace_back(std::move(entity_message));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get subscribers info
|
||||||
|
rmw_names_and_types_t reader_names_and_types =
|
||||||
|
rmw_get_zero_initialized_names_and_types();
|
||||||
|
if (RMW_RET_OK != graphCache_.get_reader_names_and_types_by_node(node_name, node_namespace,
|
||||||
|
uros::agent::utils::Demangle::demangle_ros_topic_from_topic,
|
||||||
|
uros::agent::utils::Demangle::demangle_if_ros_type,
|
||||||
|
&allocator, &reader_names_and_types))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < reader_names_and_types.names.size; ++i)
|
||||||
|
{
|
||||||
|
micro_ros_msgs::msg::Entity entity_message;
|
||||||
|
entity_message.entity_type = micro_ros_msgs::msg::Entity::SUBSCRIBER;
|
||||||
|
entity_message.name = std::move(std::string(reader_names_and_types.names.data[i]));
|
||||||
|
|
||||||
|
for (size_t j = 0; j < reader_names_and_types.types[i].size; ++j)
|
||||||
|
{
|
||||||
|
entity_message.types.emplace_back(reader_names_and_types.types[i].data[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
node_message.entities.emplace_back(std::move(entity_message));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get services
|
||||||
|
//// Get servers
|
||||||
|
rmw_names_and_types_t service_server_names_and_types =
|
||||||
|
rmw_get_zero_initialized_names_and_types();
|
||||||
|
if (RMW_RET_OK != graphCache_.get_names_and_types(
|
||||||
|
uros::agent::utils::Demangle::demangle_service_request_from_topic,
|
||||||
|
uros::agent::utils::Demangle::demangle_service_type_only,
|
||||||
|
&allocator, &service_server_names_and_types))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < service_server_names_and_types.names.size; ++i)
|
||||||
|
{
|
||||||
|
micro_ros_msgs::msg::Entity entity_message;
|
||||||
|
entity_message.entity_type = micro_ros_msgs::msg::Entity::SERVICE_SERVER;
|
||||||
|
entity_message.name = std::move(std::string(service_server_names_and_types.names.data[i]));
|
||||||
|
|
||||||
|
for (size_t j = 0; j < service_server_names_and_types.types[i].size; ++j)
|
||||||
|
{
|
||||||
|
entity_message.types.emplace_back(service_server_names_and_types.types[i].data[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
node_message.entities.emplace_back(std::move(entity_message));
|
||||||
|
}
|
||||||
|
|
||||||
|
//// Get clients
|
||||||
|
rmw_names_and_types_t service_client_names_and_types =
|
||||||
|
rmw_get_zero_initialized_names_and_types();
|
||||||
|
if (RMW_RET_OK != graphCache_.get_names_and_types(
|
||||||
|
uros::agent::utils::Demangle::demangle_service_reply_from_topic,
|
||||||
|
uros::agent::utils::Demangle::demangle_service_type_only,
|
||||||
|
&allocator, &service_client_names_and_types))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < service_client_names_and_types.names.size; ++i)
|
||||||
|
{
|
||||||
|
micro_ros_msgs::msg::Entity entity_message;
|
||||||
|
entity_message.entity_type = micro_ros_msgs::msg::Entity::SERVICE_CLIENT;
|
||||||
|
entity_message.name = std::move(std::string(service_client_names_and_types.names.data[i]));
|
||||||
|
|
||||||
|
for (size_t j = 0; j < service_client_names_and_types.types[i].size; ++j)
|
||||||
|
{
|
||||||
|
entity_message.types.emplace_back(service_client_names_and_types.types[i].data[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
node_message.entities.emplace_back(std::move(entity_message));
|
||||||
|
}
|
||||||
|
|
||||||
|
graph_message.nodes.emplace_back(std::move(node_message));
|
||||||
|
|
||||||
|
if (RMW_RET_OK != rmw_names_and_types_fini(&writer_names_and_types) ||
|
||||||
|
RMW_RET_OK != rmw_names_and_types_fini(&reader_names_and_types) ||
|
||||||
|
RMW_RET_OK != rmw_names_and_types_fini(&service_server_names_and_types) ||
|
||||||
|
RMW_RET_OK != rmw_names_and_types_fini(&service_client_names_and_types))
|
||||||
|
{
|
||||||
|
std::cerr << "Problem while freeing resources in Micro-ROS Graph Manager"
|
||||||
|
<< ", file: '" << __FILE__ << "', line: '" << __LINE__ << "'." << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ros_to_microros_graph_datawriter_->write(static_cast<void *>(&graph_message));
|
||||||
|
|
||||||
|
if (RCUTILS_RET_OK != rcutils_string_array_fini(&node_names) ||
|
||||||
|
RCUTILS_RET_OK != rcutils_string_array_fini(&node_namespaces))
|
||||||
|
{
|
||||||
|
std::cerr << "Problem while freeing resources in Micro-ROS Graph Manager"
|
||||||
|
<< ", file: '" << __FILE__ << "', line: '" << __LINE__ << "'." << std::endl;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::add_participant(
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
bool from_microros,
|
||||||
|
const std::string& enclave)
|
||||||
|
{
|
||||||
|
const eprosima::fastdds::dds::DomainParticipantQos qos = participant->get_qos();
|
||||||
|
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", participant->guid());
|
||||||
|
|
||||||
|
graphCache_.add_participant(gid, enclave);
|
||||||
|
|
||||||
|
// Do not add root node and
|
||||||
|
// do not announce non-micro-ROS participants
|
||||||
|
if (qos.name().to_string() != "/" && from_microros)
|
||||||
|
{
|
||||||
|
std::string isolated_node_name, isolated_namespace;
|
||||||
|
get_name_and_namespace(qos.name().to_string(), isolated_node_name, isolated_namespace);
|
||||||
|
|
||||||
|
rmw_dds_common::msg::ParticipantEntitiesInfo info =
|
||||||
|
graphCache_.add_node(gid, isolated_node_name, isolated_namespace);
|
||||||
|
|
||||||
|
auto it = micro_ros_graph_datawriters_.find(participant);
|
||||||
|
if (it == micro_ros_graph_datawriters_.end())
|
||||||
|
{
|
||||||
|
// Create datawriter
|
||||||
|
eprosima::fastdds::dds::DataWriter * datawriter = publisher_->create_datawriter(ros_discovery_topic_.get(), datawriter_qos_);
|
||||||
|
|
||||||
|
it = micro_ros_graph_datawriters_.insert(
|
||||||
|
std::make_pair(participant, datawriter)).first;
|
||||||
|
}
|
||||||
|
|
||||||
|
it->second->write(static_cast<void *>(&info));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::remove_participant(
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
bool from_microros)
|
||||||
|
{
|
||||||
|
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", participant->guid());
|
||||||
|
graphCache_.remove_participant(gid);
|
||||||
|
|
||||||
|
if (from_microros)
|
||||||
|
{
|
||||||
|
rmw_dds_common::msg::ParticipantEntitiesInfo info;
|
||||||
|
rmw_dds_common::convert_gid_to_msg(&gid, &info.gid);
|
||||||
|
auto it = micro_ros_graph_datawriters_.find(participant);
|
||||||
|
it->second->write(static_cast<void *>(&info));
|
||||||
|
publisher_->delete_datawriter(it->second);
|
||||||
|
micro_ros_graph_datawriters_.erase(participant);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::add_datawriter(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datawriter_guid,
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataWriter* datawriter)
|
||||||
|
{
|
||||||
|
const std::string& topic_name = datawriter->get_topic()->get_name();
|
||||||
|
const std::string& type_name = datawriter->get_topic()->get_type_name();
|
||||||
|
this->add_datawriter(datawriter_guid, topic_name, type_name,
|
||||||
|
participant->guid(), datawriter->get_qos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::add_datawriter(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datawriter_guid,
|
||||||
|
const std::string& topic_name,
|
||||||
|
const std::string& type_name,
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& participant_guid,
|
||||||
|
const eprosima::fastdds::dds::DataWriterQos& writer_qos)
|
||||||
|
{
|
||||||
|
const rmw_gid_t datawriter_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", datawriter_guid);
|
||||||
|
const rmw_gid_t participant_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", participant_guid);
|
||||||
|
const rmw_qos_profile_t qos_profile = fastdds_qos_to_rmw_qos(writer_qos);
|
||||||
|
|
||||||
|
graphCache_.add_entity(datawriter_gid, topic_name, type_name,
|
||||||
|
rosidl_get_zero_initialized_type_hash(), participant_gid, qos_profile, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::remove_datawriter(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datawriter_guid)
|
||||||
|
{
|
||||||
|
const rmw_gid_t datawriter_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", datawriter_guid);
|
||||||
|
|
||||||
|
graphCache_.remove_entity(datawriter_gid, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::add_datareader(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datareader_guid,
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const eprosima::fastdds::dds::DataReader* datareader)
|
||||||
|
{
|
||||||
|
const std::string& topic_name = datareader->get_topicdescription()->get_name();
|
||||||
|
const std::string& type_name = datareader->get_topicdescription()->get_type_name();
|
||||||
|
this->add_datareader(datareader_guid, topic_name, type_name,
|
||||||
|
participant->guid(), datareader->get_qos());
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::add_datareader(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datareader_guid,
|
||||||
|
const std::string& topic_name,
|
||||||
|
const std::string& type_name,
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& participant_guid,
|
||||||
|
const eprosima::fastdds::dds::DataReaderQos& reader_qos)
|
||||||
|
{
|
||||||
|
const rmw_gid_t datareader_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", datareader_guid);
|
||||||
|
const rmw_gid_t participant_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", participant_guid);
|
||||||
|
const rmw_qos_profile_t qos_profile = fastdds_qos_to_rmw_qos(reader_qos);
|
||||||
|
|
||||||
|
// TODO(acuadros95): Use typesupport to calculate type hash on micro-ROS and save and get it from reader_qos.user_data.
|
||||||
|
// Related PRs:
|
||||||
|
// https://github.com/ros2/rmw_dds_common/pull/70
|
||||||
|
// https://github.com/ros2/rmw_fastrtps/pull/671
|
||||||
|
// https://github.com/ros2/rmw_fastrtps/pull/680
|
||||||
|
graphCache_.add_entity(datareader_gid, topic_name, type_name,
|
||||||
|
rosidl_get_zero_initialized_type_hash(), participant_gid, qos_profile, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::remove_datareader(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& datareader_guid)
|
||||||
|
{
|
||||||
|
const rmw_gid_t datareader_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", datareader_guid);
|
||||||
|
|
||||||
|
graphCache_.remove_entity(datareader_gid, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::associate_entity(
|
||||||
|
const eprosima::fastdds::rtps::GUID_t& entity_guid,
|
||||||
|
const eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
const dds::xrce::ObjectKind& entity_kind)
|
||||||
|
{
|
||||||
|
const rmw_gid_t entity_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", entity_guid);
|
||||||
|
const rmw_gid_t participant_gid = rmw_fastrtps_shared_cpp::create_rmw_gid(
|
||||||
|
"rmw_fastrtps_cpp", participant->guid());
|
||||||
|
|
||||||
|
eprosima::fastdds::dds::DomainParticipantQos qos = participant->get_qos();
|
||||||
|
rmw_dds_common::msg::ParticipantEntitiesInfo info;
|
||||||
|
|
||||||
|
switch (entity_kind)
|
||||||
|
{
|
||||||
|
case dds::xrce::OBJK_DATAWRITER:
|
||||||
|
{
|
||||||
|
std::string isolated_node_name, isolated_namespace;
|
||||||
|
get_name_and_namespace(qos.name().c_str(), isolated_node_name, isolated_namespace);
|
||||||
|
info = graphCache_.associate_writer(
|
||||||
|
entity_gid, participant_gid, isolated_node_name, isolated_namespace);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case dds::xrce::OBJK_DATAREADER:
|
||||||
|
{
|
||||||
|
std::string isolated_node_name, isolated_namespace;
|
||||||
|
get_name_and_namespace(qos.name().c_str(), isolated_node_name, isolated_namespace);
|
||||||
|
info = graphCache_.associate_reader(
|
||||||
|
entity_gid, participant_gid, isolated_node_name, isolated_namespace);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = micro_ros_graph_datawriters_.find(participant);
|
||||||
|
it->second->write(static_cast<void *>(&info));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename FastDDSQos>
|
||||||
|
const rmw_qos_profile_t GraphManager::fastdds_qos_to_rmw_qos(
|
||||||
|
const FastDDSQos& fastdds_qos)
|
||||||
|
{
|
||||||
|
rmw_qos_profile_t rmw_qos = rmw_qos_profile_unknown;
|
||||||
|
switch (fastdds_qos.reliability().kind)
|
||||||
|
{
|
||||||
|
case eprosima::fastdds::dds::ReliabilityQosPolicyKind::BEST_EFFORT_RELIABILITY_QOS:
|
||||||
|
{
|
||||||
|
rmw_qos.reliability = RMW_QOS_POLICY_RELIABILITY_BEST_EFFORT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case eprosima::fastdds::dds::ReliabilityQosPolicyKind::RELIABLE_RELIABILITY_QOS:
|
||||||
|
{
|
||||||
|
rmw_qos.reliability = RMW_QOS_POLICY_RELIABILITY_RELIABLE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
rmw_qos.reliability = RMW_QOS_POLICY_RELIABILITY_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (fastdds_qos.durability().kind)
|
||||||
|
{
|
||||||
|
case eprosima::fastdds::dds::DurabilityQosPolicyKind::TRANSIENT_LOCAL_DURABILITY_QOS:
|
||||||
|
{
|
||||||
|
rmw_qos.durability = RMW_QOS_POLICY_DURABILITY_TRANSIENT_LOCAL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case eprosima::fastdds::dds::DurabilityQosPolicyKind::VOLATILE_DURABILITY_QOS:
|
||||||
|
{
|
||||||
|
rmw_qos.durability = RMW_QOS_POLICY_DURABILITY_VOLATILE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
rmw_qos.durability = RMW_QOS_POLICY_DURABILITY_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rmw_qos.deadline.sec = fastdds_qos.deadline().period.seconds;
|
||||||
|
rmw_qos.deadline.nsec = fastdds_qos.deadline().period.nanosec;
|
||||||
|
|
||||||
|
rmw_qos.lifespan.sec = fastdds_qos.lifespan().duration.seconds;
|
||||||
|
rmw_qos.lifespan.nsec = fastdds_qos.lifespan().duration.nanosec;
|
||||||
|
|
||||||
|
switch (fastdds_qos.liveliness().kind)
|
||||||
|
{
|
||||||
|
case eprosima::fastdds::dds::LivelinessQosPolicyKind::AUTOMATIC_LIVELINESS_QOS:
|
||||||
|
{
|
||||||
|
rmw_qos.liveliness = RMW_QOS_POLICY_LIVELINESS_AUTOMATIC;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case eprosima::fastdds::dds::LivelinessQosPolicyKind::MANUAL_BY_TOPIC_LIVELINESS_QOS:
|
||||||
|
{
|
||||||
|
rmw_qos.liveliness = RMW_QOS_POLICY_LIVELINESS_MANUAL_BY_TOPIC;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
rmw_qos.liveliness = RMW_QOS_POLICY_LIVELINESS_UNKNOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rmw_qos.liveliness_lease_duration.sec = fastdds_qos.liveliness().lease_duration.seconds;
|
||||||
|
rmw_qos.liveliness_lease_duration.nsec = fastdds_qos.liveliness().lease_duration.nanosec;
|
||||||
|
|
||||||
|
return rmw_qos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::update_node_entities_info()
|
||||||
|
{
|
||||||
|
rmw_dds_common::msg::ParticipantEntitiesInfo entities_info;
|
||||||
|
eprosima::fastdds::dds::SampleInfo sample_info;
|
||||||
|
if (ros_discovery_datareader_->take_next_sample(&entities_info, &sample_info) ==
|
||||||
|
eprosima::fastdds::dds::RETCODE_OK)
|
||||||
|
{
|
||||||
|
if (sample_info.instance_state == eprosima::fastdds::dds::InstanceStateKind::ALIVE_INSTANCE_STATE)
|
||||||
|
{
|
||||||
|
graphCache_.update_participant_entities(entities_info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::get_name_and_namespace(
|
||||||
|
std::string participant_name,
|
||||||
|
std::string& node_name,
|
||||||
|
std::string& node_namespace)
|
||||||
|
{
|
||||||
|
// Remove first / if exists
|
||||||
|
if (participant_name.rfind("/", 0) == 0)
|
||||||
|
{
|
||||||
|
participant_name.erase(participant_name.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split node name in domain and node name
|
||||||
|
std::istringstream iss(participant_name);
|
||||||
|
std::vector<std::string> result;
|
||||||
|
std::string token;
|
||||||
|
|
||||||
|
while(std::getline(iss, token, '/'))
|
||||||
|
{
|
||||||
|
result.push_back(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.size() > 1)
|
||||||
|
{
|
||||||
|
node_namespace = "/" + result[0];
|
||||||
|
for (size_t i = 1; i < result.size(); i++)
|
||||||
|
{
|
||||||
|
node_name.append(result[i] + "/");
|
||||||
|
}
|
||||||
|
node_name.pop_back();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node_name = participant_name;
|
||||||
|
node_namespace = "/";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphManager::ParticipantListener::ParticipantListener(
|
||||||
|
GraphManager* graph_manager)
|
||||||
|
: eprosima::fastdds::dds::DomainParticipantListener()
|
||||||
|
, graphManager_from_(graph_manager)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::ParticipantListener::on_participant_discovery(
|
||||||
|
eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
eprosima::fastdds::rtps::ParticipantDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::dds::ParticipantBuiltinTopicData& info,
|
||||||
|
bool& should_be_ignored)
|
||||||
|
{
|
||||||
|
static_cast<void>(participant);
|
||||||
|
static_cast<void>(should_be_ignored);
|
||||||
|
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DISCOVERED_PARTICIPANT:
|
||||||
|
{
|
||||||
|
auto map = rmw::impl::cpp::parse_key_value(info.user_data);
|
||||||
|
auto name_found = map.find("enclave");
|
||||||
|
|
||||||
|
if (map.end() == name_found)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const std::string enclave =
|
||||||
|
std::string(name_found->second.begin(), name_found->second.end());
|
||||||
|
|
||||||
|
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.guid);
|
||||||
|
graphManager_from_->get_graph_cache().add_participant(gid, enclave);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case eprosima::fastdds::rtps::ParticipantDiscoveryStatus::REMOVED_PARTICIPANT:
|
||||||
|
case eprosima::fastdds::rtps::ParticipantDiscoveryStatus::DROPPED_PARTICIPANT:
|
||||||
|
{
|
||||||
|
const rmw_gid_t gid = rmw_fastrtps_shared_cpp::create_rmw_gid("rmw_fastrtps_cpp", info.guid);
|
||||||
|
graphManager_from_->get_graph_cache().remove_participant(gid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static eprosima::fastdds::dds::DataWriterQos writer_qos_conversion(
|
||||||
|
const eprosima::fastdds::dds::PublicationBuiltinTopicData& writer_info)
|
||||||
|
{
|
||||||
|
eprosima::fastdds::dds::DataWriterQos datawriter_qos;
|
||||||
|
eprosima::fastdds::dds::RTPSReliableWriterQos reliable_writer_qos;
|
||||||
|
reliable_writer_qos.disable_positive_acks = writer_info.disable_positive_acks;
|
||||||
|
|
||||||
|
datawriter_qos.durability(writer_info.durability);
|
||||||
|
datawriter_qos.durability_service(writer_info.durability_service);
|
||||||
|
datawriter_qos.deadline(writer_info.deadline);
|
||||||
|
datawriter_qos.latency_budget(writer_info.latency_budget);
|
||||||
|
datawriter_qos.liveliness(writer_info.liveliness);
|
||||||
|
datawriter_qos.reliability(writer_info.reliability);
|
||||||
|
datawriter_qos.lifespan(writer_info.lifespan);
|
||||||
|
datawriter_qos.user_data(writer_info.user_data);
|
||||||
|
datawriter_qos.ownership(writer_info.ownership);
|
||||||
|
datawriter_qos.ownership_strength(writer_info.ownership_strength);
|
||||||
|
datawriter_qos.destination_order(writer_info.destination_order);
|
||||||
|
datawriter_qos.reliable_writer_qos(reliable_writer_qos);
|
||||||
|
datawriter_qos.representation(writer_info.representation);
|
||||||
|
datawriter_qos.data_sharing(writer_info.data_sharing);
|
||||||
|
|
||||||
|
return datawriter_qos;
|
||||||
|
}
|
||||||
|
|
||||||
|
static eprosima::fastdds::dds::DataReaderQos reader_qos_conversion(
|
||||||
|
const eprosima::fastdds::rtps::SubscriptionBuiltinTopicData& reader_info)
|
||||||
|
{
|
||||||
|
eprosima::fastdds::dds::DataReaderQos datareader_qos;
|
||||||
|
eprosima::fastdds::dds::RTPSReliableReaderQos reliable_reader_qos;
|
||||||
|
reliable_reader_qos.disable_positive_acks = reader_info.disable_positive_acks;
|
||||||
|
|
||||||
|
datareader_qos.durability(reader_info.durability);
|
||||||
|
datareader_qos.deadline(reader_info.deadline);
|
||||||
|
datareader_qos.latency_budget(reader_info.latency_budget);
|
||||||
|
datareader_qos.lifespan(reader_info.lifespan);
|
||||||
|
datareader_qos.liveliness(reader_info.liveliness);
|
||||||
|
datareader_qos.reliability(reader_info.reliability);
|
||||||
|
datareader_qos.ownership(reader_info.ownership);
|
||||||
|
datareader_qos.destination_order(reader_info.destination_order);
|
||||||
|
datareader_qos.user_data(reader_info.user_data);
|
||||||
|
datareader_qos.time_based_filter(reader_info.time_based_filter);
|
||||||
|
datareader_qos.type_consistency(reader_info.type_consistency);
|
||||||
|
datareader_qos.reliable_reader_qos(reliable_reader_qos);
|
||||||
|
datareader_qos.representation(reader_info.representation);
|
||||||
|
datareader_qos.data_sharing(reader_info.data_sharing);
|
||||||
|
|
||||||
|
return datareader_qos;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void GraphManager::ParticipantListener::process_discovery_info<eprosima::fastdds::rtps::ReaderDiscoveryStatus, eprosima::fastdds::rtps::SubscriptionBuiltinTopicData>(
|
||||||
|
eprosima::fastdds::rtps::ReaderDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::rtps::SubscriptionBuiltinTopicData& reader_info)
|
||||||
|
{
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case eprosima::fastdds::rtps::ReaderDiscoveryStatus::CHANGED_QOS_READER:
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case eprosima::fastdds::rtps::ReaderDiscoveryStatus::DISCOVERED_READER:
|
||||||
|
{
|
||||||
|
const std::string topic_name = reader_info.topic_name.to_string();
|
||||||
|
const std::string type_name = reader_info.type_name.to_string();
|
||||||
|
|
||||||
|
graphManager_from_->add_datareader(reader_info.guid, topic_name, type_name,
|
||||||
|
reader_info.participant_guid, reader_qos_conversion(reader_info));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
graphManager_from_->remove_datareader(reader_info.guid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
void GraphManager::ParticipantListener::process_discovery_info<eprosima::fastdds::rtps::WriterDiscoveryStatus, eprosima::fastdds::rtps::PublicationBuiltinTopicData>(
|
||||||
|
eprosima::fastdds::rtps::WriterDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::rtps::PublicationBuiltinTopicData& writer_info)
|
||||||
|
{
|
||||||
|
switch (reason)
|
||||||
|
{
|
||||||
|
case eprosima::fastdds::rtps::WriterDiscoveryStatus::CHANGED_QOS_WRITER:
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case eprosima::fastdds::rtps::WriterDiscoveryStatus::DISCOVERED_WRITER:
|
||||||
|
{
|
||||||
|
const std::string topic_name = writer_info.topic_name.to_string();
|
||||||
|
const std::string type_name = writer_info.type_name.to_string();
|
||||||
|
|
||||||
|
graphManager_from_->add_datawriter(writer_info.guid, topic_name, type_name,
|
||||||
|
writer_info.participant_guid, writer_qos_conversion(writer_info));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
graphManager_from_->remove_datawriter(writer_info.guid);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::ParticipantListener::on_data_reader_discovery(
|
||||||
|
eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
eprosima::fastdds::rtps::ReaderDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::dds::SubscriptionBuiltinTopicData& info,
|
||||||
|
bool& should_be_ignored)
|
||||||
|
{
|
||||||
|
static_cast<void>(participant);
|
||||||
|
static_cast<void>(should_be_ignored);
|
||||||
|
|
||||||
|
process_discovery_info<eprosima::fastdds::rtps::ReaderDiscoveryStatus, eprosima::fastdds::rtps::SubscriptionBuiltinTopicData>(reason, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::ParticipantListener::on_data_writer_discovery(
|
||||||
|
eprosima::fastdds::dds::DomainParticipant* participant,
|
||||||
|
eprosima::fastdds::rtps::WriterDiscoveryStatus reason,
|
||||||
|
const eprosima::fastdds::dds::PublicationBuiltinTopicData& info,
|
||||||
|
bool& should_be_ignored)
|
||||||
|
{
|
||||||
|
static_cast<void>(participant);
|
||||||
|
static_cast<void>(should_be_ignored);
|
||||||
|
|
||||||
|
process_discovery_info<eprosima::fastdds::rtps::WriterDiscoveryStatus, eprosima::fastdds::rtps::PublicationBuiltinTopicData>(reason, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphManager::DatareaderListener::DatareaderListener(
|
||||||
|
GraphManager* graph_manager)
|
||||||
|
: eprosima::fastdds::dds::DataReaderListener()
|
||||||
|
, graphManager_from_(graph_manager)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphManager::DatareaderListener::on_data_available(
|
||||||
|
eprosima::fastdds::dds::DataReader* /*sub*/)
|
||||||
|
{
|
||||||
|
graphManager_from_->update_node_entities_info();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace graph_manager
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
|
||||||
|
#endif // _UROS_AGENT_GRAPH_MANAGER_CPP
|
||||||
@@ -0,0 +1,241 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_CPP_
|
||||||
|
#define UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_CPP_
|
||||||
|
|
||||||
|
#include <agent/graph_manager/graph_typesupport.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
namespace graph_manager {
|
||||||
|
|
||||||
|
ParticipantEntitiesInfoTypeSupport::ParticipantEntitiesInfoTypeSupport()
|
||||||
|
: TopicDataType()
|
||||||
|
{
|
||||||
|
type_support_ = rosidl_typesupport_cpp::get_message_type_support_handle<
|
||||||
|
rmw_dds_common::msg::ParticipantEntitiesInfo>();
|
||||||
|
type_support_ = get_message_typesupport_handle(type_support_,
|
||||||
|
"rosidl_typesupport_fastrtps_cpp");
|
||||||
|
callbacks_ = static_cast<const message_type_support_callbacks_t *>(type_support_->data);
|
||||||
|
|
||||||
|
std::ostringstream ss;
|
||||||
|
const std::string message_namespace(callbacks_->message_namespace_);
|
||||||
|
const std::string message_name(callbacks_->message_name_);
|
||||||
|
|
||||||
|
if (!message_namespace.empty())
|
||||||
|
{
|
||||||
|
ss << message_namespace << "::";
|
||||||
|
}
|
||||||
|
ss << "dds_::" << message_name << "_";
|
||||||
|
this->set_name(ss.str().c_str());
|
||||||
|
|
||||||
|
char full_bounded;
|
||||||
|
max_serialized_type_size = 4 + callbacks_->max_serialized_size(full_bounded);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParticipantEntitiesInfoTypeSupport::serialize(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation)
|
||||||
|
{
|
||||||
|
static_cast<void>(data_representation);
|
||||||
|
|
||||||
|
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char *>(payload.data),
|
||||||
|
payload.max_size);
|
||||||
|
eprosima::fastcdr::Cdr scdr(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
|
||||||
|
eprosima::fastcdr::DDS_CDR);
|
||||||
|
|
||||||
|
scdr.serialize_encapsulation();
|
||||||
|
if (callbacks_->cdr_serialize(data, scdr))
|
||||||
|
{
|
||||||
|
payload.encapsulation = (scdr.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS) ?
|
||||||
|
CDR_BE : CDR_LE;
|
||||||
|
payload.length = static_cast<uint32_t>(scdr.get_serialized_data_length());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParticipantEntitiesInfoTypeSupport::deserialize(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
void * data)
|
||||||
|
{
|
||||||
|
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char *>(payload.data),
|
||||||
|
payload.length);
|
||||||
|
eprosima::fastcdr::Cdr dcdr(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
|
||||||
|
eprosima::fastcdr::DDS_CDR);
|
||||||
|
|
||||||
|
dcdr.read_encapsulation();
|
||||||
|
return callbacks_->cdr_deserialize(dcdr, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ParticipantEntitiesInfoTypeSupport::calculate_serialized_size(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation)
|
||||||
|
{
|
||||||
|
static_cast<void>(data_representation);
|
||||||
|
|
||||||
|
return static_cast<uint32_t>(4 + callbacks_->get_serialized_size(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void * ParticipantEntitiesInfoTypeSupport::create_data()
|
||||||
|
{
|
||||||
|
return static_cast<void *>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ParticipantEntitiesInfoTypeSupport::delete_data(
|
||||||
|
void * data)
|
||||||
|
{
|
||||||
|
(void) data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParticipantEntitiesInfoTypeSupport::compute_key(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
|
||||||
|
bool force_md5 /* = false */)
|
||||||
|
{
|
||||||
|
(void) payload;
|
||||||
|
(void) ihandle;
|
||||||
|
(void) force_md5;
|
||||||
|
return is_compute_key_provided;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ParticipantEntitiesInfoTypeSupport::compute_key(
|
||||||
|
const void * const data,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& handle,
|
||||||
|
bool force_md5 /* = false */)
|
||||||
|
{
|
||||||
|
(void) data;
|
||||||
|
(void) handle;
|
||||||
|
(void) force_md5;
|
||||||
|
return is_compute_key_provided;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
MicrorosGraphInfoTypeSupport::MicrorosGraphInfoTypeSupport()
|
||||||
|
: TopicDataType()
|
||||||
|
{
|
||||||
|
type_support_ = rosidl_typesupport_cpp::get_message_type_support_handle<
|
||||||
|
micro_ros_msgs::msg::Graph>();
|
||||||
|
type_support_ = get_message_typesupport_handle(type_support_,
|
||||||
|
"rosidl_typesupport_fastrtps_cpp");
|
||||||
|
callbacks_ = static_cast<const message_type_support_callbacks_t *>(type_support_->data);
|
||||||
|
|
||||||
|
std::ostringstream ss;
|
||||||
|
const std::string message_namespace(callbacks_->message_namespace_);
|
||||||
|
const std::string message_name(callbacks_->message_name_);
|
||||||
|
|
||||||
|
if (!message_namespace.empty())
|
||||||
|
{
|
||||||
|
ss << message_namespace << "::";
|
||||||
|
}
|
||||||
|
ss << "dds_::" << message_name << "_";
|
||||||
|
this->set_name(ss.str().c_str());
|
||||||
|
|
||||||
|
char full_bounded;
|
||||||
|
max_serialized_type_size = 4 + callbacks_->max_serialized_size(full_bounded);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MicrorosGraphInfoTypeSupport::serialize(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation)
|
||||||
|
{
|
||||||
|
static_cast<void>(data_representation);
|
||||||
|
|
||||||
|
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char *>(payload.data),
|
||||||
|
payload.max_size);
|
||||||
|
eprosima::fastcdr::Cdr scdr(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
|
||||||
|
eprosima::fastcdr::DDS_CDR);
|
||||||
|
|
||||||
|
scdr.serialize_encapsulation();
|
||||||
|
if (callbacks_->cdr_serialize(data, scdr))
|
||||||
|
{
|
||||||
|
payload.encapsulation = (scdr.endianness() == eprosima::fastcdr::Cdr::BIG_ENDIANNESS) ?
|
||||||
|
CDR_BE : CDR_LE;
|
||||||
|
payload.length = static_cast<uint32_t>(scdr.get_serialized_data_length());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MicrorosGraphInfoTypeSupport::deserialize(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
void* data)
|
||||||
|
{
|
||||||
|
eprosima::fastcdr::FastBuffer fastbuffer(reinterpret_cast<char *>(payload.data),
|
||||||
|
payload.length);
|
||||||
|
eprosima::fastcdr::Cdr dcdr(fastbuffer, eprosima::fastcdr::Cdr::DEFAULT_ENDIAN,
|
||||||
|
eprosima::fastcdr::DDS_CDR);
|
||||||
|
|
||||||
|
dcdr.read_encapsulation();
|
||||||
|
return callbacks_->cdr_deserialize(dcdr, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t MicrorosGraphInfoTypeSupport::calculate_serialized_size(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::dds::DataRepresentationId_t data_representation)
|
||||||
|
{
|
||||||
|
static_cast<void>(data_representation);
|
||||||
|
|
||||||
|
return static_cast<uint32_t>(4 + callbacks_->get_serialized_size(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
void * MicrorosGraphInfoTypeSupport::create_data()
|
||||||
|
{
|
||||||
|
return static_cast<void *>(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MicrorosGraphInfoTypeSupport::delete_data(
|
||||||
|
void * data)
|
||||||
|
{
|
||||||
|
(void) data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MicrorosGraphInfoTypeSupport::compute_key(
|
||||||
|
eprosima::fastdds::rtps::SerializedPayload_t& payload,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
|
||||||
|
bool force_md5 /* = false */)
|
||||||
|
{
|
||||||
|
(void) payload;
|
||||||
|
(void) ihandle;
|
||||||
|
(void) force_md5;
|
||||||
|
return is_compute_key_provided;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MicrorosGraphInfoTypeSupport::compute_key(
|
||||||
|
const void* const data,
|
||||||
|
eprosima::fastdds::rtps::InstanceHandle_t& ihandle,
|
||||||
|
bool force_md5 /* = false */)
|
||||||
|
{
|
||||||
|
(void) data;
|
||||||
|
(void) ihandle;
|
||||||
|
(void) force_md5;
|
||||||
|
return is_compute_key_provided;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace graph_manager
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
|
||||||
|
#endif // UROS_AGENT_GRAPH_PARTICIPANTS_TYPESUPPORT_CPP_
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
// Copyright 2020 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
#ifndef UROS_AGENT_UTILS_DEMANGLE_CPP_
|
||||||
|
#define UROS_AGENT_UTILS_DEMANGLE_CPP_
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <rcpputils/find_and_replace.hpp>
|
||||||
|
#include <rcutils/logging_macros.h>
|
||||||
|
#include <rcutils/types.h>
|
||||||
|
|
||||||
|
#include <rmw_fastrtps_shared_cpp/namespace_prefix.hpp>
|
||||||
|
|
||||||
|
#include <agent/utils/demangle.hpp>
|
||||||
|
|
||||||
|
namespace uros {
|
||||||
|
namespace agent {
|
||||||
|
namespace utils {
|
||||||
|
|
||||||
|
std::string Demangle::demangle_if_ros_topic(
|
||||||
|
const std::string& topic_name)
|
||||||
|
{
|
||||||
|
return _strip_ros_prefix_if_exists(topic_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::demangle_if_ros_type(
|
||||||
|
const std::string& dds_type_string)
|
||||||
|
{
|
||||||
|
if ('_' != dds_type_string[dds_type_string.size() - 1])
|
||||||
|
{
|
||||||
|
// not a ROS type
|
||||||
|
return dds_type_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string dds_prefix("dds_::");
|
||||||
|
size_t dds_prefix_pos = dds_type_string.find(dds_prefix);
|
||||||
|
if (std::string::npos == dds_prefix_pos)
|
||||||
|
{
|
||||||
|
// not a ROS type
|
||||||
|
return dds_type_string;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string type_namespace = dds_type_string.substr(0, dds_prefix_pos);
|
||||||
|
type_namespace = rcpputils::find_and_replace(type_namespace, "::", "/");
|
||||||
|
size_t start = dds_prefix_pos + dds_prefix.size();
|
||||||
|
const std::string type_name =
|
||||||
|
dds_type_string.substr(start, dds_type_string.length() - start - 1);
|
||||||
|
return type_namespace + type_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::demangle_ros_topic_from_topic(
|
||||||
|
const std::string& topic_name)
|
||||||
|
{
|
||||||
|
return _resolve_prefix(topic_name, ros_topic_prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::_demangle_service_from_topic(
|
||||||
|
const std::string& prefix,
|
||||||
|
const std::string& topic_name,
|
||||||
|
const std::string& suffix)
|
||||||
|
{
|
||||||
|
const std::string service_name = _resolve_prefix(topic_name, prefix);
|
||||||
|
if (service_name.empty())
|
||||||
|
{
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t suffix_position = service_name.rfind(suffix);
|
||||||
|
if (std::string::npos == suffix_position)
|
||||||
|
{
|
||||||
|
RCUTILS_LOG_WARN_NAMED(
|
||||||
|
"rmw_fastrtps_shared_cpp",
|
||||||
|
"service topic has prefix but no suffix; report this: '%s'",
|
||||||
|
topic_name.c_str());
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (0 != (service_name.length() - suffix_position - suffix.length()))
|
||||||
|
{
|
||||||
|
RCUTILS_LOG_WARN_NAMED(
|
||||||
|
"rmw_fastrtps_shared_cpp",
|
||||||
|
"service topic has service prefix and a suffix"
|
||||||
|
", but not at the end; report this: '%s'",
|
||||||
|
topic_name.c_str());
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return service_name.substr(0, suffix_position);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::demangle_service_from_topic(
|
||||||
|
const std::string& topic_name)
|
||||||
|
{
|
||||||
|
const std::string demangled_topic = demangle_service_reply_from_topic(topic_name);
|
||||||
|
|
||||||
|
if (!demangled_topic.empty())
|
||||||
|
{
|
||||||
|
return demangled_topic;
|
||||||
|
}
|
||||||
|
return demangle_service_request_from_topic(topic_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::demangle_service_request_from_topic(
|
||||||
|
const std::string& topic_name)
|
||||||
|
{
|
||||||
|
return _demangle_service_from_topic(ros_service_requester_prefix, topic_name, "Request");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::demangle_service_reply_from_topic(
|
||||||
|
const std::string& topic_name)
|
||||||
|
{
|
||||||
|
return _demangle_service_from_topic(ros_service_response_prefix, topic_name, "Reply");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::demangle_service_type_only(
|
||||||
|
const std::string& dds_type_name)
|
||||||
|
{
|
||||||
|
const std::string dds_prefix("dds_::");
|
||||||
|
auto suffixes = {std::string("_Response_"), std::string("_Request_")};
|
||||||
|
size_t dds_prefix_pos = dds_type_name.find(dds_prefix);
|
||||||
|
|
||||||
|
// Perform checks
|
||||||
|
if (std::string::npos == dds_prefix_pos)
|
||||||
|
{
|
||||||
|
// not a ROS service type
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t suffix_position = std::string::npos;
|
||||||
|
for (const auto& suffix : suffixes)
|
||||||
|
{
|
||||||
|
suffix_position = dds_type_name.rfind(suffix);
|
||||||
|
if (std::string::npos != suffix_position)
|
||||||
|
{
|
||||||
|
if (0 != (dds_type_name.length() - suffix_position - suffix.length()))
|
||||||
|
{
|
||||||
|
RCUTILS_LOG_WARN_NAMED(
|
||||||
|
"rmw_fastrtps_shared_cpp",
|
||||||
|
"service type contains 'dds_::' and a suffix"
|
||||||
|
", but not at the end; repor this: '%s'",
|
||||||
|
dds_type_name.c_str());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (std::string::npos == suffix_position)
|
||||||
|
{
|
||||||
|
RCUTILS_LOG_WARN_NAMED(
|
||||||
|
"rmw_fastrtps_shared_cpp",
|
||||||
|
"service type contains 'dds_::' but"
|
||||||
|
" does not have a suffix; report this: '%s'",
|
||||||
|
dds_type_name.c_str());
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything is OK. Reformat it from '[type_namespace::]dds_::<type><suffix>'
|
||||||
|
// to '[type_namespace/]<type>'
|
||||||
|
std::string type_namespace = dds_type_name.substr(0, dds_prefix_pos);
|
||||||
|
type_namespace = rcpputils::find_and_replace(type_namespace, "::", "/");
|
||||||
|
size_t start = dds_prefix_pos + dds_prefix.length();
|
||||||
|
const std::string type_name = dds_type_name.substr(start, suffix_position - start);
|
||||||
|
return type_namespace + type_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Demangle::identity_demangle(
|
||||||
|
const std::string& name)
|
||||||
|
{
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace utils
|
||||||
|
} // namespace agent
|
||||||
|
} // namespace uros
|
||||||
|
|
||||||
|
#endif // UROS_AGENT_UTILS_DEMANGLE_CPP_
|
||||||
+54
-198
@@ -1,5 +1,4 @@
|
|||||||
|
// Copyright 2017-present Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
||||||
// Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
@@ -13,225 +12,82 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifdef _WIN32
|
#include <agent/Agent.hpp>
|
||||||
#include <uxr/agent/transport/udp/UDPServerWindows.hpp>
|
|
||||||
#include <uxr/agent/transport/tcp/TCPServerWindows.hpp>
|
|
||||||
|
|
||||||
#elif __unix__
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <libgen.h>
|
|
||||||
|
|
||||||
#include <uxr/agent/transport/serial/SerialServerLinux.hpp>
|
|
||||||
#include <uxr/agent/transport/udp/UDPServerLinux.hpp>
|
|
||||||
#include <uxr/agent/transport/tcp/TCPServerLinux.hpp>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <iterator>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <limits>
|
#include <vector>
|
||||||
#include "rclcpp/rclcpp.hpp"
|
|
||||||
|
|
||||||
void showHelp()
|
|
||||||
{
|
|
||||||
std::cout << "Usage: program <command>" << std::endl;
|
|
||||||
std::cout << "List of commands:" << std::endl;
|
|
||||||
#ifdef _WIN32
|
|
||||||
std::cout << " udp <local_port>" << std::endl;
|
|
||||||
std::cout << " tcp <local_port>" << std::endl;
|
|
||||||
#else
|
|
||||||
std::cout << " serial <device_name>" << std::endl;
|
|
||||||
std::cout << " pseudo-serial" << std::endl;
|
|
||||||
std::cout << " udp <local_port> [<discovery_port>]" << std::endl;
|
|
||||||
std::cout << " tcp <local_port> [<discovery_port>]" << std::endl;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void initializationError()
|
|
||||||
{
|
|
||||||
std::cout << "Error: Invalid arguments." << std::endl;
|
|
||||||
showHelp();
|
|
||||||
std::exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t parsePort(const std::string& str_port)
|
|
||||||
{
|
|
||||||
uint16_t valid_port = 0;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
int port = std::stoi(str_port);
|
|
||||||
if(port > (std::numeric_limits<uint16_t>::max)())
|
|
||||||
{
|
|
||||||
std::cout << "Error: port number '" << port << "out of range." << std::endl;
|
|
||||||
initializationError();
|
|
||||||
}
|
|
||||||
valid_port = uint16_t(port);
|
|
||||||
}
|
|
||||||
catch (const std::invalid_argument& )
|
|
||||||
{
|
|
||||||
initializationError();
|
|
||||||
}
|
|
||||||
return valid_port;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
eprosima::uxr::Server* server = nullptr;
|
uros::agent::Agent micro_ros_agent;
|
||||||
std::vector<std::string> cl(0);
|
|
||||||
|
|
||||||
if (1 == argc)
|
/** Bypass '--ros-args' flag, as we use our own CLI parser.
|
||||||
|
* As a workaround for launch files, arguments will be passed from
|
||||||
|
* ros2launch as a single token with spaces,
|
||||||
|
* to preserve the correct argument order; split it here.
|
||||||
|
* TODO(jamoralp): investigate ROS2 tools for properly parsing params from launch
|
||||||
|
**/
|
||||||
|
std::vector<std::string> params;
|
||||||
|
for (int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
showHelp();
|
if(strcmp("--ros-args", argv[i]) == 0)
|
||||||
std::cout << std::endl;
|
{
|
||||||
std::cout << "Enter command: ";
|
argc = i;
|
||||||
|
break;
|
||||||
std::string raw_cl;
|
|
||||||
std::getline(std::cin, raw_cl);
|
|
||||||
std::istringstream iss(raw_cl);
|
|
||||||
cl.insert(cl.begin(), std::istream_iterator<std::string>(iss), std::istream_iterator<std::string>());
|
|
||||||
std::cout << raw_cl << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int i = 1; i < argc; ++i)
|
|
||||||
{
|
|
||||||
cl.push_back(argv[i]);
|
|
||||||
}
|
}
|
||||||
|
params.emplace_back(std::string(argv[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if((1 == cl.size()) && (("-h" == cl[0]) || ("--help" == cl[0])))
|
auto it = std::find(params.begin(), params.end(), "--ros-args");
|
||||||
|
if (params.end() != it)
|
||||||
{
|
{
|
||||||
showHelp();
|
if ((it - params.begin()) != 2)
|
||||||
}
|
|
||||||
else if((2 <= cl.size()) && ("udp" == cl[0]))
|
|
||||||
{
|
{
|
||||||
std::cout << "UDP agent initialization... ";
|
std::ostringstream ss;
|
||||||
uint16_t port = parsePort(cl[1]);
|
ss << "Error: when using ros2 launch, please specify ";
|
||||||
#ifdef _WIN32
|
ss << "your arguments in a single variable." << std::endl;
|
||||||
server = new eprosima::uxr::UDPServer(port);
|
ss << "Instead of 'arguments: {'udp4', '-p', '8888'}', do ";
|
||||||
#else
|
ss << "'arguments: {'udp4 -p 8888'}" << std::endl;
|
||||||
server = (3 == cl.size()) //discovery port
|
|
||||||
? new eprosima::uxr::UDPServer(port, parsePort(cl[2]))
|
|
||||||
: new eprosima::uxr::UDPServer(port);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else if((2 <= cl.size()) && ("tcp" == cl[0]))
|
|
||||||
{
|
|
||||||
std::cout << "TCP agent initialization... ";
|
|
||||||
uint16_t port = parsePort(cl[1]);
|
|
||||||
#ifdef _WIN32
|
|
||||||
server = new eprosima::uxr::TCPServer(port);
|
|
||||||
#else
|
|
||||||
server = (3 == cl.size()) //discovery port
|
|
||||||
? new eprosima::uxr::TCPServer(port, parsePort(cl[2]))
|
|
||||||
: new eprosima::uxr::TCPServer(port);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#ifndef _WIN32
|
|
||||||
else if((2 == cl.size()) && ("serial" == cl[0]))
|
|
||||||
{
|
|
||||||
std::cout << "Serial agent initialization... ";
|
|
||||||
|
|
||||||
/* Open serial device. */
|
std::cerr << ss.str();
|
||||||
int fd = open(cl[1].c_str(), O_RDWR | O_NOCTTY);
|
return 1;
|
||||||
if (0 < fd)
|
|
||||||
{
|
|
||||||
struct termios tty_config;
|
|
||||||
memset(&tty_config, 0, sizeof(tty_config));
|
|
||||||
if (0 == tcgetattr(fd, &tty_config))
|
|
||||||
{
|
|
||||||
/* Setting CONTROL OPTIONS. */
|
|
||||||
tty_config.c_cflag |= CREAD; // Enable read.
|
|
||||||
tty_config.c_cflag |= CLOCAL; // Set local mode.
|
|
||||||
tty_config.c_cflag &= ~PARENB; // Disable parity.
|
|
||||||
tty_config.c_cflag &= ~CSTOPB; // Set one stop bit.
|
|
||||||
tty_config.c_cflag &= ~CSIZE; // Mask the character size bits.
|
|
||||||
tty_config.c_cflag |= CS8; // Set 8 data bits.
|
|
||||||
tty_config.c_cflag &= ~CRTSCTS; // Disable hardware flow control.
|
|
||||||
|
|
||||||
/* Setting LOCAL OPTIONS. */
|
|
||||||
tty_config.c_lflag &= ~ICANON; // Set non-canonical input.
|
|
||||||
tty_config.c_lflag &= ~ECHO; // Disable echoing of input characters.
|
|
||||||
tty_config.c_lflag &= ~ECHOE; // Disable echoing the erase character.
|
|
||||||
tty_config.c_lflag &= ~ISIG; // Disable SIGINTR, SIGSUSP, SIGDSUSP and SIGQUIT signals.
|
|
||||||
|
|
||||||
/* Setting INPUT OPTIONS. */
|
|
||||||
tty_config.c_iflag &= ~IXON; // Disable output software flow control.
|
|
||||||
tty_config.c_iflag &= ~IXOFF; // Disable input software flow control.
|
|
||||||
tty_config.c_iflag &= ~INPCK; // Disable parity check.
|
|
||||||
tty_config.c_iflag &= ~ISTRIP; // Disable strip parity bits.
|
|
||||||
tty_config.c_iflag &= ~IGNBRK; // No ignore break condition.
|
|
||||||
tty_config.c_iflag &= ~IGNCR; // No ignore carrier return.
|
|
||||||
tty_config.c_iflag &= ~INLCR; // No map NL to CR.
|
|
||||||
tty_config.c_iflag &= ~ICRNL; // No map CR to NL.
|
|
||||||
|
|
||||||
/* Setting OUTPUT OPTIONS. */
|
|
||||||
tty_config.c_oflag &= ~OPOST; // Set raw output.
|
|
||||||
|
|
||||||
/* Setting OUTPUT CHARACTERS. */
|
|
||||||
tty_config.c_cc[VMIN] = 10;
|
|
||||||
tty_config.c_cc[VTIME] = 1;
|
|
||||||
|
|
||||||
/* Setting BAUD RATE. */
|
|
||||||
cfsetispeed(&tty_config, B115200);
|
|
||||||
cfsetospeed(&tty_config, B115200);
|
|
||||||
|
|
||||||
if (0 == tcsetattr(fd, TCSANOW, &tty_config))
|
|
||||||
{
|
|
||||||
server = new eprosima::uxr::SerialServer(fd, 0);
|
|
||||||
}
|
}
|
||||||
}
|
const std::string& agent_args(params.at(1));
|
||||||
}
|
std::istringstream iss(agent_args);
|
||||||
}
|
std::vector<std::string> agent_args_split(
|
||||||
else if ((1 == cl.size()) && ("pseudo-serial" == cl[0]))
|
std::istream_iterator<std::string>{iss},
|
||||||
{
|
std::istream_iterator<std::string>());
|
||||||
std::cout << "Pseudo-Serial initialization... ";
|
|
||||||
|
|
||||||
/* Open pseudo-terminal. */
|
char** agent_argv = new char*[agent_args_split.size() + 1];
|
||||||
char* dev = NULL;
|
agent_argv[0] = argv[0];
|
||||||
int fd = posix_openpt(O_RDWR | O_NOCTTY);
|
char** agent_argv_it = &agent_argv[1];
|
||||||
if (-1 != fd)
|
|
||||||
|
for (const auto& arg : agent_args_split)
|
||||||
{
|
{
|
||||||
if (grantpt(fd) == 0 && unlockpt(fd) == 0 && (dev = ptsname(fd)))
|
*agent_argv_it = new char[arg.length() + 1];
|
||||||
{
|
strcpy(*agent_argv_it, arg.c_str());
|
||||||
struct termios attr;
|
agent_argv_it++;
|
||||||
tcgetattr(fd, &attr);
|
|
||||||
cfmakeraw(&attr);
|
|
||||||
tcflush(fd, TCIOFLUSH);
|
|
||||||
tcsetattr(fd, TCSANOW, &attr);
|
|
||||||
std::cout << "Device: " << dev << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
server = new eprosima::uxr::SerialServer(fd, 0x00);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
else
|
|
||||||
{
|
|
||||||
initializationError();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nullptr != server)
|
bool success = micro_ros_agent.create(agent_args_split.size() + 1, agent_argv);
|
||||||
|
|
||||||
|
for (size_t i = 1; i <= agent_args_split.size(); ++i)
|
||||||
{
|
{
|
||||||
/* Launch server. */
|
delete [] agent_argv[i];
|
||||||
if (server->run())
|
|
||||||
{
|
|
||||||
std::cout << "OK" << std::endl;
|
|
||||||
std::cin.clear();
|
|
||||||
char exit_flag = 0;
|
|
||||||
while ('q' != exit_flag)
|
|
||||||
{
|
|
||||||
std::cout << "Enter 'q' for exit" << std::endl;
|
|
||||||
std::cin >> exit_flag;
|
|
||||||
}
|
}
|
||||||
server->stop();
|
delete [] agent_argv;
|
||||||
}
|
|
||||||
else
|
if (!success)
|
||||||
{
|
{
|
||||||
std::cout << "ERROR" << std::endl;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (!micro_ros_agent.create(argc, argv))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
micro_ros_agent.run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -18,12 +18,12 @@ import xml.etree.ElementTree
|
|||||||
|
|
||||||
from rosidl_cmake import convert_camel_case_to_lower_case_underscore
|
from rosidl_cmake import convert_camel_case_to_lower_case_underscore
|
||||||
from rosidl_cmake import expand_template
|
from rosidl_cmake import expand_template
|
||||||
from rosidl_cmake import extract_message_types
|
|
||||||
from rosidl_cmake import get_newest_modification_time
|
from rosidl_cmake import get_newest_modification_time
|
||||||
from rosidl_parser import parse_message_file
|
from rosidl_adapter.parser import parse_message_file
|
||||||
from rosidl_parser import parse_service_file
|
from rosidl_adapter.parser import parse_service_file
|
||||||
from rosidl_parser import validate_field_types
|
from rosidl_adapter.parser import validate_field_types
|
||||||
|
|
||||||
|
from rosidl_cmake import generate_files
|
||||||
|
|
||||||
def GetPackage(Dir):
|
def GetPackage(Dir):
|
||||||
|
|
||||||
@@ -164,21 +164,20 @@ def generate_XML(args):
|
|||||||
# Generate source file path
|
# Generate source file path
|
||||||
src_file = os.path.join(srcs_dir, "%s_%s_%s.xml" % (spec.base_type.pkg_name, subfolder, spec.msg_name))
|
src_file = os.path.join(srcs_dir, "%s_%s_%s.xml" % (spec.base_type.pkg_name, subfolder, spec.msg_name))
|
||||||
|
|
||||||
|
|
||||||
# Data writer
|
# Data writer
|
||||||
#file_content = " <dds>\n"
|
file_content = " <dds>\n"
|
||||||
file_content = " <data_writer profile_name=\"%s_%s_%s_p\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <data_writer profile_name=\"%s_%s_%s_p\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " <kind>NO_KEY</kind>\n"
|
file_content += " <kind>NO_KEY</kind>\n"
|
||||||
file_content += " <name>%s%s_%s_%s</name>\n" % (ros2_prefix, spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <name>%s%s_%s_%s</name>\n" % (ros2_prefix, spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " </topic>\n"
|
file_content += " </topic>\n"
|
||||||
file_content += " </data_writer>\n"
|
file_content += " </data_writer>\n"
|
||||||
#file_content += " </dds>\n"
|
file_content += " </dds>\n"
|
||||||
|
|
||||||
|
|
||||||
# Data reader
|
# Data reader
|
||||||
#file_content += " <dds>\n"
|
file_content += " <dds>\n"
|
||||||
file_content += " <data_reader profile_name=\"%s_%s_%s_s\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <data_reader profile_name=\"%s_%s_%s_s\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " <kind>NO_KEY</kind>\n"
|
file_content += " <kind>NO_KEY</kind>\n"
|
||||||
@@ -186,16 +185,16 @@ def generate_XML(args):
|
|||||||
file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " </topic>\n"
|
file_content += " </topic>\n"
|
||||||
file_content += " </data_reader>\n"
|
file_content += " </data_reader>\n"
|
||||||
#file_content += " </dds>\n"
|
file_content += " </dds>\n"
|
||||||
|
|
||||||
|
|
||||||
# Topic
|
# Topic
|
||||||
#file_content += " <dds>\n"
|
file_content += " <dds>\n"
|
||||||
file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <topic profile_name=\"%s_%s_%s_t\">\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " <name>%s%s_%s_%s</name>\n" % (ros2_prefix, spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <name>%s%s_%s_%s</name>\n" % (ros2_prefix, spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
file_content += " <dataType>%s::%s::dds_::%s_</dataType>\n" % (spec.base_type.pkg_name, subfolder, spec.msg_name)
|
||||||
file_content += " </topic>\n"
|
file_content += " </topic>\n"
|
||||||
#file_content += " </dds>\n"
|
file_content += " </dds>\n"
|
||||||
|
|
||||||
|
|
||||||
# Write file content
|
# Write file content
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
Changelog for package microxrcedds_agent_cmake_module
|
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
0.0.1 (2019-04-24)
|
|
||||||
------------------
|
|
||||||
* Initial release
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
# Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.5)
|
|
||||||
|
|
||||||
project(microxrcedds_agent_cmake_module)
|
|
||||||
|
|
||||||
find_package(ament_cmake REQUIRED)
|
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
|
||||||
find_package(ament_lint_auto REQUIRED)
|
|
||||||
ament_lint_auto_find_test_dependencies()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ament_package(
|
|
||||||
CONFIG_EXTRAS "microxrcedds_agent_cmake_module-extras.cmake"
|
|
||||||
)
|
|
||||||
|
|
||||||
install(DIRECTORY cmake
|
|
||||||
DESTINATION share/${PROJECT_NAME}
|
|
||||||
)
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
# Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
#
|
|
||||||
# CMake module for finding eProsima MICROXRCEDDS_AGENT.
|
|
||||||
#
|
|
||||||
# Output variables:
|
|
||||||
#
|
|
||||||
# - MicroXRCEDDS_Agent_FOUND: flag indicating if the package was found
|
|
||||||
# - MicroXRCEDDS_Agent_INCLUDE_DIR: Paths to the header files
|
|
||||||
#
|
|
||||||
# Example usage:
|
|
||||||
#
|
|
||||||
# find_package(uros_agent_cmake_module REQUIRED)
|
|
||||||
# find_package(MicroXRCEDDS_Agent MODULE)
|
|
||||||
# # use MicroXRCEDDS_Agent_* variables
|
|
||||||
#
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
# lint_cmake: -convention/filename, -package/stdargs
|
|
||||||
|
|
||||||
set(MicroXRCEDDS_Agent_FOUND FALSE)
|
|
||||||
|
|
||||||
find_package(microxrcedds_agent REQUIRED CONFIG)
|
|
||||||
find_package(fastcdr REQUIRED CONFIG)
|
|
||||||
find_package(fastrtps REQUIRED CONFIG)
|
|
||||||
|
|
||||||
find_path(MicroXRCEDDS_Agent_INCLUDE_DIR NAMES uxr)
|
|
||||||
|
|
||||||
string(REGEX MATCH "^[0-9]+\\.[0-9]+" microxrcedds_agent_MAJOR_MINOR_VERSION "${microxrcedds_agent_VERSION}")
|
|
||||||
string(REGEX MATCH "^[0-9]+\\.[0-9]+" fastcdr_MAJOR_MINOR_VERSION "${fastcdr_VERSION}")
|
|
||||||
string(REGEX MATCH "^[0-9]+\\.[0-9]+" fastrtps_MAJOR_MINOR_VERSION "${fastrtps_VERSION}")
|
|
||||||
|
|
||||||
##
|
|
||||||
find_library(MicroXRCEDDS_Agent_LIBRARY_RELEASE
|
|
||||||
NAMES microxrcedds_agent-${microxrcedds_agent_MAJOR_MINOR_VERSION} microxrcedds_agent)
|
|
||||||
|
|
||||||
find_library(MicroXRCEDDS_Agent_LIBRARY_DEBUG
|
|
||||||
NAMES microxrcedds_agentd-${microxrcedds_agent_MAJOR_MINOR_VERSION} microxrcedds_agentd)
|
|
||||||
|
|
||||||
if(MicroXRCEDDS_Agent_LIBRARY_RELEASE AND MicroXRCEDDS_Agent_LIBRARY_DEBUG)
|
|
||||||
set(MicroXRCEDDS_Agent_LIBRARIES
|
|
||||||
optimized ${MicroXRCEDDS_Agent_LIBRARY_RELEASE}
|
|
||||||
debug ${MicroXRCEDDS_Agent_LIBRARY_DEBUG}
|
|
||||||
)
|
|
||||||
elseif(MicroXRCEDDS_Agent_LIBRARY_RELEASE)
|
|
||||||
set(MicroXRCEDDS_Agent_LIBRARIES
|
|
||||||
${MicroXRCEDDS_Agent_LIBRARY_RELEASE}
|
|
||||||
)
|
|
||||||
elseif(MicroXRCEDDS_Agent_LIBRARY_DEBUG)
|
|
||||||
set(MicroXRCEDDS_Agent_LIBRARIES
|
|
||||||
${MicroXRCEDDS_Agent_LIBRARY_DEBUG}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
set(MicroXRCEDDS_Agent_LIBRARIES "")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
##
|
|
||||||
find_library(FastRTPS_LIBRARY_RELEASE
|
|
||||||
NAMES fastrtps-${fastrtps_MAJOR_MINOR_VERSION} fastrtps)
|
|
||||||
|
|
||||||
find_library(FastRTPS_LIBRARY_DEBUG
|
|
||||||
NAMES fastrtpsd-${fastrtps_MAJOR_MINOR_VERSION} fastrtpsd)
|
|
||||||
|
|
||||||
if(FastRTPS_LIBRARY_RELEASE AND FastRTPS_LIBRARY_DEBUG)
|
|
||||||
set(FastRTPS_LIBRARIES
|
|
||||||
optimized ${FastRTPS_LIBRARY_RELEASE}
|
|
||||||
debug ${FastRTPS_LIBRARY_DEBUG}
|
|
||||||
)
|
|
||||||
elseif(FastRTPS_LIBRARY_RELEASE)
|
|
||||||
set(FastRTPS_LIBRARIES
|
|
||||||
${MicroXRCEDDS_Agent_LIBRARY_RELEASE}
|
|
||||||
)
|
|
||||||
elseif(FastRTPS_LIBRARY_DEBUG)
|
|
||||||
set(FastRTPS_LIBRARIES
|
|
||||||
${MicroXRCEDDS_Agent_LIBRARY_DEBUG}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
set(FastRTPS_LIBRARIES "")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
##
|
|
||||||
find_library(FastCDR_LIBRARY_RELEASE
|
|
||||||
NAMES fastcdr-${fastcdr_MAJOR_MINOR_VERSION} fastcdr)
|
|
||||||
|
|
||||||
find_library(FastCDR_LIBRARY_DEBUG
|
|
||||||
NAMES fastcdrd-${fastcdr_MAJOR_MINOR_VERSION} fastcdrd)
|
|
||||||
|
|
||||||
if(FastCDR_LIBRARY_RELEASE AND FastCDR_LIBRARY_DEBUG)
|
|
||||||
set(FastCDR_LIBRARIES
|
|
||||||
optimized ${FastCDR_LIBRARY_RELEASE}
|
|
||||||
debug ${FastCDR_LIBRARY_DEBUG}
|
|
||||||
)
|
|
||||||
elseif(FastCDR_LIBRARY_RELEASE)
|
|
||||||
set(FastCDR_LIBRARIES
|
|
||||||
${FastCDR_LIBRARY_RELEASE}
|
|
||||||
)
|
|
||||||
elseif(FastCDR_LIBRARY_DEBUG)
|
|
||||||
set(FastCDR_LIBRARIES
|
|
||||||
${FastCDR_LIBRARY_DEBUG}
|
|
||||||
)
|
|
||||||
else()
|
|
||||||
set(FastCDR_LIBRARIES "")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
include(FindPackageHandleStandardArgs)
|
|
||||||
find_package_handle_standard_args(MicroXRCEDDS_Agent
|
|
||||||
FOUND_VAR MicroXRCEDDS_Agent_FOUND
|
|
||||||
REQUIRED_VARS
|
|
||||||
MicroXRCEDDS_Agent_INCLUDE_DIR
|
|
||||||
MicroXRCEDDS_Agent_LIBRARIES
|
|
||||||
)
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# Copyright 2018 Proyectos y Sistemas de Mantenimiento SL (eProsima).
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
list(INSERT CMAKE_MODULE_PATH 0
|
|
||||||
"${microxrcedds_agent_cmake_module_DIR}/Modules")
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
|
||||||
<package format="3">
|
|
||||||
<name>microxrcedds_agent_cmake_module</name>
|
|
||||||
<version>0.0.1</version>
|
|
||||||
<description>Provide CMake module to find eProsima Micro XRCE-DDS Agent</description>
|
|
||||||
<maintainer email="borjaouterelo@eprosima.com">Borja Outerelo</maintainer>
|
|
||||||
<license>Apache License 2.0</license>
|
|
||||||
<author>Borja Outerelo</author>
|
|
||||||
|
|
||||||
<buildtool_depend>ament_cmake</buildtool_depend>
|
|
||||||
|
|
||||||
<test_depend>ament_lint_auto</test_depend>
|
|
||||||
<test_depend>ament_lint_common</test_depend>
|
|
||||||
|
|
||||||
<build_depend>microxrcedds_agent</build_depend>
|
|
||||||
<build_export_depend>microxrcedds_agent</build_export_depend>
|
|
||||||
|
|
||||||
<export>
|
|
||||||
<build_type>ament_cmake</build_type>
|
|
||||||
</export>
|
|
||||||
</package>
|
|
||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# Confirm that the transport is valid
|
||||||
|
transport="$(snapctl get transport)"
|
||||||
|
case "$transport" in
|
||||||
|
udp4) ;;
|
||||||
|
udp6) ;;
|
||||||
|
tcp4) ;;
|
||||||
|
tcp6) ;;
|
||||||
|
serial) ;;
|
||||||
|
pseudoterminal) ;;
|
||||||
|
*)
|
||||||
|
echo "'$transport' is not a supported transport" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Confirm that the middleware is valid
|
||||||
|
middleware="$(snapctl get middleware)"
|
||||||
|
case "$middleware" in
|
||||||
|
dds) ;;
|
||||||
|
rtps) ;;
|
||||||
|
ced) ;;
|
||||||
|
*)
|
||||||
|
echo "'$middleware' is not a supported middleware" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ "$transport" = "serial" ] || [ "$transport" = "pseudoterminal" ]; then
|
||||||
|
# A serial transport if being used, which requires a valid baud rate
|
||||||
|
# as well as a valid device
|
||||||
|
baudrate="$(snapctl get baudrate)"
|
||||||
|
if ! expr "$baudrate" : '^[0-9]\+$' > /dev/null; then
|
||||||
|
echo "'$baudrate' is not a valid baud rate" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
device="$(snapctl get device)"
|
||||||
|
if [ -z "$device" ]; then
|
||||||
|
echo "Device must be specified" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
port="$(snapctl get port)"
|
||||||
|
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then
|
||||||
|
echo "'$port' is not a valid port" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Confirm that discovery is a boolean
|
||||||
|
discovery="$(snapctl get discovery)"
|
||||||
|
case "$discovery" in
|
||||||
|
true)
|
||||||
|
# Confirm that discovery port is valid
|
||||||
|
port="$(snapctl get discovery-port)"
|
||||||
|
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then
|
||||||
|
echo "'$port' is not a valid discovery port" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
false) ;;
|
||||||
|
*)
|
||||||
|
echo "'$discovery' is not a valid boolean for discovery" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Confirm that the verbosity is valid
|
||||||
|
verbosity="$(snapctl get verbosity)"
|
||||||
|
if ! expr "$verbosity" : '^[0-6]$' > /dev/null; then
|
||||||
|
echo "'$verbosity' is not a valid verbosity" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Confirm that p2p port is valid (assuming it's set)
|
||||||
|
p2p_port="$(snapctl get p2p-port)"
|
||||||
|
if [ -n "$p2p_port" ]; then
|
||||||
|
port="$(snapctl get p2p-port)"
|
||||||
|
if ! expr "$port" : '^[0-9]\+$' > /dev/null; then
|
||||||
|
echo "'$port' is not a valid p2p port" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Confirm that daemon is a boolean, and enable the service if true
|
||||||
|
daemon="$(snapctl get daemon)"
|
||||||
|
case "$daemon" in
|
||||||
|
true)
|
||||||
|
snapctl start --enable "$SNAP_INSTANCE_NAME.daemon"
|
||||||
|
|
||||||
|
# In case it was alraedy started and the configuration changed,
|
||||||
|
# restart the service
|
||||||
|
snapctl restart "$SNAP_INSTANCE_NAME.daemon"
|
||||||
|
;;
|
||||||
|
false)
|
||||||
|
snapctl stop --disable "$SNAP_INSTANCE_NAME.daemon"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "'$daemon' is not a valid boolean for daemon" >&2
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
Executable
+19
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
# Set default configuration values
|
||||||
|
snapctl set transport=udp4
|
||||||
|
snapctl set middleware=dds
|
||||||
|
snapctl set verbosity=4
|
||||||
|
snapctl set discovery=false
|
||||||
|
snapctl set discovery-port=7400
|
||||||
|
snapctl set p2p-port! # unset
|
||||||
|
|
||||||
|
# Network-specific things
|
||||||
|
snapctl set port=8888
|
||||||
|
|
||||||
|
# Serial-specific things
|
||||||
|
snapctl set baudrate=115200
|
||||||
|
snapctl set device! # unset
|
||||||
|
|
||||||
|
# By default the daemon is disabled
|
||||||
|
snapctl set daemon=false
|
||||||
Executable
+27
@@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/sh -e
|
||||||
|
|
||||||
|
set -- --middleware "$(snapctl get middleware)" "$@"
|
||||||
|
set -- --verbose "$(snapctl get verbosity)" "$@"
|
||||||
|
|
||||||
|
transport="$(snapctl get transport)"
|
||||||
|
if [ "$transport" = "serial" ] || [ "$transport" = "pseudoterminal" ]; then
|
||||||
|
set -- --dev "$(snapctl get device)" "$@"
|
||||||
|
else
|
||||||
|
set -- --port "$(snapctl get port)" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$(snapctl get discovery)" = "true" ]; then
|
||||||
|
set -- --discovery "$@"
|
||||||
|
|
||||||
|
discovery_port="$(snapctl get discovery-port)"
|
||||||
|
if [ -n "$discovery_port" ]; then
|
||||||
|
set -- --disport "$discovery_port" "$@"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
p2p_port="$(snapctl get p2p-port)"
|
||||||
|
if [ -n "$p2p_port" ]; then
|
||||||
|
set -- --p2p "$p2p_port" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec "$SNAP/lib/micro_ros_agent/micro_ros_agent" "$transport" "$@"
|
||||||
@@ -0,0 +1,168 @@
|
|||||||
|
name: micro-ros-agent
|
||||||
|
base: core20
|
||||||
|
version: git
|
||||||
|
summary: Bridge between Micro ROS client applications and ROS 2
|
||||||
|
description: |
|
||||||
|
Micro-ROS, whose default implementation is based on eProsima's
|
||||||
|
Micro XRCE-DDS middleware, is composed of client applications
|
||||||
|
which interact with the ROS 2 world by means of an Agent.
|
||||||
|
This agent keeps tracks of the entities created by means of
|
||||||
|
requests performed on the microcontroller side, and uses them
|
||||||
|
to communicate with the ROS 2 dataspace.
|
||||||
|
|
||||||
|
Being an extension of the Micro XRCE-DDS Agent, the micro-ROS
|
||||||
|
agent supports being run by the user like this:
|
||||||
|
|
||||||
|
$ micro-ros-agent --help
|
||||||
|
|
||||||
|
In addition, the Agent supports running as a service that can be
|
||||||
|
enabled with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent daemon=true
|
||||||
|
|
||||||
|
If the service is enabled, by default it uses the `udp4` transport on
|
||||||
|
port 8888. The following parameters can be changed (these are
|
||||||
|
specific to the service, the `micro-ros-agent` command simply
|
||||||
|
takes command-line arguments, but the capabilities are the same):
|
||||||
|
|
||||||
|
* `transport`. Supported transports are `udp4`, `udp6`, `tcp4`,
|
||||||
|
`tcp6`, `serial`, and `pseudoterminal`. Default is `udp4`. Change
|
||||||
|
with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent transport="new transport"
|
||||||
|
|
||||||
|
* `middleware`. Supported kinds of middleware are `ced`, `rtps`, and
|
||||||
|
`dds`. Default is `dds`. Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent middleware="new middleware"
|
||||||
|
|
||||||
|
* `verbosity`. Supported verbosity levels are 0-6, defaulting to 4.
|
||||||
|
Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent verbosity="selected verbosity"
|
||||||
|
|
||||||
|
* `discovery`. Enable or disable the discovery server. Defaults to
|
||||||
|
"false". Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent discovery="true or false"
|
||||||
|
|
||||||
|
* `discovery-port`. Port on which the discovery server (see above)
|
||||||
|
listens. Defaults to 7400. Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent discovery-port="selected port"
|
||||||
|
|
||||||
|
* `p2p-port`. Port to use for the P2P profile. Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent p2p-port="selected port"
|
||||||
|
|
||||||
|
* `port`. Port on which the agent listens. Only applicable to one of
|
||||||
|
the UDP or TCP transports (see above). Defaults to 8888. Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent port="selected port"
|
||||||
|
|
||||||
|
* `baudrate`. Baud rate to use when accessing serial ports. Only
|
||||||
|
applicable when using the `serial` or `pseudoterminal` transport.
|
||||||
|
Defaults to 115200. Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent baudrate="baud rate"
|
||||||
|
|
||||||
|
* `device`. The serial device to use. Only applicable when using the
|
||||||
|
`serial` or `pseudoterminal` transport. Change with:
|
||||||
|
|
||||||
|
$ snap set micro-ros-agent device="device path"
|
||||||
|
|
||||||
|
If connecting the micro-ROS Agent using an IP based connection mode,
|
||||||
|
that is, `udp4`, `udp6`, `tcp4` or `tcp6`, care must be taken to
|
||||||
|
connect first the `micro-ros-agent-shm-netplug` plug.
|
||||||
|
This is due to the fact that ROS 2 Foxy is using Fast-DDS as the
|
||||||
|
default DDS middleware, and Fast-DDS comes with *shared memory transport*.
|
||||||
|
Thus, this plugin must be enabled, in order to gain access to the
|
||||||
|
`/dev/shm` folder from the snap image, prior to running it:
|
||||||
|
|
||||||
|
$ sudo snap connect micro-ros-agent:micro-ros-agent-shm-netplug
|
||||||
|
|
||||||
|
When using the snap with a serial device, some steps need to be taken
|
||||||
|
in order to establish a successful connection:
|
||||||
|
|
||||||
|
* Refresh your local installation of the snap `core` package:
|
||||||
|
|
||||||
|
$ sudo snap refresh core --edge
|
||||||
|
|
||||||
|
* Enable the hotplug feature and restart the `snapd` daemon:
|
||||||
|
|
||||||
|
$ sudo snap set core experimental.hotplug=true
|
||||||
|
$ sudo systemctl restart snapd
|
||||||
|
|
||||||
|
* After plugging the microcontroller to the serial port, execute
|
||||||
|
the `snap interface serial-port` command. You should see something
|
||||||
|
like this:
|
||||||
|
|
||||||
|
name: serial-port
|
||||||
|
summary: allows accessing a specific serial port
|
||||||
|
plugs:
|
||||||
|
- micro-ros-agent
|
||||||
|
slots:
|
||||||
|
- snapd:cp2102cp2109uartbrid (allows accessing a specific serial port)
|
||||||
|
|
||||||
|
* Connect your snap image to the desired serial port (replace accordingly):
|
||||||
|
|
||||||
|
$ snap connect micro-ros-agent:serial-port snapd:cp2102cp2109uartbrid
|
||||||
|
|
||||||
|
After this, you can execute your snap as usual,
|
||||||
|
using `sudo micro-ros-agent serial -d <serial-dev>`.
|
||||||
|
|
||||||
|
grade: stable
|
||||||
|
confinement: strict
|
||||||
|
|
||||||
|
architectures:
|
||||||
|
- build-on: amd64
|
||||||
|
- build-on: arm64
|
||||||
|
- build-on: armhf
|
||||||
|
- build-on: ppc64el
|
||||||
|
|
||||||
|
parts:
|
||||||
|
|
||||||
|
uros-agent:
|
||||||
|
plugin: colcon
|
||||||
|
source: .
|
||||||
|
override-build: |
|
||||||
|
set +u
|
||||||
|
git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git -b $ROS_DISTRO
|
||||||
|
git clone https://github.com/eProsima/Micro-CDR.git -b $ROS_DISTRO
|
||||||
|
git clone https://github.com/micro-ROS/micro_ros_msgs.git -b $ROS_DISTRO
|
||||||
|
git clone https://github.com/micro-ROS/rosidl_typesupport_microxrcedds.git -b $ROS_DISTRO
|
||||||
|
git clone https://github.com/micro-ROS/rmw-microxrcedds.git -b $ROS_DISTRO
|
||||||
|
git clone https://github.com/micro-ROS/micro-ROS-Agent.git -b $ROS_DISTRO
|
||||||
|
. /opt/ros/$ROS_DISTRO/setup.sh
|
||||||
|
colcon build --merge-install --install-base $SNAPCRAFT_PRIME --cmake-args "-DUAGENT_BUILD_EXECUTABLE=OFF -DUAGENT_USE_SYSTEM_FASTDDS=ON" --packages-up-to micro_ros_agent
|
||||||
|
set -u
|
||||||
|
build-packages: [make, gcc, g++]
|
||||||
|
stage-packages: [ros-foxy-ros2launch]
|
||||||
|
|
||||||
|
runner:
|
||||||
|
plugin: dump
|
||||||
|
source: snap/local/
|
||||||
|
organize:
|
||||||
|
'*': usr/bin/
|
||||||
|
|
||||||
|
plugs:
|
||||||
|
micro-ros-agent-shm-netplug:
|
||||||
|
interface: system-files
|
||||||
|
allow-auto-connection: true
|
||||||
|
write:
|
||||||
|
- /dev/shm
|
||||||
|
|
||||||
|
apps:
|
||||||
|
micro-ros-agent:
|
||||||
|
command: lib/micro_ros_agent/micro_ros_agent
|
||||||
|
environment:
|
||||||
|
LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SNAP/lib"
|
||||||
|
plugs: [network, network-bind, serial-port, micro-ros-agent-shm-netplug]
|
||||||
|
extensions: [ros2-foxy]
|
||||||
|
|
||||||
|
daemon:
|
||||||
|
command: usr/bin/micro-ros-agent-daemon
|
||||||
|
environment:
|
||||||
|
LD_LIBRARY_PATH: "$LD_LIBRARY_PATH:$SNAP/lib"
|
||||||
|
daemon: simple
|
||||||
|
plugs: [network, network-bind, serial-port, micro-ros-agent-shm-netplug]
|
||||||
Reference in New Issue
Block a user