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 class WorldState;
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 class PostureMC : public MotionCommand, public PostureEngine {
00029 public:
00030
00031
00032
00033
00034 PostureMC()
00035 : MotionCommand(),PostureEngine(),dirty(true),hold(true),tolerance(.035f),
00036 targetReached(false),targetTimestamp(0),timeout(2000)
00037 { init(); }
00038
00039
00040 PostureMC(const std::string& filename)
00041 : MotionCommand(),PostureEngine(),dirty(true),hold(true),tolerance(.035f),
00042 targetReached(false),targetTimestamp(0),timeout(2000)
00043 { init(); loadFile(filename.c_str()); }
00044
00045
00046 PostureMC(const WorldState* st)
00047 : MotionCommand(),PostureEngine(st),dirty(true),hold(true),tolerance(.035f),
00048 targetReached(false),targetTimestamp(0),timeout(2000)
00049 { init(); }
00050
00051
00052 virtual ~PostureMC() {}
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075 PostureMC& setDirty(bool d=true);
00076
00077
00078 virtual PostureMC& setHold(bool h=true) { hold=h; return *this; }
00079 virtual bool getHold() { return hold; }
00080
00081 virtual PostureMC& setTolerance(float t) { tolerance=t; return *this; }
00082 virtual float getTolerance() { return tolerance; }
00083 virtual PostureMC& setTimeout(unsigned int delay) { timeout=delay; return *this; }
00084 virtual unsigned int getTimeout() { return timeout; }
00085
00086
00087 void noMaxSpeed() { for(unsigned int i=0; i<NumOutputs; i++) maxSpeeds[i]=0; }
00088
00089
00090
00091
00092
00093 void defaultMaxSpeed(float x=1);
00094
00095
00096
00097
00098 void setMaxSpeed(unsigned int i, float x) { maxSpeeds[i]=x*FrameTime/1000.f; }
00099
00100
00101
00102
00103 float getMaxSpeed(unsigned int i) { return maxSpeeds[i]*1000/FrameTime; }
00104
00105
00106
00107 float getCurrentValue(unsigned int i) { return curPositions[i]; }
00108
00109
00110
00111
00112
00113
00114 virtual int updateOutputs();
00115 virtual int isDirty() { return dirty || !targetReached; }
00116
00117
00118
00119
00120
00121 virtual int isAlive();
00122 virtual void doStart() { MotionCommand::doStart(); setDirty(); }
00123
00124
00125
00126
00127 inline virtual void takeSnapshot() { setDirty(); PostureEngine::takeSnapshot(); }
00128 inline virtual void takeSnapshot(const WorldState& st) { setDirty(); PostureEngine::takeSnapshot(st); }
00129 inline virtual void setWeights(float w) { setWeights(w,0,NumOutputs); }
00130 inline virtual void setWeights(float w, unsigned int lowjoint, unsigned int highjoint) { setDirty(); PostureEngine::setWeights(w,lowjoint,highjoint); }
00131 inline virtual void clear() { setDirty(); PostureEngine::clear(); }
00132 inline virtual PostureEngine& setOverlay(const PostureEngine& pe) { setDirty(); PostureEngine::setOverlay(pe); return *this; }
00133 inline virtual PostureEngine& setUnderlay(const PostureEngine& pe) { setDirty(); PostureEngine::setUnderlay(pe); return *this; }
00134 inline virtual PostureEngine& setAverage(const PostureEngine& pe,float w=0.5) { setDirty(); PostureEngine::setAverage(pe,w); return *this; }
00135 inline virtual PostureEngine& setCombine(const PostureEngine& pe) { setDirty(); PostureEngine::setCombine(pe); return *this; }
00136
00137 inline PostureEngine& setOutputCmd(unsigned int i, const OutputCmd& c)
00138 { dirty=true; targetReached=false; curPositions[i]=motman->getOutputCmd(i).value; PostureEngine::setOutputCmd(i,c); return *this; }
00139
00140 inline virtual unsigned int loadBuffer(const char buf[], unsigned int len, const char* filename=NULL)
00141 { setDirty(); return PostureEngine::loadBuffer(buf,len,filename); }
00142
00143 inline virtual bool solveLinkPosition(const fmat::SubVector<3, const float>& Ptgt, unsigned int link, const fmat::SubVector<3, const float>& Peff)
00144 { setDirty(); return PostureEngine::solveLinkPosition(Ptgt,link,Peff); }
00145
00146 inline virtual bool solveLinkPosition(float Ptgt_x, float Ptgt_y, float Ptgt_z, unsigned int link, float Peff_x, float Peff_y, float Peff_z) { setDirty(); return PostureEngine::solveLinkPosition(Ptgt_x,Ptgt_y,Ptgt_z,link,Peff_x,Peff_y,Peff_z); }
00147
00148 inline virtual bool solveLinkVector(const fmat::SubVector<3, const float>& Ptgt, unsigned int link, const fmat::SubVector<3, const float>& Peff)
00149 { setDirty(); return PostureEngine::solveLinkVector(Ptgt,link,Peff); }
00150
00151 inline virtual bool solveLinkVector(float Ptgt_x, float Ptgt_y, float Ptgt_z, unsigned int link, float Peff_x, float Peff_y, float Peff_z)
00152 { setDirty(); return PostureEngine::solveLinkVector(Ptgt_x,Ptgt_y,Ptgt_z,link,Peff_x,Peff_y,Peff_z); }
00153
00154
00155 protected:
00156 void init();
00157
00158 bool dirty;
00159 bool hold;
00160 float tolerance;
00161 bool targetReached;
00162 unsigned int targetTimestamp;
00163 unsigned int timeout;
00164 float curPositions[NumOutputs];
00165 float maxSpeeds[NumOutputs];
00166 };
00167
00168
00169
00170
00171
00172
00173 #endif