MotionSequenceMC.hGo to the documentation of this file.00001
00002 #ifndef INCLUDED_MotionSequenceMC_h_
00003 #define INCLUDED_MotionSequenceMC_h_
00004
00005 #include "MotionSequenceEngine.h"
00006 #include "MotionCommand.h"
00007 #include "MotionManager.h"
00008
00009
00010
00011
00012
00013
00014 template<unsigned int MAXMOVE>
00015 class MotionSequenceMC : public MotionCommand, public MotionSequenceEngine {
00016 public:
00017 static const unsigned int CAPACITY=MAXMOVE;
00018
00019
00020 MotionSequenceMC()
00021 : MotionCommand(), MotionSequenceEngine(), moves()
00022 {
00023 clear();
00024 }
00025
00026 explicit MotionSequenceMC(const std::string& filename)
00027 : MotionCommand(), MotionSequenceEngine(), moves()
00028 {
00029 clear();
00030 LoadFile(filename.c_str());
00031 setTime(1);
00032 }
00033
00034 virtual ~MotionSequenceMC() {}
00035
00036 virtual int isDirty() { return isPlaying(); }
00037 virtual int isAlive() { return (playspeed>0) ? (playtime<=endtime) : (playtime>0); }
00038
00039
00040 virtual int updateOutputs() {
00041 MotionSequenceEngine::updateOutputs();
00042 if(!isPlaying()) {
00043 for(unsigned int i=0; i<NumOutputs; i++)
00044 motman->setOutput(this,i,getOutputCmd(i));
00045 } else {
00046
00047 for(unsigned int i=0; i<NumOutputs; i++) {
00048 Move_idx_t prev=prevs[i],next=nexts[i];
00049 OutputCmd frames[NumFrames];
00050 frames[0]=getOutputCmd(i);
00051 for(unsigned int t=playtime+FrameTime,j=1;j<NumFrames;j++,t+=FrameTime) {
00052 setRange(t,prev,next);
00053 if(next!=invalid_move)
00054 calcOutput(frames[j],t,moves[prev],moves[next]);
00055 else if(hold)
00056 frames[j]=moves[prev].cmd;
00057 }
00058
00059
00060
00061 motman->setOutput(this,i,frames);
00062 }
00063
00064 }
00065 return NumOutputs;
00066
00067
00068 }
00069
00070 virtual void clear() {
00071 moves.clear();
00072 for(unsigned int i=0; i<NumOutputs; i++) {
00073 prevs[i]=starts[i]=moves.new_back();
00074 moves.back().cmd.unset();
00075 moves.back().next=invalid_move;
00076 moves.back().prev=invalid_move;
00077 moves.back().starttime=0;
00078 nexts[i]=invalid_move;
00079 }
00080 setTime(1);
00081 }
00082
00083 virtual unsigned int getMaxFrames() const { return moves.getMaxCapacity(); }
00084 virtual unsigned int getUsedFrames() const { return moves.size(); }
00085
00086 protected:
00087
00088 typedef ListMemBuf<Move,MAXMOVE,Move_idx_t> list_t;
00089
00090
00091 list_t moves;
00092
00093 virtual Move& getKeyFrame(Move_idx_t x) { return moves[x]; }
00094 virtual const Move& getKeyFrame(Move_idx_t x) const { return moves[x]; }
00095 virtual Move_idx_t newKeyFrame() {
00096 Move_idx_t i=moves.new_front();
00097 if(i==invalid_move)
00098 serr->printf("ERROR: MotionSequenceMC %d has run out of memory\n",getID());
00099 return i;
00100 }
00101
00102 virtual void eraseKeyFrame(Move_idx_t x) { moves.erase(x); }
00103
00104 void setRange(unsigned int t,Move_idx_t& prev, Move_idx_t& next) const {
00105 if(next!=invalid_move && moves[next].starttime<=t) {
00106 do {
00107 prev=next;
00108 next=moves[prev].next;
00109 } while(next!=invalid_move && moves[next].starttime<=t);
00110 } else {
00111 while(moves[prev].prev!=invalid_move && t<moves[prev].starttime) {
00112 next=prev;
00113 prev=moves[next].prev;
00114 }
00115 }
00116 }
00117 };
00118
00119 typedef MotionSequenceMC<NumOutputs*2> TinyMotionSequenceMC;
00120 typedef MotionSequenceMC<NumOutputs*3> SmallMotionSequenceMC;
00121 typedef MotionSequenceMC<NumOutputs*6> MediumMotionSequenceMC;
00122 typedef MotionSequenceMC<NumOutputs*11> LargeMotionSequenceMC;
00123 typedef MotionSequenceMC<NumOutputs*26> XLargeMotionSequenceMC;
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 #endif
|