Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
00001 //-*-c++-*- 00002 #ifndef INCLUDED_PostureEngine_h 00003 #define INCLUDED_PostureEngine_h 00004 00005 #include "OutputCmd.h" 00006 #include "Shared/RobotInfo.h" 00007 #include "Shared/LoadSave.h" 00008 00009 //! A class for storing a set of positions and weights for all the outputs 00010 /*! Handy for any class which wants to deal with setting joints and postures without writing a custom class 00011 * @see PostureMC */ 00012 class PostureEngine : public LoadSave { 00013 public: 00014 //!constructor 00015 PostureEngine() : LoadSave() {} 00016 //!constructor, loads a position from a file - not necessarily quick! 00017 /*! @todo might want to make a library of common positions so they don't have to be loaded repeatedly from memstick */ 00018 PostureEngine(const char * filename) : LoadSave() { LoadFile(filename); } 00019 //! destructor 00020 virtual ~PostureEngine(); 00021 00022 //! sets the internal #cmds to the current state of the outputs 00023 virtual void takeSnapshot(); 00024 00025 //! sets all joints to unused 00026 virtual void clear(); 00027 00028 //! sets joints of this to all joints of @a pe which are not equal to unused (layers @a pe over this) stores into this 00029 virtual PostureEngine& setOverlay(const PostureEngine& pe); 00030 //! sets joints of this to all joints of @a pe which are not equal to unused (layers @a pe over this) returns new PostureEngine 00031 virtual PostureEngine createOverlay(const PostureEngine& pe) const; 00032 00033 //! sets joints of this which are equal to unused to @a pe, (layers this over @a pe) stores into this 00034 virtual PostureEngine& setUnderlay(const PostureEngine& pe); 00035 //! sets joints of this which are equal to unused to @a pe, (layers this over @a pe) returns new PostureEngine 00036 virtual PostureEngine createUnderlay(const PostureEngine& pe) const; 00037 00038 //! computes a weighted average of this vs. @a pe, @a w being the weight towards @a pe (so @a w==1 just copies @a pe) 00039 virtual PostureEngine& setAverage(const PostureEngine& pe,float w=0.5); 00040 //! computes a weighted average of this vs. @a pe, @a w being the weight towards @a pe (so @a w==1 just copies @a pe) 00041 virtual PostureEngine createAverage(const PostureEngine& pe,float w=0.5) const; 00042 00043 //! computes a weighted average of this vs. @a pe, using the weight values of the joints, storing the total weight in the result's weight value 00044 virtual PostureEngine& setCombine(const PostureEngine& pe); 00045 //! computes a weighted average of this vs. @a pe, using the weight values of the joints, storing the total weight in the result's weight value 00046 virtual PostureEngine createCombine(const PostureEngine& pe) const; 00047 00048 //! returns the sum squared error between this and pe's output values, but only between outputs which are both not unused 00049 /*! @todo create a version which looks at weights? This doesn't use them. */ 00050 float diff(const PostureEngine& pe) const; 00051 00052 //! returns the average sum squared error between this and pe's output values for outputs which are both not unused 00053 /*! @todo create a version which looks at weights? This doesn't use them. */ 00054 float avgdiff(const PostureEngine& pe) const; 00055 00056 //! returns the max sum squared error between this and pe's output values for outputs which are both not unused 00057 /*! @todo create a version which looks at weights? This doesn't use them. */ 00058 float maxdiff(const PostureEngine& pe) const; 00059 00060 //! NOT VIRTUAL! You should be able to call this to set outputs without checking out, just a peekMotion(). Theoretically. 00061 //!@name Output Accessors 00062 inline PostureEngine& setOutputCmd(unsigned int i, const OutputCmd& c) { cmds[i]=c; return *this; } //!<sets output @a i to OutputCmd @a c, returns @c *this so you can chain them 00063 inline OutputCmd& getOutputCmd(unsigned int i) { return cmds[i]; } //!< returns output @a i, returns a reference so you can also set "through" this call. 00064 inline const OutputCmd& getOutputCmd(unsigned int i) const { return cmds[i]; } //!< returns output @a i 00065 //@} 00066 00067 //!Uses LoadSave interface so you can load/save to files, uses a human-readable storage format 00068 //!@name LoadSave 00069 virtual unsigned int getBinSize() const; 00070 virtual unsigned int LoadBuffer(const char buf[], unsigned int len); 00071 virtual unsigned int SaveBuffer(char buf[], unsigned int len) const; 00072 //@} 00073 00074 protected: 00075 //!used by LoadBuffer()/SaveBuffer(), checks to see if the amount read/written (@a res) is nonzero, increments @a buf, decrements @a len, or displays @a msg if @a is zero 00076 static bool ChkAdvance(int res, const char** buf, unsigned int* len, const char* msg); 00077 //!used by LoadBuffer()/SaveBuffer(), checks to see if the amount read/written (@a res) is nonzero, increments @a buf, decrements @a len, or displays @a msg with @a arg1 if @a is zero 00078 static bool ChkAdvance(int res, const char** buf, unsigned int* len, const char* msg, int arg1); 00079 00080 //!the table of outputs' values and weights, can be accessed through setOutputCmd() and getOutputCmd() 00081 OutputCmd cmds[NumOutputs]; 00082 }; 00083 00084 /*! @file 00085 * @brief Describes PostureEngine, a base class for managing the values and weights of all the outputs 00086 * @todo write a binary version of Load/Save commands for faster access 00087 * @author ejt (Creator) 00088 * 00089 * $Author: ejt $ 00090 * $Name: tekkotsu-2_0 $ 00091 * $Revision: 1.3 $ 00092 * $State: Rel $ 00093 * $Date: 2003/09/25 15:27:23 $ 00094 */ 00095 00096 #endif
Tekkotsu v2.0 |
Generated Wed Jan 21 03:20:29 2004 by Doxygen 1.3.4 |