tf_comp_test.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 #include <tf2/LinearMath/Quaternion.h>
00003 #include <tf2_ros/buffer.h>
00004 #include <tf2_ros/transform_listener.h>
00005 #include <tf2_ros/transform_broadcaster.h>
00006 #include <labust/tools/conversions.hpp>
00007 
00008 int main(int argc, char* argv[])
00009 {
00010         ros::init(argc,argv,"tf_test_comp");
00011         tf2_ros::Buffer buffer;
00012         tf2_ros::TransformListener listener(buffer);
00013         tf2_ros::TransformBroadcaster broadcast;
00014         ros::Rate rate(10);
00015         ros::NodeHandle nh;
00016 
00017         double yaw(0);
00018 
00019         while (ros::ok())
00020         {
00021                 rate.sleep();
00022                 ros::spinOnce();
00023 
00024                 try
00025                 {
00026                         geometry_msgs::TransformStamped out;
00027                         out.header.frame_id = "local";
00028                         out.child_frame_id = "base_link";
00029                         out.transform.translation.x = 10;
00030                         out.transform.translation.y = -17;
00031                         out.transform.translation.z = 0;
00032                         labust::tools::quaternionFromEulerZYX(0,0,yaw, out.transform.rotation);
00033                         yaw += 0.3;
00034                         out.header.stamp =  ros::Time::now();
00035                         broadcast.sendTransform(out);
00036 
00037                         geometry_msgs::TransformStamped transformLocal, transformGPS;
00038                         ros::Time past = ros::Time::now() - ros::Duration(5.0);
00039                         transformLocal = buffer.lookupTransform("local", "gps_frame", past);
00040                         transformGPS = buffer.lookupTransform("base_link", "gps_frame", ros::Time(0));
00041 
00042                         std::cout<<"GPS position: "<<transformLocal.transform.translation.x<<", "<<transformLocal.transform.translation.y<<std::endl;
00043                         std::cout<<"GPS offset: "<<transformGPS.transform.translation.x<<","<<transformGPS.transform.translation.y<<","<<transformGPS.transform.translation.z<<std::endl;
00044 
00045                         Eigen::Quaternion<double> rot(transformLocal.transform.rotation.w,
00046                                         transformLocal.transform.rotation.x,
00047                                         transformLocal.transform.rotation.y,
00048                                         transformLocal.transform.rotation.z);
00049 
00050                         Eigen::Vector3d offset(transformGPS.transform.translation.x,
00051                                         transformGPS.transform.translation.y,
00052                                         transformGPS.transform.translation.z);
00053                         Eigen::Vector3d pos_corr = rot.matrix()*offset;
00054 
00055 
00056                         std::cout<<"correction:"<<pos_corr(0)<<","<<pos_corr(1)<<std::endl;
00057                         std::cout<<"Base_link position:"<<(transformLocal.transform.translation.x - pos_corr(0))<<","<<(transformLocal.transform.translation.y - pos_corr(1))<<std::endl;
00058                 }
00059                 catch(tf2::TransformException& ex)
00060                 {
00061                         ROS_WARN("Unable to decode GPS measurement. Missing frame : %s",ex.what());
00062                 }
00063         }
00064 
00065         return 0;
00066 }
00067 
00068 
00069 


labust_navigation
Author(s): Gyula Nagy
autogenerated on Fri Aug 28 2015 11:23:33