Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

PostureNode.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_PostureNode_h_
00003 #define INCLUDED_PostureNode_h_
00004 
00005 #include "MCNode.h"
00006 #include "Events/EventRouter.h"
00007 #include "Motion/PostureMC.h"
00008 #include "Shared/MarkScope.h"
00009 
00010 //!default name for PostureNode's (have to instantiate a variable in order to use as a template argument)
00011 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00012 extern const char defPostureNodeName[];
00013 //!default description for PostureNode's (have to instantiate a variable in order to use as a template argument)
00014 /*! instantiation will be placed in MCNode.cc to avoid file bloat */
00015 extern const char defPostureNodeDesc[];
00016 
00017 //! A simple StateNode that executes a PostureMC motion command
00018 /*! Caches the posture file in a private PostureEngine because the
00019  *  motion command might be shared with other functions that are
00020  *  using it for other purposes */
00021 class PostureNode : public MCNode<PostureMC,defPostureNodeName,defPostureNodeDesc,true> {
00022 public:
00023   
00024   //! Constructor: takes optional instance name and filename.
00025   /*! Caches the posture file in a private PostureEngine because the
00026    motion command might be shared with other functions that are
00027    using it for other purposes */
00028   PostureNode(const std::string &nodename=defPostureNodeName, const std::string &filename=std::string())
00029   : MCNode<PostureMC,defPostureNodeName,defPostureNodeDesc,true>(nodename), posture()
00030   {
00031     if ( filename.size() > 0 )
00032       posture.loadFile(filename.c_str());
00033   }
00034   
00035   virtual void preStart() {
00036     MCNode<PostureMC,defPostureNodeName,defPostureNodeDesc,true>::preStart();
00037     getMC()->setAverage(posture,1);  // copy cached posture into the motion command
00038   }
00039   
00040   //! loads the specified file into #posture, note this @em doesn't affect the current PostureMC, just the cached one which will be loaded into it on next activation.  See getPosture(), getMC_ID()
00041   virtual void loadFile(const std::string &filename) {
00042     posture.loadFile(filename.c_str());
00043     getMC()->setAverage(posture,1);
00044   }
00045   
00046   //! accessor for #posture, note this @em doesn't affect the current PostureMC, just the cached one which will be loaded into it on next activation.  See getMC_ID()
00047   virtual PostureEngine& getPosture() { return posture; }
00048   //! accessor for #posture, note this @em doesn't return the current PostureMC, just the cached one which will be loaded into it on next activation.  See getMC_ID()
00049   virtual const PostureEngine& getPosture() const { return posture; }
00050   
00051 protected:
00052   //! The internal cache of joint positions, copied to the motion command when activated.
00053   /*! This allows the motion command to be shared by other nodes/behaviors, which might modify
00054    *  the posture on an ongoing basis. */
00055   PostureEngine posture;
00056 };
00057 
00058 /*! @file
00059  * @brief Defines PostureNode, a simple StateNode that runs a PostureMC motion command
00060  * @author dst
00061  */
00062 
00063 #endif

Tekkotsu v5.1CVS
Generated Fri Mar 16 05:26:50 2012 by Doxygen 1.6.3