Feature Request: Dynamic Type Handling for Generic Subscriptions

Ouverte
#2,568 16 commentaires 0 réactions 1 personne assignée Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@Barry-Xu-2018 y travaille déjà.

Depuis le 22/6/2024.

Évaluation

Cette issue n'a pas encore été évaluée.

Description

question

Feature request

Feature description

I am developing an application where I need to subscribe to topics with unknown message types (similar to rosbag2). In the subscription callback, I need access to the deserialized message and its fields without knowing the type in advance.

There is a related example here, but it requires specifying the type (T2) beforehand. I am looking for a way to use only the topic type as a string to dynamically obtain the message class.

Using snippets here and there from rclcpp I put together this incomplete example:

node->create_generic_subscription(
  topic_name,
  topic_type,
  qos,
  [this, topic_name, topic_type](std::shared_ptr<const rclcpp::SerializedMessage> message,
  const rclcpp::MessageInfo & mi) {
    void* deserialized_msg = nullptr;
    auto ts_lib = rclcpp::get_typesupport_library(topic_type, "rosidl_typesupport_cpp");
    auto type_support = rclcpp::get_message_typesupport_handle(topic_type, "rosidl_typesupport_cpp", *ts_lib);
    rmw_deserialize(&message->get_rcl_serialized_message(), type_support, deserialized_msg);
  });

The issue is that deserialized_msg is a null pointer ('void *'), and I am unsure how to proceed from here.

If there is currently no way to achieve this, please consider this a feature request. I am open to contributing with some guidance on the implementation. Thanks!

Related:

https://answers.ros.org/question/405796/deserialize-message-with-topic-name-ros2/
https://github.com/ros2/rclcpp/issues/2260
https://github.com/ros2/ros2/issues/1374
https://github.com/facontidavide/rosx_introspection

Langage dominant
C++
Étoiles
829
Forks
587
Merge moyen
4 j 6 h
PR mergées (30 j)
30

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de ros2/rclcpp

Toutes les issues de ros2/rclcpp

Issues similaires

Plus d'issues C++

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.