buffer_core.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00032 #ifndef TF2_BUFFER_CORE_H
00033 #define TF2_BUFFER_CORE_H
00034 
00035 #include "transform_storage.h"
00036 
00037 #include <string>
00038 
00039 #include "ros/duration.h"
00040 #include "ros/time.h"
00041 //#include "geometry_msgs/TwistStamped.h"
00042 #include "geometry_msgs/TransformStamped.h"
00043 
00045 //#include "tf/tf.h"
00046 
00047 #include <boost/unordered_map.hpp>
00048 #include <boost/thread/mutex.hpp>
00049 #include <boost/function.hpp>
00050 
00051 namespace tf2
00052 {
00053 
00054 typedef std::pair<ros::Time, CompactFrameID> P_TimeAndFrameID;
00055 typedef uint32_t TransformableCallbackHandle;
00056 typedef uint64_t TransformableRequestHandle;
00057 
00058 class TimeCacheInterface;
00059 
00060 enum TransformableResult
00061 {
00062   TransformAvailable,
00063   TransformFailure,
00064 };
00065 
00084 class BufferCore
00085 {
00086 public:
00087   /************* Constants ***********************/
00088   static const double DEFAULT_CACHE_TIME = 10.0;  
00089   static const uint32_t MAX_GRAPH_DEPTH = 1000UL;  
00090   static const int64_t DEFAULT_MAX_EXTRAPOLATION_DISTANCE = 0ULL; 
00091 
00097   BufferCore(ros::Duration cache_time_ = ros::Duration(DEFAULT_CACHE_TIME));
00098   virtual ~BufferCore(void);
00099 
00101   void clear();
00102 
00109   bool setTransform(const geometry_msgs::TransformStamped& transform, const std::string & authority, bool is_static = false);
00110 
00111   /*********** Accessors *************/
00112 
00122   geometry_msgs::TransformStamped 
00123     lookupTransform(const std::string& target_frame, const std::string& source_frame,
00124                     const ros::Time& time) const;
00125 
00138   geometry_msgs::TransformStamped
00139     lookupTransform(const std::string& target_frame, const ros::Time& target_time,
00140                     const std::string& source_frame, const ros::Time& source_time,
00141                     const std::string& fixed_frame) const;
00142   
00163   /*
00164   geometry_msgs::Twist
00165     lookupTwist(const std::string& tracking_frame, const std::string& observation_frame, const std::string& reference_frame,
00166                 const tf::Point & reference_point, const std::string& reference_point_frame, 
00167                 const ros::Time& time, const ros::Duration& averaging_interval) const;
00168   */
00181   /*
00182   geometry_msgs::Twist
00183     lookupTwist(const std::string& tracking_frame, const std::string& observation_frame, 
00184                 const ros::Time& time, const ros::Duration& averaging_interval) const;
00185   */
00193   bool canTransform(const std::string& target_frame, const std::string& source_frame,
00194                     const ros::Time& time, std::string* error_msg = NULL) const;
00195   
00205   bool canTransform(const std::string& target_frame, const ros::Time& target_time,
00206                     const std::string& source_frame, const ros::Time& source_time,
00207                     const std::string& fixed_frame, std::string* error_msg = NULL) const;
00208 
00212   std::string allFramesAsYAML() const;
00213 
00217   std::string allFramesAsString() const;
00218   
00219   typedef boost::function<void(TransformableRequestHandle request_handle, const std::string& target_frame, const std::string& source_frame,
00220                                ros::Time time, TransformableResult result)> TransformableCallback;
00221 
00223   TransformableCallbackHandle addTransformableCallback(const TransformableCallback& cb);
00225   void removeTransformableCallback(TransformableCallbackHandle handle);
00227   TransformableRequestHandle addTransformableRequest(TransformableCallbackHandle handle, const std::string& target_frame, const std::string& source_frame, ros::Time time);
00229   void cancelTransformableRequest(TransformableRequestHandle handle);
00230 
00231 private:
00232 
00233 
00237   std::string allFramesAsStringNoLock() const;  
00238 
00239 
00240   /******************** Internal Storage ****************/
00241   
00244   typedef std::vector<TimeCacheInterface*> V_TimeCacheInterface;
00245   V_TimeCacheInterface frames_;
00246   
00248   mutable boost::mutex frame_mutex_;
00249 
00251   typedef boost::unordered_map<std::string, CompactFrameID> M_StringToCompactFrameID;
00252   M_StringToCompactFrameID frameIDs_;
00254   std::vector<std::string> frameIDs_reverse;
00256   std::map<CompactFrameID, std::string> frame_authority_;
00257 
00258 
00260   ros::Duration cache_time_;
00261 
00262   mutable std::vector<P_TimeAndFrameID> lct_cache_;
00263 
00264   typedef boost::unordered_map<TransformableCallbackHandle, TransformableCallback> M_TransformableCallback;
00265   M_TransformableCallback transformable_callbacks_;
00266   uint32_t transformable_callbacks_counter_;
00267   boost::mutex transformable_callbacks_mutex_;
00268 
00269   struct TransformableRequest
00270   {
00271     ros::Time time;
00272     TransformableRequestHandle request_handle;
00273     TransformableCallbackHandle cb_handle;
00274     CompactFrameID target_id;
00275     CompactFrameID source_id;
00276     std::string target_string;
00277     std::string source_string;
00278   };
00279   typedef std::vector<TransformableRequest> V_TransformableRequest;
00280   V_TransformableRequest transformable_requests_;
00281   boost::mutex transformable_requests_mutex_;
00282   uint64_t transformable_requests_counter_;
00283 
00284   struct RemoveRequestByCallback;
00285   struct RemoveRequestByID;
00286 
00287   /************************* Internal Functions ****************************/
00288 
00295   TimeCacheInterface* getFrame(CompactFrameID c_frame_id) const;
00296 
00297   TimeCacheInterface* allocateFrame(CompactFrameID cfid, bool is_static);
00298 
00299 
00300   bool warnFrameId(const char* function_name_arg, const std::string& frame_id) const;
00301   CompactFrameID validateFrameId(const char* function_name_arg, const std::string& frame_id) const;
00302 
00304   CompactFrameID lookupFrameNumber(const std::string& frameid_str) const;
00305 
00307   CompactFrameID lookupOrInsertFrameNumber(const std::string& frameid_str);
00308 
00310   const std::string& lookupFrameString(CompactFrameID frame_id_num) const;
00311 
00312   void createConnectivityErrorString(CompactFrameID source_frame, CompactFrameID target_frame, std::string* out) const;
00313 
00316   int getLatestCommonTime(CompactFrameID target_frame, CompactFrameID source_frame, ros::Time& time, std::string* error_string) const;
00317 
00318   template<typename F>
00319   int walkToTopParent(F& f, ros::Time time, CompactFrameID target_id, CompactFrameID source_id, std::string* error_string) const;
00320 
00321   void testTransformableRequests();
00322   bool canTransformInternal(CompactFrameID target_id, CompactFrameID source_id,
00323                     const ros::Time& time, std::string* error_msg) const;
00324   bool canTransformNoLock(CompactFrameID target_id, CompactFrameID source_id,
00325                       const ros::Time& time, std::string* error_msg) const;
00326 
00328   //Using tf for now will be replaced fully
00329   //  tf::Transformer old_tf_;
00330 };
00331   
00332 }
00333 #endif //TF2_CORE_H


tf2
Author(s): Tully Foote, Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Mon Oct 6 2014 00:12:43