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

Dynamic Subscription (REP-2011 subset) #1374

Open
27 of 31 tasks
methylDragon opened this issue Jan 30, 2023 · 16 comments
Open
27 of 31 tasks

Dynamic Subscription (REP-2011 subset) #1374

methylDragon opened this issue Jan 30, 2023 · 16 comments
Assignees

Comments

@methylDragon
Copy link
Contributor

methylDragon commented Jan 30, 2023

Description

This issue describes and lists the relevant PRs that allow subscriptions to receive messages (i.e. DynamicData) with descriptions/types constructed at runtime, and use that type to access fields of those messages without using message-specific compiled structs, as specified in ros-infrastructure/rep#358

Note: This does NOT include:

  • Dynamic publishing: a feature where publishers can publish dynamic messages
    • (static pub -> dynamic sub works. But there is no notion yet of dynamic pub, so no way for dynamic pub -> static/dynamic sub yet.)
  • Service/action support: And also no support for services or actions yet.
  • Support for other middlewares other than FastRTPS

Also, this feature set only supports rmw_fastrtps currently.

Demoing This Feature

The status of this feature development is reflected in https://github.com/methylDragon/ros-type-introspection-prototype

⚠️⚠️⚠️ Take note that the repos file is modified to prevent the building of any middleware implementations other than FastDDS

You MUST not have sourced any other ROS 2 workspace or distros! The presence of any other middleware will trigger the building of rmw implementations, and since new rmw interfaces were defined, this will cause compilation failures.

git clone -b runtime_interface_reflection https://github.com/methylDragon/ros-type-introspection-prototype.git
cd ros-type-introspection-prototype
git submodule update --init --recursive

mkdir -p prototype_ws/src/ros2_repos
cd prototype_ws

vcs import src/ros2_repos < src/ros2.repos

rosdep install --from-paths src -y --ignore-src
source install/setup.bash
colcon build --packages-up-to dynamic_typesupport_examples ros2run

Then in two terminals:

source install/setup.bash
ros2 run dynamic_typesupport_examples static_pub
source install/setup.bash
ros2 run dynamic_typesupport_examples dynamic_sub_serialized

Feature Description

  • A C unified serialization support library for run-time type reflection and construction, and utilities that support it
    • And the associated specific serialization support libraries
    • And C++ wrappers to manage memory for those C types (in rclcpp)
  • A C library for manipulating the runtime type description message structs
  • New rmw interfaces for:
    • Obtaining middleware-specific serialization support
    • Checking if a middleware supports:
      • Runtime type discovery
      • Taking message buffers as runtime type (i.e. DynamicData)
    • A new middleware agnostic runtime type rosidl_message_type_support_t implementation
  • A new DynamicSubscription subscription class that supports a callback that takes dynamic data
    • Should support taking serialized messages and converting them into dynamic data for the callback
    • And also taking dynamic data directly from the middleware
  • Necessary changes in rclcpp to allow the DynamicSubscription to work

Prototype serialization support libraries and implementations of this feature will be made for FastDDS in rmw, rcl, rclcpp, and rmw_fastrtps.

Implementation Considerations

See REP-2011 for the feature specification.
(The REP will have to be updated slightly since the implementation of this feature exposed certain necessary refinements.)

FastDDS was chosen for the prototype implementation because it is currently the default rmw for ROS 2.

Additionally, some other REP-2011 features have barebones/minimal implementations that were created to support this feature. As other subsets of REP-2011 get implemented (e.g. the type description message and its utilities), sections of this feature will need to be swapped out with those implementations, namely:

  • The type description message's C struct and how it is used
  • The usage of type hashing

Relevant PRs

The top level PRs need to be merged and built alongside each other. The demos repo (and setup instructions above) will ensure the proper branches are checked out for the build.

Interim Stubs
These are so we can get in ABI stable backports (to tide us over the freeze)

Stub Impl

TODOs

  • Initial implementation
  • Taking dynamic data directly
  • Minor: Clarify if I should be calling it dynamic_type/dynamic_data or runtime_type/runtime_data
  • type description utils
  • Migrate rosidl_dynamic_typesupport to use type description
  • BONUS: defer construction till build()
  • rclcpp wrappers for dynamic typesupport structs
  • Populate rmw impl virtual methods (so the other rmw implementations can build)
  • Linting (I am deliberately leaving this till last because linting will cause the serialization support library interface and implementation PRs to become prohibitively long)

When this feature is considered more stable:

  • Tests
  • Separate serialization_support_lib (and its associate libraries) out into their own ros2 repositories
  • Update ros2 examples

Additional Waves

Additional notes/issues

const correctness and lifetime management of rosidl_message_type_support_t

The rosidl_message_type_support_t was, in all cases prior to this feature, populated and used as a compile-time static objects.

This feature makes it so that users can generate and populate their own type support structs, which means that they will have to manage its lifetime.

Furthermore, the const void * typesupport implementation of the struct means that runtime mutation of the typesupport implementation is not logically const correct even though it is physically const correct. This is troublesome because mutation of the typesupport is necessary for deferring the getting of dynamic types.

FastDDS Issues

For Posterity

If you want to add new (C compatible) serialization support functionality, follow these steps!

Details
  1. Update the common interface (rosidl_dynamic_typesupport)
    1. Headers
      1. Abstract interface: serialization_support_interface.h
      2. API Caller: The respective header (e.g. dynamic_data.h)
    2. Sources
      1. API Caller: The respective source (e.g. dynamic_data.c)
  2. Update the implementations
    1. Headers:
      1. API Impl: The respective header (e.g. dynamic_data.h)
    2. Sources
      1. Abstract Interface Impl (e.g. serialization_support.cpp)
      2. API Impl: The respective source (e.g. dynamic_data.cpp)
  3. Update the wrappers
    1. For each client library, update the appropriate wrapper class
      1. Headers: e.g. rclcpp: DynamicMessage.h
      2. Source: e.g. rclcpp: DynamicMessage.cpp
@allenh1
Copy link

allenh1 commented Feb 8, 2023

@methylDragon Hey! I was trying to run the demo locally, but I had trouble compiling:

Finished <<< rmw_connextdds_common [4.04s]
Starting >>> rmw_connextdds
Starting >>> rmw_connextddsmicro
Finished <<< rmw_connextdds [5.13s]            
Finished <<< rcl_interfaces [30.8s]            
Finished <<< rmw_connextddsmicro [5.36s]                                     
Finished <<< std_msgs [32.5s]                                                
Starting >>> runtime_type_support_examples_msgs
Finished <<< rmw_fastrtps_shared_cpp [16.3s]                                 
Finished <<< test_msgs [42.0s]                                               
Starting >>> rmw_fastrtps_cpp
Starting >>> rmw_fastrtps_dynamic_cpp         
Finished <<< runtime_type_support_examples_msgs [10.0s]
Finished <<< rmw_fastrtps_cpp [16.3s]                                          
Finished <<< rmw_fastrtps_dynamic_cpp [17.2s]                                
Starting >>> rmw_implementation
Finished <<< rmw_implementation [11.3s]                                
Starting >>> rcl
--- stderr: rcl                                        
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: ../librcl.so: undefined reference to `rmw_get_serialization_support'
collect2: error: ld returned 1 exit status
gmake[2]: *** [test/CMakeFiles/test_rmw_impl_id_check_exe.dir/build.make:138: test/test_rmw_impl_id_check_exe] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:336: test/CMakeFiles/test_rmw_impl_id_check_exe.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< rcl [17.3s, exited with code 2]

Summary: 119 packages finished [4min 52s]
  1 package failed: rcl
  34 packages had stderr output: ament_copyright ament_cppcheck ament_cpplint ament_flake8 ament_index_python ament_lint ament_lint_cmake ament_package ament_pep257 ament_pycodestyle ament_uncrustify ament_xmllint domain_coordinator fastrtps foonathan_memory_vendor google_benchmark_vendor launch launch_testing launch_xml launch_yaml mimick_vendor osrf_pycommon performance_test_fixture rcl rcl_yaml_param_parser rcutils rmw_connextdds_common rmw_cyclonedds_cpp rosidl_cli rosidl_pycommon rosidl_typesupport_c rpyutils rti_connext_dds_cmake_module uncrustify_vendor
  4 packages not processed

Am I missing changes or something?

@methylDragon
Copy link
Contributor Author

methylDragon commented Feb 8, 2023

@methylDragon Hey! I was trying to run the demo locally, but I had trouble compiling:

Finished <<< rmw_connextdds_common [4.04s]
Starting >>> rmw_connextdds
Starting >>> rmw_connextddsmicro
Finished <<< rmw_connextdds [5.13s]            
Finished <<< rcl_interfaces [30.8s]            
Finished <<< rmw_connextddsmicro [5.36s]                                     
Finished <<< std_msgs [32.5s]                                                
Starting >>> runtime_type_support_examples_msgs
Finished <<< rmw_fastrtps_shared_cpp [16.3s]                                 
Finished <<< test_msgs [42.0s]                                               
Starting >>> rmw_fastrtps_cpp
Starting >>> rmw_fastrtps_dynamic_cpp         
Finished <<< runtime_type_support_examples_msgs [10.0s]
Finished <<< rmw_fastrtps_cpp [16.3s]                                          
Finished <<< rmw_fastrtps_dynamic_cpp [17.2s]                                
Starting >>> rmw_implementation
Finished <<< rmw_implementation [11.3s]                                
Starting >>> rcl
--- stderr: rcl                                        
/usr/lib/gcc/x86_64-pc-linux-gnu/12/../../../../x86_64-pc-linux-gnu/bin/ld: ../librcl.so: undefined reference to `rmw_get_serialization_support'
collect2: error: ld returned 1 exit status
gmake[2]: *** [test/CMakeFiles/test_rmw_impl_id_check_exe.dir/build.make:138: test/test_rmw_impl_id_check_exe] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:336: test/CMakeFiles/test_rmw_impl_id_check_exe.dir/all] Error 2
gmake[1]: *** Waiting for unfinished jobs....
gmake: *** [Makefile:146: all] Error 2
---
Failed   <<< rcl [17.3s, exited with code 2]

Summary: 119 packages finished [4min 52s]
  1 package failed: rcl
  34 packages had stderr output: ament_copyright ament_cppcheck ament_cpplint ament_flake8 ament_index_python ament_lint ament_lint_cmake ament_package ament_pep257 ament_pycodestyle ament_uncrustify ament_xmllint domain_coordinator fastrtps foonathan_memory_vendor google_benchmark_vendor launch launch_testing launch_xml launch_yaml mimick_vendor osrf_pycommon performance_test_fixture rcl rcl_yaml_param_parser rcutils rmw_connextdds_common rmw_cyclonedds_cpp rosidl_cli rosidl_pycommon rosidl_typesupport_c rpyutils rti_connext_dds_cmake_module uncrustify_vendor
  4 packages not processed

Am I missing changes or something?

Hey @allenh1 ! The examples won't compile if you have the other non-FastDDS middlewares in your workspace. (I see that your colcon is building rmw_cyclonedds without complaints, for example.)

The ros2.repos file I have supplied with the examples should have commented out iceoryx, and cyclone (and omitted connext). Check to make sure you didn't source any other ROS 2 workspaces/bases before compiling and running the commands! (Check your bashrc too!)

@methylDragon
Copy link
Contributor Author

methylDragon commented Feb 8, 2023

Ah, apologies @allenh1 , it turns out that I also missed out pushing a change...

I need to update rmw_implementation. Sorry about that, let me get back to you soon.

EDIT: I've updated it. You can delete your cloned workspace and rerun the same commands, and it should work (remember to ensure that there are no other middlewares available in your workspace other than FastDDS!) 🤞
Sorry again!

@allenh1
Copy link

allenh1 commented Feb 8, 2023

Ah, apologies @allenh1 , it turns out that I also missed out pushing a change...

@methylDragon awesome. Thanks! I'll give this a try shortly.

@methylDragon
Copy link
Contributor Author

methylDragon commented Feb 8, 2023

Oh.. you also need to build ros2cli (and ros2run) also 🤦 , my fault for working in a dirty workspace where I had run colcon build before

I've refined the setup commands.

@methylDragon
Copy link
Contributor Author

methylDragon commented Apr 2, 2023

Builds here are ordered from most recent to oldest.


https://gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/828f2208a5a0e2c66491b2badb052ba20514ef96/runtime_interface_reflection.repos

interface -> methods (because Microsoft does #define interface struct;) 🤦‍♂️

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Move dynamic typesupport struct to rosidl and fix some memory issues via valgrind (Some memory corruption errors I have no idea how to fix, still...)

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Add support for type description changes and codegen (still trying to debug exports on Windows)

https://gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/828f2208a5a0e2c66491b2badb052ba20514ef96/runtime_interface_reflection.repos

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Fix warnings and windows linking errors, trying to export on public

gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/53ddc68894bc9a8cc1e941519a48c93a3d245020/runtime_interface_reflection.repos

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Constant stream of failed windows builds

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Fix usage of `rosidl_typesupport` and `rosidl_typesupport_fastrtps`

Another one https://gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/53ddc68894bc9a8cc1e941519a48c93a3d245020/runtime_interface_reflection.repos

I missed out using Emerson's branch of rosidl_typesupport and rosidl_typesupport_fastrtps

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Fixing windows build

Another one, windows build fixed

https://gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/78091c76c4d7a6806be61f0d27a9e36d4bfa938a/runtime_interface_reflection.repos

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Initial Build

https://gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/78091c76c4d7a6806be61f0d27a9e36d4bfa938a/runtime_interface_reflection.repos

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@methylDragon
Copy link
Contributor Author

methylDragon commented Apr 6, 2023

We're just gonna try testing with and without a gtest linking fix on test_quality_of_service

(Fix is in:)

== Before fix ==
https://gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/828f2208a5a0e2c66491b2badb052ba20514ef96/runtime_interface_reflection.repos

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

== After Fix ==
https://gist.githubusercontent.com/methylDragon/1f63b89429c327cc13002538c5294a29/raw/c4690ada72b89328ad72e0e9c9e17383d32a112a/odr_fix.repos

ODR fix, fixed ODR:

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@methylDragon methylDragon changed the title Runtime Interface Reflection Subscription Prototype (REP-2011 subset) Dynamic Subscription (REP-2011 subset) Apr 6, 2023
@methylDragon
Copy link
Contributor Author

methylDragon commented Apr 7, 2023

  • Linux Build Status

  • Linux-aarch64 Build Status

  • Windows Build Status

  • Windows Debug Build Status

  • RHEL Build Status

@methylDragon
Copy link
Contributor Author

Allocator refactor is being built on top of this wave of PRs: #1405

@methylDragon
Copy link
Contributor Author

methylDragon commented Apr 7, 2023

Canary build for windows warnings

  • Windows Build Status

@methylDragon
Copy link
Contributor Author

methylDragon commented Apr 8, 2023

  • Linux Build Status

  • Linux-aarch64 Build Status

  • Windows Build Status

  • Windows Debug Build Status Run 2 Build Status Run 3 Build Status

  • RHEL Build Status

@wjwwood
Copy link
Member

wjwwood commented Apr 8, 2023

I've approved all the prs, and windows debug is at least into running tests, so hopefully it comes back green-ish tomorrow. I'll merge all of these then.

@wjwwood
Copy link
Member

wjwwood commented Apr 8, 2023

Tests lgtm, let me double check the prs since some other stuff was merged.

@wjwwood
Copy link
Member

wjwwood commented Apr 8, 2023

They look ok, I'm going to merge 🤞, let's see what the nightlies say!

@ros-discourse
Copy link

This issue has been mentioned on ROS Discourse. There might be relevant details there:

https://discourse.ros.org/t/ros2-inter-distro-communication-issue-eloquent-to-humble-with-fast-dds/33550/3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

4 participants