Homepage Demos Overview Downloads Tutorials Reference
Credits
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Search

PostureMC.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_PostureMC_h
00003 #define INCLUDED_PostureMC_h
00004 
00005 #include "MotionCommand.h"
00006 #include "PostureEngine.h"
00007 #include "MotionManager.h"
00008 
00009 //! a MotionCommand shell for PostureEngine
00010 /*! @note PostureMC does not autoprune by default - this is contrary to the default for other MotionCommands */
00011 class PostureMC : public MotionCommand, public PostureEngine {
00012 public:
00013   //!constructor
00014   PostureMC() : MotionCommand(),PostureEngine(),dirty(true),tolerance(.01) { setAutoPrune(false); }
00015   //!constructor, loads from @a filename
00016   PostureMC(const char* filename) : MotionCommand(),PostureEngine(filename),dirty(true),tolerance(.01) { setAutoPrune(false); }
00017   //!destructor
00018   virtual ~PostureMC() {}
00019   
00020   //!@name New Stuff
00021   /*!@brief call this if you call PostureEngine::setOutputCmd(), that doesn't know about dirty flags */
00022   /* This is the downside of making setOutputCmd() not virtual - if you pass this around as just a
00023    * PostureEngine, calls made to that won't be able to update the dirty flag automatically.  However,
00024    * if the object is typed as a PostureMC at the time the call is made, then you don't have to worry.\n
00025    * These are also not virtual - otherwise you'd have to still check the motion out and it would make
00026    * this all pointless! @return @c *this */
00027   PostureMC& setDirty(bool d=true) { dirty=d; return *this; } 
00028   bool isDirty() const {return dirty;} //!< if you want to check the dirty flag
00029   virtual PostureMC& setTolerance(float t) { tolerance=t; return *this; } //!< sets #tolerance, returns @c *this
00030   virtual float getTolerance() { return tolerance; } //!< returns #tolerance
00031   //@}
00032 
00033 
00034   //!@name MotionCommand Stuff
00035   virtual int updateOutputs() {
00036     for(unsigned int i=0; i<NumOutputs; i++)
00037       if(cmds[i].weight>0)
00038         motman->setOutput(this,i,cmds[i]);
00039     bool r=dirty; dirty=false; return r;
00040   }
00041   virtual int isDirty() { return dirty; }
00042 
00043   //! returns non-zero (true) if PostureEngine::maxdiff() between this and the current position is over #tolerance
00044   /*! This is handy so you can set to have the robot go to a position and then automatically remove
00045    *  the MotionCommand when it gets there - but beware fighting Postures which average out and neither
00046    *  succeeds */
00047   virtual int isAlive() {
00048     if(dirty || getAutoPrune()==false) //doesn't bother computing if we're staying alive anyway
00049       return true;
00050     PostureEngine tmp; 
00051     tmp.takeSnapshot(); 
00052     return (maxdiff(tmp)>tolerance);
00053   }
00054   //@}
00055 
00056   //!Had to override stuff to manage a dirty flag
00057   //!@name PostureEngine Stuff
00058   inline virtual void takeSnapshot() { dirty=true; PostureEngine::takeSnapshot(); }
00059   inline virtual void clear() { dirty=true; PostureEngine::clear(); }
00060   inline virtual PostureMC& setOverlay(const PostureEngine& pe) { dirty=true; PostureEngine::setOverlay(pe); return *this; }
00061   inline virtual PostureMC& setUnderlay(const PostureEngine& pe) { dirty=true; PostureEngine::setUnderlay(pe); return *this; }
00062   inline virtual PostureMC& setAverage(const PostureEngine& pe,float w=0.5) { dirty=true; PostureEngine::setAverage(pe,w); return *this; }
00063   inline virtual PostureMC& setCombine(const PostureEngine& pe) { dirty=true; PostureEngine::setCombine(pe); return *this; }
00064   inline PostureMC& setOutputCmd(unsigned int i, const OutputCmd& c) { dirty=true; PostureEngine::setOutputCmd(i,c); return *this; }
00065   inline virtual unsigned int LoadBuffer(const char buf[], unsigned int len) { dirty=true; return PostureEngine::LoadBuffer(buf,len); }
00066   //@}
00067 
00068 protected:
00069   bool dirty; //!< true if changes have been made since last updateOutputs()
00070   float tolerance; //!< when autopruning, if the maxdiff() of this posture and the robot's current position is below this value, isAlive() will be false, defaults to 0.01 (5.7 degree error)
00071 
00072   //!defines Registerable stuff
00073   /*  REGDEFCUSTOMMEM(PostureMC) {
00074     MotionCommand::registerDataRegions(regions);
00075     registerRegion(regions,&cmds,&cmds,sizeof(cmds));//for PostureEngine, LoadSave doesn't have any (nonstatic) members
00076     registerRegion(regions,&dirty,&tolerance,sizeof(tolerance));
00077     }*/
00078 };
00079 
00080 /*! @file
00081  * @brief Defines PostureMC, a MotionCommand shell for PostureEngine
00082  * @author ejt (Creator)
00083  *
00084  * $Author: ejt $
00085  * $Name: tekkotsu-1_4_1 $
00086  * $Revision: 1.3 $
00087  * $State: Exp $
00088  * $Date: 2003/03/04 05:46:07 $
00089  */
00090 
00091 #endif

Tekkotsu v1.4
Generated Sat Jul 19 00:06:31 2003 by Doxygen 1.3.2