odom->base_link

turtle_tf_listener.cpp
#include 
#include 
#include 
using namespace std;
double x,y,z,ww,zz,hh,ii,Aww,Azz,Ahh,Aii;
int main(int argc, char** argv){
  ros::init(argc, argv, "my_tf_listener");

  ros::NodeHandle node;
  tf::TransformListener listener;
  ros::Rate rate(10.0);
  while (node.ok()){
    tf::StampedTransform transform;
    try{

      listener.waitForTransform("odom", "base_link", ros::Time(0), ros::Duration(1.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: "<

turtle_tf_broadcaster.cpp

#include 
#include 

int main(int argc, char** argv){
  ros::init(argc, argv, "my_tf_broadcaster");

  ros::NodeHandle node;

  static tf::TransformBroadcaster br;
  tf::Transform transform;
  ros::Rate r(100);

  while(node.ok()){
  transform.setOrigin( tf::Vector3(1.0, 2.0, 0.0) );


  tf::Quaternion q;
  q.setRPY(1.0, 0.2, 0.3);
  transform.setRotation(q);
  br.sendTransform(tf::StampedTransform(transform, ros::Time::now(), "odom", "base_link"));
  r.sleep();
  }

return 0;
};


你可能感兴趣的:(※【ROS】)