Skip to content

Commit

Permalink
Move tf2::impl::toQuaternion to tf2_geometry_msgs
Browse files Browse the repository at this point in the history
Closes: ros#275

This breaks the cycle between tf2 and tf2_geometry_msgs.
I didn't add deprecated attributes for functions having
tf2_geometry_msgs in the method signature, as they would need to have
the right header imported anyhow.
  • Loading branch information
jspricke committed Apr 5, 2022
1 parent f3e6990 commit 15b77ac
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 48 deletions.
2 changes: 1 addition & 1 deletion test_tf2/test/test_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// limitations under the License.

#include <gtest/gtest.h>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#include <tf2/utils.h>
#include <tf2_kdl/tf2_kdl.h>
#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#include <ros/time.h>

double epsilon = 1e-9;
Expand Down
56 changes: 9 additions & 47 deletions tf2/include/tf2/impl/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,64 +15,26 @@
#ifndef TF2_IMPL_UTILS_H
#define TF2_IMPL_UTILS_H

#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
#include <tf2/transform_datatypes.h>
#include <tf2/LinearMath/Quaternion.h>

namespace tf2 {
namespace impl {

/** Function needed for the generalization of toQuaternion
* \param q a tf2::Quaternion
* \return a copy of the same quaternion
*/
inline
tf2::Quaternion toQuaternion(const tf2::Quaternion& q) {
return q;
}

/** Function needed for the generalization of toQuaternion
* \param q a geometry_msgs::Quaternion
* \return a copy of the same quaternion as a tf2::Quaternion
*/
// functions moved to tf2_geometry_msgs/tf2_geometry_msgs.h to break a cycle
#ifndef TF2_GEOMETRY_MSGS_H
inline
tf2::Quaternion toQuaternion(const geometry_msgs::Quaternion& q) {
tf2::Quaternion res;
fromMsg(q, res);
return res;
}
tf2::Quaternion toQuaternion(const tf2::Quaternion& q)
__attribute__((deprecated("toQuaternion moved to tf2_geometry_msgs, please include tf2_geometry_msgs/tf2_geometry_msgs.h before tf2/impl/utils.h")));

/** Function needed for the generalization of toQuaternion
* \param q a geometry_msgs::QuaternionStamped
* \return a copy of the same quaternion as a tf2::Quaternion
*/
inline
tf2::Quaternion toQuaternion(const geometry_msgs::QuaternionStamped& q) {
tf2::Quaternion res;
fromMsg(q.quaternion, res);
return res;
}

/** Function needed for the generalization of toQuaternion
* \param t some tf2::Stamped object
* \return a copy of the same quaternion as a tf2::Quaternion
*/
template<typename T>
tf2::Quaternion toQuaternion(const tf2::Stamped<T>& t) {
geometry_msgs::QuaternionStamped q = toMsg(t);
return toQuaternion(q);
}
tf2::Quaternion toQuaternion(const tf2::Stamped<T>& t)
__attribute__((deprecated("toQuaternion moved to tf2_geometry_msgs, please include tf2_geometry_msgs/tf2_geometry_msgs.h before tf2/impl/utils.h")));

/** Generic version of toQuaternion. It tries to convert the argument
* to a geometry_msgs::Quaternion
* \param t some object
* \return a copy of the same quaternion as a tf2::Quaternion
*/
template<typename T>
tf2::Quaternion toQuaternion(const T& t) {
geometry_msgs::Quaternion q = toMsg(t);
return toQuaternion(q);
}
tf2::Quaternion toQuaternion(const T& t)
__attribute__((deprecated("toQuaternion moved to tf2_geometry_msgs, please include tf2_geometry_msgs/tf2_geometry_msgs.h before tf2/impl/utils.h")));
#endif

/** The code below is blantantly copied from urdfdom_headers
* only the normalization has been added.
Expand Down
55 changes: 55 additions & 0 deletions tf2_geometry_msgs/include/tf2_geometry_msgs/tf2_geometry_msgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,61 @@ void fromMsg(const geometry_msgs::Quaternion& in, tf2::Quaternion& out)
out = tf2::Quaternion(in.x, in.y, in.z, in.w);
}

namespace impl {

/** Function needed for the generalization of toQuaternion
* \param q a tf2::Quaternion
* \return a copy of the same quaternion
*/
inline
tf2::Quaternion toQuaternion(const tf2::Quaternion& q) {
return q;
}

/** Function needed for the generalization of toQuaternion
* \param q a geometry_msgs::Quaternion
* \return a copy of the same quaternion as a tf2::Quaternion
*/
inline
tf2::Quaternion toQuaternion(const geometry_msgs::Quaternion& q) {
tf2::Quaternion res;
fromMsg(q, res);
return res;
}

/** Function needed for the generalization of toQuaternion
* \param q a geometry_msgs::QuaternionStamped
* \return a copy of the same quaternion as a tf2::Quaternion
*/
inline
tf2::Quaternion toQuaternion(const geometry_msgs::QuaternionStamped& q) {
tf2::Quaternion res;
fromMsg(q.quaternion, res);
return res;
}

/** Function needed for the generalization of toQuaternion
* \param t some tf2::Stamped object
* \return a copy of the same quaternion as a tf2::Quaternion
*/
template<typename T>
tf2::Quaternion toQuaternion(const tf2::Stamped<T>& t) {
geometry_msgs::QuaternionStamped q = toMsg(t);
return toQuaternion(q);
}

/** Generic version of toQuaternion. It tries to convert the argument
* to a geometry_msgs::Quaternion
* \param t some object
* \return a copy of the same quaternion as a tf2::Quaternion
*/
template<typename T>
tf2::Quaternion toQuaternion(const T& t) {
geometry_msgs::Quaternion q = toMsg(t);
return toQuaternion(q);
}
} // namespace


/***********************/
/** QuaternionStamped **/
Expand Down

0 comments on commit 15b77ac

Please sign in to comment.