Homepage Demos Overview Downloads Tutorials Reference
Credits

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 class WorldState;
00010 
00011 //! a MotionCommand shell for PostureEngine
00012 /*! Will autoprune by default once it reaches the target pose.
00013  * 
00014  *  If you want to keep it alive so your behavior can use the posture
00015  *  to move around, either call setAutoPrune(@c false), or pass
00016  *  @c false to the MotionManager::addMotion() function.
00017  */
00018 class PostureMC : public MotionCommand, public PostureEngine {
00019 public:
00020   //!constructor
00021   PostureMC() : MotionCommand(),PostureEngine(),dirty(true),tolerance(.01) { }
00022   //!constructor, loads from @a filename
00023   PostureMC(const char* filename) : MotionCommand(),PostureEngine(filename),dirty(true),tolerance(.01) { }
00024   //!constructor, initializes joint positions to the current state of the outputs as defined by @a state
00025   PostureMC(const WorldState* st) : MotionCommand(),PostureEngine(st),dirty(true),tolerance(.01) { }
00026   //!destructor
00027   virtual ~PostureMC() {}
00028   
00029   //!@name New Stuff
00030   /*!@brief call this if you call PostureEngine::setOutputCmd(), that doesn't know about dirty flags */
00031   /* This is the downside of making setOutputCmd() not virtual - if you pass this around as just a
00032    * PostureEngine, calls made to that won't be able to update the dirty flag automatically.  However,
00033    * if the object is typed as a PostureMC at the time the call is made, then you don't have to worry.\n
00034    * These are also not virtual - otherwise you'd have to still check the motion out and it would make
00035    * this all pointless! @return @c *this */
00036   PostureMC& setDirty(bool d=true) { dirty=d; return *this; } 
00037   bool isDirty() const {return dirty;} //!< if you want to check the dirty flag
00038   virtual PostureMC& setTolerance(float t) { tolerance=t; return *this; } //!< sets #tolerance, returns @c *this
00039   virtual float getTolerance() { return tolerance; } //!< returns #tolerance
00040   //@}
00041 
00042 
00043   //!@name MotionCommand Stuff
00044   virtual int updateOutputs() {
00045     for(unsigned int i=0; i<NumOutputs; i++)
00046       if(cmds[i].weight>0)
00047         motman->setOutput(this,i,cmds[i]);
00048     bool r=dirty; dirty=false; return r;
00049   }
00050   virtual int isDirty() { return dirty; }
00051 
00052   //! returns non-zero (true) if PostureEngine::maxdiff() between this and the current position is over #tolerance
00053   /*! This is handy so you can set to have the robot go to a position and then automatically remove
00054    *  the MotionCommand when it gets there - but beware fighting Postures which average out and neither
00055    *  succeeds */
00056   virtual int isAlive() {
00057     if(dirty || getAutoPrune()==false) //doesn't bother computing if we're staying alive anyway
00058       return true;
00059     PostureEngine tmp; 
00060     tmp.takeSnapshot(); 
00061     return (maxdiff(tmp)>tolerance);
00062   }
00063   //@}
00064 
00065   //!Had to override stuff to manage a dirty flag
00066   //!@name PostureEngine Stuff
00067   inline virtual void takeSnapshot() { dirty=true; PostureEngine::takeSnapshot(); }
00068   inline virtual void takeSnapshot(const WorldState* st) { dirty=true; PostureEngine::takeSnapshot(st); }
00069   inline virtual void clear() { dirty=true; PostureEngine::clear(); }
00070   inline virtual PostureEngine& setOverlay(const PostureEngine& pe) { dirty=true; PostureEngine::setOverlay(pe); return *this; }
00071   inline virtual PostureEngine& setUnderlay(const PostureEngine& pe) { dirty=true; PostureEngine::setUnderlay(pe); return *this; }
00072   inline virtual PostureEngine& setAverage(const PostureEngine& pe,float w=0.5) { dirty=true; PostureEngine::setAverage(pe,w); return *this; }
00073   inline virtual PostureEngine& setCombine(const PostureEngine& pe) { dirty=true; PostureEngine::setCombine(pe); return *this; }
00074   inline PostureEngine& setOutputCmd(unsigned int i, const OutputCmd& c) { dirty=true; PostureEngine::setOutputCmd(i,c); return *this; }
00075   inline virtual unsigned int LoadBuffer(const char buf[], unsigned int len) { dirty=true; return PostureEngine::LoadBuffer(buf,len); }
00076   //@}
00077 
00078 protected:
00079   bool dirty; //!< true if changes have been made since last updateOutputs()
00080   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)
00081 
00082   //!defines Registerable stuff
00083   /*  REGDEFCUSTOMMEM(PostureMC) {
00084     MotionCommand::registerDataRegions(regions);
00085     registerRegion(regions,&cmds,&cmds,sizeof(cmds));//for PostureEngine, LoadSave doesn't have any (nonstatic) members
00086     registerRegion(regions,&dirty,&tolerance,sizeof(tolerance));
00087     }*/
00088 };
00089 
00090 /*! @file
00091  * @brief Defines PostureMC, a MotionCommand shell for PostureEngine
00092  * @author ejt (Creator)
00093  *
00094  * $Author: ejt $
00095  * $Name: tekkotsu-2_2_1 $
00096  * $Revision: 1.8 $
00097  * $State: Exp $
00098  * $Date: 2004/08/30 20:26:45 $
00099  */
00100 
00101 #endif

Tekkotsu v2.2.1
Generated Tue Nov 23 16:36:39 2004 by Doxygen 1.3.9.1