kinfamproperties.cpp
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 
40 #include "kinfamproperties.hpp"
41 #include "motionproperties.hpp"
42 
43 #include <rtt/Property.hpp>
44 #include <rtt/PropertyBag.hpp>
45 
46 #include <boost/lexical_cast.hpp>
47 #include <string>
48 
49 namespace RTT
50 {
51  void decomposeProperty(const Joint& joint, PropertyBag& targetbag)
52  {
53  targetbag.setType("KDL.Joint");
54  targetbag.add( new Property<std::string>("Type", "Type of Joint",joint.getTypeName()));
55  }
56 
57  bool composeProperty(const PropertyBag& bag, Joint& joint)
58  {
59  if ( bag.getType() == "KDL.Joint" ){ // check the type
60  Property<std::string> type_name = bag.getPropertyType<std::string>("Type");
61  if ( !type_name.ready() )
62  return false;
63  if (type_name.value()=="RotX"){
64  joint=Joint(Joint::RotX);
65  return true;
66  }else if(type_name.value()=="RotY"){
67  joint=Joint(Joint::RotY);
68  return true;
69  }else if(type_name.value()=="RotZ"){
70  joint=Joint(Joint::RotZ);
71  return true;
72  }else if(type_name.value()=="TransX"){
73  joint=Joint(Joint::TransX);
74  return true;
75  }else if(type_name.value()=="TransY"){
76  joint=Joint(Joint::TransY);
77  return true;
78  }else if(type_name.value()=="TransZ"){
79  joint=Joint(Joint::TransZ);
80  return true;
81  }else if(type_name.value()=="None"){
82  joint=Joint(Joint::None);
83  return true;
84  }
85  else
86  return false;
87  }
88  return false;
89  }
90 
91  void decomposeProperty(const Segment& segment, PropertyBag& targetbag)
92  {
93  PropertyBag frame_bag;
94  PropertyBag joint_bag;
95  targetbag.setType("KDL.Segment");
96  decomposeProperty(segment.getJoint(), joint_bag);
97  targetbag.add(new Property<PropertyBag>("joint","The joint at the base of this segment",joint_bag));
98  decomposeProperty(segment.getFrameToTip(), frame_bag);
99  targetbag.add(new Property<PropertyBag>("frame","The offset frame from the joint at the base to the end of the link",frame_bag));
100  }
101 
102  bool composeProperty(const PropertyBag& bag, Segment& segment)
103  {
104  if ( bag.getType() == "KDL.Segment" ){ // check the type
105  Property<PropertyBag> joint_bag = bag.getPropertyType<PropertyBag>("joint");
106  Property<PropertyBag> frame_bag = bag.getPropertyType<PropertyBag>("frame");
107  if(!(frame_bag.ready()&&joint_bag.ready()))
108  return false;
109  Property<Joint> joint_prop(joint_bag.getName(),joint_bag.getDescription());
110  joint_prop.getTypeInfo()->composeType(joint_bag.getDataSource(),
111  joint_prop.getDataSource());
112  Property<Frame> frame_prop(frame_bag.getName(),frame_bag.getDescription());
113  frame_prop.getTypeInfo()->composeType(frame_bag.getDataSource(),
114  frame_prop.getDataSource());
115  segment=Segment(joint_prop.value(),frame_prop.value());
116  return true;
117  }
118  else
119  return false;
120  }
121 
122  void decomposeProperty(const Chain& chain, PropertyBag& targetbag)
123  {
124  targetbag.setType("KDL.Chain");
125  PropertyBag segment_bag;
126  for(unsigned int i=0;i<chain.getNrOfSegments();i++){
127  decomposeProperty(chain.getSegment(i),segment_bag);
128  targetbag.add(new Property<PropertyBag>("Segment","Segment of the chain",segment_bag));
129  }
130  }
131 
132  bool composeProperty(const PropertyBag& bag, Chain& chain)
133  {
134  Chain chain_new;
135  if( bag.getType() =="KDL.Chain"){
136  for(unsigned int i=0;i<bag.size();i++){
137  RTT::base::PropertyBase* segment_bag = bag.getItem(i);
138  if(!segment_bag->ready())
139  return false;
140  Property<Segment> segment_prop(segment_bag->getName(),
141  segment_bag->getDescription());
142  segment_prop.getTypeInfo()->composeType(segment_bag->getDataSource(),
143  segment_prop.getDataSource());
144  chain_new.addSegment(segment_prop.value());
145  }
146  chain = chain_new;
147  return true;
148  }else
149  return false;
150  }
151 
152  void decomposeProperty(const JntArray& jntarray, PropertyBag& targetbag)
153  {
154  targetbag.setType("KDL.JntArray");
155  for(int i = 0; i < jntarray.data.rows(); i++)
156  {
157  std::string rindx = boost::lexical_cast<std::string>( i );
158  targetbag.add(new Property<double>("Element" + rindx,"JntArray element",jntarray.data(i)));
159  }
160  }
161 
162  bool composeProperty(const PropertyBag& bag, JntArray& jntarray)
163  {
164  JntArray jntarray_new(bag.size());
165  if( bag.getType() =="KDL.JntArray"){
166  for(unsigned int i = 0; i < bag.size(); i++){
167  RTT::base::PropertyBase* jntarray_bag = bag.getItem(i);
168  if(!jntarray_bag->ready())
169  return false;
170  Property<double> jntarray_prop(jntarray_bag->getName(), jntarray_bag->getDescription());
171  jntarray_prop.getTypeInfo()->composeType(jntarray_bag->getDataSource(), jntarray_prop.getDataSource());
172  jntarray_new.data(i) = jntarray_prop.value();
173  }
174  jntarray = jntarray_new;
175  return true;
176  } else
177  return false;
178  }
179 
180  void decomposeProperty(const Jacobian& jacobian, PropertyBag& targetbag)
181  {
182  targetbag.setType("KDL.Jacobian");
183  for(int i = 0; i < jacobian.data.rows(); i++){
184  for(int j = 0; j < jacobian.data.cols(); j++){
185  std::string rindx = boost::lexical_cast<std::string>( i );
186  std::string cindx = boost::lexical_cast<std::string>( j );
187  targetbag.add(new Property<double>("Element (" + rindx + "," + cindx + ")","Jacobian element",jacobian.data(i,j)));
188  }
189  }
190  }
191 
192  bool composeProperty(const PropertyBag& bag, Jacobian& jacobian)
193  {
194  Jacobian jacobian_new((bag.size() / 6));
195 
196  if( bag.getType() =="KDL.Jacobian"){
197  for(unsigned int i = 0; i < 6; i++){
198  for(unsigned int j = 0; j < bag.size() / 6; j++){
199  RTT::base::PropertyBase* data_bag = bag.getItem((bag.size() / 6) * i + j);
200  if(!data_bag->ready())
201  return false;
202  Property<double> data_prop(data_bag->getName(), data_bag->getDescription());
203  data_prop.getTypeInfo()->composeType(data_bag->getDataSource(), data_prop.getDataSource());
204  jacobian_new.data(i,j) = data_prop.value();
205  }
206  }
207  jacobian = jacobian_new;
208  return true;
209  }
210  else
211  return false;
212  }
213 }
virtual base::DataSourceBase::shared_ptr getDataSource() const
bool composeType(base::DataSourceBase::shared_ptr source, base::DataSourceBase::shared_ptr target) const
void add(base::PropertyBase *p)
const Segment & getSegment(unsigned int nr) const
Property< T > * getPropertyType(const std::string &name) const
const std::string & getType() const
bool composeProperty(const PropertyBag &bag, Joint &joint)
unsigned int getNrOfSegments() const
void setType(const std::string &newtype)
void addSegment(const Segment &segment)
Frame getFrameToTip() const
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix< double, 6, Eigen::Dynamic > data
reference_t value()
Eigen::VectorXd data
void decomposeProperty(const Joint &joint, PropertyBag &targetbag)
const Joint & getJoint() const
const std::string & getDescription() const
virtual const types::TypeInfo * getTypeInfo() const
base::PropertyBase * getItem(int i) const
const std::string & getName() const
const std::string getTypeName() const
size_t size() const
virtual DataSourceBase::shared_ptr getDataSource() const =0


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