kdlTypekit.hpp
Go to the documentation of this file.
1 /******************************************************************************
2 * This file is part of the KDL project *
3 * *
4 * (C) 2010 Ruben Smits *
5 * 2010 Steven Bellens *
6 * ruben.smits@mech.kuleuven.be *
7 * steven.bellens@mech.kuleuven.be *
8 * Department of Mechanical Engineering, *
9 * Katholieke Universiteit Leuven, Belgium. *
10 * *
11 * You may redistribute this software and/or modify it under either the *
12 * terms of the GNU Lesser General Public License version 2.1 (LGPLv2.1 *
13 * <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>) or (at your *
14 * discretion) of the Modified BSD License: *
15 * Redistribution and use in source and binary forms, with or without *
16 * modification, are permitted provided that the following conditions *
17 * are met: *
18 * 1. Redistributions of source code must retain the above copyright *
19 * notice, this list of conditions and the following disclaimer. *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * 3. The name of the author may not be used to endorse or promote *
24 * products derived from this software without specific prior written *
25 * permission. *
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR *
27 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
28 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,*
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, *
34 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING *
35 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
36 * POSSIBILITY OF SUCH DAMAGE. *
37 * *
38 *******************************************************************************/
39 /* @Description:
40  * @brief KDL typekit for Orocos RTT
41  * @Author: Ruben Smits, Steven Bellens
42  */
43 
44 #ifndef ORO_KDL_TYPEKIT_HPP
45 #define ORO_KDL_TYPEKIT_HPP
46 
49 #include <kdl/frames.hpp>
50 #include <rtt/types/Types.hpp>
54 #include <rtt/types/carray.hpp>
56 #include <rtt/types/Operators.hpp>
58 #include <rtt/internal/mystd.hpp>
61 
62 #include <kdl/frames_io.hpp>
63 
64 #include <kdl/jntarray.hpp>
65 #include <kdl/jacobian.hpp>
66 
67 #include "motionproperties.hpp"
68 #include "kinfamproperties.hpp"
69 
70 namespace KDL
71 {
72  using namespace RTT;
73  using namespace RTT::detail;
74  using namespace std;
75 
85  template<class KDLType, int size>
86  double& get_container_item(KDLType & cont, int index)
87  {
88  if (index >= size || index < 0)
90  return cont[index];
91  }
92 
100  template<class KDLType, int size>
101  double get_container_item_copy(const KDLType & cont, int index)
102  {
103  if (index >= size || index < 0)
104  return internal::NA<double>::na();
105  return cont[index];
106  }
107 
113  {
114  public:
115  virtual std::string getName();
116 
117  virtual bool loadTypes();
118  virtual bool loadConstructors();
119  virtual bool loadOperators();
120  };
121 
125  template<class KDLType, int size>
127  : public StructTypeInfo<KDLType,true>
128  {
129  KDLVectorTypeInfo(std::string name) : StructTypeInfo<KDLType,true>(name) {}
130 
131  virtual bool decomposeTypeImpl(const KDLType& source, PropertyBag& targetbag ) const {
132  decomposeProperty( source, targetbag );
133  return true;
134  }
135 
136  virtual bool composeTypeImpl(const PropertyBag& source, KDLType& result) const {
137  return composeProperty( source, result );
138  }
139 
142  // discover if user gave us a part name or index:
144  if ( id_indx ) {
145  try {
146  if ( item->isAssignable() )
147  return internal::newFunctorDataSource(&get_container_item<KDLType,size>, internal::GenerateDataSource()(item.get(), id_indx.get() ) );
148  else
149  return internal::newFunctorDataSource(&get_container_item_copy<KDLType,size>, internal::GenerateDataSource()(item.get(), id_indx.get() ) );
150  } catch(...) {}
151  }
152  if (id_indx) {
153  log(Error) << "KDLVectorTypeInfo: Invalid index : " << id_indx->get() <<":"<< id_indx->getTypeName() << endlog();
154  }
155  if ( ! id_indx)
156  log(Error) << "KDLVectorTypeInfo: Not a member or index : " << id <<":"<< id->getTypeName() << endlog();
158  }
159  };
160 
164  template<class KDLType>
165  struct KDLTypeInfo
166  : public StructTypeInfo<KDLType,true>
167  {
168  KDLTypeInfo(std::string name) : StructTypeInfo<KDLType,true>(name) {}
169 
170  virtual bool decomposeTypeImpl(const KDLType& source, PropertyBag& targetbag ) const {
171  decomposeProperty( source, targetbag );
172  return true;
173  }
174 
175  virtual bool composeTypeImpl(const PropertyBag& source, KDLType& result) const {
176  return composeProperty( source, result );
177  }
178 
179  };
180 
185 }
186 #endif
double log(double a)
virtual result_t get() const =0
virtual bool decomposeTypeImpl(const KDLType &source, PropertyBag &targetbag) const
Definition: kdlTypekit.hpp:131
virtual bool decomposeTypeImpl(const KDLType &source, PropertyBag &targetbag) const
Definition: kdlTypekit.hpp:170
double get_container_item_copy(const KDLType &cont, int index)
Definition: kdlTypekit.hpp:101
virtual bool composeTypeImpl(const PropertyBag &source, KDLType &result) const
Definition: kdlTypekit.hpp:175
KDLTypekitPlugin KDLTypekit
Definition: kdlTypekit.cpp:48
KDLVectorTypeInfo(std::string name)
Definition: kdlTypekit.hpp:129
bool composeProperty(const PropertyBag &bag, Property< MultiVector< S, T > > &result)
KDLTypeInfo(std::string name)
Definition: kdlTypekit.hpp:168
void decomposeProperty(const Joint &joint, PropertyBag &targetbag)
double & get_container_item(KDLType &cont, int index)
Definition: kdlTypekit.hpp:86
boost::intrusive_ptr< DataSource< T > > shared_ptr
static DataSource< T > * narrow(base::DataSourceBase *db)
base::DataSourceBase::shared_ptr getMember(base::DataSourceBase::shared_ptr item, base::DataSourceBase::shared_ptr id) const
Definition: kdlTypekit.hpp:140
virtual std::string getTypeName() const
boost::intrusive_ptr< DataSourceBase > shared_ptr
virtual bool composeTypeImpl(const PropertyBag &source, KDLType &result) const
Definition: kdlTypekit.hpp:136


kdl_typekit
Author(s): Steven Bellens, Ruben Smits
autogenerated on Wed Jul 3 2019 19:39:45