frame_manager.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2009, 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 
00030 #ifndef RVIZ_FRAME_MANAGER_H
00031 #define RVIZ_FRAME_MANAGER_H
00032 
00033 #include <map>
00034 
00035 #include <QObject>
00036 
00037 #include <ros/time.h>
00038 
00039 #include <OGRE/OgreVector3.h>
00040 #include <OGRE/OgreQuaternion.h>
00041 
00042 #include <boost/thread/mutex.hpp>
00043 
00044 #include <geometry_msgs/Pose.h>
00045 
00046 #ifndef Q_MOC_RUN
00047 #include <tf/message_filter.h>
00048 #endif
00049 
00050 namespace tf
00051 {
00052 class TransformListener;
00053 }
00054 
00055 namespace rviz
00056 {
00057 class Display;
00058 
00063 class FrameManager: public QObject
00064 {
00065 Q_OBJECT
00066 public:
00067 
00068   enum SyncMode {
00069     SyncOff = 0,
00070     SyncExact,
00071     SyncApprox
00072   };
00073 
00074   FrameManager();
00075 
00081   ~FrameManager();
00082 
00087    void setFixedFrame(const std::string& frame);
00088 
00090    void setPause( bool pause );
00091 
00092    bool getPause() { return pause_; }
00093 
00095    void setSyncMode( SyncMode mode );
00096 
00097    SyncMode getSyncMode() { return sync_mode_; }
00098 
00100    void syncTime( ros::Time time );
00101 
00103    ros::Time getTime() { return sync_time_; }
00104 
00110   template<typename Header>
00111   bool getTransform(const Header& header, Ogre::Vector3& position, Ogre::Quaternion& orientation)
00112   {
00113     return getTransform(header.frame_id, header.stamp, position, orientation);
00114   }
00115 
00122   bool getTransform(const std::string& frame, ros::Time time, Ogre::Vector3& position, Ogre::Quaternion& orientation);
00123 
00130   template<typename Header>
00131   bool transform(const Header& header, const geometry_msgs::Pose& pose, Ogre::Vector3& position, Ogre::Quaternion& orientation)
00132   {
00133     return transform(header.frame_id, header.stamp, pose, position, orientation);
00134   }
00135 
00143   bool transform(const std::string& frame, ros::Time time, const geometry_msgs::Pose& pose, Ogre::Vector3& position, Ogre::Quaternion& orientation);
00144 
00146   void update();
00147 
00153   bool frameHasProblems(const std::string& frame, ros::Time time, std::string& error);
00154 
00160   bool transformHasProblems(const std::string& frame, ros::Time time, std::string& error);
00161 
00170   template<class M>
00171   void registerFilterForTransformStatusCheck(tf::MessageFilter<M>* filter, Display* display)
00172   {
00173     filter->registerCallback(boost::bind(&FrameManager::messageCallback<M>, this, _1, display));
00174     filter->registerFailureCallback(boost::bind(&FrameManager::failureCallback<M>, this, _1, _2, display));
00175   }
00176 
00178   const std::string& getFixedFrame() { return fixed_frame_; }
00179 
00181   tf::TransformListener* getTFClient() { return tf_.get(); }
00182 
00184   const boost::shared_ptr<tf::TransformListener>& getTFClientPtr() { return tf_; }
00185 
00195   std::string discoverFailureReason(const std::string& frame_id,
00196                                     const ros::Time& stamp,
00197                                     const std::string& caller_id,
00198                                     tf::FilterFailureReason reason);
00199 
00200 Q_SIGNALS:
00202   void fixedFrameChanged();
00203 
00204 private:
00205 
00206   bool adjustTime( const std::string &frame, ros::Time &time );
00207 
00208   template<class M>
00209   void messageCallback(const boost::shared_ptr<M const>& msg, Display* display)
00210   {
00211     messageArrived(msg->header.frame_id, msg->header.stamp, msg->__connection_header ? (*msg->__connection_header)["callerid"] : "unknown", display);
00212   }
00213 
00214   template<class M>
00215   void failureCallback(const boost::shared_ptr<M const>& msg, tf::FilterFailureReason reason, Display* display)
00216   {
00217     messageFailed(msg->header.frame_id, msg->header.stamp, msg->__connection_header ? (*msg->__connection_header)["callerid"] : "unknown", reason, display);
00218   }
00219 
00220   void messageArrived(const std::string& frame_id, const ros::Time& stamp, const std::string& caller_id, Display* display);
00221   void messageFailed(const std::string& frame_id, const ros::Time& stamp, const std::string& caller_id, tf::FilterFailureReason reason, Display* display);
00222 
00223   struct CacheKey
00224   {
00225     CacheKey(const std::string& f, ros::Time t)
00226     : frame(f)
00227     , time(t)
00228     {}
00229 
00230     bool operator<(const CacheKey& rhs) const
00231     {
00232       if (frame != rhs.frame)
00233       {
00234         return frame < rhs.frame;
00235       }
00236 
00237       return time < rhs.time;
00238     }
00239 
00240     std::string frame;
00241     ros::Time time;
00242   };
00243 
00244   struct CacheEntry
00245   {
00246     CacheEntry(const Ogre::Vector3& p, const Ogre::Quaternion& o)
00247     : position(p)
00248     , orientation(o)
00249     {}
00250 
00251     Ogre::Vector3 position;
00252     Ogre::Quaternion orientation;
00253   };
00254   typedef std::map<CacheKey, CacheEntry > M_Cache;
00255 
00256   boost::mutex cache_mutex_;
00257   M_Cache cache_;
00258 
00259   boost::shared_ptr<tf::TransformListener> tf_;
00260   std::string fixed_frame_;
00261 
00262   bool pause_;
00263 
00264   SyncMode sync_mode_;
00265 
00266   // the current synchronized time, used to overwrite ros:Time(0)
00267   ros::Time sync_time_;
00268 
00269   // used for approx. syncing
00270   double sync_delta_;
00271   double current_delta_;
00272 };
00273 
00274 }
00275 
00276 #endif // RVIZ_FRAME_MANAGER_H


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Oct 6 2014 07:26:35