Homepage Demos Overview Downloads Tutorials Reference
Credits

MotionSequence Class Reference

#include <MotionSequenceMC.h>

Inheritance diagram for MotionSequence:

Inheritance graph
[legend]
List of all members.

Detailed Description

A handy little (or not so little) class for switching between a sequence of postures.

Outputs are handled independently. It's easy to add keyframes which modify all of the outputs, but since each output is tracked individually, OutputCmd's with 0 weight can be used to not affect other motions. For instance, pan the head left to right while moving the right leg up and down several times, you won't have to specify the position of the head in its motion at each of the leg motion keyframes.

Be aware that the 0 time frame will be replaced on a call to play() with the current body posture. However, this only applies to outputs which have a non-zero weighted frame defined at some point. The weights, of the 0 time frame will remain unchanged. These weights are initially set to 0, so that it's possible to 'fade in' the first frame of the motion sequence from whereever the body happens to be (or already doing)

To fade out at the end, set a frame with 0 weight for everything. Otherwise it will simply die suddenly. When a joint reaches its last keyframe, it will be set to 0 weight for all future updateOutputs() (unless of course the playhead is reset)

Currently, MotionSequence's are intended mainly for building, not editing. It's easy to add keyframes, but hard/impossible to delete them.

The MotionSequence base class is an abstract class so that you can create memory efficient motion sequences and simply refer to them by the common base class instead of having to worry about the actual size allocated in the template, MotionSequenceMC.

See also:
MotionSequence::SizeSmall, MotionSequence::SizeMedium, MotionSequence::SizeLarge, MotionSequence::SizeXLarge,
The file format used is as follows: ('<' and '>' are not meant literally)
 *       First line: #MSq
 *  Zero or more of: delay <time-delta>              (moves playhead forward, in milliseconds)
 *               or: settime <time>                  (sets play time to specified value, in ms)
 *               or: <outputname> <value> [<weight>] (sets the specified output to the value - assumes 1 for weight)
 *               or: load <filename>                 (file is a posture, sets position)
 *               or: overlay <filename>              (file can be a posture or another motion sequence)
 *               or: degrees                         (following <value>s will be interpreted as degrees [default])
 *               or: radians                         (following <value>s will be interpreted as radians)
 *        Last line: #END
 *  
After loading a motion sequence, the playtime is left at the end. This is to make it easy to append/overlay motion sequences

Lines beginning with '#' are ignored. Output names are defined in RobotInfo.h, RobotInfo::outputNames.

Definition at line 63 of file MotionSequenceMC.h.

Public Member Functions

 MotionSequence ()
 constructor, will start playing immediately

virtual ~MotionSequence ()
 destructor

Inherited from MotionCommand
virtual int updateOutputs ()
 is called once per update cycle, can do any processing you need to change your priorities or set output commands on the MotionManager

virtual int isDirty ()
 not used by MotionManager at the moment, but could be used to reduce recomputation, and you may find it useful

virtual int isAlive ()
 used to prune "dead" motions from the MotionManager

LoadSave related
virtual unsigned int getBinSize () const
 inherited, returns the size used to save the sequence

virtual unsigned int LoadBuffer (const char buf[], unsigned int len)
 inherited, doesn't clear before loading - call clear yourself if you want to reset, otherwise it will overlay. Leaves playtime at end of load.

virtual unsigned int SaveBuffer (char buf[], unsigned int len) const
 inherited, saves the motion sequence - will save a flat file - doesn't remember references to other files which were loaded

void setSaveDegrees ()
 will store angles as degrees on future saves

bool isSaveDegrees () const
 returns true if will store angles as degrees on future saves

void setSaveRadians ()
 will store angles as radians on future saves

bool isSaveRadians () const
 returns true if will store angles as degrees on future saves

Sequence Construction
virtual void clear ()=0
 empties out the sequence (constant time operation - faster than a series of pops)

void setPlayTime (unsigned int x)
 set the time for both playback and editing (in milliseconds)

void setOutputCmd (unsigned int i, const OutputCmd &cmd)
 will insert a keyframe for the given output, or change an existing one

const OutputCmdgetOutputCmd (unsigned int i)
 gets the value of output i at the playhead

void setPose (const PostureEngine &pose)
 calls setOutputCmd on each of the OutputCmds in pose

void overlayPose (const PostureEngine &pose)
 calls setOutputCmd on non-zero weighted OutputCmds in pose

void compress ()
 compresses the sequence by eliminating sequences of moves which are identical

virtual unsigned int getMaxFrames () const=0
 returns the maximum number of key frames (Move's) which can be stored, determined by the instantiating MotionSequenceMC's template parameter

virtual unsigned int getUsedFrames () const=0
 returns the number of used key frames (Move's) which have been stored by the instantiation MotionSequence subclass

void makeSafe (const float vels[NumOutputs], float margin)
 will insert time into the motion where needed to keep the joint velocities at or below the speeds given in vels * margin

Playback Control
bool isPlaying ()
 returns true if currently playing

void play ()
 restarts playback from beginning

void pause ()
 pauses playback until another call to play() or resume()

void resume ()
 begins playback from the current playtime

unsigned int getPlayTime () const
 returns the current position of the playback (in milliseconds), see setPlayTime()

unsigned int getEndTime () const
 returns the length of the motion sequence (in milliseconds)

void setPlaySpeed (float x)
 sets the playback speed (e.g. 1=regular, 0.5=half speed, -1=backwards)

float getPlaySpeed () const
 returns the playback speed


Static Public Attributes

Template Sizes
To avoid code bloat if there are a large number of different sized MotionSequences, use these sizes where possible.

const unsigned int SizeTiny = NumOutputs*2
 Tiny, but enough to handle a transition into a full-body pose.

const unsigned int SizeSmall = NumOutputs*3
 Small, but still big enough to handle most of the included MS's (2 full-body frames ~ around 1KB).

const unsigned int SizeMedium = NumOutputs*6
 Medium (5 full body frames ~ est 4KB).

const unsigned int SizeLarge = NumOutputs*11
 Large (10 full body frames ~ est 8KB).

const unsigned int SizeXLarge = NumOutputs*26
 eXtra Large (25 full body frames ~ est 16KB)


Protected Types

typedef unsigned short Move_idx_t
 type for indexes to move structures in #moves


Protected Member Functions

virtual MovegetKeyFrame (Move_idx_t x)=0
 returns the Move struct corresponding to x in the subclass's actual data structure

virtual const MovegetKeyFrame (Move_idx_t x) const=0
 returns the Move struct corresponding to x in the subclass's actual data structure

virtual Move_idx_t newKeyFrame ()=0
 causes subclass to create a new Move structure, returns its index

virtual void eraseKeyFrame (Move_idx_t x)=0
 causes subclass to mark the corresponding Move structure as free

void calcOutput (OutputCmd &ans, unsigned int t, const Move &prev, const Move &next) const
 Does the actual calculation of position information. Perhaps replace with a Bezier or spline or something?

virtual void setRange (unsigned int t, Move_idx_t &prev, Move_idx_t &next) const=0
 Sets prev and next to the appropriate values for the given time and output index.

unsigned int setNextFrameTime (Move_idx_t p[NumOutputs], Move_idx_t n[NumOutputs]) const
 sets playtime to next time for which any output has a keyframe, -1 if none exists


Static Protected Member Functions

bool ChkAdvance (int res, const char **buf, unsigned int *len, const char *msg)
 used by LoadBuffer()/SaveBuffer(), checks to see if the amount read/written (res) is nonzero, increments buf, decrements len, or displays msg if is zero

bool ChkAdvance (int res, const char **buf, unsigned int *len, const char *msg, int arg1)
 used by LoadBuffer()/SaveBuffer(), checks to see if the amount read/written (res) is nonzero, increments buf, decrements len, or displays msg with arg1 if is zero

unsigned int readWord (const char buf[], const char *const buflen, char word[], const unsigned int wordlen)
 reads a line from a file, parsing it into variables, returns ending position

unsigned int getOutputIndex (const char name[], unsigned int i)
 returns the index for the output named in the string or NumOutputs if not found, begins search through RobotInfo::outputName's at index i


Protected Attributes

Move_idx_t starts [NumOutputs]
 the beginning frame for each output animation

Move_idx_t prevs [NumOutputs]
 the previous frame (the starttime for this frame will always be less than or equal to playtime)

Move_idx_t nexts [NumOutputs]
 the upcoming frame (the starttime for this frame will always be greater than playtime)

OutputCmd curs [NumOutputs]
 merely a cache of current values (if computed, see curstamps)

unsigned int curstamps [NumOutputs]
 timestamp of corresponding value in curs

unsigned int playtime
 the current time of playback, 0 is start of sequence

unsigned int lasttime
 the time of the last update

unsigned int endtime
 max of #moves's Move::starttime's

float playspeed
 multiplies the difference between current time and starttime, negative will cause play backwards

bool playing
 true if playing, false if paused

float loadSaveMode
 1 to use radians, M_PI/180 for degrees during a save


Static Protected Attributes

Move_idx_t invalid_move = -1U
 used to mark the ends of the Move linked lists


Member Typedef Documentation

typedef unsigned short MotionSequence::Move_idx_t [protected]
 

type for indexes to move structures in #moves

Definition at line 121 of file MotionSequenceMC.h.

Referenced by compress(), getBinSize(), makeSafe(), resume(), SaveBuffer(), setNextFrameTime(), and setOutputCmd().


Constructor & Destructor Documentation

MotionSequence::MotionSequence  )  [inline]
 

constructor, will start playing immediately

Definition at line 66 of file MotionSequenceMC.h.

virtual MotionSequence::~MotionSequence  )  [inline, virtual]
 

destructor

Definition at line 68 of file MotionSequenceMC.h.


Member Function Documentation

void MotionSequence::calcOutput OutputCmd ans,
unsigned int  t,
const Move prev,
const Move next
const [inline, protected]
 

Does the actual calculation of position information. Perhaps replace with a Bezier or spline or something?

Definition at line 154 of file MotionSequenceMC.h.

Referenced by compress(), getOutputCmd(), MotionSequenceMC< MAXMOVE >::updateOutputs(), and DynamicMotionSequence::updateOutputs().

bool MotionSequence::ChkAdvance int  res,
const char **  buf,
unsigned int *  len,
const char *  msg,
int  arg1
[static, protected]
 

used by LoadBuffer()/SaveBuffer(), checks to see if the amount read/written (res) is nonzero, increments buf, decrements len, or displays msg with arg1 if is zero

Definition at line 361 of file MotionSequenceMC.cc.

bool MotionSequence::ChkAdvance int  res,
const char **  buf,
unsigned int *  len,
const char *  msg
[static, protected]
 

used by LoadBuffer()/SaveBuffer(), checks to see if the amount read/written (res) is nonzero, increments buf, decrements len, or displays msg if is zero

Definition at line 350 of file MotionSequenceMC.cc.

Referenced by LoadBuffer(), and SaveBuffer().

virtual void MotionSequence::clear  )  [pure virtual]
 

empties out the sequence (constant time operation - faster than a series of pops)

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

void MotionSequence::compress  ) 
 

compresses the sequence by eliminating sequences of moves which are identical

Definition at line 272 of file MotionSequenceMC.cc.

virtual void MotionSequence::eraseKeyFrame Move_idx_t  x  )  [protected, pure virtual]
 

causes subclass to mark the corresponding Move structure as free

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

Referenced by compress().

unsigned int MotionSequence::getBinSize  )  const [virtual]
 

inherited, returns the size used to save the sequence

Implements LoadSave.

Definition at line 39 of file MotionSequenceMC.cc.

unsigned int MotionSequence::getEndTime  )  const [inline]
 

returns the length of the motion sequence (in milliseconds)

Definition at line 114 of file MotionSequenceMC.h.

virtual const Move& MotionSequence::getKeyFrame Move_idx_t  x  )  const [protected, pure virtual]
 

returns the Move struct corresponding to x in the subclass's actual data structure

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

virtual Move& MotionSequence::getKeyFrame Move_idx_t  x  )  [protected, pure virtual]
 

returns the Move struct corresponding to x in the subclass's actual data structure

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

Referenced by compress(), getBinSize(), getOutputCmd(), makeSafe(), resume(), SaveBuffer(), setNextFrameTime(), and setOutputCmd().

virtual unsigned int MotionSequence::getMaxFrames  )  const [pure virtual]
 

returns the maximum number of key frames (Move's) which can be stored, determined by the instantiating MotionSequenceMC's template parameter

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

const OutputCmd & MotionSequence::getOutputCmd unsigned int  i  ) 
 

gets the value of output i at the playhead

Definition at line 28 of file MotionSequenceMC.cc.

Referenced by MotionSequenceMC< MAXMOVE >::updateOutputs(), and DynamicMotionSequence::updateOutputs().

unsigned int MotionSequence::getOutputIndex const char  name[],
unsigned int  i
[static, protected]
 

returns the index for the output named in the string or NumOutputs if not found, begins search through RobotInfo::outputName's at index i

Definition at line 399 of file MotionSequenceMC.cc.

Referenced by LoadBuffer().

float MotionSequence::getPlaySpeed  )  const [inline]
 

returns the playback speed

Definition at line 116 of file MotionSequenceMC.h.

unsigned int MotionSequence::getPlayTime  )  const [inline]
 

returns the current position of the playback (in milliseconds), see setPlayTime()

Definition at line 113 of file MotionSequenceMC.h.

virtual unsigned int MotionSequence::getUsedFrames  )  const [pure virtual]
 

returns the number of used key frames (Move's) which have been stored by the instantiation MotionSequence subclass

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

virtual int MotionSequence::isAlive  )  [inline, virtual]
 

used to prune "dead" motions from the MotionManager

note that a motion could be "paused" or inactive and therefore not dirty, but still alive, biding its time to "strike" ;)

Returns:
zero if the motion is still processing, non-zero otherwise

Implements MotionCommand.

Definition at line 82 of file MotionSequenceMC.h.

Referenced by isPlaying().

virtual int MotionSequence::isDirty  )  [inline, virtual]
 

not used by MotionManager at the moment, but could be used to reduce recomputation, and you may find it useful

Returns:
zero if none of the commands have changed since last getJointCmd(), else non-zero

Implements MotionCommand.

Definition at line 81 of file MotionSequenceMC.h.

bool MotionSequence::isPlaying  )  [inline]
 

returns true if currently playing

Definition at line 109 of file MotionSequenceMC.h.

Referenced by isDirty(), MotionSequenceMC< MAXMOVE >::updateOutputs(), updateOutputs(), and DynamicMotionSequence::updateOutputs().

bool MotionSequence::isSaveDegrees  )  const [inline]
 

returns true if will store angles as degrees on future saves

Definition at line 90 of file MotionSequenceMC.h.

bool MotionSequence::isSaveRadians  )  const [inline]
 

returns true if will store angles as degrees on future saves

Definition at line 92 of file MotionSequenceMC.h.

Referenced by getBinSize(), and SaveBuffer().

unsigned int MotionSequence::LoadBuffer const char  buf[],
unsigned int  len
[virtual]
 

inherited, doesn't clear before loading - call clear yourself if you want to reset, otherwise it will overlay. Leaves playtime at end of load.

Implements LoadSave.

Definition at line 68 of file MotionSequenceMC.cc.

void MotionSequence::makeSafe const float  vels[NumOutputs],
float  margin
 

will insert time into the motion where needed to keep the joint velocities at or below the speeds given in vels * margin

Definition at line 299 of file MotionSequenceMC.cc.

virtual Move_idx_t MotionSequence::newKeyFrame  )  [protected, pure virtual]
 

causes subclass to create a new Move structure, returns its index

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

Referenced by setOutputCmd().

void MotionSequence::overlayPose const PostureEngine pose  ) 
 

calls setOutputCmd on non-zero weighted OutputCmds in pose

Definition at line 266 of file MotionSequenceMC.cc.

Referenced by LoadBuffer().

void MotionSequence::pause  )  [inline]
 

pauses playback until another call to play() or resume()

Definition at line 111 of file MotionSequenceMC.h.

void MotionSequence::play  ) 
 

restarts playback from beginning

Definition at line 327 of file MotionSequenceMC.cc.

Referenced by DriveMeBehavior::processEvent(), and updateOutputs().

unsigned int MotionSequence::readWord const char  buf[],
const char *const  buflen,
char  word[],
const unsigned int  wordlen
[static, protected]
 

reads a line from a file, parsing it into variables, returns ending position

Definition at line 383 of file MotionSequenceMC.cc.

Referenced by LoadBuffer().

void MotionSequence::resume  ) 
 

begins playback from the current playtime

Definition at line 335 of file MotionSequenceMC.cc.

Referenced by play().

unsigned int MotionSequence::SaveBuffer char  buf[],
unsigned int  len
const [virtual]
 

inherited, saves the motion sequence - will save a flat file - doesn't remember references to other files which were loaded

Implements LoadSave.

Definition at line 171 of file MotionSequenceMC.cc.

unsigned int MotionSequence::setNextFrameTime Move_idx_t  p[NumOutputs],
Move_idx_t  n[NumOutputs]
const [protected]
 

sets playtime to next time for which any output has a keyframe, -1 if none exists

Definition at line 372 of file MotionSequenceMC.cc.

Referenced by getBinSize(), makeSafe(), and SaveBuffer().

void MotionSequence::setOutputCmd unsigned int  i,
const OutputCmd cmd
 

will insert a keyframe for the given output, or change an existing one

Definition at line 237 of file MotionSequenceMC.cc.

Referenced by LoadBuffer(), overlayPose(), and setPose().

void MotionSequence::setPlaySpeed float  x  )  [inline]
 

sets the playback speed (e.g. 1=regular, 0.5=half speed, -1=backwards)

Definition at line 115 of file MotionSequenceMC.h.

void MotionSequence::setPlayTime unsigned int  x  ) 
 

set the time for both playback and editing (in milliseconds)

Definition at line 231 of file MotionSequenceMC.cc.

Referenced by MotionSequenceMC< MAXMOVE >::clear(), DynamicMotionSequence::clear(), DynamicMotionSequence::DynamicMotionSequence(), LoadBuffer(), MotionSequenceMC< MAXMOVE >::MotionSequenceMC(), play(), and updateOutputs().

void MotionSequence::setPose const PostureEngine pose  ) 
 

calls setOutputCmd on each of the OutputCmds in pose

Definition at line 261 of file MotionSequenceMC.cc.

Referenced by LoadBuffer().

virtual void MotionSequence::setRange unsigned int  t,
Move_idx_t prev,
Move_idx_t next
const [protected, pure virtual]
 

Sets prev and next to the appropriate values for the given time and output index.

Implemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

Referenced by setNextFrameTime(), and setPlayTime().

void MotionSequence::setSaveDegrees  )  [inline]
 

will store angles as degrees on future saves

Definition at line 89 of file MotionSequenceMC.h.

Referenced by LoadBuffer().

void MotionSequence::setSaveRadians  )  [inline]
 

will store angles as radians on future saves

Definition at line 91 of file MotionSequenceMC.h.

Referenced by LoadBuffer().

int MotionSequence::updateOutputs  )  [virtual]
 

is called once per update cycle, can do any processing you need to change your priorities or set output commands on the MotionManager

Returns:
zero if no changes were made, non-zero otherwise
See also:
RobotInfo::NumFrames

RobotInfo::FrameTime

Implements MotionCommand.

Reimplemented in DynamicMotionSequence, and MotionSequenceMC< MAXMOVE >.

Definition at line 11 of file MotionSequenceMC.cc.

Referenced by MotionSequenceMC< MAXMOVE >::updateOutputs(), and DynamicMotionSequence::updateOutputs().


Member Data Documentation

OutputCmd MotionSequence::curs[NumOutputs] [protected]
 

merely a cache of current values (if computed, see curstamps)

Definition at line 138 of file MotionSequenceMC.h.

Referenced by getOutputCmd().

unsigned int MotionSequence::curstamps[NumOutputs] [protected]
 

timestamp of corresponding value in curs

Definition at line 139 of file MotionSequenceMC.h.

Referenced by getOutputCmd().

unsigned int MotionSequence::endtime [protected]
 

max of #moves's Move::starttime's

Definition at line 142 of file MotionSequenceMC.h.

Referenced by getEndTime(), MotionSequence(), play(), and setOutputCmd().

MotionSequence::Move_idx_t MotionSequence::invalid_move = -1U [static, protected]
 

used to mark the ends of the Move linked lists

Definition at line 9 of file MotionSequenceMC.cc.

Referenced by getOutputCmd(), setNextFrameTime(), and setOutputCmd().

unsigned int MotionSequence::lasttime [protected]
 

the time of the last update

Definition at line 141 of file MotionSequenceMC.h.

Referenced by MotionSequence(), resume(), and updateOutputs().

float MotionSequence::loadSaveMode [protected]
 

1 to use radians, M_PI/180 for degrees during a save

Definition at line 146 of file MotionSequenceMC.h.

Referenced by getBinSize(), isSaveDegrees(), isSaveRadians(), LoadBuffer(), MotionSequence(), SaveBuffer(), setSaveDegrees(), and setSaveRadians().

Move_idx_t MotionSequence::nexts[NumOutputs] [protected]
 

the upcoming frame (the starttime for this frame will always be greater than playtime)

Definition at line 137 of file MotionSequenceMC.h.

Referenced by getOutputCmd(), setOutputCmd(), and setPlayTime().

bool MotionSequence::playing [protected]
 

true if playing, false if paused

Definition at line 144 of file MotionSequenceMC.h.

Referenced by isPlaying(), MotionSequence(), pause(), and resume().

float MotionSequence::playspeed [protected]
 

multiplies the difference between current time and starttime, negative will cause play backwards

Definition at line 143 of file MotionSequenceMC.h.

Referenced by getPlaySpeed(), isAlive(), MotionSequence(), play(), setPlaySpeed(), and updateOutputs().

unsigned int MotionSequence::playtime [protected]
 

the current time of playback, 0 is start of sequence

Definition at line 140 of file MotionSequenceMC.h.

Referenced by getOutputCmd(), getPlayTime(), LoadBuffer(), MotionSequence(), setOutputCmd(), setPlayTime(), and updateOutputs().

Move_idx_t MotionSequence::prevs[NumOutputs] [protected]
 

the previous frame (the starttime for this frame will always be less than or equal to playtime)

Definition at line 136 of file MotionSequenceMC.h.

Referenced by getOutputCmd(), setOutputCmd(), and setPlayTime().

const unsigned int MotionSequence::SizeLarge = NumOutputs*11 [static]
 

Large (10 full body frames ~ est 8KB).

Definition at line 75 of file MotionSequenceMC.h.

const unsigned int MotionSequence::SizeMedium = NumOutputs*6 [static]
 

Medium (5 full body frames ~ est 4KB).

Definition at line 74 of file MotionSequenceMC.h.

const unsigned int MotionSequence::SizeSmall = NumOutputs*3 [static]
 

Small, but still big enough to handle most of the included MS's (2 full-body frames ~ around 1KB).

Definition at line 73 of file MotionSequenceMC.h.

const unsigned int MotionSequence::SizeTiny = NumOutputs*2 [static]
 

Tiny, but enough to handle a transition into a full-body pose.

Definition at line 72 of file MotionSequenceMC.h.

const unsigned int MotionSequence::SizeXLarge = NumOutputs*26 [static]
 

eXtra Large (25 full body frames ~ est 16KB)

Definition at line 76 of file MotionSequenceMC.h.

Move_idx_t MotionSequence::starts[NumOutputs] [protected]
 

the beginning frame for each output animation

Definition at line 135 of file MotionSequenceMC.h.

Referenced by compress(), getBinSize(), makeSafe(), resume(), and SaveBuffer().


The documentation for this class was generated from the following files:

Tekkotsu v2.1
Generated Tue Mar 16 23:22:18 2004 by Doxygen 1.3.5