tf_pair.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  *  Copyright (c) 2014, Willow Garage, Inc.
00004  *  All rights reserved.
00005  *
00006  *  Redistribution and use in source and binary forms, with or without
00007  *  modification, are permitted provided that the following conditions
00008  *  are met:
00009  *
00010  *   * Redistributions of source code must retain the above copyright
00011  *     notice, this list of conditions and the following disclaimer.
00012  *   * Redistributions in binary form must reproduce the above
00013  *     copyright notice, this list of conditions and the following
00014  *     disclaimer in the documentation and/or other materials provided
00015  *     with the distribution.
00016  *   * Neither the name of the Willow Garage nor the names of its
00017  *     contributors may be used to endorse or promote products derived
00018  *     from this software without specific prior written permission.
00019  *
00020  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031  *  POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  * Author: Julius Kammerl (jkammerl@willowgarage.com)
00034  *
00035  */
00036 
00037 
00038 #include <tf/tfMessage.h>
00039 #include <tf/transform_datatypes.h>
00040 
00041 
00042 class TFPair
00043 {
00044 public:
00045 
00046   TFPair() :
00047     is_okay(true),
00048     angular_thres_(0.0f),
00049     trans_thres_(0.0f),
00050     updated_(false),
00051     first_transmission_(true)
00052   {
00053   }
00054 
00055   TFPair(const std::string& source_frame,
00056          const std::string& target_frame,
00057          float angular_thres = 0.0f,
00058          float trans_thres = 0.0f) :
00059       is_okay(true),
00060       source_frame_(source_frame),
00061       target_frame_(target_frame),
00062       angular_thres_(angular_thres),
00063       trans_thres_(trans_thres),
00064       updated_(false),
00065       first_transmission_(true)
00066   {
00067   }
00068 
00069   ~TFPair()
00070   {
00071   }
00072 
00073   void setSourceFrame(const std::string& source_frame)
00074   {
00075     source_frame_ = source_frame;
00076     updated_ = true;
00077   }
00078 
00079   const std::string& getSourceFrame() const
00080   {
00081     return source_frame_;
00082   }
00083 
00084   void setTargetFrame(const std::string& target_frame)
00085   {
00086     target_frame_ = target_frame;
00087     updated_ = true;
00088   }
00089 
00090   const std::string& getTargetFrame() const
00091   {
00092     return target_frame_;
00093   }
00094 
00095   void setAngularThres(float angular_thres)
00096   {
00097     angular_thres_ = angular_thres;
00098     updated_ = true;
00099   }
00100 
00101   float getAngularThres()
00102   {
00103     return angular_thres_;
00104   }
00105 
00106   void setTransThres(float trans_thres)
00107   {
00108     trans_thres_ = trans_thres;
00109     updated_ = true;
00110   }
00111 
00112   float getTransThres()
00113   {
00114     return trans_thres_;
00115   }
00116 
00117   void updateTransform(geometry_msgs::TransformStamped& update)
00118   {
00119     tf::transformMsgToTF(update.transform, tf_received_);
00120     updated_ = true;
00121   }
00122 
00123   void transmissionTriggered()
00124   {
00125     tf_transmitted_ = tf_received_;
00126   }
00127 
00128   bool updateNeeded()
00129   {
00130     bool result = false;
00131 
00132     if (updated_)
00133     {
00134       if (trans_thres_ == 0.0 || angular_thres_ == 0.0
00135           || tf_transmitted_.getOrigin().distance(tf_received_.getOrigin()) > trans_thres_
00136           || tf_transmitted_.getRotation().angle(tf_received_.getRotation()) > angular_thres_
00137           || first_transmission_)
00138       {
00139         result = true;
00140         first_transmission_ = false;
00141       }       
00142     }
00143 
00144     updated_ = false;
00145 
00146     return result;
00147   }
00148 
00149   const std::string getID()
00150   {
00151     return source_frame_+"-"+target_frame_;
00152   }
00153 
00154 public:
00155   bool is_okay; 
00156 
00157 private:
00158   std::string source_frame_;
00159   std::string target_frame_;
00160 
00161   float angular_thres_;
00162   float trans_thres_;
00163 
00164   tf::Transform tf_transmitted_;
00165   tf::Transform tf_received_;
00166 
00167   bool updated_;
00168   bool first_transmission_;
00169 
00170 };
00171 
00172 typedef boost::shared_ptr<TFPair> TFPairPtr;


tf2_web_republisher
Author(s): Julius Kammer
autogenerated on Thu Jun 6 2019 20:34:26