tf_kdl.cpp
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 #include "tf_conversions/tf_kdl.h"
00031 #include "kdl_conversions/kdl_msg.h"
00032 
00033 namespace tf {
00034 
00035   void poseTFToKDL(const tf::Pose& t, KDL::Frame& k)
00036   {
00037     for (unsigned int i = 0; i < 3; ++i)
00038       k.p[i] = t.getOrigin()[i];
00039     for (unsigned int i = 0; i < 9; ++i)
00040       k.M.data[i] = t.getBasis()[i/3][i%3];
00041   }
00042 
00043   void poseKDLToTF(const KDL::Frame& k, tf::Pose& t)
00044   {
00045     t.setOrigin(tf::Vector3(k.p[0], k.p[1], k.p[2]));
00046     t.setBasis(tf::Matrix3x3(k.M.data[0], k.M.data[1], k.M.data[2],
00047                            k.M.data[3], k.M.data[4], k.M.data[5],
00048                            k.M.data[6], k.M.data[7], k.M.data[8]));
00049   }
00050 
00051   void quaternionTFToKDL(const tf::Quaternion& t, KDL::Rotation& k)
00052   {
00053     k = KDL::Rotation::Quaternion(t[0], t[1], t[2], t[3]);
00054   }
00055 
00056   void quaternionKDLToTF(const KDL::Rotation &k, tf::Quaternion &t)
00057   {
00058     double x, y, z, w;
00059     k.GetQuaternion(x, y, z, w);
00060     t = tf::Quaternion(x, y, z, w);
00061   }
00062 
00063   void transformTFToKDL(const tf::Transform &t, KDL::Frame &k)
00064   {
00065     for (unsigned int i = 0; i < 3; ++i)
00066       k.p[i] = t.getOrigin()[i];
00067     for (unsigned int i = 0; i < 9; ++i)
00068       k.M.data[i] = t.getBasis()[i/3][i%3];
00069   }
00070 
00071   void transformKDLToTF(const KDL::Frame &k, tf::Transform &t)
00072   {
00073     t.setOrigin(tf::Vector3(k.p[0], k.p[1], k.p[2]));
00074     t.setBasis(tf::Matrix3x3(k.M.data[0], k.M.data[1], k.M.data[2],
00075                            k.M.data[3], k.M.data[4], k.M.data[5],
00076                            k.M.data[6], k.M.data[7], k.M.data[8]));
00077   }
00078 
00079   void vectorTFToKDL(const tf::Vector3& t, KDL::Vector& k)
00080   {
00081     k[0] = t[0];
00082     k[1] = t[1];
00083     k[2] = t[2];
00084   }
00085 
00086   void vectorKDLToTF(const KDL::Vector& k, tf::Vector3& t)
00087   {
00088     t[0] = k[0];
00089     t[1] = k[1];
00090     t[2] = k[2];
00091   }
00092  
00093  
00094   /* DEPRECATED FUNCTIONS */
00095   geometry_msgs::Pose addDelta(const geometry_msgs::Pose &pose, const geometry_msgs::Twist &twist, const double &t)
00096   {
00097     geometry_msgs::Pose result;
00098     KDL::Twist kdl_twist;
00099     KDL::Frame kdl_pose_id, kdl_pose;
00100 
00101     poseMsgToKDL(pose,kdl_pose);
00102     twistMsgToKDL(twist,kdl_twist);
00103     kdl_pose = KDL::addDelta(kdl_pose_id,kdl_twist,t)*kdl_pose;
00104     poseKDLToMsg(kdl_pose,result);
00105     return result;
00106   }
00107 
00108 }  // namespace tf
00109 


tf_conversions
Author(s): Tully Foote
autogenerated on Mon Oct 6 2014 00:18:24