00001
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
00010 class PostureMC : public MotionCommand, public PostureEngine {
00011 public:
00012
00013 PostureMC() : MotionCommand(),PostureEngine(),dirty(true),tolerance(.01) { }
00014
00015 PostureMC(const char* filename) : MotionCommand(),PostureEngine(filename),dirty(true),tolerance(.01) { }
00016
00017 virtual ~PostureMC() {}
00018
00019
00020
00021
00022
00023
00024
00025
00026 PostureMC& setDirty(bool d=true) { dirty=d; return *this; }
00027 bool isDirty() const {return dirty;}
00028 virtual PostureMC& setTolerance(float t) { tolerance=t; return *this; }
00029 virtual float getTolerance() { return tolerance; }
00030
00031
00032
00033
00034 virtual int updateOutputs() {
00035 for(unsigned int i=0; i<NumOutputs; i++)
00036 if(cmds[i].weight>0)
00037 motman->setOutput(this,i,cmds[i]);
00038 bool r=dirty; dirty=false; return r;
00039 }
00040 virtual int isDirty() { return dirty; }
00041
00042
00043
00044
00045
00046 virtual int isAlive() {
00047 if(dirty || getAutoPrune()==false)
00048 return true;
00049 PostureEngine tmp;
00050 tmp.takeSnapshot();
00051 return (maxdiff(tmp)>tolerance);
00052 }
00053
00054
00055
00056
00057 inline virtual void takeSnapshot() { dirty=true; PostureEngine::takeSnapshot(); }
00058 inline virtual void clear() { dirty=true; PostureEngine::clear(); }
00059 inline virtual PostureMC& setOverlay(const PostureEngine& pe) { dirty=true; PostureEngine::setOverlay(pe); return *this; }
00060 inline virtual PostureMC& setUnderlay(const PostureEngine& pe) { dirty=true; PostureEngine::setUnderlay(pe); return *this; }
00061 inline virtual PostureMC& setAverage(const PostureEngine& pe,float w=0.5) { dirty=true; PostureEngine::setAverage(pe,w); return *this; }
00062 inline virtual PostureMC& setCombine(const PostureEngine& pe) { dirty=true; PostureEngine::setCombine(pe); return *this; }
00063 inline PostureMC& setOutputCmd(unsigned int i, const OutputCmd& c) { dirty=true; PostureEngine::setOutputCmd(i,c); return *this; }
00064 inline virtual unsigned int LoadBuffer(const char buf[], unsigned int len) { dirty=true; return PostureEngine::LoadBuffer(buf,len); }
00065
00066
00067 protected:
00068 bool dirty;
00069 float tolerance;
00070
00071
00072
00073
00074
00075
00076
00077 };
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 #endif