rviz中marker显示

rviz中marker显示

最近想对激光雷达数据做一些处理,其中必然少不了可视化部分,可以帮助我们看到每一步的效果。marker提供了一个很好的工具,今天折腾了一下marker中point的使用:
问题:配置points基本信息后报错如下:

rviz中marker显示_第1张图片

    visualization_msgs::Marker points;
    points.header.frame_id  = "/my_frame";
    points.header.stamp = ros::Time::now();
    points.ns =  "points";
    points.action = visualization_msgs::Marker::ADD;
    points.pose.orientation.w  = 1.0;
 
    points.id = 0;
 
    points.type = visualization_msgs::Marker::POINTS;
 
    points.scale.x = 0.2;
    points.scale.y = 0.2;

    points.color.g = 1.0f;
    points.color.a = 1.0;

参考代码,发现在配置完成后需要给定points坐标,不给定的花就会出现如商报错信息,结合参考代码,修改后的代码如下:

#include 
#include 
 
int main( int argc, char** argv )
{
  ros::init(argc, argv, "points_marker");
  ros::NodeHandle n;
  ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("point_marker", 10);
 
  ros::Rate r(30);
 
  float f = 0.0;
  while (ros::ok())
  {
    visualization_msgs::Marker points;
    points.header.frame_id  = "/my_frame";
    points.header.stamp = ros::Time::now();
    points.ns =  "points";
    points.action = visualization_msgs::Marker::ADD;
    points.pose.orientation.w  = 1.0;
 
    points.id = 0;
 
    points.type = visualization_msgs::Marker::POINTS;
    points.scale.x = 0.2;
    points.scale.y = 0.2;

    points.color.g = 1.0f;
    points.color.a = 1.0;
    
    geometry_msgs::Point p;
    p.x = 0;
    p.y = 0;
    p.z = 0;
    points.points.push_back(p);

    marker_pub.publish(points); 
    r.sleep();
  }
}

最终在RVIZ中可视化points
rviz中marker显示_第2张图片

你可能感兴趣的:(机器人)