Ros2-galactic下使用std_msgs::msg::Bool

Posted KAI-yq

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ros2-galactic下使用std_msgs::msg::Bool相关的知识,希望对你有一定的参考价值。

  1. CMakeList.txt
find_package(ament_cmake REQUIRED)
find_package(std_msgs REQUIRED)

ament_auto_add_executable(pose_initializer_node
  src/pose_initializer/pose_initializer_node.cpp
  src/pose_initializer/pose_initializer_core.cpp
)
ament_target_dependencies(pose_initializer_node std_msgs)
  1. package.xml
  <depend>std_msgs</depend>
  1. cpp
hpp:
#include "std_msgs/msg/bool.hpp"

rclcpp::Subscription<std_msgs::msg::Bool>::SharedPtr sub_init_pose_control_;
rclcpp::Publisher<geometry_msgs::msg::PoseWithCovarianceStamped>::SharedPtr pub_initial_pose_cov_;

cpp:
GnssModule::GnssModule(rclcpp::Node * node)

  sub_init_pose_control_ = node->create_subscription<std_msgs::msg::Bool>(
    "/InitPoseControl", 1, std::bind(&GnssModule::callbackInitialPoseControl, this, _1));


void GnssModule::callbackInitialPoseControl(std_msgs::msg::Bool msg)

  if(msg.data)
   is_init_ = true; 
  else
   is_init_ = false; 

  1. 参考链接:https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html

以上是关于Ros2-galactic下使用std_msgs::msg::Bool的主要内容,如果未能解决你的问题,请参考以下文章

-Publishing and Subscribing .3.2

-Publishing and Subscribing .3.2

Publisher和Subscriber节点

ROS----示例

ROS1/2 C++ talker.cpp 对比案例

ROS-4 : ROS节点和主题