eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.65k stars 384 forks source link

message_filters::Synchronizer failed when roudi client is enabled ? #2339

Closed lix19937 closed 1 month ago

lix19937 commented 1 month ago

Required information

Operating system: Ubuntu 20.04 LTS
ROS2 galactic

Observed result or behaviour:
one console windows, ros2 bag play camera4.db3 which has 4 topic
one console windows, iox-roudi -c ./config/roudi_config.toml
one console windows, run ros2 node to sub 4 topic

Expected result or behaviour: I expect 4 message_filters::Subscriber ptr are not nullptr !
but now at least one ptr of message_filters::Subscriber ptrs is nullptr.
when i disable roudi client, by follow cmd, 4 message_filters::Subscriber ptr are not nullptr !

export RMW_IMPLEMENTATION=""    #rmw_cyclonedds_cpp   
export CYCLONEDDS_URI=""        #file://`pwd`/config/cyclonedds.xml

@elBoberido or others give some advice ?

follow core code

#include "havp_imp_node.h"
#include <boost/bind.hpp>
#include <fstream>

#define __CREATE_FILTER_SUB___(x_sub, msg_type, topic)                              \
  do                                                                                \
  {                                                                                 \
    if (x_sub == nullptr)                                                           \
      x_sub = std::make_unique<message_filters::Subscriber<msg_type>>(this, topic); \
  } while (0)

void HavpIMPNode::InitSubs(void)
{
  __CREATE_FILTER_SUB___(fisheye_front_sub_camera_, driver_interfaces::msg::Camera5400K,
                         havp::base_node::havp_sensor_camera_around_front_topic_str);
  __CREATE_FILTER_SUB___(fisheye_left_sub_camera_, driver_interfaces::msg::Camera5400K,
                         havp::base_node::havp_sensor_camera_around_left_topic_str);
  __CREATE_FILTER_SUB___(fisheye_back_sub_camera_, driver_interfaces::msg::Camera5400K,
                         havp::base_node::havp_sensor_camera_around_rear_topic_str);
  __CREATE_FILTER_SUB___(fisheye_right_sub_camera_, driver_interfaces::msg::Camera5400K,
                         havp::base_node::havp_sensor_camera_around_right_topic_str);
  if (img_sync_camera_ == nullptr)
  {
    img_sync_camera_ = std::make_unique<message_filters::Synchronizer<ImpSyncPolicyCamera>>(ImpSyncPolicyCamera(10),
                                                                                            *fisheye_front_sub_camera_,
                                                                                            *fisheye_left_sub_camera_,
                                                                                            *fisheye_back_sub_camera_,
                                                                                            *fisheye_right_sub_camera_);
    img_sync_camera_->registerCallback(boost::bind(&HavpIMPNode::SubMsgCallbackCamera, this, _1, _2, _3, _4));
  }

  printf("InitSubs done\n");
}

void HavpIMPNode::InitPubs(void)
{
  pub_ = this->create_publisher<havp_imp_msgs::msg::FishCombineImg>(
      havp::base_node::havp_camera_fish_combine_image_topic_str, depth_);
}

void HavpIMPNode::SubMsgCallbackCamera(driver_interfaces::msg::Camera5400K::ConstSharedPtr msg_f,
                                       driver_interfaces::msg::Camera5400K::ConstSharedPtr msg_l,
                                       driver_interfaces::msg::Camera5400K::ConstSharedPtr msg_b,
                                       driver_interfaces::msg::Camera5400K::ConstSharedPtr msg_r)
{
#ifdef _IS_USE_SHM_
  auto loaned_msg = pub_->borrow_loaned_message();
  if (!loaned_msg.is_valid())
  {
    printf("Failed to borrow_loaned_message!\n");
    return;
  }
  auto &pub_msg = loaned_msg.get();
#else
  auto &pub_msg = pub_msg_;
#endif
  const unsigned char *input[] = {
      (const unsigned char *)(msg_f->img_data.data()), // yv422-packed  length: 1920*1440*2
      (const unsigned char *)(msg_l->img_data.data()),
      (const unsigned char *)(msg_b->img_data.data()),
      (const unsigned char *)(msg_r->img_data.data())};

  for (int i = 0; i < 4; ++i)
  {
    if (input[i] != nullptr)
    {
      printf(" %d  %d  %d  %d \n", int(input[i][0]), int(input[i][100]), int(input[i][1000]), int(input[i][1920 * 1440 * 2 - 1]));
    }
    else
    {
      printf("sync failed \n");
      exit(1)
    }
  }

#ifdef _IS_USE_SHM_
  pub_->publish(std::move(pub_msg));
#else
  pub_->publish(pub_msg);
#endif
}

ref https://www.learnros2.com/ros/tutorials/subscription-and-message-filters-demo

elBoberido commented 1 month ago

Sorry, but this is not related to iceoryx itself but probably how iceoryx is integrated in rmw_cyclonedds. I'm afraid but we cannot help you here.

We are working on an rmw_iceoryx2 and next week there is a developer meetup. Would be great to see you there and get some feeback of your needs.

lix19937 commented 1 month ago

Thanks. @elBoberido