【问题标题】:ROS node subscription not connectedROS节点订阅未连接
【发布时间】:2021-05-25 15:38:22
【问题描述】:

我正在使用 rosbag 发布各种主题,并且我试图让我的示例程序允许一个节点通过类方法函数订阅这些主题。但是没有在控制台上为订阅者打印任何内容。我试过roswtf,我得到了

 WARNING The following node subscriptions are unconnected:
 * /roscpp_pcl_example:
 * /camera/depth/points

这是我的程序代码,我不确定问题出在哪里。这些是我对 API https://wiki.ros.org/roscpp_tutorials/Tutorials/UsingClassMethodsAsCallbacks 的参考 http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29


// Include the ROS library
#include <ros/ros.h>

// Include pcl
#include <pcl_conversions/pcl_conversions.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

// Include PointCloud2 message
#include <sensor_msgs/PointCloud2.h>
#include <std_msgs/String.h>

// Topics
static const std::string SUB_TOPIC_1 = "/ecu_pcl";
static const std::string SUB_TOPIC_2 = "/velodyne_back/velodyne_points";
static const std::string SUB_TOPIC_3 = "/velodyne_center/velodyne_points";
static const std::string SUB_TOPIC_4 = "/velodyne_front/velodyne_points"


//define class with member functions for callback usage
//allows for subscription of various topics in the same node
class callback_node{
    public:

    void callback1(const std_msgs::String::ConstPtr& msg)
    {
      ROS_INFO_STREAM(msg->data.c_str());
    }

    void callback2(const std_msgs::String::ConstPtr& msg)
    {
      ROS_INFO_STREAM(msg->data.c_str());
    }

    void callback3(const std_msgs::String::ConstPtr& msg)
    {
      ROS_INFO_STREAM(msg->data.c_str());
    }

    void callback4(const std_msgs::String::ConstPtr& msg)
    {
      ROS_INFO_STREAM(msg->data.c_str());
    }

    

};

int main (int argc, char** argv)
{
    // Initialize the ROS Node "roscpp_pcl_example"
    ros::init (argc, argv, "roscpp_pcl_example");
    ros::NodeHandle nh;
    callback_node callback_obj;
    // Print "Hello" message with node name to the terminal and ROS log file
    ROS_INFO_STREAM("Hello from ROS Node: " << ros::this_node::getName());

    // Create ROS Subscribers to SUB_TOPIC with a queue_size of 1000 and a callback function via class methods
    ros::Subscriber sub1 = nh.subscribe(SUB_TOPIC_1, 1000, &callback_node::callback1, &callback_obj);
    ros::Subscriber sub2 = nh.subscribe(SUB_TOPIC_2, 1000, &callback_node::callback2, &callback_obj);
    ros::Subscriber sub3 = nh.subscribe(SUB_TOPIC_3, 1000, &callback_node::callback3, &callback_obj);
    ros::Subscriber sub4 = nh.subscribe(SUB_TOPIC_4, 1000, &callback_node::callback4, &callback_obj);


    // Spin
    ros::spin();

    // Success
    return 0;
}

【问题讨论】:

    标签: c++ c ros robotics


    【解决方案1】:

    立即让我眼前一亮的一件事是,您实际上已将 std_msgs::String::ConstPtr 作为主题类型,但主题 /ecu_pcl/velodyne_points 不应该是 std_msgs::String 类型,而是应该有不同的数据类型,我假设的点云,比如 sensor_msgs::PointCloud2。因此,您必须将回调修改为正确的数据类型,例如sensor_msgs::PointCloud2::ConstPtr.

    让我惊讶的是roswtf 给你的消息:

    WARNING The following node subscriptions are unconnected:
      * /roscpp_pcl_example:
        * /camera/depth/points
    

    这意味着您的节点 roscpp_pcl_example 订阅了主题 /camera/depth/points 没有人实际发布。然而你的代码 sn-p 没有提到/camera/depth/points。 (是只展示了节点的部分源代码还是忘记用catkin build重新编译代码?)


    无论如何要调试它,请尝试以下操作:

    • 通过在您为以下步骤打开的每个控制台中执行 $ source devel/setup.bash 来确保您找到了正确的工作区
    • 打开控制台并浏览您要播放的rosbag 并执行$ rosbag info &lt;filename.bag&gt; 并检查输出。确保您的节点所需的所有主题都已实际记录!
    • 如果是这种情况,请继续使用 $ rostopic play &lt;filename.bag&gt;
    • 现在通过打开一个新控制台、寻找工作区并输入 $ rostopic list 来检查所有主题是否已正确发布。
    • 然后使用 $ rostopic info &lt;topicname&gt; 从该列表中查看每个主题的类型。
    • 最后确保您为您的订阅者使用正确的主题类型。您可能需要相应地更新您的CMakeLists.txtpackage.xml

    【讨论】:

    • 实际上在采购和 catkin_make 之后,我仍然得到那个没有意义的顽固 /camera/depth/points。以前我可能已经用它做了一些事情,但我已经做了一个 catkin_make,它不应该在那里
    • 我不确定是否有另一种我不知道的干净重建方式,但我刚刚创建了一个新的 pkg 来运行,它不包含该相机主题
    • 在这种情况下,您可以尝试调用catkin_make clean 来清理工作区。这应该删除所有以前的构建代码。但很高兴它以这种方式工作!
    猜你喜欢
    • 1970-01-01
    • 2022-08-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 2016-02-07
    • 2021-07-28
    • 1970-01-01
    相关资源
    最近更新 更多