CMotionContainer Class Reference

Motion Command, Interpolation and Storage Class (threaded). More...

#include <motion.h>

List of all members.

Public Types

enum  CAPTURE_TYPES { CAPTURE_TIME, CAPTURE_KEY }
enum  MOTION_COMMAND_TYPES {
  COMMAND_NONE, COMMAND_WALK, COMMAND_STANDWALK, COMMAND_TURNRIGHT,
  COMMAND_TURNLEFT, COMMAND_STOP, COMMAND_COUNT
}
 Motion Command Types. More...
enum  MOTION_CONTROL_COMMAND_TYPES { CONTROL_COMMAND_STOP, CONTROL_COMMAND_COUNT }
 Motion Command Types. More...

Public Member Functions

void calcTrajectory ()
 Processes motion and control commands.
void interpolate ()
 Interpolates between the points in a trajectory or joint angles.
void updateRobot ()
 Reads current servo and sensor data from the robot and sends new joint angles to the robot (threaded).
void stop ()
 Stops the execution of a motion sequence.
void addSequenceToTrajectory (int ids[], int len, int pause, bool checkCollision=true, int kid=15)
 Adds motion sequence data to limb trajectory lists.
CMotiongetIntermediateMotion (CMotion *target, int id=INTERMEDIATE_MOTION, int ipoType=INTERMEDIATE_IPOTYPE, int pause=INTERMEDIATE_PAUSE)
 Calculates a smooth transition between the current pose and the target motion.
CMotiongetIntermediateMotion (CMotionData *target, int id=INTERMEDIATE_MOTION, int ipoType=INTERMEDIATE_IPOTYPE, int pause=INTERMEDIATE_PAUSE)
int getSequenceLength (int *ids, int len)
 Returns the total playtime of an array of motion sequences.
void addCommand (char *cmd, int params[], int paramCount)
 Adds a motion command to the cmds list.
void addCommand (char *cmd, int param1, int param2)
void addControlCommand (char *cmd, int params[], int paramCount)
 Adds a control command to the cmdControls list.
int getIpoState ()
 Returns the state of the read/write thread.
int enableIpo (bool enable)
 Suspends or Resumes the read/write thread.
 CMotionContainer ()
void init ()
 Initialization.
void process ()
 Thread function.
void playSequence (int id[], int pause, int ipo, int loop, int num)
 Plays multiple motion sequences.
void stopSequence (bool wait)
 Stops the playing of motion sequences.
void joinSequence (int store, int ids[], int len)
 Joins motion sequences.
void capture (int id, byte input)
 Captures movement data.
void stopCapture ()
 Stops the capture process.
void moveLimb (int id, float x, float y, float z, float rotx, float roty, float rotz, int time=1000, bool sync=true)
 Moves a limb to the specified position with the specified orientation.
void moveLink (int id, float angle, int time=1000, bool sync=true)
 Moves a servo motor to the specified position.
void loadMotionFromFile (int startid, char *filename, int start, int end)
 Loads motion data from a .mtn file into the motion buffer.

Public Attributes

CList motionList
 Motion buffer.
CMotionSequence motions [MOTION_COUNT]
 Motion buffer.
CList cmds
 Motion Command Buffer, will be executed one after another.
CList cmdControl
 Motion Control Command Buffer, will be executed one after another.
CList joints [AX12_COUNT]
 Target Angle Buffer for every joint angle.
CListtrajectory
 Target pose Buffer for every limb.
CList interpolated
 List of interpolated robot poses (CIpoData).

Static Public Attributes

static const char * command_names [COMMAND_COUNT]
 Motion Command Names (console input).
static const char * control_command_names [CONTROL_COMMAND_COUNT]
 Motion Command Names (console input).
static int ipoPause = MOTION_IPO_PAUSE
static int capturePause = MOTION_CAPTURE_PAUSE
static int statePause = MOTION_STATE_PAUSE
static int trajectoryPause = MOTION_TRAJ_PAUSE
static int trajectoryLookAhead = TRAJ_LOOKAHEAD
static int interpolationLookAhead = IPO_LOOKAHEAD
static int collisionLookAhead = COLLISION_LOOKAHEAD
static int ipoMinPause = MOTION_IPO_MINPAUSE

Private Types

enum  MOTION_STATES {
  MOTION_NONE, MOTION_PLAY, MOTION_STOP, MOTION_CAPTURE,
  MOTION_STOPCAPTURE
}
 States of the motion thread. More...
enum  IPO_STATES { IPO_ON, IPO_OFF }
 Handshake constants to control ipo thread. More...

Private Member Functions

void setState (int newstate)
 Set state of read/write thread.
int getState ()
 Returns current state of read/write thread.
void captureMotion (int id, int type)
 Captures Robot movement and stores the result in the motion buffer (threaded).
void play ()
 Plays motion sequences (threaded).

Private Attributes

int state
 Current state of the motion thread.
int stateParam [5]
 Parameter values associated with current state.
int ipoState
 Current state of the read/write thread.
int ipoReturn
 Handshake variable to suspend/resume read/write thread.


Detailed Description

Motion Command, Interpolation and Storage Class (threaded).

The class is used as a singleton and runs in its own thread (synchronization by state variables, see MOTION_STATES).
Furthermore, the class splits up into three modules which each run in an own thread.
The modules are:

Additionally the class provides a global storage for motion sequences (motions) and mechanisms to:


Member Enumeration Documentation

enum CMotionContainer::MOTION_STATES [private]

States of the motion thread.

Enumerator:
MOTION_NONE 
MOTION_PLAY 
MOTION_STOP 
MOTION_CAPTURE 
MOTION_STOPCAPTURE 

enum CMotionContainer::IPO_STATES [private]

Handshake constants to control ipo thread.

Enumerator:
IPO_ON 
IPO_OFF 

enum CMotionContainer::CAPTURE_TYPES

Enumerator:
CAPTURE_TIME 
CAPTURE_KEY 

enum CMotionContainer::MOTION_COMMAND_TYPES

Motion Command Types.

Enumerator:
COMMAND_NONE 
COMMAND_WALK 
COMMAND_STANDWALK 
COMMAND_TURNRIGHT 
COMMAND_TURNLEFT 
COMMAND_STOP 
COMMAND_COUNT 

enum CMotionContainer::MOTION_CONTROL_COMMAND_TYPES

Motion Command Types.

Enumerator:
CONTROL_COMMAND_STOP 
CONTROL_COMMAND_COUNT 


Constructor & Destructor Documentation

CMotionContainer::CMotionContainer (  ) 


Member Function Documentation

void CMotionContainer::setState ( int  newstate  )  [private]

Set state of read/write thread.

See also:
IPO_STATES

int CMotionContainer::getState (  )  [private]

Returns current state of read/write thread.

See also:
IPO_STATES

void CMotionContainer::captureMotion ( int  id,
int  type 
) [private]

Captures Robot movement and stores the result in the motion buffer (threaded).

Will be called automatically after a call to capture.
Reduces servo motor torque to a minimum so the user can move the limbs of the robot by hand. Depending on the type of the capture process the motion data will be captured every MOTION_IPO_PAUSE milliseconds or when the user presses the spacebar.

Parameters:
id Index in the motion buffer where the captured movement is stored
type Type of the capture process (contigous or discrete)
See also:
CAPTURE_STATES

void CMotionContainer::play (  )  [private]

Plays motion sequences (threaded).

Will be called automatically after a call to playSequence.
Stops the read/write thread and processes all motions in the motionList. Additional motions can be added during runtime (via playSequence). Interpolates between the key frames in the motion sequences and provides a smooth transition between the different motions.

See also:
playSequence

void CMotionContainer::calcTrajectory (  ) 

Processes motion and control commands.

Depending on the processed command one or several limb trajectories (lists of CPoints) will be generated and stored in the corresponding trajectory list.

void CMotionContainer::interpolate (  ) 

Interpolates between the points in a trajectory or joint angles.

The function takes data from the following sources:

First, data from the trajectory lists is taken and IPO_COUNT interpolated points are calculated (by interpolation in cartesian (plus inverse kinematics) or joint space). If not enough data is present, f.e. no motion for limb number 2 was specified, the actual (read from the robot) limb pose will be used. Afterwards, the non-empty joint angles lists are processed and the interpolated angles will be used instead of the ones retrieved through the trajectory lists.

The result of the interpolation process are a number of objects of type CIpoData which will be added to the interpolated list.

void CMotionContainer::updateRobot (  ) 

Reads current servo and sensor data from the robot and sends new joint angles to the robot (threaded).

If active (see enableIpo) every MOTION_IPO_PAUSE milliseconds the current robot pose and/or the sensor data will be read from the robot. Then the next object in the interpolated list will be processed (collision check, ...) and the interpolated angles will be send to the robot.
If a collision occurs all robot movement will be stopped (optional, see )
Additionally the current robot pose is visualized in the opengl-viewer and limb information is shown in the console.

void CMotionContainer::stop (  ) 

Stops the execution of a motion sequence.

See also:
play, playSequence

void CMotionContainer::addSequenceToTrajectory ( int  ids[],
int  len,
int  pause,
bool  checkCollision = true,
int  kid = 15 
)

Adds motion sequence data to limb trajectory lists.

Splits every key frame into target poses for every limb and adds the data to the trajectory lists.

CMotion * CMotionContainer::getIntermediateMotion ( CMotion target,
int  id = INTERMEDIATE_MOTION,
int  ipoType = INTERMEDIATE_IPOTYPE,
int  pause = INTERMEDIATE_PAUSE 
)

Calculates a smooth transition between the current pose and the target motion.

The resulting motion sequence will be stored at index id in the motion buffer.

Parameters:
target Motion Sequence Container (the motion to play next)

CMotion * CMotionContainer::getIntermediateMotion ( CMotionData target,
int  id = INTERMEDIATE_MOTION,
int  ipoType = INTERMEDIATE_IPOTYPE,
int  pause = INTERMEDIATE_PAUSE 
)

int CMotionContainer::getSequenceLength ( int *  ids,
int  len 
)

Returns the total playtime of an array of motion sequences.

void CMotionContainer::addCommand ( char *  cmd,
int  params[],
int  paramCount 
)

Adds a motion command to the cmds list.

void CMotionContainer::addCommand ( char *  cmd,
int  param1,
int  param2 
)

void CMotionContainer::addControlCommand ( char *  cmd,
int  params[],
int  paramCount 
)

Adds a control command to the cmdControls list.

int CMotionContainer::getIpoState (  ) 

Returns the state of the read/write thread.

int CMotionContainer::enableIpo ( bool  enable  ) 

Suspends or Resumes the read/write thread.

void CMotionContainer::init (  ) 

Initialization.

void CMotionContainer::process (  ) 

Thread function.

void CMotionContainer::playSequence ( int  id[],
int  pause,
int  ipo,
int  loop,
int  num 
)

Plays multiple motion sequences.

Supports looping, different interpolation types.

Parameters:
id Array of indexes of motion sequences in /a motions
pause Time in milliseconds between interpolation points
ipo Interpolation type, see IPO_TYPES
loop How often to repeat the motion
num Length of id

void CMotionContainer::stopSequence ( bool  wait  ) 

Stops the playing of motion sequences.

Calls stop in its own thread.

Parameters:
wait Not used at the moment

void CMotionContainer::joinSequence ( int  store,
int  ids[],
int  len 
)

Joins motion sequences.

The key frames of all motion sequences will be joined and stored under the index store.

void CMotionContainer::capture ( int  id,
byte  input 
)

Captures movement data.

See also:
captureMotion

void CMotionContainer::stopCapture (  ) 

Stops the capture process.

void CMotionContainer::moveLimb ( int  id,
float  x,
float  y,
float  z,
float  rotx,
float  roty,
float  rotz,
int  time = 1000,
bool  sync = true 
)

Moves a limb to the specified position with the specified orientation.

The pose will be added to the corresponding trajectory list (does use inverse kinematics to retrieve the corresponding joint angles).

void CMotionContainer::moveLink ( int  id,
float  angle,
int  time = 1000,
bool  sync = true 
)

Moves a servo motor to the specified position.

The target angle will be added to the corresponding angle list.

void CMotionContainer::loadMotionFromFile ( int  startid,
char *  filename,
int  start,
int  end 
)

Loads motion data from a .mtn file into the motion buffer.

The .mtn-file filename will be parsed and the keyframes from start to end will be stored in the motion buffer, starting with index start.


Member Data Documentation

int CMotionContainer::state [private]

Current state of the motion thread.

See also:
MOTION_STATES

int CMotionContainer::stateParam[5] [private]

Parameter values associated with current state.

int CMotionContainer::ipoState [private]

Current state of the read/write thread.

See also:
IPO_STATES

int CMotionContainer::ipoReturn [private]

Handshake variable to suspend/resume read/write thread.

const char * CMotionContainer::command_names [static]

Initial value:

 {
"STAND","WALK","WALKSTAND","TURNRIGHT","TURNLEFT","STOP" 
}
Motion Command Names (console input).

const char* CMotionContainer::control_command_names[CONTROL_COMMAND_COUNT] [static]

Motion Command Names (console input).

int CMotionContainer::ipoPause = MOTION_IPO_PAUSE [static]

int CMotionContainer::capturePause = MOTION_CAPTURE_PAUSE [static]

int CMotionContainer::statePause = MOTION_STATE_PAUSE [static]

int CMotionContainer::trajectoryPause = MOTION_TRAJ_PAUSE [static]

int CMotionContainer::trajectoryLookAhead = TRAJ_LOOKAHEAD [static]

int CMotionContainer::interpolationLookAhead = IPO_LOOKAHEAD [static]

int CMotionContainer::collisionLookAhead = COLLISION_LOOKAHEAD [static]

int CMotionContainer::ipoMinPause = MOTION_IPO_MINPAUSE [static]

CList CMotionContainer::motionList

Motion buffer.

Can be filled by calls to playSequence, cleared by stop and run by play, which will be called automatically.

CMotionSequence CMotionContainer::motions[MOTION_COUNT]

Motion buffer.

Stores motion sequences.

CList CMotionContainer::cmds

Motion Command Buffer, will be executed one after another.

CList CMotionContainer::cmdControl

Motion Control Command Buffer, will be executed one after another.

CList CMotionContainer::joints[AX12_COUNT]

Target Angle Buffer for every joint angle.

CList* CMotionContainer::trajectory

Target pose Buffer for every limb.

CList CMotionContainer::interpolated

List of interpolated robot poses (CIpoData).


The documentation for this class was generated from the following files:
Generated on Mon Apr 21 23:27:44 2008 for BioloidControl by  doxygen 1.5.2