|
| 1 | +/* |
| 2 | + * Copyright 2010, |
| 3 | + * François Bleibel, |
| 4 | + * Olivier Stasse, |
| 5 | + * |
| 6 | + * CNRS/AIST |
| 7 | + * |
| 8 | + * This file is part of sot-core. |
| 9 | + * sot-core is free software: you can redistribute it and/or |
| 10 | + * modify it under the terms of the GNU Lesser General Public License |
| 11 | + * as published by the Free Software Foundation, either version 3 of |
| 12 | + * the License, or (at your option) any later version. |
| 13 | + * sot-core is distributed in the hope that it will be |
| 14 | + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 15 | + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | + * GNU Lesser General Public License for more details. You should |
| 17 | + * have received a copy of the GNU Lesser General Public License along |
| 18 | + * with sot-core. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +#ifndef __SOT_MATRIX_HOMOGENEOUS_H__ |
| 22 | +#define __SOT_MATRIX_HOMOGENEOUS_H__ |
| 23 | + |
| 24 | + |
| 25 | +/* --- Matrix --- */ |
| 26 | +#include <sot/core/api.hh> |
| 27 | +#include <Eigen/Geometry> |
| 28 | +#include <Eigen/Core> |
| 29 | +#include <dynamic-graph/linear-algebra.h> |
| 30 | +#include <dynamic-graph/eigen-io.h> |
| 31 | + |
| 32 | +/* --------------------------------------------------------------------- */ |
| 33 | +/* --------------------------------------------------------------------- */ |
| 34 | +/* --------------------------------------------------------------------- */ |
| 35 | +namespace dynamicgraph { |
| 36 | + namespace sot { |
| 37 | + typedef Eigen::Transform<double,3, Eigen::Affine> SOT_CORE_EXPORT MatrixHomogeneous; |
| 38 | + typedef Eigen::Matrix<double,3,3> SOT_CORE_EXPORT MatrixRotation; |
| 39 | + typedef Eigen::AngleAxis<double> SOT_CORE_EXPORT VectorUTheta; |
| 40 | + typedef Eigen::Quaternion<double> SOT_CORE_EXPORT VectorQuaternion; |
| 41 | + typedef Eigen::Vector3d SOT_CORE_EXPORT VectorRotation; |
| 42 | + typedef Eigen::Vector3d SOT_CORE_EXPORT VectorRollPitchYaw; |
| 43 | + typedef Eigen::Matrix<double,6,6> SOT_CORE_EXPORT MatrixForce; |
| 44 | + typedef Eigen::Matrix<double,6,6> SOT_CORE_EXPORT MatrixTwist; |
| 45 | + |
| 46 | + inline void buildFrom (const MatrixHomogeneous& MH, MatrixTwist& MT) { |
| 47 | + |
| 48 | + Eigen::Vector3d _t = MH.translation(); |
| 49 | + MatrixRotation R(MH.linear()); |
| 50 | + Eigen::Matrix3d Tx; |
| 51 | + Tx << 0, -_t(2), _t(1), |
| 52 | + _t(2), 0, -_t(0), |
| 53 | + -_t(1), _t(0), 0; |
| 54 | + Eigen::Matrix3d sk; sk = Tx*R; |
| 55 | + |
| 56 | + MT.block<3,3>(0,0) = R; |
| 57 | + MT.block<3,3>(0,3) = sk; |
| 58 | + MT.block<3,3>(3,0).setZero(); |
| 59 | + MT.block<3,3>(3,3) = R; |
| 60 | + } |
| 61 | + |
| 62 | + } // namespace sot |
| 63 | +} // namespace dynamicgraph |
| 64 | + |
| 65 | +namespace Eigen { |
| 66 | + inline std::ostream& operator << (std::ostream &os, |
| 67 | + Eigen::AngleAxis<double> inst) { |
| 68 | + os << inst.toRotationMatrix() <<std::endl; |
| 69 | + return os; |
| 70 | + } |
| 71 | + |
| 72 | + inline std::ostream& operator << (std::ostream &os, |
| 73 | + Eigen::Transform<double, 3, Eigen::Affine> inst) { |
| 74 | + os << inst.matrix() <<std::endl; |
| 75 | + return os; |
| 76 | + } |
| 77 | + |
| 78 | + //TODO : CHECK TYPE AND WRITE PROPER |
| 79 | + inline std::istringstream& operator >> (std::istringstream &iss, |
| 80 | + Eigen::Transform<double,3,Eigen::Affine> &inst) { |
| 81 | + std::string ss("new test string"); |
| 82 | + Matrix3d m; |
| 83 | + m = AngleAxisd(0.0, Vector3d::UnitZ()); |
| 84 | + inst = m; |
| 85 | + iss >> ss; |
| 86 | + return iss; |
| 87 | + } |
| 88 | + |
| 89 | + //TODO : CHECK TYPE AND WRITE PROPER |
| 90 | + inline std::istringstream& operator >> (std::istringstream &iss, |
| 91 | + Eigen::AngleAxis<double> &inst) { |
| 92 | + std::string ss("new test string"); |
| 93 | + Matrix3d m; |
| 94 | + m = AngleAxisd(0.0, Vector3d::UnitZ()); |
| 95 | + inst = m; |
| 96 | + iss >> ss; |
| 97 | + return iss; |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +#endif /* #ifndef __SOT_MATRIX_HOMOGENEOUS_H__ */ |
0 commit comments