Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_UROS: factor out common ROS client code #25179

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

srmainwaring
Copy link
Contributor

This is a follow up to #25154 that factors duplicate code from AP_DDS and AP_UROS into a common library AP_ROS.

The functions are templated on the ROS message types because the ROS message interfaces generated for the XRCE-DDS-Client and micro-ROS are not the same. The method names are almost identical so templating allows the reading and writing to the message libraries to be duck-typed with the exception of string and sequences. These are handled by templated accessors with specialisations for the message types that are required (String, TFMessage, BatteryState).

Dependencies

@srmainwaring srmainwaring marked this pull request as draft October 4, 2023 10:48
@srmainwaring srmainwaring requested review from Ryanf55, pedro-fuoco and tridge and removed request for pedro-fuoco October 4, 2023 10:48
@srmainwaring srmainwaring mentioned this pull request Oct 4, 2023
4 tasks
@srmainwaring srmainwaring force-pushed the prs/pr-micro-ros-common-templates branch 3 times, most recently from e918eaa to 3ca6006 Compare October 5, 2023 09:40
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

modules: update ardupliot_uros

- Added mode_switch service interface for esp32
- Added mode_switch service interface for stm32.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
- Add option --enable-uros.
- Add define AP_UROS_ENABLED.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

Tools: ros2: disable DSS in colcon build

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

Tools: ros2: update README

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
AP_UROS: search for micro-ROS client library in ardupilot_uros module

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add vector3 subscriber example

- PoC - will only work for SITL / POSIX (must add use custom transport)

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: move init and create code into respective functions

- Make rcl objects member variables.
- Update checks macros to report to GCS.
- Move rcl initialisation to init().
- Move subscriber creation to create().

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add custom transport

- Adapt UDP custom transport from AP_DDS.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: enable custom transport

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add publisher example

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add publisher example

- Send message to GCS.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: include additional ROS message types

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add time publisher

- Add time publisher.
- Rename node to 'ardupilot_uros'.
- Change timer period to 1 ms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add publishers for local pose and twist

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add publishers for battery, clock, nav sat, static tf

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: clarify number of handles calculation

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: implement topic writers using code from AP_DDS

- Strings and sequence values are not populated as memory must be allocated.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add code for static transform from AP_DDS

- Strings and sequence values are not populated as memory must be allocated.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: manage memory for topic strings and sequences

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: only update nav sat fix on new data to match AP_DDS

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add subscriber to sensor_msgs/msg/Joy

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: remove demo subscriber to geometry_msgs/msg/Vector3

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: update @todo formatting

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add function declarations for Ubuntu build

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: disable tf2_msgs for esp32 dev

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: move global variables into AP_UROS_Client class

- Make singleton.
- Make update_topic member function.
- Add trampoline for thread task.
- Move thread to core 1 and adjust priority.
- Customise initialisation.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: fix initialisation of local twist publisher

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: publish geopose, static_tf, and subscribe to tf

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: use trampoline functions for timer and message callbacks

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add arm motors service

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add parameter server

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add README

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: display parameter changes in GCS

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: implementation of custom serial transport

- Note this is ESP32 specific.
- Requires micro-ROS client library to be built for custom transport.
- UART_NUM_2 not managed by AP_HAL
- Return if publisher or subscriber initialisation fails

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: call uros_port->begin(0) to ensure thread owns port

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: support build for stm32 - disable param server

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: support both esp32 and stm32

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add compile option for param server

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: update macros for debug and error messages

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: fix bug introduced into entity handle count

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: update print format specifier for TF message

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: enable UDP transport for SITL

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: update print format specifier for TF message

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add microros library distro options to wscript

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: fix library paths in wscript

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add stubs for mode switch service

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: implement arming service

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: implement mode switch service

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add stub for velocity control subscriber

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add classes adapted from AP_DDS to manage external control

- Functions are stubs only.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: adapt external control functions to micro-ROS message types

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: enable external odom in uros client

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: update GCS messages for services

- Add UROS: prefix.

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: update README

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: add space after template keyword

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: add accessor templates for strings and a sequence of transforms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: use accessor templates for strings in external control

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: add mutable versions of accessor templates

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: consolidate code for populating published messages

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: consolidate code for publishing nav sat fix

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: rename mutable transforms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: use mutable transforms template for static transforms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: fix formatting

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: add accessor templates for battery state

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_ROS: consolidate code for publishing battery state

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add specialisations for string and sequence accessors

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: adjust indentation

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add mutable versions of accessor templates

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: use common code from AP_ROS for published topics

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: consolidate code for publishing nav sat fix

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: delete code moved to AP_ROS

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: rename mutable transforms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: consolidate code for publishing static transforms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: move template specialisation definitions to cpp to prevent duplicate symbols

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_UROS: add accessor templates for battery state

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: use common code from AP_ROS for external control

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: use common code from AP_ROS for time type conversion

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: add mutable versions of accessor templates

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: use common code from AP_ROS for published topics

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: consolidate code for publishing nav sat fix

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: delete code moved to AP_ROS

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: rename mutable transforms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: consolidate code for publishing static transforms

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: move template specialisation definitions to cpp to prevent duplicate symbols

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: fix formatting

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: add accessor templates for battery state

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>

AP_DDS: consolidate code for publishing battery state

Signed-off-by: Rhys Mainwaring <rhys.mainwaring@me.com>
@srmainwaring srmainwaring force-pushed the prs/pr-micro-ros-common-templates branch from 3ca6006 to 6560d16 Compare October 11, 2023 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🏗 In progress
Development

Successfully merging this pull request may close these issues.

1 participant