Rviz教程-Marker:点和线(C++)
来源:互联网 发布:无法初始网络小引擎 编辑:程序博客网 时间:2024/05/29 18:03
描述:如何使用visualization_msgs/Marker消息发送点和线到rviz中。
1. 介绍
在Markers: Basic Shapes中,学会了如何使用可以markers发送简单的形状到rviz中,这个教程会介绍 POINTS, LINE_STRIP 和 LINE_LIST marker类型。对于全部的类型清单,看这里 。
2. 使用Points, Line Strips, 和 Line Lists
POINTS, LINE_STRIP 和 LINE_LIST markers 所有都使用visualization_msgs/Marker 消息的点成员。POINTS类型在每个点添加的位置放置一个点。LINE_STRIP类型将每个点用作一个连接的线中的定点,其中点0和点1连接,1和2连接,等等。LINE_LIST类型在每对点外创建一个不相连的线,也就是0连接1,2连接3,等等。
2.1 代码及解释
#include <ros/ros.h>#include <visualization_msgs/Marker.h>#include <cmath>int main( int argc, char** argv ){ ros::init(argc, argv, "points_and_lines"); ros::NodeHandle n; ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 10); ros::Rate r(30); float f = 0.0; while (ros::ok()) { //创建一个 visualization_msgs/Marker消息,并且初始化所有共享的数据。消息成员默认为0,仅仅设置位姿成员w。 visualization_msgs::Marker points, line_strip, line_list; points.header.frame_id = line_strip.header.frame_id = line_list.header.frame_id = "/my_frame"; points.header.stamp = line_strip.header.stamp = line_list.header.stamp = ros::Time::now(); points.ns = line_strip.ns = line_list.ns = "points_and_lines"; points.action = line_strip.action = line_list.action = visualization_msgs::Marker::ADD; points.pose.orientation.w = line_strip.pose.orientation.w = line_list.pose.orientation.w = 1.0; //分配三个不同的id到三个markers。points_and_lines名称空间的使用确保彼此不会相互冲突。 points.id = 0; line_strip.id = 1; line_list.id = 2; //设置marker类型到 POINTS, LINE_STRIP 和 LINE_LIST points.type = visualization_msgs::Marker::POINTS; line_strip.type = visualization_msgs::Marker::LINE_STRIP; line_list.type = visualization_msgs::Marker::LINE_LIST; // scale成员对于这些marker类型是不同的,POINTS marker分别使用x和y作为宽和高,然而LINE_STRIP和LINE_LIST marker仅仅使用x,定义为线的宽度。单位是米。 points.scale.x = 0.2; points.scale.y = 0.2; // LINE_STRIP/LINE_LIST markers use only the x component of scale, for the line width line_strip.scale.x = 0.1; line_list.scale.x = 0.1; // 点为绿色 points.color.g = 1.0f; points.color.a = 1.0; // Line strip 是蓝色 line_strip.color.b = 1.0; line_strip.color.a = 1.0; // Line list 为红色 line_list.color.r = 1.0; line_list.color.a = 1.0; //使用正弦和余弦生成螺旋结构。POINTS和LINE_STRIP markers都仅仅需要1个点作为每个顶点,然而LINE_LIST marker需要2个点 。 for (uint32_t i = 0; i < 100; ++i) { float y = 5 * sin(f + i / 100.0f * 2 * M_PI); float z = 5 * cos(f + i / 100.0f * 2 * M_PI); geometry_msgs::Point p; p.x = (int32_t)i - 50; p.y = y; p.z = z; points.points.push_back(p); line_strip.points.push_back(p); // The line list needs two points for each line line_list.points.push_back(p); p.z += 1.0; line_list.points.push_back(p); } //发布各个markers marker_pub.publish(points); marker_pub.publish(line_strip); marker_pub.publish(line_list); r.sleep(); f += 0.04; }}
2.3 查看marker效果
在CMakeLists.txt文件中添加:
add_executable(points_and_lines src/points_and_lines.cpp)target_link_libraries(points_and_lines ${catkin_LIBRARIES})
然后
$ catkin_make$ rosrun rviz rviz &$ rosrun using_markers points_and_lines
将会看到一个旋转的螺旋结构:
0 0
- Rviz教程-Marker:点和线(C++)
- Rviz教程-Marker:发送基本的形状(C++)
- Rviz教程(五):Interactive Markers: Writing a Simple Interactive Marker Server
- Rviz教程(十一):Rviz in Stereo
- rviz--显示类型-Marker
- Rviz教程(二):Markers: Sending Basic Shapes (C++)
- Rviz教程(三):Markers: Points and Lines (C++)
- Rviz教程(一):用户指南
- (十)ROS在rviz中显示空间中的直线(visualization_msgs/Marker 消息)
- Rviz教程(十):Librviz: Incorporating RViz into a Custom GUI
- Rviz教程(四):Interactive Markers: Getting Started
- Rviz教程(六):Interactive Markers: Basic Controls
- Rviz教程(七):Plugins: New Display Type
- Rviz教程(八):Plugins: New Dockable Panel
- Rviz教程(九):Plugins: New Tool Type
- rviz安装和启动
- RVIZ(一):Markers:sending Basic Shapes (C++)
- Rviz黑屏(没有网格和画面)解决办法
- HDU 2084 数塔【dp(递推)+(记忆化)】
- 在IOS中嵌套H5页面发生空白的问题
- MySQL数据库的函数
- python实现线性表顺序存储的插入操作
- Android Stadio 代码模板 fbc的使用
- Rviz教程-Marker:点和线(C++)
- poj 3264 线段树,链表实现
- shell脚本编程(一)
- redis 配置详解
- svn和git的区别
- ioctl那些事儿
- 网站制作完成之后,对页面进行测试,测试内容主要包括哪几个方面?
- Myeclipse SSH配置
- 网络编程学习笔记一:Socket编程