libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
chompUtils.hpp
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2009, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
38 #ifndef CHOMP_UTILS_H_
39 #define CHOMP_UTILS_H_
40 
41 //#include <kdl/jntarray.hpp>
42 //#include <chomp_motion_planner/chomp_robot_model.h>
43 #include <iostream>
44 #include <vector>
45 
46 
47 #include <Eigen/Core>
48 #include <Eigen/Geometry>
49 
50 //using namespace std;
51 
52 //namespace chomp
53 //{
54 
55  static const int DIFF_RULE_LENGTH = 7;
56  static const int NUM_DIFF_RULES = 3;
57 
58  // the differentiation rules (centered at the center)
59  static const double DIFF_RULES[NUM_DIFF_RULES][DIFF_RULE_LENGTH] = {
60  {0, 0, -2/6.0, -3/6.0, 6/6.0, -1/6.0, 0}, // velocity
61  {0, -1/12.0, 16/12.0, -30/12.0, 16/12.0, -1/12.0, 0}, // acceleration
62  {0, 1/12.0, -17/12.0, 46/12.0, -46/12.0, 17/12.0, -1/12.0} // jerk
63  };
64 
65 
66 inline void stdVectorToEigenTransform(const std::vector<double>& stl, Eigen::Affine3d& T)
67  {
68  for (int j=0; j<4; j++)
69  {
70  for (int i=0; i<3; i++)
71  {
72  T(i,j) = stl[i*4+j];
73  }
74  }
75 
76  T(3,0) = 0;
77  T(3,1) = 0;
78  T(3,2) = 0;
79  T(3,3) = 1;
80 
81  //cout << "Transfo : " << endl << T.matrix() << endl;
82  }
83 
84 inline void eigenTransformToStdVector(const Eigen::Affine3d& T, std::vector<double>& stl )
85 {
86  stl.resize(12);
87  for (int j=0; j<4; j++)
88  {
89  for (int i=0; i<3; i++)
90  {
91  stl[i*4+j] = T(i,j);
92  }
93  }
94 }
95 
96 // inline void debugJointArray(KDL::JntArray& joint_array)
97 // {
98 // for (unsigned int i=0; i<joint_array.rows(); i++)
99 // {
100 // std::cout << joint_array(i) << "\t";
101 // }
102 // std::cout << std::endl;
103 // }
104 //
105 // template<typename KDLType, typename EigenType>
106 // void kdlVecToEigenVec(std::vector<KDLType>& kdl_v, std::vector<Eigen::Map<EigenType> >& eigen_v, int rows, int cols)
107 // {
108 // int size = kdl_v.size();
109 // eigen_v.clear();
110 // for (int i=0; i<size; i++)
111 // {
112 // eigen_v.push_back(Eigen::Map<EigenType>(kdl_v[i].data, rows, cols));
113 // }
114 // }
115 //
116 // template<typename KDLType, typename EigenType>
117 // void kdlVecVecToEigenVecVec(std::vector<std::vector<KDLType> >& kdl_vv, std::vector<std::vector<Eigen::Map<EigenType> > > & eigen_vv, int rows, int cols)
118 // {
119 // int size = kdl_vv.size();
120 // eigen_vv.resize(size);
121 // for (int i=0; i<size; i++)
122 // {
123 // kdlVecToEigenVec(kdl_vv[i], eigen_vv[i], rows, cols);
124 // }
125 // }
126 
127 
128 //} //namespace chomp
129 
130 
131 #endif /* CHOMP_UTILS_H_ */
132 
133