#include <motion.h>
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. | |
CMotion * | 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. | |
CMotion * | getIntermediateMotion (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. | |
CList * | trajectory |
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. |
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:
enum CMotionContainer::MOTION_STATES [private] |
enum CMotionContainer::IPO_STATES [private] |
CMotionContainer::CMotionContainer | ( | ) |
void CMotionContainer::setState | ( | int | newstate | ) | [private] |
int CMotionContainer::getState | ( | ) | [private] |
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.
id | Index in the motion buffer where the captured movement is stored | |
type | Type of the capture process (contigous or discrete) |
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.
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:
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 | ( | ) |
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.
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.
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.
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 | |||
) |
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.
int CMotionContainer::state [private] |
int CMotionContainer::stateParam[5] [private] |
Parameter values associated with current state.
int CMotionContainer::ipoState [private] |
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" }
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] |
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.
Motion Command Buffer, will be executed one after another.
Motion Control Command Buffer, will be executed one after another.
CList CMotionContainer::joints[AX12_COUNT] |
Target Angle Buffer for every joint angle.
Target pose Buffer for every limb.
List of interpolated robot poses (CIpoData).