MathEngine
Home Page       Structures       File List       Functions and Macros      

MdtBcl.h

Go to the documentation of this file.
00001 #ifndef _MDTBCL_H
00002 #define _MDTBCL_H
00003 /*
00004   Copyright 2000 MathEngine
00005 
00006   $Name: t-release-0-0-5-msvcrt $
00007 
00008   $Id: MdtBcl.h,v 1.21 2000/08/02 20:13:29 lucyb Exp $
00009 */
00010 
00011 /** @file
00012  * Mdt constraints header File.
00013  *
00014  * All angles are specified in radians.
00015  */
00016 
00017 #include "MePrecision.h"
00018 
00019 #include "MdtKea.h"
00020 #include "MdtBclLimit.h"
00021 #include "MdtBclContactParams.h"
00022 
00023 /*
00024   Mdt Basic Constraint Library Data Structure Tags
00025 */
00026 
00027 /*
00028   The first Constraint type MUST be defined as 0, and the others must follow
00029   in strict ascending sequence, with no gaps, otherwise there will be an
00030   access violation in MdtWorldStep
00031 */
00032 
00033 /** The enumeration of joint types supported by the MdtBcl module. */
00034 
00035 typedef enum
00036 {
00037     MdtBclBSJOINT = 0,
00038     MdtBclHINGE,
00039     MdtBclPRISMATIC,
00040     MdtBclCARWHEEL,
00041     MdtBclCONTACT,
00042     MdtBclFIXEDPATH,
00043     MdtBclFPFOJOINT,
00044     MdtBclUNIVERSAL,
00045     MdtBclLINEAR1,
00046     MdtBclLINEAR2
00047 }
00048 MdtBclJointType;
00049 
00050 /** Flag used to indicate the absence of an attached body */
00051 #define MdtBclNO_BODY           -1
00052 
00053 /**
00054  * Kea parameters structure.
00055  */
00056 typedef struct
00057 {
00058     /**
00059      * Amount of time to evolve system by.
00060      */
00061     MeReal stepsize;
00062 
00063     /**
00064      * Numerical tolerance used by matrix solver.
00065      *
00066      * Default = 0.01.
00067      */
00068     MeReal epsilon;
00069 
00070     /**
00071      * Constraint relaxation rate.
00072      *
00073      * Default = 0.2.
00074      */
00075     MeReal gamma;
00076 }
00077 MdtBclSolverParameters;
00078 
00079 /**
00080  * MdtBcl constraint header struct.
00081  *
00082  * Contains data common to all MdtBcl constraints.
00083  */
00084 typedef struct
00085 {
00086     /**
00087      * Data stucture tag.
00088      */
00089     int tag;
00090 
00091     /**
00092      * Length of WHOLE constraint data structure.
00093      */
00094     int len;
00095     /** padding - not used. */
00096     int pad[2];
00097 
00098     /**
00099      * Body indices in the immBody array of constrained bodies.
00100      *
00101      * Unused bodies or constraints to the world should be set to
00102      * MdtBclNO_BODY.
00103      */
00104     int body[4];
00105 }
00106 MdtBclConstraintHeader;
00107 
00108 /**
00109  * MdtBcl ball and socket constraint structure..
00110  */
00111 typedef struct
00112 {
00113     /** Data stucture tag should be MdtBclBSJOINT. */
00114     MdtBclConstraintHeader head;
00115 
00116     /** Joint position in the first body reference frame.  */
00117     MeVector3 pos1;
00118     /** Joint position in the second body reference frame. */
00119     MeVector3 pos2;
00120 
00121     /** Primary rotation axis 1 (fixed in 1st body ref. frame). */
00122     MeVector3 axis_n1;
00123     /** Primary rotation axis 2 (fixed in 2nd body ref. frame). */
00124     MeVector3 axis_m1;
00125 
00126     /**
00127      * Secondary rotation axis, orthogonal to axis_n1
00128      * (fixed in 1st body ref. frame).
00129      */
00130     MeVector3 axis_n2;
00131     /**
00132      * Secondary rotation axis, orthogonal to axis_m1
00133      * (fixed in 2nd body ref. frame).
00134      */
00135     MeVector3 axis_m2;
00136 
00137     /**
00138      * This vector is maintained (read-only) in order to
00139      * ensure smooth rotation when n1 and m1 are nearly parallel
00140      * or anti-parallel (i.e. theta ~ 0 or theta ~ pi).
00141      */
00142     MeVector3 n1_cross_m1;
00143     /**
00144      * Optional limits set to motion about the rotation axes.
00145      *
00146      * These are (in array order):
00147      *
00148      * 0 - rho (twist angle)
00149      * 1 - theta (cone, or polar, angle)
00150      * 2 - phi (segment, or longitudinal, angle).
00151      */
00152     MdtBclLimit limit[3];
00153 }
00154 MdtBclBSJoint;
00155 
00156 /**
00157  * MdtBcl Contact constraint struct.
00158  *
00159  * @see MdtBclContactParams
00160  */
00161 typedef struct
00162 {
00163     /** Data stucture tag should be MdtBclCONTACT. */
00164     MdtBclConstraintHeader head;
00165 
00166     /*
00167       Contact Geometry (different every time)
00168     */
00169 
00170     /** Position of contact (world reference frame). */
00171     MeVector3 cpos;
00172     /** Unit normal at contact (world reference frame). */
00173     MeVector3 normal;
00174 
00175     /** Penetration depth of bodies at contact. */
00176     MeReal penetration;
00177 
00178     /** Padding - not used. */
00179     int pad[3];
00180 
00181     /**
00182      * Principal friction direction.
00183      *
00184      * World reference frame, unit length and perpendicular to normal.
00185      */
00186     MeVector3 direction;
00187 
00188     /** Friction and restitution prarmeters. */
00189     MdtBclContactParams params;
00190 }
00191 MdtBclContact;
00192 
00193 /**
00194  * MdtBcl Hinge constraint structure.
00195  *
00196  * A hinge constraint limits a body to rotate about one axis relative to
00197  * its parent.
00198  */
00199 typedef struct
00200 {
00201     /** Data stucture tag should be MdtBclHINGE. */
00202     MdtBclConstraintHeader head;
00203 
00204     /** Position of joint (first body reference frame). */
00205     MeVector3 pos1;
00206     /** Position of joint (second body reference frame). */
00207     MeVector3 pos2;
00208     /** Hinge axis (first body reference frame). */
00209     MeVector3 axis1;
00210     /** Hinge axis (second body reference frame). */
00211     MeVector3 axis2;
00212 
00213     /** Optional limits set to motion about the hinge axis. */
00214     MdtBclLimit limit;
00215 
00216     /**
00217      * Reference axis perpendicular to raxis_b and hinge axis
00218      * in first body reference frame.
00219      */
00220     MeVector3 raxis_a;
00221     /**
00222      * Reference axis perpendicular to raxis_a and hinge axis
00223      * in first body reference frame.
00224      */
00225     MeVector3 raxis_b;
00226     /**
00227      * Reference axis perpendicular to raxis_b and hinge axis
00228      * in second body reference frame.
00229      */
00230     MeVector3 raxis_a2;
00231 }
00232 MdtBclHinge;
00233 
00234 /**
00235  * MdtBcl Prismatic constraint structure.
00236  *
00237  * A prismatic constraint fixes the orientation of two bodies, and limits
00238  * their position along a line.
00239  */
00240 typedef struct
00241 {
00242     /** Data stucture tag should be MdtBclPRISMATIC. */
00243     MdtBclConstraintHeader head;
00244 
00245     /** Sliding axis (first body reference frame). */
00246     MeVector3 axis1;
00247     /** Initial position of first body (inertial reference frame). */
00248     MeVector3 pos1;
00249 
00250     /** Optional limits set to motion along the sliding axis. */
00251     MdtBclLimit limit;
00252 }
00253 MdtBclPrismatic;
00254 
00255 /**
00256  * MdtBcl Car Wheel constraint structure.
00257  *
00258  * A hinge that can be steered along a steering axis, is powered along
00259  * the hinge and steering axes, and has suspension along the steering
00260  * axis. Body 1 is the chassis and body 2 is the wheel. The connection
00261  * point for the wheel body is its center of mass.
00262  */
00263 typedef struct
00264 {
00265     /** Data stucture tag should be MdtBclCARWHEEL. */
00266     MdtBclConstraintHeader head;
00267 
00268     /*
00269       Car wheel constraint.
00270     */
00271 
00272     /** Connection point relative to chassis. */
00273     MeVector3 pos1;
00274     /** Steering axis in the chassis frame. */
00275     MeVector3 saxis1;
00276     /** Hinge axis in the chassis frame. */
00277     MeVector3 haxis1;
00278     /** Hinge axis in the wheel frame. */
00279     MeVector3 haxis2;
00280 
00281     /*
00282       Other parameters.
00283     */
00284 
00285     /** Proportional (spring) constant for suspension.
00286       * Typical values are usually in the range 1-10.
00287       */
00288     MeReal skp;
00289     /** Derivative (damping) constant for suspension.
00290       * Typical values are usually in the range 1-10.
00291       */
00292     MeReal skd;
00293     /** Steering desired angular velocity, in radians per second. */
00294     MeReal svel;
00295     /** Maximum steering motor torque (in Nm). */
00296     MeReal sfmax;
00297     /** Hinge desired angular velocity, in radians per second. */
00298     MeReal hvel;
00299     /** Maximum hinge motor torque (in Nm). */
00300     MeReal hfmax;
00301     /** 1 if steering axis locked at angle = 0. */
00302     int slock;
00303 
00304     /** Suspension hi limit (in meters), relative to the attachment point. */
00305     MeReal shi;
00306     /** Suspension low limit (in meters), relative to the attachment point. */
00307     MeReal slo;
00308     /** Suspension reference point (in meters), relative to the attachment
00309       * point. This is the `resting' position of the suspension. */
00310     MeReal sref;
00311     /** Suspension limit softness. */
00312     MeReal slsoft;
00313 
00314     /** PADDING - unused. */
00315     int pad[2];
00316 }
00317 MdtBclCarWheel;
00318 
00319 
00320 /**
00321  * Fixed Path constraint data structure.
00322  *
00323  * A fixed path constraint is used to kinematically control the movement
00324  * of a dynamic body.  This means a dynamic body may be forced to
00325  * animate (translation only for this constraint type) and the resulting
00326  * forces are passed on to other constrained bodies.
00327  */
00328 typedef struct
00329 {
00330     /** Data stucture tag should be MdtBclFIXEDPATH. */
00331     MdtBclConstraintHeader head;
00332 
00333     /*
00334       Ball And Socket data:
00335     */
00336 
00337     /** Position of joint (1st body reference frame). */
00338     MeVector3 pos1;
00339     /** Position of joint (2nd body reference frame). */
00340     MeVector3 pos2;
00341 
00342     /*
00343       Kinematic data for fixed path:
00344     */
00345 
00346     /** Kinematic velocity of 1st body (1st body reference frame). */
00347     MeVector3 vel1;
00348     /** Kinematic velocity of 2nd body (2nd body reference frame). */
00349     MeVector3 vel2;
00350 }
00351 MdtBclFixedPath;
00352 
00353 /**
00354  * Fixed Path, Fixed Orientation constraint data structure.
00355  *
00356  * A fixed path constraint is used to kinematically control the movement
00357  * of a dynamic body.  This means a dynamic body may be forced to
00358  * animate (translation or rotation) and the resulting forces are passed
00359  * on to other constrained bodies.
00360  */
00361 typedef struct
00362 {
00363     /** Data stucture tag should be MdtBclFPFOJOINT. */
00364     MdtBclConstraintHeader head;
00365 
00366     /*
00367       Ball And Socket data:
00368     */
00369 
00370     /** Position of joint (1st body reference frame). */
00371     MeVector3 pos1;
00372     /** Position of joint (2nd body reference frame). */
00373     MeVector3 pos2;
00374     /** Invariant relative orientation of the bodies. */
00375     MeVector3 rel_ori;
00376 }
00377 MdtBclFPFOJoint;
00378 
00379 /**
00380  * Universal Joint constraint data structure.
00381  */
00382 typedef struct
00383 {
00384     /** Data stucture tag should be MdtBclUNIVERSAL. */
00385     MdtBclConstraintHeader head;
00386 
00387     /*
00388       Ball And Socket data:
00389     */
00390 
00391     /** Position of joint (1st body reference frame). */
00392     MeVector3 pos1;
00393     /** Position of joint (2nd body reference frame). */
00394     MeVector3 pos2;
00395 
00396     /*
00397       Body-frame fixed axes:
00398     */
00399 
00400     /** Joint axis 1 (fixed in 1st body ref. frame). */
00401     MeVector3 axis1;
00402     /** Joint axis 2 (fixed in 2nd body ref. frame). */
00403     MeVector3 axis2;
00404     /**
00405      * Dot product of the initial orientations of the two axes in the
00406      * inertial reference frame: invariant for this joint.
00407      */
00408     MeReal axis1_dot_axis2;
00409 
00410     /** padding - not used. */
00411     int pad[3];
00412 }
00413 MdtBclUniversal;
00414 
00415 /**
00416  * Linear1 constraint data structure.
00417  *
00418  * Constrains one body to lie in plane relative to the other, and does
00419  * not constraint orientation.
00420  */
00421 typedef struct
00422 {
00423     /** Data stucture tag should be MdtBclLINEAR1. */
00424     MdtBclConstraintHeader head;
00425 
00426     /*
00427       Ball And Socket data:
00428     */
00429 
00430     /** Position of joint (1st body reference frame). */
00431     MeVector3 pos1;
00432     /** Position of joint (2nd body reference frame). */
00433     MeVector3 pos2;
00434 
00435     /**
00436      * Dot product of the separation vector of the two bodies and the
00437      * normal vector (fixed in the body[1] reference frame): invariant
00438      * for this joint.
00439      */
00440     MeReal displacement;
00441 
00442     /** padding - not used. */
00443     int pad[3];
00444 }
00445 MdtBclLinear1;
00446 
00447 /**
00448  * Linear2 constraint data structure.
00449  *
00450  * Constrains one body to lie along a line relative to the other, and
00451  * does not constrain orientation.
00452  */
00453 typedef struct
00454 {
00455     /** Data stucture tag - should be MdtBclLINEAR2. */
00456     MdtBclConstraintHeader head;
00457 
00458     /*
00459       Linear2 data:
00460     */
00461 
00462     /** Position of joint (1st body reference frame). */
00463     MeVector3 pos1;
00464     /** Position of joint (2nd body reference frame). */
00465     MeVector3 pos2;
00466 
00467     /**
00468      * Vector fixed in the body[1] reference frame (or the inertial
00469      * frame, if no second body) on which the joint position is
00470      * constrained to lie.
00471      */
00472     MeVector3 direction;
00473     /**
00474      * A vector fixed in 2nd body reference frame which is perpendicular
00475      * to the joint direction.
00476      */
00477     MeVector3 vec1;
00478     /**
00479      * A vector fixed in 2nd body reference frame which is perpendicular
00480      * to both the joint direction and vec1.
00481      */
00482     MeVector3 vec2;
00483 }
00484 MdtBclLinear2;
00485 
00486 #ifdef __cplusplus
00487 extern "C"
00488 {
00489 #endif
00490 
00491 /*
00492   Basic Constraint Library Add... Functions
00493 
00494   Functions for adding a constraint to the MdtKeaConstraints
00495   structure. Converts constraints from the geometric data
00496   structures above, into matrix rows to be passed to the solver.
00497 */
00498 
00499 void    MdtBclAddBSJoint(MdtKeaConstraints *const clist,
00500             void *const constraint,
00501             const MdtKeaTransformation *const tlist,
00502             MdtKeaBody *const blist,
00503             const MdtBclSolverParameters *const params);
00504 
00505 void    MdtBclAddHinge(MdtKeaConstraints *const clist,
00506             void *const constraint,
00507             const MdtKeaTransformation *const tlist,
00508             MdtKeaBody *const blist,
00509             const MdtBclSolverParameters *const params);
00510 
00511 void    MdtBclAddPrismatic(MdtKeaConstraints *const clist,
00512             void *const constraint,
00513             const MdtKeaTransformation *const tlist,
00514             MdtKeaBody *const blist,
00515             const MdtBclSolverParameters *const params);
00516 
00517 void    MdtBclAddCarWheel(MdtKeaConstraints *const clist,
00518             void *const constraint,
00519             const MdtKeaTransformation *const tlist,
00520             MdtKeaBody *const blist,
00521             const MdtBclSolverParameters *const params);
00522 
00523 void    MdtBclAddContact(MdtKeaConstraints *const clist,
00524             void *const constraint,
00525             const MdtKeaTransformation *const tlist,
00526             MdtKeaBody *const blist,
00527             const MdtBclSolverParameters *const params);
00528 
00529 void    MdtBclAddFixedPath(MdtKeaConstraints *const clist,
00530             void *const constraint,
00531             const MdtKeaTransformation *const tlist,
00532             MdtKeaBody *const blist,
00533             const MdtBclSolverParameters *const params);
00534 
00535 void    MdtBclAddFPFOJoint(MdtKeaConstraints *const clist,
00536             void *const constraint,
00537             const MdtKeaTransformation *const tlist,
00538             MdtKeaBody *const blist,
00539             const MdtBclSolverParameters *const params);
00540 
00541 void    MdtBclAddUniversal(MdtKeaConstraints *const clist,
00542             void *const constraint,
00543             const MdtKeaTransformation *const tlist,
00544             MdtKeaBody *const blist,
00545             const MdtBclSolverParameters *const params);
00546 
00547 void    MdtBclAddLinear1(MdtKeaConstraints *const clist,
00548             void *const constraint,
00549             const MdtKeaTransformation *const tlist,
00550             MdtKeaBody *const blist,
00551             const MdtBclSolverParameters *const params);
00552 
00553 void    MdtBclAddLinear2(MdtKeaConstraints *const clist,
00554             void *const constraint,
00555             const MdtKeaTransformation *const tlist,
00556             MdtKeaBody *const blist,
00557             const MdtBclSolverParameters *const params);
00558 
00559 void    MdtBclInitConstraintRowList(MdtKeaConstraints *const clist);
00560 void    MdtBclEndPartition(MdtKeaConstraints  *const clist);
00561 void    MdtBclStartPartition(MdtKeaConstraints *const clist);
00562 void    MdtBclEndConstraint(MdtKeaConstraints  *const clist,
00563             const unsigned rows_added);
00564 
00565 /*
00566   The following are useful macros for finding the maximum number of
00567   constraint rows that can be added by a type of constraints.
00568 
00569   This can be used to provide an upper bound on the amount of memory to
00570   allocate fo constraint input. Some rows may be actuation or limits.
00571 */
00572 
00573 /**
00574  * Maximum rows added by a Ball And Socket Joint constraint.
00575  */
00576 #define MdtBclGETMAXROWSBSJOINT         (6)
00577 /**
00578  * Maximum rows added by a Hinge constraint.
00579  */
00580 #define MdtBclGETMAXROWSHINGE           (6)
00581 /**
00582  * Maximum rows added by a Prismatic constraint.
00583  */
00584 #define MdtBclGETMAXROWSPRISMATIC       (6)
00585 /**
00586  * Maximum rows added by a Car Wheel constraint.
00587  */
00588 #define MdtBclGETMAXROWSCARWHEEL        (6)
00589 /**
00590  * Maximum rows added by a Contact constraint.
00591  */
00592 #define MdtBclGETMAXROWSCONTACT         (3)
00593 /**
00594  * Maximum rows added by a Fixed Path constraint.
00595  */
00596 #define MdtBclGETMAXROWSFIXEDPATH       (3)
00597 /**
00598  * Maximum rows added by a Fixed Path Fixed Orientation constraint.
00599  */
00600 #define MdtBclGETMAXROWSFPFOJOINT       (6)
00601 /**
00602  * Maximum rows added by a Universal Joint constraint.
00603  */
00604 #define MdtBclGETMAXROWSUNIVERSAL       (4)
00605 /**
00606  * Maximum rows added by a Linear1 constraint.
00607  */
00608 #define MdtBclGETMAXROWSLINEAR1         (1)
00609 /**
00610  * Maximum rows added by a Linear2 constraint.
00611  */
00612 #define MdtBclGETMAXROWSLINEAR2         (2)
00613 
00614 #ifdef __cplusplus
00615 }
00616 #endif
00617 
00618 #endif

MathEngine Dynamics Toolkit - Version 0.0.5 Alpha - Reference Manual generated using doxygen at Wed Oct 11 00:34:45 2000

Copyright MathEngine PLC 2000, all rights reserved.