如何接收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