0、头文件某个类中定义一个成员变量
ros::Publisher pub_;
1、在构造函数中初始化变量,定义话题的名称和数量,名称output,数量1
pub_ = nh->advertise<geometry_msgs::PoseStamped>("output", 1);
2、发布这个话题
//表示该箭头消息所描述的目标方向是相对于机器人坐标系中的"base_link"框架
target.header.frame_id = "base_link"; //设置了消息的头部信息
//通过将四元数的分量(x、y、z、w)设置为transDockPos变量中存储的旋转四元数分量。这些分量描述了箭头方向的旋转。
target.pose.orientation.x = transDockPos.getRotation().x();
target.pose.orientation.y = transDockPos.getRotation().y();
target.pose.orientation.z = transDockPos.getRotation().z();
target.pose.orientation.w = transDockPos.getRotation().w();
// 广播
pub_.publish(target);