ROS发布多边形话题PolygonStamped数据并在rviz中显示
wiki:rvizDisplayTypesPolygon
实验环境Ubuntu20.04 ROS(noetic)
1.新建工程
mkdir -p catkin_ws/src
cd catkin_ws/src
catkin_create_pkg polygon_demo roscpp geometry_msgs
cd ..
catkin_make
2.编辑主函数
路径:polygon_demo/src/publisher.cpp
topic名字为polygonpublisher
frame_id为map
#include <ros/ros.h>
#include <geometry_msgs/PolygonStamped.h>
#include <geometry_msgs/Point32.h>
int main (int argc, char **argv)
{
// 初始化ROS节点 节点名字
ros::init (argc, argv, "polygonpublisher");
// 节点句柄
ros::NodeHandle nh;
// 发布消息 话题名字 队列大小
ros::Publisher pub = nh.advertise<geometry_msgs::PolygonStamped>("polygonpublisher"