4 #include <Eigen/Geometry> 6 #include <base/Time.hpp> 7 #include <aggregator/StreamAligner.hpp> 9 #include <boost/bind.hpp> 10 #include <base/samples/RigidBodyState.hpp> 22 Transformation(
const std::string &sourceFrame,
const std::string &targetFrame)
24 , sourceFrame(sourceFrame)
25 , targetFrame(targetFrame)
26 , generatedTransformations(0)
29 , failedInterpolationImpossible(0) {};
32 std::string sourceFrame;
33 std::string targetFrame;
34 std::string sourceFrameMapped;
35 std::string targetFrameMapped;
36 std::vector<TransformationElement *> transformationChain;
38 mutable base::Time lastGeneratedValue;
39 mutable uint64_t generatedTransformations;
40 mutable uint64_t failedNoChain;
41 mutable uint64_t failedNoSample;
42 mutable uint64_t failedInterpolationImpossible;
43 boost::function<void (const base::Time &ts)> transformationChangedCallback;
45 void setFrameMapping(
const std::string &frameName,
const std::string &newName);
56 void setTransformationChain(
const std::vector<TransformationElement *> &chain);
78 if(sourceFrameMapped.empty())
81 return sourceFrameMapped;
89 if(targetFrameMapped.empty())
92 return targetFrameMapped;
101 transformationChain.clear();
102 lastGeneratedValue = base::Time();
103 generatedTransformations = 0;
106 failedInterpolationImpossible = 0;
122 bool getChain(
const base::Time& atTime, std::vector<TransformationType>& result,
bool interpolate =
false)
const;
125 bool get(
const base::Time& atTime, T& result,
bool interpolate =
false)
const;
126 bool getChain(
const base::Time& atTime, std::vector<Eigen::Affine3d>& result,
bool interpolate =
false)
const;
134 TransformationElement(
const std::string &sourceFrame,
const std::string &targetFrame): sourceFrame(sourceFrame), targetFrame(targetFrame) {};
144 virtual bool getTransformation(
const base::Time &atTime,
bool doInterpolation, TransformationType &tr) = 0;
152 elementChangedCallbacks.push_back(callback);
160 elementChangedCallbacks.clear();
182 std::string sourceFrame;
183 std::string targetFrame;
194 virtual bool getTransformation(
const base::Time& atTime,
bool doInterpolation, TransformationType& tr)
196 tr = staticTransform;
201 TransformationType staticTransform;
211 DynamicTransformationElement(
const std::string& sourceFrame,
const std::string& targetFrame, aggregator::StreamAligner& aggregator,
int priority = -10);
214 virtual bool getTransformation(
const base::Time& atTime,
bool doInterpolation, TransformationType& result);
223 void aggregatorCallback(
const base::Time &ts,
const TransformationType &value);
225 aggregator::StreamAligner &aggregator;
226 base::Time lastTransformTime;
227 TransformationType lastTransform;
239 virtual bool getTransformation(
const base::Time& atTime,
bool doInterpolation, TransformationType& tr);
243 nonInverseElement->addTransformationChangedCallback(callback);
267 std::pair<int, int> getElementsCount()
const;
287 bool getTransformationChain(std::string from, std::string to, std::vector<TransformationElement *> &result);
294 return availableElements;
309 void dumpTree()
const;
313 const int maxSeekDepth;
329 std::vector< TransformationNode* >::const_iterator checkForMatchingChildFrame(
const std::string &to,
const TransformationNode &node);
332 std::vector<TransformationElement *> availableElements;
348 void recomputeAvailableTransformations();
358 : priority( priority ) {};
368 virtual void clear();
376 void addTransformationChain(std::string from, std::string to,
const std::vector<TransformationElement *> &chain);
386 Transformation ®isterTransformation(std::string sourceFrame, std::string targetFrame);
393 return transformations;
418 template <
class T>
int registerDataStream(base::Time dataPeriod, boost::function<
void (
const base::Time &ts,
const T &value)> callback,
int priority = -1,
const std::string &name = std::string())
420 return aggregator.registerStream<T>(boost::bind( callback, _1, _2), 0, dataPeriod, priority, name);
430 return aggregator.registerStream<T>(boost::bind( callback, _1, _2, boost::ref(transformation) ), 0, dataPeriod, priority, name);
438 return aggregator.unregisterStream(idx);
446 return aggregator.disableStream( idx );
454 return aggregator.enableStream( idx );
462 return aggregator.isStreamActive( idx );
467 aggregator.push(idx, ts,
false);
474 template <
class T>
void pushData(
int idx,
const base::Time &ts,
const T& data )
476 aggregator.push(idx, ts, data);
483 return aggregator.step();
491 return aggregator.getStatus();
496 aggregator.setTimeout(t);
506 virtual void pushDynamicTransformation(
const TransformationType &tr);
511 void pushStaticTransformation(
const TransformationType &tr);
514 void setFrameMapping(
const std::string &frameName,
const std::string &newName);
522 return aggregator.getStatus();
539 result = T::Identity();
546 for(std::vector<TransformationElement *>::const_iterator it = transformationChain.begin(); it != transformationChain.end(); it++)
548 TransformationType tr;
549 if(!(*it)->getTransformation(atTime, interpolate, tr))
552 failedInterpolationImpossible++;
564 result = result * trans;
566 lastGeneratedValue = atTime;
567 generatedTransformations++;
572 #endif // TRANSFORMER_H