CorbaKDLConversion.hpp
Go to the documentation of this file.
1 #ifndef ORO_KDL_CORBAKDLCONVERSION_HPP
2 #define ORO_KDL_CORBAKDLCONVERSION_HPP 1
3 
4 #include <kdl_typekit/transports/corba/KDLTypesC.h>
6 #include <kdl/frames.hpp>
7 #include <kdl/jacobian.hpp>
8 #include <kdl/jntarray.hpp>
9 #include <Eigen/Dense>
10 
11 namespace RTT
12 {
13  namespace corba{
14 
15  template<>
17  {
18  typedef KDL::Corba::DoubleSequence CorbaType;
20  static CorbaType toAny(const KDL::Vector& orig) {
21  log(Debug)<< "Converting type 'KDL::Vector' to sequence<CORBA::Double>." <<endlog();
22  CorbaType ret;
23  ret.length( 3 );
24  ret[0] = orig.x();
25  ret[1] = orig.y();
26  ret[2] = orig.z();
27  return ret;
28  }
29 
30  static bool updateAny( StdType const& t, CORBA::Any& any ) {
31  any <<= toAny( t );
32  return true;
33  }
34 
35 
36  static bool update(const CORBA::Any& any, StdType& _value) {
37  log(Debug)<< "update KDL::Vector" <<endlog();
38  CorbaType* result;
39  if ( any >>= result ) {
40  return toStdType(_value,*result);
41  }
42  return false;
43  }
44 
45  static CORBA::Any_ptr createAny( const StdType& t ) {
46  CORBA::Any_ptr ret = new CORBA::Any();
47  *ret <<= toAny( t );
48  return ret;
49  }
50 
51  static bool toCorbaType(CorbaType& cb, const StdType& tp){
52  cb = toAny(tp);
53  return true;
54  }
55 
56  static bool toStdType(StdType& tp, const CorbaType& cb){
57  log(Debug)<< "Converting type sequence<CORBA::Double> to 'KDL::Vector'" <<endlog();
58  tp.x(cb[0]);
59  tp.y(cb[1]);
60  tp.z(cb[2]);
61  return true;
62  }
63 
64  };
65 
66  template<>
68  {
69  typedef KDL::Corba::DoubleSequence CorbaType;
71  static CorbaType toAny(const KDL::Rotation& orig) {
72  log(Debug)<< "Converting type 'KDL::Rotation' to sequence<CORBA::Double>." <<endlog();
73  CorbaType ret;
74  ret.length( 9 );
75  ret[0] = orig(0,0);
76  ret[1] = orig(0,1);
77  ret[2] = orig(0,2);
78  ret[3] = orig(1,0);
79  ret[4] = orig(1,1);
80  ret[5] = orig(1,2);
81  ret[6] = orig(2,0);
82  ret[7] = orig(2,1);
83  ret[8] = orig(2,2);
84  return ret;
85  }
86 
87  static bool toStdType(StdType& tp ,const CorbaType& cb) {
88  log(Debug)<< "Converting type sequence<CORBA::Double> to 'KDL::Rotation'" <<endlog();
89  tp = StdType(cb[0],cb[1],cb[2],cb[3],cb[4],cb[5],cb[6],cb[7],cb[8]);
90  return true;
91  }
92 
93  static bool toCorbaType(CorbaType& cb, const StdType& tp){
94  cb = toAny(tp);
95  return true;
96  }
97 
98  static bool update(const CORBA::Any& any, StdType& _value) {
99  log(Debug)<< "update KDL::Rotation" <<endlog();
100  CorbaType* result;
101  if ( any >>= result ) {
102  return toStdType(_value,*result);
103  }
104  return false;
105  }
106 
108  CORBA::Any_ptr ret = new CORBA::Any();
109  *ret <<= toAny( t );
110  return ret;
111  }
112 
113  static bool updateAny( StdType const& t, CORBA::Any& any ) {
114  any <<= toAny( t );
115  return true;
116  }
117 
118  };
119 
120  template<>
122  {
123  typedef KDL::Corba::DoubleSequence CorbaType;
125  static CorbaType toAny(const KDL::Frame& orig) {
126  log(Debug)<< "Converting type 'KDL::Frame' to sequence<CORBA::Double>." <<endlog();
127  CorbaType ret;
128  ret.length( 12 );
129  ret[0] = orig.p.x();
130  ret[1] = orig.p.y();
131  ret[2] = orig.p.z();
132  ret[3] = orig.M(0,0);
133  ret[4] = orig.M(0,1);
134  ret[5] = orig.M(0,2);
135  ret[6] = orig.M(1,0);
136  ret[7] = orig.M(1,1);
137  ret[8] = orig.M(1,2);
138  ret[9] = orig.M(2,0);
139  ret[10] = orig.M(2,1);
140  ret[11] = orig.M(2,2);
141  return ret;
142  }
143 
144  static bool updateAny( StdType const& t, CORBA::Any& any ) {
145  any <<= toAny( t );
146  return true;
147  }
148  static bool update(const CORBA::Any& any, StdType& _value) {
149  log(Debug)<< "update KDL::Frame" <<endlog();
150  CorbaType* result;
151  if ( any >>= result ) {
152  return toStdType(_value,*result);
153  }
154  return false;
155  }
156 
157  static CORBA::Any_ptr createAny( const StdType& t ) {
158  CORBA::Any_ptr ret = new CORBA::Any();
159  *ret <<= toAny( t );
160  return ret;
161  }
162 
163  static bool toStdType(StdType& tp, const CorbaType& cb) {
164  log(Debug)<< "Converting type sequence<CORBA::Double> to 'KDL::Frame'" <<endlog();
165  tp.p.x(cb[0]);
166  tp.p.y(cb[1]);
167  tp.p.z(cb[2]);
168  tp.M(0,0)=cb[3];
169  tp.M(0,1)=cb[4];
170  tp.M(0,2)=cb[5];
171  tp.M(1,0)=cb[6];
172  tp.M(1,1)=cb[7];
173  tp.M(1,2)=cb[8];
174  tp.M(2,0)=cb[9];
175  tp.M(2,1)=cb[10];
176  tp.M(2,2)=cb[11];
177  return true;
178  }
179 
180  static bool toCorbaType(CorbaType& cb, const StdType& tp){
181  cb = toAny(tp);
182  return true;
183  }
184 
185  };
186 
187  template<>
189  {
190  typedef KDL::Corba::DoubleSequence CorbaType;
192  static CorbaType toAny(const KDL::Wrench& orig) {
193  log(Debug)<< "Converting type 'KDL::Wrench' to sequence<CORBA::Double>." <<endlog();
194  CorbaType ret;
195  ret.length( 6 );
196  ret[0] = orig.force.x();
197  ret[1] = orig.force.y();
198  ret[2] = orig.force.z();
199  ret[3] = orig.torque.x();
200  ret[4] = orig.torque.y();
201  ret[5] = orig.torque.z();
202  return ret;
203  }
204 
205  static bool updateAny( StdType const& t, CORBA::Any& any ) {
206  any <<= toAny( t );
207  return true;
208  }
209 
210 
211  static bool update(const CORBA::Any& any, StdType& _value) {
212  log(Debug)<< "update KDL::Vector" <<endlog();
213  CorbaType* result;
214  if ( any >>= result ) {
215  return toStdType(_value,*result);
216  }
217  return false;
218  }
219 
220  static CORBA::Any_ptr createAny( const StdType& t ) {
221  CORBA::Any_ptr ret = new CORBA::Any();
222  *ret <<= toAny( t );
223  return ret;
224  }
225 
226  static bool toStdType(StdType& tp, const CorbaType& cb){
227  log(Debug)<< "Converting type sequence<CORBA::Double> to 'KDL::Wrench'" <<endlog();
228  tp.force.x(cb[0]);
229  tp.force.y(cb[1]);
230  tp.force.z(cb[2]);
231  tp.torque.x(cb[3]);
232  tp.torque.y(cb[4]);
233  tp.torque.z(cb[5]);
234  return true;
235  }
236  static bool toCorbaType(CorbaType& cb, const StdType& tp){
237  cb = toAny(tp);
238  return true;
239  }
240 
241  };
242 
243  template<>
245  {
246  typedef KDL::Corba::DoubleSequence CorbaType;
248  static CorbaType toAny(const KDL::Twist& orig) {
249  log(Debug)<< "Converting type 'KDL::Twist' to sequence<CORBA::Double>." <<endlog();
250  CorbaType ret;
251  ret.length( 6 );
252  ret[0] = orig.vel.x();
253  ret[1] = orig.vel.y();
254  ret[2] = orig.vel.z();
255  ret[3] = orig.rot.x();
256  ret[4] = orig.rot.y();
257  ret[5] = orig.rot.z();
258  return ret;
259  }
260 
261  static bool updateAny( StdType const& t, CORBA::Any& any ) {
262  any <<= toAny( t );
263  return true;
264  }
265 
266 
267  static bool update(const CORBA::Any& any, StdType& _value) {
268  log(Debug)<< "update KDL::Vector" <<endlog();
269  CorbaType* result;
270  if ( any >>= result ) {
271  return toStdType(_value,*result);
272  }
273  return false;
274  }
275 
276  static CORBA::Any_ptr createAny( const StdType& t ) {
277  CORBA::Any_ptr ret = new CORBA::Any();
278  *ret <<= toAny( t );
279  return ret;
280  }
281 
282  static bool toCorbaType(CorbaType& cb, const StdType& tp){
283  cb = toAny(tp);
284  return true;
285  }
286 
287  static bool toStdType(StdType& tp, const CorbaType& cb){
288  log(Debug)<< "Converting type sequence<CORBA::Double> to 'KDL::Twist'" <<endlog();
289  tp.vel.x(cb[0]);
290  tp.vel.y(cb[1]);
291  tp.vel.z(cb[2]);
292  tp.rot.x(cb[3]);
293  tp.rot.y(cb[4]);
294  tp.rot.z(cb[5]);
295  return true;
296  }
297  };
298  template<>
300  {
301  typedef KDL::Corba::DoubleSequence CorbaType;
303  static CorbaType* toAny(const StdType& tp) {
304  CorbaType* cb = new CorbaType();
305  toCorbaType(*cb, tp);
306  return cb;
307  }
308 
309  static bool update(const CORBA::Any& any, StdType& _value) {
310  CorbaType* result;
311  if ( any >>= result ) {
312  return toStdType(_value, *result);
313  }
314  return false;
315  }
316 
317  static CORBA::Any_ptr createAny( const StdType& t ) {
318  CORBA::Any_ptr ret = new CORBA::Any();
319  *ret <<= toAny( t );
320  return ret;
321  }
322 
323  static bool updateAny( StdType const& t, CORBA::Any& any ) {
324  any <<= toAny( t );
325  return true;
326  }
327 
328  static bool toCorbaType(CorbaType& cb, const StdType& tp){
329 
330  size_t rows = static_cast<size_t>(tp.data.rows());
331  size_t cols = static_cast<size_t>(tp.data.cols());
332 
333  cb.length( (CORBA::ULong)(tp.data.size() + 2) );
334 
335  cb[0] = static_cast<double>(rows);
336  cb[1] = static_cast<double>(cols);
337 
338  Eigen::Map<Eigen::MatrixXd>(cb.get_buffer() + 2 , rows, cols) = tp.data;
339 
340  return true;
341  }
342 
343  static bool toStdType(StdType& tp, const CorbaType& cb){
344  if(cb.length() < 2){
345  return false;
346  }
347 
348  size_t rows = static_cast<size_t>(cb[0]);
349  size_t cols = static_cast<size_t>(cb[1]);
350 
351  tp.resize(cols);
352 
353  tp.data = Eigen::MatrixXd::Map(cb.get_buffer()+2,rows,cols);
354  return true;
355  }
356 
357  };
358 
359  template<>
361  {
362  typedef KDL::Corba::DoubleSequence CorbaType;
364 
365  static CorbaType* toAny(const StdType& tp) {
366  CorbaType* cb = new CorbaType();
367  toCorbaType(*cb, tp);
368  return cb;
369  }
370 
371  static bool update(const CORBA::Any& any, StdType& _value) {
372  CorbaType* result;
373  if ( any >>= result ) {
374  return toStdType(_value, *result);
375  }
376  return false;
377  }
378 
379  static CORBA::Any_ptr createAny( const StdType& t ) {
380  CORBA::Any_ptr ret = new CORBA::Any();
381  *ret <<= toAny( t );
382  return ret;
383  }
384 
385  static bool updateAny( StdType const& t, CORBA::Any& any ) {
386  any <<= toAny( t );
387  return true;
388  }
389 
390  static bool toCorbaType(CorbaType& cb, const StdType& tp){
391  cb.length( (CORBA::ULong)(tp.rows() ));
392  Eigen::Map<Eigen::VectorXd>(cb.get_buffer() , cb.length()) = tp.data;
393  return true;
394  }
395 
396  static bool toStdType(StdType& tp, const CorbaType& cb){
397  tp.resize( cb.length() );
398  tp.data = Eigen::VectorXd::Map(cb.get_buffer() , cb.length());
399  return true;
400  }
401  };
402  } //namespace corba
403 } //namespace RTT
404 
405 #endif // ORO_KDL_CORBAKDLCONVERSION_HPP
static CORBA::Any_ptr createAny(const StdType &t)
static CorbaType toAny(const KDL::Twist &orig)
static bool toStdType(StdType &tp, const CorbaType &cb)
static CorbaType * toAny(const StdType &tp)
static bool update(const CORBA::Any &any, StdType &_value)
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool updateAny(StdType const &t, CORBA::Any &any)
unsigned int rows() const
static bool toCorbaType(CorbaType &cb, const StdType &tp)
void resize(unsigned int newNrOfColumns)
static CorbaType toAny(const KDL::Wrench &orig)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static CORBA::Any_ptr createAny(const StdType &t)
static CorbaType toAny(const KDL::Vector &orig)
Vector vel
Any * Any_ptr
static CORBA::Any_ptr createAny(const StdType &t)
static bool update(const CORBA::Any &any, StdType &_value)
static bool update(const CORBA::Any &any, StdType &_value)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static bool toStdType(StdType &tp, const CorbaType &cb)
static CorbaType toAny(const KDL::Rotation &orig)
Vector torque
static bool toStdType(StdType &tp, const CorbaType &cb)
double z() const
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static bool updateAny(StdType const &t, CORBA::Any &any)
static CorbaType toAny(const KDL::Frame &orig)
Rotation M
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Matrix< double, 6, Eigen::Dynamic > data
static CORBA::Any_ptr createAny(const StdType &t)
static CORBA::Any_ptr createAny(const KDL::Rotation &t)
Vector rot
double y() const
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
double x() const
Eigen::VectorXd data
static bool update(const CORBA::Any &any, StdType &_value)
static bool updateAny(StdType const &t, CORBA::Any &any)
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool updateAny(StdType const &t, CORBA::Any &any)
static bool updateAny(StdType const &t, CORBA::Any &any)
static CorbaType * toAny(const StdType &tp)
static bool updateAny(StdType const &t, CORBA::Any &any)
Vector force
static bool update(const CORBA::Any &any, StdType &_value)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
void resize(unsigned int newSize)
static bool toStdType(StdType &tp, const CorbaType &cb)
static bool update(const CORBA::Any &any, StdType &_value)
static bool update(const CORBA::Any &any, StdType &_value)
static CORBA::Any_ptr createAny(const StdType &t)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static bool toCorbaType(CorbaType &cb, const StdType &tp)
static Logger & log()
static Logger::LogFunction endlog()
static bool updateAny(StdType const &t, CORBA::Any &any)
static CORBA::Any_ptr createAny(const StdType &t)


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