0
$\begingroup$

I try to synchronize two ROS2 topic using message_filter (sync_policies/approximate_time):

  • a sensor_msgs::msgs::Imu from an Imu
  • a sensor_msgs::msgs::PointCloud2 from a radar, which is published with the QoS rclcpp::SensorDataQoS()

By default, the subscriber of each topic is Reliable, which is incompatible with the pointcloud2 publisher QoS which is Best effort.

I suppose that keep the SensorDataQoS() is the best for datas from a radar or a lidar. So, how is it possible to synchronize the pointcloud2 topic with an another topic, keeping the QoS? Is there a way to specify the QoS in subscriber with message_filter? Or should I use an another way?

My code:

Synchro.hpp

using namespace message_filters;
using namespace sensor_msgs;

class Synchro : public rclcpp::Node
{
  public:
    explicit Synchro(const rclcpp::NodeOptions &options = rclcpp::NodeOptions());
    ~Synchro() {};

  protected:
   //callback
    void topic_callback(const msg::PointCloud2::ConstSharedPtr& msg_pc, const msg::Imu::ConstSharedPtr& msg_imu);

    // ROS2 subscriber and related topic name
    Subscriber<msg::PointCloud2> subscriber_pc_;
    Subscriber<msg::Imu> subscriber_imu_;

   using ApproxSync = sync_policies::ApproximateTime<msg::PointCloud2, msg::Imu>;
    typedef Synchronizer<ApproxSync> Sync;
    std::shared_ptr<Sync> sync_;
};

Synchro.cpp

using std::placeholders::_1;
using std::placeholders::_2;
using namespace sensor_msgs;

Synchro::Synchro(const rclcpp::NodeOptions& options) : Node("synchro_node",options) 
{
  //sub creation
  subscriber_pc_.subscribe(this, param_topic_pointcloud_in);
  subscriber_imu_.subscribe(this, param_topic_imu_in);

  ////The following line is my way to create a subscriber with a specific QoS but this declaration doesn't build**
  //subscriber_pc_ = this->create_subscription<msg::PointCloud2>(param_topic_pointcloud_in,rclcpp::SensorDataQoS(), this, _1);

  //Synchro callback
  sync_.reset(new Sync(ApproxSync(100), subscriber_pc_, subscriber_imu_));
  sync_->setMaxIntervalDuration(rclcpp::Duration(3,0));
  sync_->registerCallback(std::bind(&Synchro::topic_callback, this, _1, _2)); 
}

void Synchro::topic_callback(const msg::PointCloud2::ConstSharedPtr& msg_pc, const msg::Imu::ConstSharedPtr& msg_imu)
{
  //my callback actions
}
$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.