(九)ROS在rviz中实时显示轨迹(nav_msgs/Path消息的使用)
2017-04-20 11:21
639 查看
如何在rviz中如何实时显示轨迹呢?
本文分析nav_msgs/Path结构,实现在rviz中画出圆形轨迹。
参考资料
参考http://answers.ros.org/question/209224/show-robot-trajectory-in-rviz-real-time/
hector_slam中实现了画轨迹。
网址http://wiki.ros.org/hector_slam/Tutorials/MappingUsingLoggedData
那么先用bag数据来跑一跑。
步骤如下:
(1)启动包
(2)回放bag
rosbag play Team_Hector_MappingBox_RoboCup_2011_Rescue_Arena.bag –clock
(3)效果
![](http://img.blog.csdn.net/20170420111855788?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva3RpZ2VyaGVybzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
(4)查看发送的topic
![](http://img.blog.csdn.net/20170420113201248?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQva3RpZ2VyaGVybzM=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
将以上结构展开如下:
std_msgs/Header结构
geometry_msgs/PoseStamped[]结构
geometry_msgs/Pose pose结构
(2)编辑主函数showpath.cpp
(3)编辑CMakeLists.txt
在最后加入
(4)编译和运行
编译
运行
查看/trajectory 信息
在globel option的Fixed Fram输入odom
左边点击add
选中path
在path的topic选项中选
/trajectory
本文分析nav_msgs/Path结构,实现在rviz中画出圆形轨迹。
1.使用参考代码画轨迹效果展示(hector_slam)
google rviz中如何实时显示轨迹?会有以下重要资料。参考资料
参考http://answers.ros.org/question/209224/show-robot-trajectory-in-rviz-real-time/
hector_slam中实现了画轨迹。
网址http://wiki.ros.org/hector_slam/Tutorials/MappingUsingLoggedData
那么先用bag数据来跑一跑。
步骤如下:
(1)启动包
roslaunch hector_slam_launch tutorial.launch
(2)回放bag
rosbag play Team_Hector_MappingBox_RoboCup_2011_Rescue_Arena.bag –clock
(3)效果
(4)查看发送的topic
rostopic echo /trajectory
2.实现在rviz中画出圆形轨迹
以上的包太复杂,本文实现最简单的画轨迹功能。2.1分析nav_msgs/Path.msg结构
nav_msgs/Path.msg结构std_msgs/Header header geometry_msgs/PoseStamped[] poses
将以上结构展开如下:
std_msgs/Header结构
uint32 seq time stamp string frame_id
geometry_msgs/PoseStamped[]结构
std_msgs/Header header geometry_msgs/Pose pose
geometry_msgs/Pose pose结构
# This represents an orientation in free space in quaternion form. float64 x float64 y float64 z float64 w
2.2实现画出圆形轨迹
(1)新建工程mkdir -p showpath/src cd src catkin_create_pkg showpath roscpp rospy sensor_msgs std_msgs nav_msgs tf cd .. catkin_make
(2)编辑主函数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 robot double dt = (current_time - last_time).toSec(); 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 messages last_time = current_time; loop_rate.sleep(); } return 0; }
(3)编辑CMakeLists.txt
在最后加入
add_executable(showpath src/showpath.cpp) target_link_libraries(showpath ${catkin_LIBRARIES})
(4)编译和运行
编译
cd /home/topeet/workspace/showpath catkin_make
运行
source ./devel/setup.bash rosrun showpath showpath
查看/trajectory 信息
rostopic echo /trajectory
3.rviz实验结果
运行rosrun rviz rviz
在globel option的Fixed Fram输入odom
左边点击add
选中path
在path的topic选项中选
/trajectory
相关文章推荐
- ROS使用OpenCV读取图像并发布图像消息在rviz中显示
- (七)ROS使用OpenCV读取图像并发布图像消息在rviz中显示
- (五)ROS 发布tf消息并在rviz中显示
- (六)ROS发布里程计(Odometry)消息并在rviz中显示
- ROS——rplidar A1在rviz中实时显示分析
- (十)ROS在rviz中显示空间中的直线(visualization_msgs/Marker 消息)
- ROS 学习系列 -- 使用Rviz观察智能车的运动轨迹 无陀螺仪计算角度转动
- 在MFC中使用Static text控件显示消息
- 开发者使用黑莓平板电脑操控遥控车(还能实时显示)
- Windows Phone 实用开发技巧(18):使用SystemTray显示全局消息提醒
- 在jsp页面中使用显示单独的多个错误消息
- xcode路径引起的问题,使用xcode-select -print-path 显示后再使用Xcode-select -switch更改
- MFC中List Control控件的使用及实时显示系统时间的方法
- C#读取WORD时发生“拒绝访问”及“消息筛选器显示应用程序正在使用中”异常的处理
- 使用Uploadify实现上传图片生成缩略图例子,实时显示进度条
- 使用 jQuery progressbar 实时显示用户资料完善度
- Windows Phone 实用开发技巧(18):使用SystemTray显示全局消息提醒 推荐
- Struts 使用要点(概述,Spring与Struts的整合,输入校验与消息显示)
- 使用AJAX实时显示数据
- 【分享】 在silverlight中使用wcf上传文件并实时显示进度