紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
message_filters的问题
-
系统UBUNTU22.04,ros2 humble
各位大佬,我在使用message_filters时,订阅多个传感器的信息,我的程序如下#include <memory> #include <iostream> #include <fstream> #include <iomanip> #include "rclcpp/rclcpp.hpp" #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> #include <arpa/inet.h> #include <netinet/in.h> #include <fcntl.h> #include <algorithm> #include <sys/shm.h> #include <message_filters/subscriber.h> #include <message_filters/time_synchronizer.h> #include <message_filters/signal9.h> #include "auv_msgs/msg/imu.hpp" #include "auv_msgs/msg/ctd.hpp" #include "auv_msgs/msg/obstacl_esonar.hpp" #include "auv_msgs/msg/usbl.hpp" #include "auv_socket/USBL_STRUCT.h" // 设置端口和数据长度 #define PORT 29 #define BUFSIZE 1024 extern bool error_flag; // 23 DVL 26 IMU 29 USBL 32 BDS char *SERVER_IP = "192.168.0.7"; using namespace std; using namespace std::chrono_literals; class imu_sensor_sub : public rclcpp::Node { public: imu_sensor_sub() : Node("imu_sensor_sub") { // 创建创建传感器订阅对象 imu_sub_.subscribe(this,"imu_data"); ctd_sub_.subscribe(this,"ctd_data"); hsonar_sub_.subscribe(this,"sf_data"); vsonar_sub_.subscribe(this,"sf_data_v"); //设置message_filters同步订阅对象 message_filters::TimeSynchronizer<auv_msgs::msg::IMU,auv_msgs::msg::CTD,auv_msgs::msg::OBSTACLEsonar,auv_msgs::msg::OBSTACLEsonar> sensor_info_(imu_sub_,ctd_sub_,hsonar_sub_,vsonar_sub_,5); sensor_info_.registerCallback(std::bind(&imu_sensor_sub::sensor_info_callback,this,std::placeholders::_1,std::placeholders::_2,std::placeholders::_3,std::placeholders::_4)); //imu_sub_ = this->create_subscription<auv_msgs::msg::IMU>("imu_data", 10, std::bind(&imu_sensor_sub::imu_callback, this, _1)); } private: void sensor_info_callback(const auv_msgs::msg::IMU &imu_msg, const auv_msgs::msg::CTD &ctd_msg, const auv_msgs::msg::OBSTACLEsonar &hsonar_msg,const auv_msgs::msg::OBSTACLEsonar &vsonar_msg) { // socket通讯,创建socket对象和进行连接 int socket_cli = socket(AF_INET, SOCK_STREAM, 0); if (socket_cli < 0) { RCLCPP_ERROR(this->get_logger(), "SENSOR SUB AND USBL TRANSMIT SOCKET ERROR"); } struct sockaddr_in sev_addr; memset(&sev_addr, 0, sizeof(sev_addr)); sev_addr.sin_family = AF_INET; sev_addr.sin_port = htons(PORT); sev_addr.sin_addr.s_addr = inet_addr(SERVER_IP); RCLCPP_INFO(this->get_logger(), "SENSOR SUB AND USBL TRANSMIT CONNECT RUNNING"); // 判断连接是否正常 if (connect(socket_cli, (struct sockaddr *)&sev_addr, sizeof(sev_addr)) < 0) { RCLCPP_ERROR(this->get_logger(), "SENSOR SUB AND USBL TRANSMIT CONNECT ERROR"); } else { RCLCPP_INFO(this->get_logger(), "SENSOR SUB AND USBL TRANSMIT CONNECTED SUCCESS"); } while (rclcpp::ok()) { } message_filters::Subscriber<auv_msgs::msg::IMU> imu_sub_; message_filters::Subscriber<auv_msgs::msg::CTD> ctd_sub_; message_filters::Subscriber<auv_msgs::msg::OBSTACLEsonar> hsonar_sub_; message_filters::Subscriber<auv_msgs::msg::OBSTACLEsonar> vsonar_sub_; /* rclcpp::Subscription<auv_msgs::msg::IMU>::SharedPtr imu_sub_; rclcpp::Subscription<auv_msgs::msg::CTD>::SharedPtr ctd_sub_; */ }; int main(int argc, char *argv[]) { rclcpp::init(argc, argv); rclcpp::spin(std::make_shared<imu_sensor_sub>()); rclcpp::shutdown(); return 0; }
终端始终报以下错误
/opt/ros/humble/include/message_filters/message_filters/signal9.h:234:14: note: candidate: ‘template<class T, class P0, class P1, class P2> message_filters::Connection message_filters::Signal9<M0, M1, M2, M3, M4, M5, M6, M7, M8>::addCallback(void (T::*)(P0, P1, P2), T*) [with T = T; P0 = P0; P1 = P1; P2 = P2; M0 = auv_msgs::msg::IMU_<std::allocator<void> >; M1 = auv_msgs::msg::CTD_<std::allocator<void> >; M2 = auv_msgs::msg::OBSTACLEsonar_<std::allocator<void> >; M3 = auv_msgs::msg::OBSTACLEsonar_<std::allocator<void> >; M4 = message_filters::NullType; M5 = message_filters::NullType; M6 = message_filters::NullType; M7 = message_filters::NullType; M8 = message_filters::NullType]’ 234 | Connection addCallback(void(T::*callback)(P0, P1, P2), T* t) | ^~~~~~~~~~~ /opt/ros/humble/include/message_filters/message_filters/signal9.h:234:14: note: template argument deduction/substitution failed: /opt/ros/humble/include/message_filters/message_filters/signal9.h:280:40: error: wrong number of template arguments (9, should be 4) 272 | return addCallback<const M0ConstPtr&, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 273 | const M1ConstPtr&, | ~~~~~~~~~~~~~~~~~~ 274 | const M2ConstPtr&, | ~~~~~~~~~~~~~~~~~~ 275 | const M3ConstPtr&, | ~~~~~~~~~~~~~~~~~~ 276 | const M4ConstPtr&, | ~~~~~~~~~~~~~~~~~~ 277 | const M5ConstPtr&, | ~~~~~~~~~~~~~~~~~~ 278 | const M6ConstPtr&, | ~~~~~~~~~~~~~~~~~~ 279 | const M7ConstPtr&, | ~~~~~~~~~~~~~~~~~~ 280 | const M8ConstPtr&>(std::bind(callback, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6, std::placeholders::_7, std::placeholders::_8, std::placeholders::_9)); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/ros/humble/include/message_filters/message_filters/signal9.h:234:14: note: provided for ‘template<class T, class P0, class P1, class P2> message_filters::Connection message_filters::Signal9<M0, M1, M2, M3, M4, M5, M6, M7, M8>::addCallback(void (T::*)(P0, P1, P2), T*) [with T = T; P0 = P0; P1 = P1; P2 = P2; M0 = auv_msgs::msg::IMU_<std::allocator<void> >; M1 = auv_msgs::msg::CTD_<std::allocator<void> >; M2 = auv_msgs::msg::OBSTACLEsonar_<std::allocator<void> >; M3 = auv_msgs::msg::OBSTACLEsonar_<std::allocator<void> >; M4 = message_filters::NullType; M5 = message_filters::NullType; M6 = message_filters::NullType; M7 = message_filters::NullType; M8 = message_filters::NullType]’ 234 | Connection addCallback(void(T::*callback)(P0, P1, P2), T* t) | ^~~~~~~~~~~ /opt/ros/humble/include/message_filters/message_filters/signal9.h:240:14: note: candidate: ‘template<class T, class P0, class P1, class P2, class P3> message_filters::Connection message_filters::Signal9<M0, M1, M2, M3, M4, M5, M6, M7, M8>::addCallback(void (T::*)(P0, P1, P2, P3), T*) [with T = T; P0 = P0; P1 = P1; P2 = P2; P3 = P3; M0 = auv_msgs::msg::IMU_<std::allocator<void> >; M1 = auv_msgs::msg::CTD_<std::allocator<void> >; M2 = auv_msgs::msg::OBSTACLEsonar_<std::allocator<void> >; M3 = auv_msgs::msg::OBSTACLEsonar_<std::allocator<void> >; M4 = message_filters::NullType; M5 = message_filters::NullType; M6 = message_filters::NullType; M7 = message_filters::NullType; M8 = message_filters::NullType]’ 240 | Connection addCallback(void(T::*callback)(P0, P1, P2, P3), T* t) | ^~~~~~~~~~~ /opt/ros/humble/include/message_filters/message_filters/signal9.h:240:14: note: template argument deduction/substitution failed: /opt/ros/humble/include/message_filters/message_filters/signal9.h:280:40: error: wrong number of template arguments (9, should be 5)
问题大概是这种,重复了九次,请问我这个问题出在哪里,模板函数明明有,奇怪