plugindefs.h
Go to the documentation of this file.
00001 // Copyright (C) 2006-2008 Rosen Diankov (rdiankov@cs.cmu.edu)
00002 //
00003 // This program is free software: you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation, either version 3 of the License, or
00006 // at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015 #ifndef ROS_PLUGINS_H
00016 #define ROS_PLUGINS_H
00017 
00018 #include <rave/rave.h>
00019 using namespace OpenRAVE;
00020 
00021 // include boost for vc++ only (to get typeof working)
00022 #ifdef _MSC_VER
00023 #include <boost/typeof/std/string.hpp>
00024 #include <boost/typeof/std/vector.hpp>
00025 #include <boost/typeof/std/list.hpp>
00026 #include <boost/typeof/std/map.hpp>
00027 #include <boost/typeof/std/string.hpp>
00028 
00029 #define FOREACH(it, v) for(BOOST_TYPEOF(v)::iterator it = (v).begin(); it != (v).end(); (it)++)
00030 #define FOREACH_NOINC(it, v) for(BOOST_TYPEOF(v)::iterator it = (v).begin(); it != (v).end(); )
00031 
00032 #define FOREACHC(it, v) for(BOOST_TYPEOF(v)::const_iterator it = (v).begin(); it != (v).end(); (it)++)
00033 #define FOREACHC_NOINC(it, v) for(BOOST_TYPEOF(v)::const_iterator it = (v).begin(); it != (v).end(); )
00034 #define RAVE_REGISTER_BOOST
00035 #else
00036 
00037 #include <string>
00038 #include <vector>
00039 #include <list>
00040 #include <map>
00041 #include <string>
00042 
00043 #define FOREACH(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); (it)++)
00044 #define FOREACH_NOINC(it, v) for(typeof((v).begin()) it = (v).begin(); it != (v).end(); )
00045 
00046 #define FOREACHC FOREACH
00047 #define FOREACHC_NOINC FOREACH_NOINC
00048 
00049 #endif
00050 
00051 #include <stdint.h>
00052 #include <fstream>
00053 #include <iostream>
00054 
00055 #include <boost/assert.hpp>
00056 #include <boost/bind.hpp>
00057 #include <boost/format.hpp>
00058 #include <boost/shared_ptr.hpp>
00059 #include <boost/thread/mutex.hpp>
00060 #include <boost/thread/thread.hpp>
00061 #include <boost/format.hpp>
00062 
00063 using namespace std;
00064 
00065 #include <sys/timeb.h>    // ftime(), struct timeb
00066 
00067 #ifndef _WIN32
00068 #include <sys/time.h>
00069 #define Sleep(milli) usleep(1000*milli)
00070 #else
00071 #define WIN32_LEAN_AND_MEAN
00072 #include <winsock2.h>
00073 #endif
00074 
00075 template<class T>
00076 inline T CLAMP_ON_RANGE(T value, T min, T max)
00077 {
00078     if (value < min) return min;
00079     if (value > max) return max;
00080     return value;
00081 }
00082 
00083 inline uint32_t timeGetTime()
00084 {
00085 #ifdef _WIN32
00086     _timeb t;
00087     _ftime(&t);
00088 #else
00089     timeb t;
00090     ftime(&t);
00091 #endif
00092 
00093     return (uint32_t)(t.time*1000+t.millitm);
00094 }
00095 
00096 #define FORIT(it, v) for(it = (v).begin(); it != (v).end(); (it)++)
00097 
00098 inline uint64_t GetMicroTime()
00099 {
00100 #ifdef _WIN32
00101     LARGE_INTEGER count, freq;
00102     QueryPerformanceCounter(&count);
00103     QueryPerformanceFrequency(&freq);
00104     return (count.QuadPart * 1000000) / freq.QuadPart;
00105 #else
00106     struct timeval t;
00107     gettimeofday(&t, NULL);
00108     return (uint64_t)t.tv_sec*1000000+t.tv_usec;
00109 #endif
00110 }
00111 
00112 #include <ros/node_handle.h>
00113 #include <ros/master.h>
00114 #include <ros/time.h>
00115 using namespace ros;
00116 
00117 #include <geometry_msgs/Pose.h>
00118 #include <tf/tf.h>
00119 inline Transform GetTransform(const geometry_msgs::Pose& pose)
00120 {
00121     return Transform(Vector(pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z), Vector(pose.position.x, pose.position.y, pose.position.z));
00122 }
00123 inline Transform GetTransform(const tf::Transform& bt)
00124 {
00125     tf::Quaternion q = bt.getRotation();
00126     tf::Vector3 o = bt.getOrigin();
00127     return Transform(Vector(q.w(),q.x(),q.y(),q.z()),Vector(o.x(),o.y(),o.z()));
00128 }
00129 inline geometry_msgs::Pose GetPose(const Transform& t) {
00130     geometry_msgs::Pose p;
00131     p.orientation.x = t.rot.y; p.orientation.y = t.rot.z; p.orientation.z = t.rot.w; p.orientation.w = t.rot.x;
00132     p.position.x = t.trans.x; p.position.y = t.trans.y; p.position.z = t.trans.z;
00133     return p;
00134 }
00135 
00136 #include <ros/package.h>
00137 
00138 inline string resolveName(const std::string& url)
00139 {
00140     if (url.find("package://") != 0)
00141         return url;
00142 
00143     std::string mod_url = url;
00144     mod_url.erase(0, strlen("package://"));
00145     size_t pos = mod_url.find("/");
00146     if (pos == std::string::npos)
00147         throw openrave_exception(str(boost::format("Could not parse %s into file:// format")%url));
00148     std::string package = mod_url.substr(0, pos);
00149     mod_url.erase(0, pos);
00150     std::string package_path = ros::package::getPath(package);
00151 
00152     if (package_path.empty())
00153         throw openrave_exception("Package [" + package + "] does not exist");
00154 
00155     return package_path + mod_url;
00156 }
00157     
00158 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


orrosplanning
Author(s): Rosen Diankov (rosen.diankov@gmail.com)
autogenerated on Sat Mar 23 2013 22:32:59