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(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个图形进行连续的变换
一、创建一个包——进行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++) 发送基础形状相关推荐
- Windows驱动开发学习笔记(二)—— 驱动调试内核编程基础
Windows驱动开发学习笔记(二)-- 驱动调试&内核编程基础 基础知识 驱动调试 PDB(Program Debug Database) WinDbg 加载 PDB 实验:调试 .sys ...
- Task02:学习笔记文本预处理;语言模型;循环神经网络基础
Task02:学习笔记文本预处理:语言模型:循环神经网络基础 文本预处理 文本是一类序列数据,一篇文章可以看作是字符或单词的序列,本节将介绍文本数据的常见预处理步骤,预处理通常包括四个步骤: 读入文本 ...
- C++学习笔记-第4单元-对象和类(基础)
C++学习笔记 文章目录 C++学习笔记 第4单元 对象和类(基础) 单元导读 4.1 用类创建对象 4.1.1 对象和类 4.1.2 创建对象并访问 4.2 对象拷贝.分离声明与实现 4.2.1 对 ...
- MySQL学习笔记——尚硅谷李玉婷经典版MySQL基础笔记(一)
MySQL学习笔记--尚硅谷李玉婷经典版MySQL基础笔记(一) MySQL学习笔记目录 MySQL学习笔记--尚硅谷李玉婷经典版MySQL基础笔记(一) 一.基础知识 1.MySQL的语法规范 2. ...
- 大数据Hadoop教程-学习笔记01【大数据导论与Linux基础】
视频教程:哔哩哔哩网站:黑马大数据Hadoop入门视频教程,总时长:14:22:04 教程资源:https://pan.baidu.com/s/1WYgyI3KgbzKzFD639lA-_g,提取码: ...
- Vue学习笔记(1)(认识Vue、基础语法)
Vue2.x学习笔记.原视频教程:最全最新Vue.Vuejs教程,从入门到精通_哔哩哔哩 (゜-゜)つロ 干杯~-bilibili 第一部分:认识Vue.Vue基本语法. 邂逅Vue.js 简单认识V ...
- PyTorch学习笔记(二):PyTorch简介与基础知识
往期学习资料推荐: 1.Pytorch实战笔记_GoAI的博客-CSDN博客 2.Pytorch入门教程_GoAI的博客-CSDN博客 本系列目录: PyTorch学习笔记(一):PyTorch环境安 ...
- mysql学习笔记(13)之mycat切分规则与es基础
mycat切分规则与es基础 mycat基础配置 mycat切分规则 es,es-head,kibana简介与安装 Windows下安装 es分布式搜索引擎安装 elasticsearch-head安 ...
- python 网络接口 开发_Python自动化学习笔记(八)——接口开发、发送网络请求、发送邮件、写日志...
1.接口开发(flask模块) Python自动化学习笔记(七)接口开发部分的内容补充 1.1参数为json格式: flask.request.is_json #判断参数是否是json格式 flask ...
最新文章
- [BZOJ 2038][2009国家集训队]小Z的袜子(hose)(莫队)
- CentOS 初体验十六:阿里云安装Nexus搭建Maven私有仓库
- Golang 的跨平台交叉编译浅析
- GNU C 、ANSI C、标准C、标准c++区别和联系
- Spring Boot2.1.5(2)---2.x 新特性
- 让sublime编译php、js
- 新春测 kinect motor
- 【雷达通信】基于matlab GUI雷达定位【含Matlab源码 302期】
- 代码走查(codereview)如何执行才能提升代码质量
- 文件服务器版压缩工具,FileOptimizer文件压缩工具
- 零基础入门AI量化交易学习笔记
- 服务器选云主机还是VPS主机呢?
- Visual SourceSafe 使用说明
- 【老九】【Python】函数与模块
- EasyExcel自定义复杂的表头并在同sheet中实现分页
- dos攻击的工具——pentmenu
- XTransfer外贸收款账户是如何收费的?
- 叶辽 c语言,段子贴,不定期更新叶辽、黄源清、守墓人都负重伤,而魔王也并不...
- TenSEAL 同态加密(密文传输)
- PG332 ERNIC Datasheet Translation
热门文章
- 饶毅:中国脑计划是我见过的最差科学经费管理,中国猴计划应该缓行
- 新型人工突触可用于高度扩展的类脑计算
- AI学会灌水和造假!Google新研究揭露了AI现实应用的陷阱
- 南洋理工大学研发植物“通信”设备,未来可成为环境探测器
- 量子信息技术研究现状与未来
- 马化腾:5G和AI双核驱动产业互联网进入“快车道”
- 两个黑箱问题 ——深度神经网络和脑神经网络
- Gartner十大IT预测:七大数字巨头,有五家将心甘情愿“自我颠覆”
- 防止酒后删库!日本人用 3 小时做了个酒精测试软件
- 漫画:如何在数组中找到和为 “特定值” 的三个数?