Navigation

    蓝鲸ROS机器人论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    ROS交流群
    ROS Group
    产品服务
    Product Service
    开源代码库
    Github
    官网
    Official website
    技术交流
    Technological exchanges
    激光雷达
    LIDAR
    ROS教程
    ROS Tourials
    深度学习
    Deep Learning
    机器视觉
    Computer Vision

    ROS2 订阅的回调函数如何实现自定义参数??

    ROS教程
    2
    2
    371
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Sandro
      Sandro last edited by

      目前订阅通用的回调函数都是只有一个参数的,如下
      MinimalSubscriber()
      : Node(“minimal_subscriber”)
      {
      subscription_ = this->create_subscription<std_msgs::msg::String>(
      “topic”, 10, std::bind(&MinimalSubscriber::topic_callback, this, _1));
      }
      private:
      void topic_callback(const std_msgs::msg::String::SharedPtr msg)const
      {
      RCLCPP_INFO(this->get_logger(), “I heard: ‘%s’”, msg->data.c_str());
      }
      是否可以增加一个参数,如下
      void topic_callback(const std_msgs::msg::String::SharedPtr msg,int falg)const
      {
      RCLCPP_INFO(this->get_logger(), “I heard: ‘%s’”, msg->data.c_str());
      }

      weijiz 1 Reply Last reply Reply Quote 0
      • weijiz
        weijiz @Sandro last edited by

        @sandro 不可以吧,回调是别的程序调用你的函数,新加的参数没有传

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        Copyright © 2015-2021 BlueWhale community