00001 //================================================================================================= 00002 // Copyright (c) 2013, Johannes Meyer and contributors, Technische Universitat Darmstadt 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 // * Redistributions of source code must retain the above copyright 00008 // notice, this list of conditions and the following disclaimer. 00009 // * Redistributions in binary form must reproduce the above copyright 00010 // notice, this list of conditions and the following disclaimer in the 00011 // documentation and/or other materials provided with the distribution. 00012 // * Neither the name of the Flight Systems and Automatic Control group, 00013 // TU Darmstadt, nor the names of its contributors may be used to 00014 // endorse or promote products derived from this software without 00015 // specific prior written permission. 00016 00017 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00018 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00019 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00020 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 00021 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00022 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00023 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00024 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00025 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00026 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00027 //================================================================================================= 00028 00029 #ifndef HECTOR_QUADROTOR_MODEL_HELPERS_H 00030 #define HECTOR_QUADROTOR_MODEL_HELPERS_H 00031 00032 #include <geometry_msgs/Wrench.h> 00033 00034 namespace hector_quadrotor_model 00035 { 00036 00037 template <typename T> static inline void checknan(T& value, const std::string& text = "") { 00038 if (!(value == value)) { 00039 #ifndef NDEBUG 00040 if (!text.empty()) std::cerr << text << " contains **!?* Nan values!" << std::endl; 00041 #endif 00042 value = T(); 00043 return; 00044 } 00045 } 00046 00047 template <typename Message, typename Vector> static inline void toVector(const Message& msg, Vector& vector) 00048 { 00049 vector.x = msg.x; 00050 vector.y = msg.y; 00051 vector.z = msg.z; 00052 } 00053 00054 template <typename Message, typename Vector> static inline void fromVector(const Vector& vector, Message& msg) 00055 { 00056 msg.x = vector.x; 00057 msg.y = vector.y; 00058 msg.z = vector.z; 00059 } 00060 00061 static inline geometry_msgs::Vector3 operator+(const geometry_msgs::Vector3& a, const geometry_msgs::Vector3& b) 00062 { 00063 geometry_msgs::Vector3 result; 00064 result.x = a.x + b.x; 00065 result.y = a.y + b.y; 00066 result.z = a.z + b.z; 00067 return result; 00068 } 00069 00070 static inline geometry_msgs::Wrench operator+(const geometry_msgs::Wrench& a, const geometry_msgs::Wrench& b) 00071 { 00072 geometry_msgs::Wrench result; 00073 result.force = a.force + b.force; 00074 result.torque = a.torque + b.torque; 00075 return result; 00076 } 00077 00078 } 00079 00080 #endif // HECTOR_QUADROTOR_MODEL_HELPERS_H