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

DynamicMotionSequence.h

Go to the documentation of this file.
00001 //-*-c++-*-
00002 #ifndef INCLUDED_DynamicMotionSequenceMC_h_
00003 #define INCLUDED_DynamicMotionSequenceMC_h_
00004 
00005 #include "MotionSequenceMC.h"
00006 #include <vector>
00007 
00008 //! Uses STL's vector for dynamic memory allocation - don't use this as a motion command, pointers in shared memory regions can be invalid in other processes
00009 /*! See MotionSequenceMC for documentation on its members */
00010 class DynamicMotionSequence : public MotionSequence {
00011 public:
00012   //!constructor
00013   DynamicMotionSequence() : MotionSequence(), moves(), erased() {clear();}
00014   //!constructor, loads from a file and then resets the playtime to beginning and begins to play
00015   explicit DynamicMotionSequence(const char* filename) : MotionSequence(), moves(), erased() {clear();LoadFile(filename);setPlayTime(1);}
00016   //!destructor
00017   virtual ~DynamicMotionSequence() {}
00018 
00019   // I put this here because i want direct access to moves so it'll be faster
00020 /*  void planJointCmds(unsigned int i, JointCmd frames[NumFrames]) {
00021     Move_idx_t prev=prevs[i],next=nexts[i];
00022     frames[0]=getJointCmd(i);
00023     for(unsigned int t=playtime+FrameTime,j=1;j<NumFrames;j++,t+=FrameTime) {
00024       setRange(t,prev,next);
00025       if(next!=invalid_move)
00026         calcJoint(frames[j],t,moves[prev],moves[next]);
00027       else
00028         frames[j]=unusedJoint;
00029     }
00030   }*/
00031   
00032 
00033   virtual int updateOutputs() {
00034     MotionSequence::updateOutputs();
00035     if(!isPlaying()) {
00036       for(unsigned int i=0; i<NumOutputs; i++) //just copies getOutputCmd(i) across frames
00037         motman->setOutput(this,i,getOutputCmd(i));
00038     } else {
00039       for(unsigned int i=0; i<NumOutputs; i++) { //fill out the buffer of commands for smoother movement
00040         Move_idx_t prev=prevs[i],next=nexts[i];
00041         OutputCmd frames[NumFrames];
00042         frames[0]=getOutputCmd(i);
00043         for(unsigned int t=playtime+FrameTime,j=1;j<NumFrames;j++,t+=FrameTime) {
00044           setRange(t,prev,next);
00045           if(next!=invalid_move)
00046             calcOutput(frames[j],t,moves[prev],moves[next]);
00047           else
00048             frames[j].unset();
00049         }
00050         motman->setOutput(this,i,frames);
00051       }
00052     }
00053     return NumOutputs;
00054     //    if(i<NumLegJointss)
00055     //      log.push_back(logent(get_time(),playtime,i,frames));
00056   }
00057   
00058   virtual void clear() {
00059     moves.clear();
00060     erased.clear();
00061     for(unsigned int i=0; i<NumOutputs; i++) {
00062       moves.push_back(Move());
00063       moves.back().cmd.unset();
00064       moves.back().next=invalid_move;
00065       moves.back().prev=invalid_move;
00066       prevs[i]=starts[i]=moves.size()-1;
00067       nexts[i]=invalid_move;
00068     }
00069     setPlayTime(1);
00070   }
00071   virtual unsigned int getMaxFrames() const { return -1U; }
00072   virtual unsigned int getUsedFrames() const { return moves.size()-erased.size(); }
00073 
00074 protected:
00075   // TYPES:
00076   typedef std::vector<Move> list_t; //!< shorthand for the ListMemBuf that stores all of the movement frames
00077 
00078   // MEMBERS:
00079   list_t moves;                     //!< stores all of the movement keyframes
00080   std::vector<Move_idx_t> erased;   //!< recycles erased keyframes, can't just shift elements in #moves, it would throw of index numbers in Move structures
00081 
00082   virtual Move& getKeyFrame(Move_idx_t x) { return moves[x]; }
00083   virtual const Move& getKeyFrame(Move_idx_t x) const { return moves[x]; }
00084   virtual Move_idx_t newKeyFrame() {
00085     if(erased.empty()) {
00086       moves.push_back(Move());
00087       return moves.size()-1;
00088     } else { //recycle from used list
00089       Move_idx_t x=erased.back();
00090       erased.pop_back();
00091       return x;
00092     }
00093   }
00094   virtual void eraseKeyFrame(Move_idx_t x) { erased.push_back(x); }
00095   void setRange(unsigned int t,Move_idx_t& prev, Move_idx_t& next) const {
00096     if(next!=invalid_move && moves[next].starttime<=t) {
00097       do {
00098         prev=next;
00099         next=moves[prev].next;
00100       } while(next!=invalid_move && moves[next].starttime<=t);
00101     } else if(t<moves[prev].starttime) {
00102       do {
00103         next=prev;
00104         prev=moves[next].prev;
00105       } while(t<moves[prev].starttime);
00106     }
00107   }
00108 };
00109 
00110 /*! @file
00111  * @brief Uses STL's vector for dynamic memory allocation - don't use this as a motion command, pointers in shared memory regions can be invalid in other processes
00112  * @author ejt (Creator)
00113  *
00114  * $Author: ejt $
00115  * $Name: tekkotsu-1_4_1 $
00116  * $Revision: 1.3 $
00117  * $State: Exp $
00118  * $Date: 2003/04/25 18:22:39 $
00119  */
00120 
00121 #endif

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