Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

DynamicMotionSequenceNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef _DynamicMotionSequenceNode_h_
00003 #define _DynamicMotionSequenceNode_h_
00004 
00005 #include "MCNode.h"
00006 #include "Motion/DynamicMotionSequence.h"
00007 #include "Motion/MotionManager.h"
00008 #include "Shared/get_time.h"
00009 #include "Shared/debuget.h"
00010 #include "Shared/MarkScope.h"
00011 
00012 //!default name for PostureNode's (have to instantiate a variable in order to use as a template argument)
00013 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00014 extern const char defDynamicMotionSequenceNodeName[];
00015 //!default description for PostureNode's (have to instantiate a variable in order to use as a template argument)
00016 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00017 extern const char defDynamicMotionSequenceNodeDesc[];
00018 
00019 //! A StateNode for playing a DynamicMotionSequence (and looping it if desired)
00020 
00021 class DynamicMotionSequenceNode : public  MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>  {
00022 public:
00023   //!constructor
00024   DynamicMotionSequenceNode()
00025     : MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>(),
00026       looping(false), filename() {}
00027 
00028   //!constructor
00029   DynamicMotionSequenceNode(const std::string& name, const std::string& file="", bool loop=false)
00030     : MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>(name),
00031       looping(loop), filename(file) {}
00032 
00033   virtual void preStart() {
00034     MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>::preStart();
00035     if(event!=NULL) {
00036       const DataEvent<std::string>* ev = dynamic_cast<const DataEvent<std::string>*>(event);
00037       if ( ev != NULL )
00038         filename = ev->getData();
00039     }
00040     update(filename);
00041   }
00042   
00043   virtual void postStart() {
00044     MCNode<DynamicMotionSequence,defDynamicMotionSequenceNodeName,defDynamicMotionSequenceNodeDesc,true>::postStart();
00045     getMC()->play();
00046   }
00047 
00048   //! sets the file to play
00049   virtual void setFile(const std::string& file) {
00050     if ( StateNode::isActive() )
00051       update(file);
00052     else
00053       filename=file;
00054   }
00055 
00056   //! turns looping on or off
00057   virtual void setLooping(bool loop) { looping=loop; }
00058 
00059   virtual void doEvent() {
00060     ASSERTRET(event->getGeneratorID()==EventBase::motmanEGID,"Unknown event");
00061     if ( event->getSourceID() == MCNodeBase::getMC_ID() ) {
00062       if(looping)
00063         getMC()->setTime(1);
00064       StateNode::postStateCompletion();
00065     }
00066   }
00067 
00068   //! returns true if currently looping
00069   virtual bool getLooping() { return looping; }
00070 
00071 protected:
00072 
00073   //! resets the motion command and starts it playing
00074   void update(const std::string& file) {
00075     if ( file.size() > 0 ) {
00076       filename=file;
00077       MMAccessor<DynamicMotionSequence> dms_acc = getMC();
00078       dms_acc->clear();
00079       dms_acc->loadFile(filename.c_str());
00080       dms_acc->setTime(1);
00081     }
00082   }
00083 
00084   bool looping; //!< true if we should loop
00085   std::string filename; //!< filename of current motion sequence
00086 
00087 };
00088 
00089 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:38 2016 by Doxygen 1.6.3