(十)ROS在rviz中显示空间中的直线(visualization_msgs/Marker 消息)

参考维基上的代码
http://wiki.ros.org/rviz/Tutorials/Markers%3A%20Points%20and%20Lines

本文修改代码实现更简单的示例,显示一排直线。效果如下:

1.效果

这里写图片描述

2.实现

(1)主函数代码如下

#include <ros/ros.h>
#include <visualization_msgs/Marker.h>

#include <cmath>

int main( int argc, char** argv )
{
  ros::init(argc, argv, "showline");
  ros::NodeHandle n;
  ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 10);
  visualization_msgs::Marker line_list;
  ros::Rate r(60);

  float f = 0.0;

  while (ros::ok())
  {

    line_list.header.frame_id = "odom";
    line_list.header.stamp = ros::Time::now();
    line_list.ns = "lines";
    line_list.action = visualization_msgs::Marker::ADD;
    line_list.pose.orientation.w = 1.0;
    line_list.id = 2;
    line_list.type = visualization_msgs::Marker::LINE_LIST;
    // LINE_STRIP/LINE_LIST markers use only the x component of scale, for the line width
    line_list.scale.x = 0.1;
    // Line list is red
    line_list.color.r = 1.0;
    line_list.color.a = 1.0;
    // Create the vertices for the points and lines
    geometry_msgs::Point p;
    p.x = f;
    p.y = 0;
    p.z = 0;
    // The line list needs two points for each line
    line_list.points.push_back(p);
    p.z += 3.0;
    line_list.points.push_back(p);
    marker_pub.publish(line_list);
    r.sleep();
    f += 1.0;
  }
}
  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值