sensor_alignment_tf_dyn.cpp
Go to the documentation of this file.
00001 #include <ros/ros.h>
00002 
00003 // PCL specific includes
00004 #include <pcl_conversions/pcl_conversions.h>
00005 #include <pcl/point_cloud.h>
00006 #include <pcl/point_types.h>
00007 #include <pcl_ros/transforms.h>
00008 
00009 #include <dynamic_reconfigure/server.h>
00010 #include <sick_scan/tf_dynConfig.h>
00011 
00012 #include <tf2/LinearMath/Quaternion.h>
00013 #include <tf2_ros/transform_broadcaster.h>
00014 #include <tf2_eigen/tf2_eigen.h>
00015 
00016 Eigen::Affine3d child_2_parent;
00017 
00018 class ConfigTrans
00019 {
00020 public:
00021     std::string parentFrame;
00022     std::string childFrame;
00023     double trans_x;
00024     double trans_y;
00025     double trans_z;
00026     double trans_rot_x;
00027     double trans_rot_y;
00028     double trans_rot_z;
00029 };
00030 
00031 ConfigTrans cfgTrans;
00032 
00033 
00034 // for setting region of interest
00035 Eigen::Vector4f min_point;
00036 Eigen::Vector4f max_point;
00037 
00038 tf2_ros::Buffer tf_buffer;
00039 
00040 
00041 void callback(sick_scan_fusion::tf_dynConfig &config, uint32_t level)
00042 {
00043     cfgTrans.parentFrame = config.parent_frame;
00044     cfgTrans.childFrame = config.child_frame;
00045 
00046     cfgTrans.trans_x = config.tf_x;
00047     cfgTrans.trans_y = config.tf_y;
00048     cfgTrans.trans_z = config.tf_z;
00049     cfgTrans.trans_rot_x = config.tf_rot_x * M_PI / 180.0;
00050     cfgTrans.trans_rot_y = config.tf_rot_y * M_PI / 180.0;
00051     cfgTrans.trans_rot_z = config.tf_rot_z * M_PI / 180.0;
00052   }
00053 
00054 int main (int argc, char** argv)
00055 {
00056     // initialize
00057     ros::init (argc, argv, "sick_scan_fusion_tf_dyn");
00058     ros::NodeHandle nh;
00059 
00060     tf2_ros::TransformListener tf_listener(tf_buffer);
00061 
00062 
00063     child_2_parent = Eigen::Affine3d::Identity();
00064    
00065     // dynamic reconfigure
00066     dynamic_reconfigure::Server<sick_scan_fusion::tf_dynConfig> server;
00067     dynamic_reconfigure::Server<sick_scan_fusion::tf_dynConfig>::CallbackType f;
00068     f = boost::bind(&callback, _1, _2);
00069     server.setCallback(f);
00070 
00071 
00072     unsigned seq= 0;
00073     ros::Rate loop_rate(100);
00074     while (ros::ok())
00075     {
00076         if ((seq % 20) == 0)
00077         {
00078         printf("Par. %s Child: %s Trans x: %0.3lf\n", cfgTrans.childFrame.c_str(), cfgTrans.parentFrame.c_str(), cfgTrans.trans_x);
00079         }static tf2_ros::TransformBroadcaster br;
00080         child_2_parent = Eigen::Affine3d::Identity();
00081         child_2_parent.translate(Eigen::Vector3d( cfgTrans.trans_x,0,0));
00082         child_2_parent.translate(Eigen::Vector3d(0,  cfgTrans.trans_y,0));
00083         child_2_parent.translate(Eigen::Vector3d(0, 0, cfgTrans.trans_z));
00084         // pitch
00085         child_2_parent.rotate(Eigen::AngleAxisd(cfgTrans.trans_rot_x, Eigen::Vector3d(1, 0, 0)));
00086         // yaw
00087         child_2_parent.rotate(Eigen::AngleAxisd(cfgTrans.trans_rot_y, Eigen::Vector3d(0, 1, 0)));
00088         // yaw
00089         child_2_parent.rotate(Eigen::AngleAxisd(cfgTrans.trans_rot_z, Eigen::Vector3d(0, 0, 1)));
00090 
00091         geometry_msgs::TransformStamped transform_base_trans = tf2::eigenToTransform(child_2_parent);
00092         transform_base_trans.header.frame_id = cfgTrans.parentFrame;
00093         transform_base_trans.child_frame_id = cfgTrans.childFrame;
00094         transform_base_trans.header.stamp = ros::Time::now();
00095         transform_base_trans.header.seq = seq;
00096         br.sendTransform(transform_base_trans);
00097 
00098         ros::spinOnce();
00099         loop_rate.sleep();
00100         ++seq;
00101     }
00102 }
00103 


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Tue Jul 9 2019 05:05:34