29 #ifndef HECTOR_QUADROTOR_MODEL_HELPERS_H 30 #define HECTOR_QUADROTOR_MODEL_HELPERS_H 32 #include <geometry_msgs/Wrench.h> 33 #include <boost/range/iterator_range.hpp> 38 template <
typename T>
int isnan(
const T& value) {
42 template <
typename T, std::
size_t N>
int isnan(
const boost::array<T,N>& array) {
43 for(
typename boost::array<T,N>::const_iterator it = array.begin(); it != array.end(); ++it)
48 template <
typename IteratorT>
int isnan(
const boost::iterator_range<IteratorT>& range,
const typename boost::iterator_range<IteratorT>::value_type& min,
const typename boost::iterator_range<IteratorT>::value_type& max) {
49 for(IteratorT it = range.begin(); it != range.end(); ++it)
54 template <
typename T>
int isinf(
const T& value) {
58 template <
typename T, std::
size_t N>
int isinf(
const boost::array<T,N>& array) {
59 for(
typename boost::array<T,N>::const_iterator it = array.begin(); it != array.end(); ++it)
64 template <
typename IteratorT>
int isinf(
const boost::iterator_range<IteratorT>& range,
const typename boost::iterator_range<IteratorT>::value_type& min,
const typename boost::iterator_range<IteratorT>::value_type& max) {
65 for(IteratorT it = range.begin(); it != range.end(); ++it)
70 template <
typename T>
void limit(T& value,
const T& min,
const T& max) {
71 if (!
isnan(min) && value < min) value = min;
72 if (!
isnan(max) && value > max) value = max;
75 template <
typename T, std::
size_t N>
void limit(boost::array<T,N>& array,
const T& min,
const T& max) {
76 for(
typename boost::array<T,N>::iterator it = array.begin(); it != array.end(); ++it)
80 template <
typename IteratorT>
void limit(
const boost::iterator_range<IteratorT>& range,
const typename boost::iterator_range<IteratorT>::value_type& min,
const typename boost::iterator_range<IteratorT>::value_type& max) {
81 for(IteratorT it = range.begin(); it != range.end(); ++it)
85 template <
typename T>
static inline void checknan(T& value,
const std::string& text =
"") {
88 if (!text.empty()) std::cerr << text <<
" contains **!?* Nan values!" << std::endl;
96 if (!text.empty()) std::cerr << text <<
" is +-Inf!" << std::endl;
103 template <
typename Message,
typename Vector>
static inline void toVector(
const Message& msg, Vector& vector)
110 template <
typename Message,
typename Vector>
static inline void fromVector(
const Vector& vector, Message& msg)
117 template <
typename Message,
typename Quaternion>
static inline void toQuaternion(
const Message& msg, Quaternion& quaternion)
119 quaternion.w = msg.w;
120 quaternion.x = msg.x;
121 quaternion.y = msg.y;
122 quaternion.z = msg.z;
125 template <
typename Message,
typename Quaternion>
static inline void fromQuaternion(
const Quaternion& quaternion, Message& msg)
127 msg.w = quaternion.w;
128 msg.x = quaternion.x;
129 msg.y = quaternion.y;
130 msg.z = quaternion.z;
133 static inline geometry_msgs::Vector3
operator+(
const geometry_msgs::Vector3& a,
const geometry_msgs::Vector3& b)
135 geometry_msgs::Vector3 result;
136 result.x = a.x + b.x;
137 result.y = a.y + b.y;
138 result.z = a.z + b.z;
142 static inline geometry_msgs::Wrench
operator+(
const geometry_msgs::Wrench& a,
const geometry_msgs::Wrench& b)
144 geometry_msgs::Wrench result;
145 result.force = a.force + b.force;
146 result.torque = a.torque + b.torque;
161 for(const_iterator it =
begin(); it !=
end(); ++it) {
162 if (it !=
begin()) os <<
" ";
173 template <
typename T> std::ostream &operator<<(std::ostream& os, const PrintVector<T>& vector) {
return vector >> os; }
177 #endif // HECTOR_QUADROTOR_MODEL_HELPERS_H
const_iterator end() const
int isnan(const T &value)
int isinf(const boost::iterator_range< IteratorT > &range, const typename boost::iterator_range< IteratorT >::value_type &min, const typename boost::iterator_range< IteratorT >::value_type &max)
static void fromVector(const Vector &vector, Message &msg)
void limit(T &value, const T &min, const T &max)
static void checknan(T &value, const std::string &text="")
std::ostream & operator>>(std::ostream &os) const
const_iterator begin() const
static void fromQuaternion(const Quaternion &quaternion, Message &msg)
int isnan(const boost::iterator_range< IteratorT > &range, const typename boost::iterator_range< IteratorT >::value_type &min, const typename boost::iterator_range< IteratorT >::value_type &max)
static void toQuaternion(const Message &msg, Quaternion &quaternion)
int isinf(const T &value)
static geometry_msgs::Vector3 operator+(const geometry_msgs::Vector3 &a, const geometry_msgs::Vector3 &b)
static void toVector(const Message &msg, Vector &vector)
PrintVector(const_iterator begin, const_iterator end, const std::string &delimiter="[ ]")