Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

MotionSequenceNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_MotionSequenceNode_h_
00003 #define INCLUDED_MotionSequenceNode_h_
00004 
00005 #include "MCNode.h"
00006 #include "Motion/MotionManager.h"
00007 #include "Motion/MotionSequenceMC.h"
00008 #include "Shared/debuget.h"
00009 #include "Shared/MarkScope.h"
00010 
00011 //!default name for PostureNode's (have to instantiate a variable in order to use as a template argument)
00012 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00013 extern const char defMotionSequenceNodeName[];
00014 //!default description for PostureNode's (have to instantiate a variable in order to use as a template argument)
00015 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00016 extern const char defMotionSequenceNodeDesc[];
00017 
00018 //! A StateNode for playing a MotionSequence (and looping it if desired)
00019 /*! Eventually, i'd like to just build the looping functionality into
00020  *  MotionSequence, but in the mean time we have this. */
00021 template<unsigned int SIZE>
00022 class MotionSequenceNode : public  MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>  {
00023 public:
00024   //!constructor
00025   MotionSequenceNode()
00026     : MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>(),
00027       looping(false), filename() {}
00028 
00029   //!constructor
00030   MotionSequenceNode(const std::string& name, const std::string& file="", bool loop=false)
00031     : MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>(name),
00032       looping(loop), filename(file) {}
00033 
00034   virtual void preStart() {
00035     MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::preStart();
00036     if(const DataEvent<std::string>* ev = dynamic_cast<const DataEvent<std::string>*>(this->event))
00037       filename = ev->getData();
00038     update(filename);
00039   }
00040   
00041   virtual void postStart() {
00042     MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::postStart();
00043     MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::getMC()->play();
00044   }
00045 
00046   //! sets the file to play
00047   virtual void setFile(const std::string& file) {
00048     if ( StateNode::isActive() )
00049       update(file);
00050     else
00051       filename=file;
00052   }
00053 
00054   //! turns looping on or off
00055   virtual void setLooping(bool loop) { looping=loop; }
00056 
00057   virtual void doEvent() {
00058     ASSERTRET(this->event->getGeneratorID()==EventBase::motmanEGID,"Unknown event");
00059     if ( this->event->getSourceID() == MCNodeBase::getMC_ID() ) {
00060       if(looping)
00061         MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::getMC()->setTime(1);
00062       StateNode::postStateCompletion();
00063     }
00064   }
00065 
00066   //! returns true if currently looping
00067   virtual bool getLooping() { return looping; }
00068 
00069 protected:
00070 
00071   //! resets the motion command and starts it playing
00072   void update(const std::string& file) {
00073     if ( file.size() > 0 ) {
00074       filename=file;
00075       MMAccessor<MotionSequenceMC<SIZE> > mma = MCNode<MotionSequenceMC<SIZE>,defMotionSequenceNodeName,defMotionSequenceNodeDesc,true>::getMC();
00076       mma->clear();
00077       mma->loadFile(filename.c_str());
00078       mma->setTime(1);
00079     }
00080   }
00081 
00082   bool looping; //!< true if we should loop
00083   std::string filename; //!< filename of current motion sequence
00084 };
00085 
00086 typedef MotionSequenceNode<TinyMotionSequenceMC::CAPACITY> TinyMotionSequenceNode; //!< streamlined access to the standard template sizes
00087 typedef MotionSequenceNode<SmallMotionSequenceMC::CAPACITY> SmallMotionSequenceNode; //!< streamlined access to the standard template sizes
00088 typedef MotionSequenceNode<MediumMotionSequenceMC::CAPACITY> MediumMotionSequenceNode; //!< streamlined access to the standard template sizes
00089 typedef MotionSequenceNode<LargeMotionSequenceMC::CAPACITY> LargeMotionSequenceNode; //!< streamlined access to the standard template sizes
00090 typedef MotionSequenceNode<XLargeMotionSequenceMC::CAPACITY> XLargeMotionSequenceNode; //!< streamlined access to the standard template sizes
00091 
00092 /*! @file
00093  * @brief Describes MotionSequenceNode, a StateNode for playing a MotionSequence (and looping it if desired)
00094  * @author ejt (Creator)
00095  */
00096 
00097 #endif

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