ROS tf变换之得到两个坐标之间的转换关系

1、two_tf_transform.cpp

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
double x,y,z,ww,zz,hh,ii,Aww,Azz,Ahh,Aii;
double theta;
int main(int argc, char** argv){
  ros::init(argc, argv, "two_tf_transform");
 
  ros::NodeHandle node;
  tf::TransformListener listener;
  ros::Rate rate(10.0);
  while (node.ok()){
    tf::StampedTransform transform;
    try{
        //得到坐标odom和坐标base_link之间的关系
      listener.waitForTransform("odom", "base_link", ros::Time(0), ros::Duration(3.0));
      listener.lookupTransform("odom", "base_link",
                               ros::Time(0), transform);
    }
    catch (tf::TransformException &ex) {
      ROS_ERROR("%s",ex.what());
      ros::Duration(1.0).sleep();
    }
 
    x=transform.getOrigin().x();
    y=transform.getOrigin().y();
    z=transform.getOrigin().z();
    cout<<"x: "<

2、CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(learn_tf)


find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  roscpp
  tf
)


catkin_package(

)


## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)


add_executable(two_tf_transform src/two_tf_transform.cpp)
target_link_libraries(two_tf_transform ${catkin_LIBRARIES})

3、package.xml



  learn_tf
  0.0.0
  The learn_tf package

  patience
  TODO


  catkin
  geometry_msgs
  roscpp
  tf
  geometry_msgs
  roscpp
  tf
  geometry_msgs
  roscpp
  tf


  
  
    

  

 

你可能感兴趣的:(ROS)