rviz学习笔记(一)——Markers: Sending Basic Shapes (C++) 发送基础形状
一、创建一个包——进行marker练习
1、创建ROS工作空间和包
mkdir -p ~/catkin_ws/src #创建工作空间目录 #创建ROS数据包
catkin_create_pkg using_markers roscpp visualization_msgs #打开包根目录,进行编译
cd ~/catkin_ws
catkin_make
2、编写cpp文件,向rviz发送数据
vim ~/catkin_ws/src/using_marker/src/using_markers.cpp
贴入代码,代码中已经附加相关注释
#include <ros/ros.h>
#include <visualization_msgs/Marker.h> //可视化 int main( int argc, char** argv )
{
//初始化ROS,幷且创建一个ROS::Publisher 在话题visualization_marker上面
ros::init(argc, argv, "basic_shapes");
ros::NodeHandle n;
ros::Rate r();
ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", ); // Set our initial shape type to be a cube
// 初始化形状为立方体
uint32_t shape = visualization_msgs::Marker::CUBE; while (ros::ok())
{
//实例化一个Marker
visualization_msgs::Marker marker; // Set the frame ID and timestamp. See the TF tutorials for information on these.
// 设置frame ID 和 时间戳
marker.header.frame_id = "/my_frame";
marker.header.stamp = ros::Time::now(); // Set the namespace and id for this marker. This serves to create a unique ID
// Any marker sent with the same namespace and id will overwrite the old one
// 为这个marker设置一个独一无二的ID,一个marker接收到相同ns和id就会用新的信息代替旧的
marker.ns = "basic_shapes";
marker.id = ; // Set the marker type. Initially this is CUBE, and cycles between that and SPHERE, ARROW, and CYLINDER
// 设置marker类型,初始化是立方体。将进行循环
marker.type = shape; // Set the marker action. Options are ADD, DELETE, and new in ROS Indigo: 3 (DELETEALL)
marker.action = visualization_msgs::Marker::ADD; // Set the pose of the marker. This is a full 6DOF pose relative to the frame/time specified in the header
// 设置marker的位置
marker.pose.position.x = ;
marker.pose.position.y = ;
marker.pose.position.z = ;
marker.pose.orientation.x = 0.0;
marker.pose.orientation.y = 0.0;
marker.pose.orientation.z = 0.0;
marker.pose.orientation.w = 1.0; // Set the scale of the marker -- 1x1x1 here means 1m on a side
// 设置marker的大小
marker.scale.x = 1.0;
marker.scale.y = 1.0;
marker.scale.z = 1.0; // Set the color -- be sure to set alpha to something non-zero!
// 设置marker的颜色
marker.color.r = 0.0f;
marker.color.g = 1.0f;
marker.color.b = 0.0f;
marker.color.a = 1.0; //取消自动删除
marker.lifetime = ros::Duration(); // Publish the marker
// 必须有订阅者才会发布消息
while (marker_pub.getNumSubscribers() < )
{
if (!ros::ok())
{
return ;
}
ROS_WARN_ONCE("Please create a subscriber to the marker");
sleep();
}
marker_pub.publish(marker); // Cycle between different shapes
// 连续改变形状
switch (shape)
{
case visualization_msgs::Marker::CUBE:
shape = visualization_msgs::Marker::SPHERE;
break;
case visualization_msgs::Marker::SPHERE:
shape = visualization_msgs::Marker::ARROW;
break;
case visualization_msgs::Marker::ARROW:
shape = visualization_msgs::Marker::CYLINDER;
break;
case visualization_msgs::Marker::CYLINDER:
shape = visualization_msgs::Marker::CUBE;
break;
} r.sleep();
}
}
在CMakeList.txt文件中加入
add_executable(basic_shapes src/basic_shapes.cpp)
target_link_libraries(basic_shapes ${catkin_LIBRARIES})
3、进行rviz设置
(1)打开roscore
(2)运行编写的发布器
rosrun using_marker basic_shapes
(3)重置rviz,运行rviz
rosmake rviz
rosrun rviz rviz
(4)在rviz中进行设置
4、rviz最终效果显示:4个图形进行连续的变换
一、创建一个包——进行marker练习
1、创建ROS工作空间和包
mkdir -p ~/catkin_ws/src #创建工作空间目录 #创建ROS数据包
catkin_create_pkg using_markers roscpp visualization_msgs #打开包根目录,进行编译
cd ~/catkin_ws
catkin_make
2、编写cpp文件,向rviz发送数据
vim ~/catkin_ws/src/using_marker/src/using_markers.cpp
贴入代码,代码中已经附加相关注释
#include <ros/ros.h>
#include <visualization_msgs/Marker.h> //可视化 int main( int argc, char** argv )
{
//初始化ROS,幷且创建一个ROS::Publisher 在话题visualization_marker上面
ros::init(argc, argv, "basic_shapes");
ros::NodeHandle n;
ros::Rate r(1);
ros::Publisher marker_pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 1); // Set our initial shape type to be a cube
// 初始化形状为立方体
uint32_t shape = visualization_msgs::Marker::CUBE; while (ros::ok())
{
//实例化一个Marker
visualization_msgs::Marker marker; // Set the frame ID and timestamp. See the TF tutorials for information on these.
// 设置frame ID 和 时间戳
marker.header.frame_id = "/my_frame";
marker.header.stamp = ros::Time::now(); // Set the namespace and id for this marker. This serves to create a unique ID
// Any marker sent with the same namespace and id will overwrite the old one
// 为这个marker设置一个独一无二的ID,一个marker接收到相同ns和id就会用新的信息代替旧的
marker.ns = "basic_shapes";
marker.id = 0; // Set the marker type. Initially this is CUBE, and cycles between that and SPHERE, ARROW, and CYLINDER
// 设置marker类型,初始化是立方体。将进行循环
marker.type = shape; // Set the marker action. Options are ADD, DELETE, and new in ROS Indigo: 3 (DELETEALL)
marker.action = visualization_msgs::Marker::ADD; // Set the pose of the marker. This is a full 6DOF pose relative to the frame/time specified in the header
// 设置marker的位置
marker.pose.position.x = 0;
marker.pose.position.y = 0;
marker.pose.position.z = 0;
marker.pose.orientation.x = 0.0;
marker.pose.orientation.y = 0.0;
marker.pose.orientation.z = 0.0;
marker.pose.orientation.w = 1.0; // Set the scale of the marker -- 1x1x1 here means 1m on a side
// 设置marker的大小
marker.scale.x = 1.0;
marker.scale.y = 1.0;
marker.scale.z = 1.0; // Set the color -- be sure to set alpha to something non-zero!
// 设置marker的颜色
marker.color.r = 0.0f;
marker.color.g = 1.0f;
marker.color.b = 0.0f;
marker.color.a = 1.0; //取消自动删除
marker.lifetime = ros::Duration(); // Publish the marker
// 必须有订阅者才会发布消息
while (marker_pub.getNumSubscribers() < 1)
{
if (!ros::ok())
{
return 0;
}
ROS_WARN_ONCE("Please create a subscriber to the marker");
sleep(1);
}
marker_pub.publish(marker); // Cycle between different shapes
// 连续改变形状
switch (shape)
{
case visualization_msgs::Marker::CUBE:
shape = visualization_msgs::Marker::SPHERE;
break;
case visualization_msgs::Marker::SPHERE:
shape = visualization_msgs::Marker::ARROW;
break;
case visualization_msgs::Marker::ARROW:
shape = visualization_msgs::Marker::CYLINDER;
break;
case visualization_msgs::Marker::CYLINDER:
shape = visualization_msgs::Marker::CUBE;
break;
} r.sleep();
}
}
在CMakeList.txt文件中加入
add_executable(basic_shapes src/basic_shapes.cpp)
target_link_libraries(basic_shapes ${catkin_LIBRARIES})
3、进行rviz设置
(1)打开roscore
(2)运行编写的发布器
rosrun using_marker basic_shapes
(3)重置rviz,运行rviz
rosmake rviz
rosrun rviz rviz
(4)在rviz中进行设置
4、rviz最终效果显示:4个图形进行连续的变换
rviz学习笔记(一)——Markers: Sending Basic Shapes (C++) 发送基础形状的更多相关文章
- 【转】Pro Android学习笔记(二):开发环境:基础概念、连接真实设备、生命周期
在Android学习笔记(二):安装环境中已经有相应的内容.看看何为新.这是在source网站上的Android架构图,和标准图没有区别,只是这张图颜色好看多了,录之.本笔记主要讲述Android开发 ...
- rviz学习笔记(二)——Markers: Points and Lines (C++) 点和线
一.在using_marker/src中编写点和线代码 vim ~/catkin_ws/src/using_marker/src/points_and_lines.cpp 编写代码,其中有注释 #in ...
- C#学习笔记12:枚举、结构、数组基础学习
枚举:public enum MyEnum { 值1, 值2, 值3 } Public enum Season { 春, 夏, 秋, 冬 } 枚举的作用:规范用户的输入,枚举可以转换为int类型,可以 ...
- Python学习笔记【第九篇】:Python面向对象基础
Python语言中一切皆对象(类.属性.方法.........) 概念 面向对象编程:Object Oriented Programming 简称OOP 面向对象程序设计 面向对象和面向过程都是解决问 ...
- JMeter学习笔记(二) 一些实际应用的基础操作
我在CSDN上面找到一位大师整理的jmeter性能测试基础,分享到这里继续学习 https://blog.csdn.net/u011541946/article/category/6893578/1
- mybatis学习笔记(六)使用generator生成mybatis基础配置代码和目录结构
原文:http://blog.csdn.net/oh_mourinho/article/details/51463413 创建maven项目 <span style="font-siz ...
- 0031 Java学习笔记-梁勇著《Java语言程序设计-基础篇 第十版》英语单词
第01章 计算机.程序和Java概述 CPU(Central Processing Unit) * 中央处理器 Control Unit * 控制单元 arithmetic/logic unit /ə ...
- 【SharePoint学习笔记】第1章 SharePoint Foundation开发基础
SharePoint Foundation开发基础 第1章 SharePoint Foundation开发基础 SharePoint能做什么 企业信息门户 应用程序工具集(文档库.工作空间.工作流.维 ...
- python学习笔记三 深浅copy,扩展数据类型(基础篇)
深浅copy以及赋值 对于字符串和数字而言,赋值.浅拷贝和深拷贝无意义,因为其永远指向同一个内存地址. import copy n1 = #n1 = 'hahahaha' #赋值n2 = n1#浅co ...
随机推荐
- Eclipse关掉项目SVN的链接
有时候 svn 会导致 eclipse 反应很慢,可以关掉 svn项目信息展现. 1. 点击项目文件夹,右键出现项目信息 2. 选择team项 3. Disconnect.
- C#.NET常见问题(FAQ)-如何让Listbox支持多选
把SelectionMode改成MultiExtended 更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.youku.com/acetaohai123 我的在线 ...
- NSobject 结构
参考地址: https://iosdevelopmenttutorials.wordpress.com/tag/uiscrollview/ Apple Documentation
- PHP传值与传址(引用)
传值和传引用的区别在于,如果一个参数比较大,占用大量的内存空间,那么传引用的话就会节省拷贝空间. 传值:是把实参的值赋值给行参 ,那么对行参的修改,不会影响实参的值 传引用 :真正的以地址的方式传递参 ...
- bash和shell的关系
bash是borne again shell的缩写,它是shell的一种,Linux上默认采用的是bash. shell脚本中的方法带不带function的区别,例如: function foo () ...
- JERSEY中文翻译(第一章、Getting Started、2.2)
前言 这是jersey2.2的用户向导,我们会尽力维护它的更新并且也会增加新的章节.当阅读本用户指南的时候,也要参阅Jersey API 文档,额外的信息补充JERSEY的新特性和API 如果你想要为 ...
- python2.7安装setuptools-36.6.0报ascii' codec can't decode byte 0xce in position 7问题
解决办法1: 原文链接:http://blog.csdn.net/all_over_servlet/article/details/45112221 修改编码为gbk,修改D:\Python27\Li ...
- Java 希尔排序
效率:O(n*logN) package sort; import utils.Util; /** * 希尔排序 * 以h为间隔,进行比較. 按一定公式.先求出最大的间隔h * 当h值大时,须要移动的 ...
- lvalue & rvalue
https://www.youtube.com/watch?v=UTUdhjzws5g 作者:知乎用户链接:https://www.zhihu.com/question/50652989/answer ...
- [转载]Windows x64下配置ffmpeg的方法
ffmpeg简介 FFmpeg 是一款跨平台的,对视频.音频进行录制.转换.播放的命令行形式软件,它使用的是 libavcodec 编解码器.FFmpeg 官方网站是 http://ffmpeg.or ...