ROS在rviz中实时显示轨迹(nav_msgs/Path消息的使用)

摘要:
消息结构描述nav_消息/路径。msg Structure#表示机器人跟随Headerheaderargeometry_ msgs/PoseStamped[]poses123几何_ msgs/PoseStaped的路径的位置数组。msg结构#APosewithreference协调框架和时间戳

消息结构说明
nav_msgs/Path.msg结构
#An array of poses that represents a Path for a robot to follow
Header header
geometry_msgs/PoseStamped[] poses
1
2
3
geometry_msgs/PoseStamped.msg结构
# A Pose with reference coordinate frame and timestamp
Header header
Pose pose
1
2
3
geometry_msgs/Pose.msg结构
# A representation of pose in free space, composed of position and orientation.
Point position
Quaternion orientation
1
2
3
geometry_msgs/Point.msg结构
# This contains the position of a point in free space
float64 x
float64 y
float64 z
1
2
3
4
geometry_msgs/Quaternion.msg结构
# This represents an orientation in free space in quaternion form.

float64 x
float64 y
float64 z
float64 w
1
2
3
4
5
6
实现代码:
#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;
}
--------------------- 

免责声明:内容来源于网络,仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇AIX里面收取SNAP日志docker 配置 mysql下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Robot Operating System (ROS)学习笔记3---键盘控制

搭建环境:XMWare Ubuntu14.04 ROS(indigo) 转载自古月居 转载连接:http://www.guyuehome.com/253 一、创建控制包1 catkin_create-pkg smartcar_teleop rospy geometry_msgs std_msgs roscpp 2 catkin_make 建包,参考:h...

Cause: java.lang.UnsupportedOperationException

运行web项目的时候出现以下错误: ### Cause: java.lang.UnsupportedOperationException    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.ja...

rosdep update问题解决终极方法

转载:https://blog.csdn.net/weixin_42584917/article/details/114448355 最香的终极解决方法,虽然有点麻烦,可是必成功yyds raw.githubusercontent.com实际上就是github的用户数据服务器,rosdep程序下载的就是github.com/ros/rosdistro这个r...

MoveIt 仿真 Gazebe 教程学习(五)

MoveIt 仿真 Gazebe 教程学习(五)  【古月居】 ROS探索总结(五)——创建简单的机器人模型smartcar,网址如下: https://www.guyuehome.com/243 还有相关的一系列文章都可以看看。 前提: 源码地址:https://github.com/huchunxu/ros_exploring 需要把里面的 ROS2...

PCL中点云数据格式之间的转化

(1) 关于pcl::PCLPointCloud2::Ptr和pcl::PointCloud<pcl::PointXYZ>两中数据结构的区别 pcl::PointXYZ::PointXYZ ( float_x, float_y, float_z...

适合初学者的ROS机器人教程(2): Ubuntu下ROS使用Gazebo和Rviz对UR5机器人建模

作者:知乎@Ai酱 本文的前提是:默认你已安装ROS和Gazebo和Rviz,并且使用Ubuntu。Gazebo显示不出东西?检查下/home/用户名/.gazebo/models下面常见的模型有木有拷贝进去有数以百计的基本模型。 安装UR5的包 $ sudo apt-get install ros-kinetic-ur-gazebo ros-...