ros-path

#include <ros/ros.h>
#include <ros/console.h>
#include <nav_msgs/Path.h>
#include <std_msgs/String.h>
#include <nav_msgs/Odometry.h>
 
 
#include <geometry_msgs/Quaternion.h>
#include <geometry_msgs/PoseStamped.h>
#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include <tf/transform_broadcaster.h>
#include <tf/tf.h>
 
 
nav_msgs::Path  path;
geometry_msgs::PoseStamped first_pose_stamped;
bool first_odom = true;
 
ros::Publisher  path_pub, angle_pub, com_pub;
ros::Subscriber odomSub, com_sub;
ros::Subscriber odom_raw_Sub;

 void com_callback(const nav_msgs::Odometry::ConstPtr& odom) {
     nav_msgs::Odometry tmp_odom;
     tmp_odom = *odom;
     tf::Quaternion q = tf::createQuaternionFromRPY( 0, 0, (tf::getYaw(odom->pose.pose.orientation) + 0.17) );
     tmp_odom.pose.pose.orientation.w = q.getW();
     tmp_odom.pose.pose.orientation.x = q.getX();
     tmp_odom.pose.pose.orientation.y = q.getY();
     tmp_odom.pose.pose.orientation.z = q.getZ();

     com_pub.publish(tmp_odom);
 }
 
 void odomCallback(const nav_msgs::Odometry::ConstPtr& odom)
 {

    if (first_odom) {
        first_odom = false;
        first_pose_stamped.pose.position.x = odom->pose.pose.position.x;
        first_pose_stamped.pose.position.y = odom->pose.pose.position.y;
        return;
    }

    geometry_msgs::PoseStamped this_pose_stamped;
    this_pose_stamped.pose.position.x = first_pose_stamped.pose.position.x;
    this_pose_stamped.pose.position.y = first_pose_stamped.pose.position.y;


 
    this_pose_stamped.header.stamp = ros::Time::now();
    this_pose_stamped.header.frame_id = "base_odom";
 
    path.poses.push_back(this_pose_stamped);
 
    path.header.stamp = ros::Time::now();
    path.header.frame_id="base_odom";
    path_pub.publish(path);

    geometry_msgs::PoseWithCovarianceStamped tmp_pose;
    tmp_pose.header.stamp = ros::Time::now();
    tmp_pose.header.frame_id = "world";
    tmp_pose.pose.pose.position = this_pose_stamped.pose.position;
    tmp_pose.pose.pose.orientation = odom->pose.pose.orientation;
    angle_pub.publish(tmp_pose);

 }
 
 
int main (int argc, char **argv)
{
    ros::init (argc, argv, "showpath");
 
    ros::NodeHandle ph;
 
    path_pub = ph.advertise<nav_msgs::Path>("trajectory",10, true);
    angle_pub = ph.advertise<geometry_msgs::PoseWithCovarianceStamped>("/angle_pose", 100, true);
    com_pub = ph.advertise<nav_msgs::Odometry>("/odom_modify", 100, true);
    odomSub  = ph.subscribe<nav_msgs::Odometry>("/odom", 10, odomCallback);
    com_sub = ph.subscribe<nav_msgs::Odometry>("/odom", 10, com_callback);
 
    ros::Rate loop_rate(50);
 
    while (ros::ok())
    {
        ros::spinOnce();               // check for incoming messages
        loop_rate.sleep();
    }
 
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值