如何接收RVIZ中的2D Pose Estimate 和2D Nav Goal


#include "ros/ros.h"
#include "std_msgs/String.h"
#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include <iostream>
#include <geometry_msgs/PointStamped.h>

void chatterCallback(const geometry_msgs::PoseWithCovarianceStamped::ConstPtr& msg)
{
  double x=msg->pose.pose.position.y;
  double y=msg->pose.pose.position.x;
  //double theta=msg->pose.pose.orientation;
  std::cout<<x<<y<<std::endl;
}

void chatterCallback1(const geometry_msgs::PointStamped::ConstPtr& msg)
{
  double x=msg->point.x;
  double y=msg->point.y;
  //double theta=msg->pose.pose.orientation;
  std::cout<<x<<y<<std::endl;
}
int main(int argc, char **argv)
{
  ros::init(argc, argv, "sub2");
  ros::NodeHandle nh;

  ros::Subscriber sub = nh.subscribe("/initialpose", 1000, chatterCallback);
 // ros::Subscriber sub = nh.subscribe("/clicked_point", 1000, chatterCallback1);
while(1)
{
  ros::spinOnce();
}
  std::cout<<"........................."<<std::endl;

  return 0;
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM