文章目录

  • 1.利用nav_msgs/Path消息实现轨迹显示
  • 2.利用visualization_msgs/Marker消息类型显示轨迹

1.利用nav_msgs/Path消息实现轨迹显示

  • 主函数showpath.cpp
#include <ros/ros.h>
#include <ros/console.h>
#include <nav_msgs/Path.h>
#include <std_msgs/String.h>
#include <geometry_msgs/Quaternion.h>
#include <geometry_msgs/PoseStamped.h>
#include <tf/transform_broadcaster.h>
#include <tf/tf.h>main (int argc, char **argv)
{ros::init (argc, argv, "showpath");ros::NodeHandle ph;ros::Publisher path_pub = ph.advertise<nav_msgs::Path>("trajectory",1, true);ros::Time current_time, last_time;current_time = ros::Time::now();last_time = ros::Time::now();nav_msgs::Path path;//nav_msgs::Path path;path.header.stamp=current_time;path.header.frame_id="odom";double x = 0.0;double y = 0.0;double th = 0.0;double vx = 0.1;double vy = -0.1;double vth = 0.1;ros::Rate loop_rate(1);while (ros::ok()){current_time = ros::Time::now();//compute odometry in a typical way given the velocities of the robotdouble dt = 0.1;double delta_x = (vx * cos(th) - vy * sin(th)) * dt;double delta_y = (vx * sin(th) + vy * cos(th)) * dt;double delta_th = vth * dt;x += delta_x;y += delta_y;th += delta_th;geometry_msgs::PoseStamped this_pose_stamped;this_pose_stamped.pose.position.x = x;this_pose_stamped.pose.position.y = y;geometry_msgs::Quaternion goal_quat = tf::createQuaternionMsgFromYaw(th);this_pose_stamped.pose.orientation.x = goal_quat.x;this_pose_stamped.pose.orientation.y = goal_quat.y;this_pose_stamped.pose.orientation.z = goal_quat.z;this_pose_stamped.pose.orientation.w = goal_quat.w;this_pose_stamped.header.stamp=current_time;this_pose_stamped.header.frame_id="odom";path.poses.push_back(this_pose_stamped);path_pub.publish(path);ros::spinOnce();               // check for incoming messageslast_time = current_time;loop_rate.sleep();}return 0;
}
  • 编辑CMakeLists.txt
    add_executable(showpath src/showpath.cpp)
    target_link_libraries(showpath ${catkin_LIBRARIES})
  • rviz显示

在globel option的Fixed Fram输入odom
左边点击add
选中path
在path的topic选项中选
/trajectory

2.利用visualization_msgs/Marker消息类型显示轨迹

如名字所示,就是画出可视化的标志物。利用Marker有两种方法可以实现画出轨迹。相对于后面的方法来说,使用Marker可以有丰富的形状选择。首先看这个类包含的成员:

//各种标志物类型的定义,每一个的具体介绍和形状可以到这里查看:http://wiki.ros.org/rviz/DisplayTypes/Marker
uint8 ARROW=0//箭头
uint8 CUBE=1//立方体
uint8 SPHERE=2//球
uint8 CYLINDER=3//圆柱体
uint8 LINE_STRIP=4//线条(点的连线)
uint8 LINE_LIST=5//线条序列
uint8 CUBE_LIST=6//立方体序列
uint8 SPHERE_LIST=7//球序列
uint8 POINTS=8//点集
uint8 TEXT_VIEW_FACING=9//显示3D的文字
uint8 MESH_RESOURCE=10//网格?
uint8 TRIANGLE_LIST=11//三角形序列
//对标记的操作
uint8 ADD=0
uint8 MODIFY=0
uint8 DELETE=2
uint8 DELETEALL=3Header header
string ns   //命名空间namespace,就是你理解的那样
int32 id    //与命名空间联合起来,形成唯一的id,这个唯一的id可以将各个标志物区分开来,使得程序可以对指定的标志物进行操作
int32 type  //类型
int32 action    //操作,是添加还是修改还是删除
geometry_msgs/Pose pose       # Pose of the object
geometry_msgs/Vector3 scale   # Scale of the object 1,1,1 means default (usually 1 meter square)
std_msgs/ColorRGBA color      # Color [0.0-1.0]
duration lifetime             # How long the object should last before being automatically deleted.  0 means forever
bool frame_locked             # If this marker should be frame-locked, i.e. retransformed into its frame every timestep#Only used if the type specified has some use for them (eg. POINTS, LINE_STRIP, ...)
geometry_msgs/Point[] points//这个是在序列、点集中才会用到,指明序列中每个点的位置
#Only used if the type specified has some use for them (eg. POINTS, LINE_STRIP, ...)
#number of colors must either be 0 or equal to the number of points
#NOTE: alpha is not yet used
std_msgs/ColorRGBA[] colors# NOTE: only used for text markers
string text# NOTE: only used for MESH_RESOURCE markers
string mesh_resource
bool mesh_use_embedded_materials

参考:https://blog.csdn.net/u013834525/article/details/80447931

ROS中rviz显示运动轨迹的常见方法相关推荐

  1. ROS+Turtlebot3+RVIZ 显示机器人历史轨迹方法

    (六)ROS发布里程计(Odometry)消息并在rviz中显示_火星机器人life的博客-CSDN博客_ros 发布odom 一.如果只是RVIZ查看移动机器人的历史轨迹方法 1. 打开gazebo ...

  2. mathtype 复制粘贴到word中公式显示不全的问题解决方法

    mathtype 复制粘贴到word中公式显示不全的问题解决方法 由于论文模板中的段落行距设置成了固定值,而复制的公式纵向过长,仅能显示固定值设定的磅值区域. 解决办法为选定该公式,格式-段落-行距- ...

  3. 问题分享:Word中图片显示不全的解决方法

    前几天,帮一个同学做论文中的统计分析,遇到一个奇怪的问题,在Excel中做完图表,粘贴到Word中,就变成了下图中的情况. 图中上方是一个正常的图表(柱形图+折线图),下方红框标识的也是一个图片,但是 ...

  4. 为什么文本框里的字只显示一半_Word文档中文字显示不全的解决方法有哪些

    在Word 文档中,如果把段落中的文字字号设置大一点的字体,可能会出现文字显示不全的情况;表格中也可能出现这种情况,文字显示一半或都显示不出来,是什么原因?以下是学习啦小编为您带来的关于Word文档中 ...

  5. easyui获取下拉框选中的文本值_Word中文本显示不全的常见3种情况及解决方法

    在日常工作使用Word文档时,经常会遇到文本显示不全的情况,比如文本框或表格里的文本显示不全等情况,你一般是怎么操作呢?以下这3种常见情况你可能也遇到过,一起看看是什么原因并解决它们吧! 1.文本显示 ...

  6. ros中rviz不显示摄像头视频问题的解决

    1.添加image add->By display type->image->OK 2.设置image的topic为[/image_raw] 3 .之后图像就出来了

  7. 奥比中光深度摄像头_乐视三合一奥比中光Orbbec Astra Pro在ROS中配置显示RGB、深度、IR图像的两种思路...

    乐视的电视机摄像头带有深度信息,可用于体感识别.视觉SLAM.点云地图构建.三维重建等应用.但是刚开始无法显示RGB彩色图像,最后解决的过程发现有两种方法可以实现,一种是基于OpenNI的,另一种是基 ...

  8. 【RK3399Pro学习笔记】十五、ROS中launch启动文件的使用方法

    目录 Launch文件语法 <launch><launch><launch> <node><node><node> 参数设置 & ...

  9. java 字符串 字符查找_java之字符串中查找字串的常见方法

    1.int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引. int indexOf(String str, int startIndex):从指定的索引处开 ...

最新文章

  1. 微信架构 支付架构(下)
  2. JPA注解@GeneratedValue
  3. 第六章:双指针,BFS,和图论 【完结】
  4. MNA-CNN: 如何在美学质量评估中储存照片原始信息
  5. 在apache访问日志中统计统计前十名pv
  6. OPenGL程序导致WM_TIMER消息不能激发
  7. Comparison of video container formats
  8. [Java基础]内部类基础
  9. tornado学习笔记day05-访问数据库
  10. 在HTML标签中 lt h5 gt 表示,HTML lt;blockquotegt; 标签
  11. 机器学习基础算法24-SVM理论部分
  12. docker 常用操作-push分享及下载
  13. docker(12):Dockerfile
  14. 【Vue基础七】--- 组件和模块概念
  15. matlab画y等于x平方,如何用matlab画Y=X^2的图啊?
  16. 推荐开源项目计划管理软件 kanboard
  17. 摄影技能技巧大全 - 太精彩啦,年后弄个单反按着练练!
  18. Debian备份与还原
  19. java对象转JSONObject、JSONObject转java对象及String转JSONObject
  20. 《思危:犹太人的赚钱哲学》阅读

热门文章

  1. Python 回调函数的简单实例
  2. linux命令切换界面,Linux图形界面与命令行界面切换
  3. 如何解决TortoiseSVN不显示状态小图标问题
  4. Spring中的AOP切面编程的三种实现方式
  5. 三十天自学操作系统读后感3
  6. 怎样建网站能为后期工作提供有利条件
  7. cmake -fpic
  8. 强烈抗议抖音关闭`OBS`第三方推流接口的倡议
  9. Winspy++ Baidu盘
  10. BigInteger方法大全