eigen_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 <eigen_conversions/eigen_kdl.h>
00031 
00032 namespace tf {
00033 
00034 void quaternionKDLToEigen(const KDL::Rotation &k, Eigen::Quaterniond &e)
00035 {
00036   // // is it faster to do this?
00037   k.GetQuaternion(e.x(), e.y(), e.z(), e.w());
00038   
00039   // or this?
00040   //double x, y, z, w;
00041   //k.GetQuaternion(x, y, z, w);
00042   //e = Eigen::Quaterniond(w, x, y, z);
00043 }
00044 
00045 void quaternionEigenToKDL(const Eigen::Quaterniond &e, KDL::Rotation &k)
00046 {
00047   k = KDL::Rotation::Quaternion(e.x(), e.y(), e.z(), e.w());  
00048 }
00049 
00050 void transformKDLToEigen(const KDL::Frame &k, Eigen::Affine3d &e)
00051 {
00052   // translation
00053   for (unsigned int i = 0; i < 3; ++i)
00054     e(i, 3) = k.p[i];                                                                                                             
00055 
00056   // rotation matrix
00057   for (unsigned int i = 0; i < 9; ++i)
00058     e(i/3, i%3) = k.M.data[i];
00059 
00060   // "identity" row
00061   e(3,0) = 0.0;
00062   e(3,1) = 0.0;
00063   e(3,2) = 0.0;
00064   e(3,3) = 1.0;
00065 }
00066 
00067 void transformEigenToKDL(const Eigen::Affine3d &e, KDL::Frame &k)
00068 {
00069   for (unsigned int i = 0; i < 3; ++i)
00070     k.p[i] = e(i, 3);                                                                                                             
00071   for (unsigned int i = 0; i < 9; ++i)
00072     k.M.data[i] = e(i/3, i%3);
00073 }
00074 
00075 void twistEigenToKDL(const Eigen::Matrix<double, 6, 1> &e, KDL::Twist &k)
00076 {
00077   for(int i = 0; i < 6; ++i)
00078     k[i] = e[i];
00079 }
00080 
00081 void twistKDLToEigen(const KDL::Twist &k, Eigen::Matrix<double, 6, 1> &e)
00082 {
00083   for(int i = 0; i < 6; ++i)
00084     e[i] = k[i];
00085 }
00086 
00087 void vectorEigenToKDL(const Eigen::Matrix<double, 3, 1> &e, KDL::Twist &k)
00088 {
00089   for(int i = 0; i < 6; ++i)
00090     k[i] = e[i];
00091 }
00092 void vectorKDLToEigen(const KDL::Vector &k, Eigen::Matrix<double, 6, 1> &e)
00093 {
00094   for(int i = 0; i < 3; ++i)
00095     e[i] = k[i];
00096 }
00097 
00098 void wrenchKDLToEigen(const KDL::Wrench &k, Eigen::Matrix<double, 6, 1> &e)
00099 {
00100   for(int i = 0; i < 6; ++i)
00101     e[i] = k[i];
00102 }
00103 
00104 void wrenchEigenToKDL(const Eigen::Matrix<double, 6, 1> &e, KDL::Wrench &k)
00105 {
00106   for(int i = 0; i < 6; ++i)
00107     k[i] = e[i];
00108 }
00109 
00110 
00111 } // namespace


eigen_conversions
Author(s): Stuart Glaser, Adam Leeper
autogenerated on Thu Aug 27 2015 13:08:33