mechanism.h File Reference

Detailed Description

Definition of the Tmechanism type and the associated functions.

See Also
Tmechanism, mechanism.c.

Definition in file mechanism.h.

Data Structures

struct  Tmechanism
 A mechanism description. More...
 

Macros

#define INIT_NUM_LINKS   10
 Initial room for links in a mechanism. More...
 
#define INIT_NUM_JOINTS   10
 Initial room for joints in a mechanism. More...
 

Functions

void InitMechanism (Tmechanism *m)
 Constructor. More...
 
unsigned int GetMechanismNLinks (Tmechanism *m)
 Gets the number of links of a mechanism. More...
 
unsigned int GetMechanismNJoints (Tmechanism *m)
 Gets the number of joints of a mechanism. More...
 
unsigned int GetMechanismNBodies (Tmechanism *m)
 Gets the number of convex sub-parts (or bodies) of a mechanism. More...
 
boolean IsMechanismAllSpheres (Tmechanism *m)
 TRUE if the mechanism is composed by spheres only. More...
 
double GetMechanismMaxCoordinate (Tmechanism *m)
 Returns the sum of the maximum coordinate value for all the links and joints in the mechanism. More...
 
signed int GetMechanismMobility (Tmechanism *m)
 Computes the mobility of a given mechanism. More...
 
void GetMechanismDefiningPoint (unsigned int lID, unsigned int bID, unsigned int pID, double *p, Tmechanism *m)
 Gets a point from the mechanism. More...
 
unsigned int AddLink2Mechanism (Tlink *l, Tmechanism *m)
 Adds a link to a mechanism. More...
 
unsigned int AddJoint2Mechanism (Tjoint *j, Tmechanism *m)
 Adds a joint to a mechanism. More...
 
unsigned int AddBody2Mechanism (unsigned int lID, Tpolyhedron *b, Tmechanism *m)
 Adds a convex sub-part to a mechanism. More...
 
unsigned int GetLinkID (char *name, Tmechanism *m)
 Gets the identifier of a link given its name. More...
 
TlinkGetMechanismLink (unsigned int i, Tmechanism *m)
 Gets a link given its identifier. More...
 
unsigned int GetMechanismLinkID (char *ln, Tmechanism *m)
 Gets a link identifier given its name. More...
 
TjointGetMechanismJoint (unsigned int i, Tmechanism *m)
 Gets a joint given its identifier. More...
 
boolean AllRevolute (Tmechanism *m)
 TRUE if all joints are revolute joints. More...
 
void PlotMechanism (Tplot3d *pt, double axesLength, Tmechanism *m)
 Adds a mechanism to a 3d scene. More...
 
void RegenerateMechanismSolution (Tparameters *p, TCuikSystem *cs, double *sol, Tmechanism *m)
 Computes the values for the non-system variables used to represent the rotation matrices for all links in the mechanism. More...
 
void RegenerateMechanismBox (Tparameters *p, TCuikSystem *cs, Tbox *b, Tmechanism *m)
 Computes the values for the non-system variables. More...
 
void GetMechanismDOFsFromTransforms (Tparameters *p, THTransform *tl, double *dof, Tmechanism *m)
 Extract the joint DOF values form the poses of all links. More...
 
void MechanismPrintAtoms (FILE *f, THTransform *tl, Tmechanism *m)
 Prints the center of the atoms in a mechanism. More...
 
void MechanismStoreRigidAtoms (FILE *f, THTransform *tl, Tmechanism *m)
 Auxiliary function for WorldStoreRigidGroups. More...
 
void MoveMechanismFromTransforms (Tparameters *pr, Tplot3d *pt, THTransform *tl, Tmechanism *m)
 Displaces a mechanism in a 3d scene. More...
 
void PrintMechanism (FILE *f, char *path, char *prefix, Tmechanism *m)
 Stores the mechanisms information into a file. More...
 
void DeleteMechanism (Tmechanism *m)
 Destructor. More...
 

Macro Definition Documentation

#define INIT_NUM_LINKS   10

Initial room for links in a mechanisms. It will be enlarged if necessary.

See Also
Tmechanism

Definition at line 28 of file mechanism.h.

Referenced by InitMechanism().

#define INIT_NUM_JOINTS   10

Initial room for joints in a mechanisms. It will be enlarged if necessary.

See Also
Tmechanism

Definition at line 36 of file mechanism.h.

Referenced by CreateBranch(), and InitMechanism().

Function Documentation

void InitMechanism ( Tmechanism m)

Defines an empty mechanism.

Parameters
mThe mechanism to initialize.

Definition at line 16 of file mechanism.c.

References Tmechanism::allSpheres, CopyVoidPtr(), DeleteVoidPtr(), INIT_NUM_JOINTS, INIT_NUM_LINKS, InitVector(), Tmechanism::joints, Tmechanism::links, Tmechanism::maxCoord, Tmechanism::nbodies, and TRUE.

Referenced by InitWorld().

unsigned int GetMechanismNLinks ( Tmechanism m)

Gets the number of links of a mechanism.

Parameters
mThe mechanism to query.
Returns
The number of links of a mechanism.

Definition at line 25 of file mechanism.c.

References Tmechanism::links, and VectorSize().

Referenced by AddLink2Mechanism(), DeleteMechanism(), GetLinkID(), GetMechanismMobility(), InitPQPCD(), InitSolidCD(), InitVcollideCD(), MechanismPrintAtoms(), MechanismStoreRigidAtoms(), MoveMechanismFromTransforms(), PlotMechanism(), PrintMechanism(), RegenerateMechanismBox(), and RegenerateMechanismSolution().

unsigned int GetMechanismNJoints ( Tmechanism m)

Gets the number of joints of a mechanism.

Parameters
mThe mechanism to query.
Returns
The number of joints of a mechanism.

Definition at line 30 of file mechanism.c.

References Tmechanism::joints, and VectorSize().

Referenced by AddJoint2Mechanism(), AllRevolute(), DeleteMechanism(), GetMechanismDOFsFromTransforms(), GetMechanismMobility(), MoveMechanismFromTransforms(), PlotMechanism(), PrintMechanism(), RegenerateMechanismBox(), and RegenerateMechanismSolution().

unsigned int GetMechanismNBodies ( Tmechanism m)

Gets the number of convex sub-parts of a mechanism added all over the links of the mechanism.

Parameters
mThe mechanism to query.
Returns
The number of convex bodies of a mechanism.

Definition at line 35 of file mechanism.c.

References Tmechanism::nbodies.

Referenced by InitPQPCD(), InitSolidCD(), and InitVcollideCD().

boolean IsMechanismAllSpheres ( Tmechanism m)

Identifies mechanisms composed by spheres only. Mechanism derived from molecules are typically composed by spheres only and we can take advantage of this by implementing speciallzed collision detection precedures.

Parameters
mThe mechanism to query.
Returns
TRUE if all (relevant) bodies are spheres.

Definition at line 40 of file mechanism.c.

References Tmechanism::allSpheres.

Referenced by IsMechanismInWorldAllSpheres(), and WorldAtomJacobian().

double GetMechanismMaxCoordinate ( Tmechanism m)

Returns the sum of the maximum coordinate value for all the links and joints in the mechanism. This is used in higher levels to define an over-estimate bounding-box of the mechanism. This bounding box is used to define the ranges for some of the coordinate and separating planes variables.

Parameters
mThe mechanism to query.
Returns
The sum of the maximum coordinate values for all links and joints.

Definition at line 45 of file mechanism.c.

References Tmechanism::maxCoord.

Referenced by GenerateWorldEquations().

signed int GetMechanismMobility ( Tmechanism m)

Computes the degrees of freedom of a mechanism.

The degrees of freedom are computed as 6 per link (but for the ground link) less the degrees of freedom reduced by the joints (6-the degrees of freedom of the joint given by GetJointDOF). Of course, this computation assumes that all link dimensions are general. For special link sizes/joint points the mechanisms can have more degrees of freedom than the returned by this function (i.e., the mechanism can be architecturally singular).

Parameters
mThe mechanism to query.
Returns
The degrees of freedom of the mechanism.

Definition at line 73 of file mechanism.c.

References GetJointDOF(), GetMechanismJoint(), GetMechanismNJoints(), and GetMechanismNLinks().

Referenced by GetWorldMobility().

void GetMechanismDefiningPoint ( unsigned int  lID,
unsigned int  bID,
unsigned int  pID,
double *  p,
Tmechanism m 
)

Gets a 3d point from the mechanism, i.e., from a convex body of a link of the mechanism.

Note that identifier are numbered form 0.

Parameters
lIDIdentifier of the link.
bIDIdentifier of the convex body.
pIDIdentifier of the point.
p3d vector where to store the point.
mThe mechanisms to query.

Definition at line 88 of file mechanism.c.

References GetLinkBody(), GetMechanismLink(), and GetPolyhedronDefiningPoint().

unsigned int AddLink2Mechanism ( Tlink l,
Tmechanism m 
)

Adds a link to a mechanism.

Parameters
lThe link to add.
mThe mechanism to update.
Returns
The identifier assigned to the new link (in principle this is the position of the vector of links where the new link is stored).

Definition at line 94 of file mechanism.c.

References Tmechanism::allSpheres, CopyLink(), GetLinkMaxCoordinate(), GetMechanismNLinks(), IsLinkAllSpheres(), LinkNBodies(), Tmechanism::links, Tmechanism::maxCoord, Tmechanism::nbodies, NEW, and SetVectorElement().

Referenced by AddLink2World().

unsigned int AddJoint2Mechanism ( Tjoint j,
Tmechanism m 
)

Adds a joint to a mechanism.

Parameters
jThe joint to add.
mThe mechanism to update.
Returns
The identifier assigned to the new joint (in principle this is the position of the vector of joints where the new joint is stored).

Definition at line 111 of file mechanism.c.

References Tmechanism::allSpheres, CopyJoint(), GetJointMaxCoordinate(), GetMechanismNJoints(), IsJointAllSpheres(), Tmechanism::joints, Tmechanism::maxCoord, NEW, and SetVectorElement().

Referenced by AddJoint2World(), and GenerateKinTree().

unsigned int AddBody2Mechanism ( unsigned int  lID,
Tpolyhedron b,
Tmechanism m 
)

Adds a convex sub-part to a mechanism.

Parameters
lIDThe link where the new sub-part has to be added.
bThe convex sub-part to add.
mThe mechanism to update.
Returns
The total number of convex bodies in the mechanism after adding the new body.

Definition at line 127 of file mechanism.c.

References AddBody2Link(), Tmechanism::allSpheres, Error(), GetLinkMaxCoordinate(), GetMechanismLink(), IsLinkAllSpheres(), Tmechanism::maxCoord, and Tmechanism::nbodies.

unsigned int GetLinkID ( char *  name,
Tmechanism m 
)

Gets the identifier of a link given its name.

Parameters
nameThe name of the link.
mThe mechanisms to query
Returns
The identifier of the link with the given name or NO_UINT if the mechanisms does not include any link with that name.

Definition at line 50 of file mechanism.c.

References FALSE, GetLinkName(), GetMechanismLink(), GetMechanismNLinks(), NO_UINT, and TRUE.

Referenced by GetWorldLinkID().

unsigned int GetMechanismLinkID ( char *  ln,
Tmechanism m 
)

Gets a link identifier given its name.

Parameters
lnThe name of the link.
mThe mechanism to query.
Returns
The identifier of the link with the given name or NO_UINT if there is no link with the provided name.

Definition at line 157 of file mechanism.c.

References FALSE, GetLinkName(), GetVectorElement(), Tmechanism::links, NO_UINT, TRUE, and VectorSize().

Referenced by GenerateWorldSingularityEquations().

Tjoint* GetMechanismJoint ( unsigned int  i,
Tmechanism m 
)

Gets a joint given its identifier.

Parameters
iThe identifier of the joint to retrive.
mThe mechanism to query.
Returns
A pointer to the joint with the given identifier or NULL if there is no joint with the provided identifier.

Definition at line 182 of file mechanism.c.

References GetVectorElement(), and Tmechanism::joints.

Referenced by AllRevolute(), Branches2Links(), DeleteMechanism(), GenerateKinTree(), GenerateWorldSingularityEquations(), GetLinkTransformsFromDOF(), GetMechanismDOFsFromTransforms(), GetMechanismMobility(), GetWorldDOFLabel(), GetWorldJoint(), GetWorldJointLabel(), GetWorldRangeDOF(), InitWorldKinCS(), IsRevoluteBinaryLink(), MoveMechanismFromTransforms(), PlotMechanism(), PrintMechanism(), PrintWorldAxes(), RegenerateMechanismBox(), RegenerateMechanismSolution(), WorldDOF2Sol(), and WorldInitDOFInfo().

boolean AllRevolute ( Tmechanism m)

Determines if all the joints in a mechanisms are revolute joints.

In mechanisms that are all revolute-based and that have revolute binary links, the reference for some links are adjusted so that we get simpler equations. (see ChangeLinkReferenceFrame)

Parameters
mThe mechanism.
Returns
TRUE if all joints are revolute joints.

Definition at line 193 of file mechanism.c.

References GetJointType(), GetMechanismJoint(), GetMechanismNJoints(), REV_JOINT, and TRUE.

Referenced by InitWorldKinCS().

void PlotMechanism ( Tplot3d pt,
double  axesLength,
Tmechanism m 
)

Adds a mechanism to a 3d scene. All convex parts of all links are added using the same frame of reference (i.e, the global one) and thus they will be displayed colliding unless they are moved.

Parameters
ptThe 3d scene where to add the mechanism.
axesLengthLength for the axes for each link. 0 not to display them.
mThe mechanism display.
See Also
MoveMechanismFromTransforms

Definition at line 209 of file mechanism.c.

References Close3dBlock(), GetMechanismJoint(), GetMechanismLink(), GetMechanismNJoints(), GetMechanismNLinks(), PlotJoint(), PlotLink(), and Start3dBlock().

Referenced by PlotWorld().

void RegenerateMechanismSolution ( Tparameters p,
TCuikSystem cs,
double *  sol,
Tmechanism m 
)

Solution points only include values for the system variables. However, in some formulations, the frame of reference for each link is represented using not only system variables, but dummy variable too. This function computes the values for the link-related dummy variables form the system ones for all the links in the mechanism.

Parameters
pThe set of parameters.
csThe cuik system on which the solutions are defiened. It is used to, given the name of the variables corresponding the reference frame of the given link, retrive its numerical identifiers, i.e., the number of range of the box to use to instantiate each variable.
solThe solution point with the values for the system variables. At the end of the function, this vector also has values for the link-related dummy variables.
mThe mechanism.

Definition at line 242 of file mechanism.c.

References GetMechanismJoint(), GetMechanismLink(), GetMechanismNJoints(), GetMechanismNLinks(), IsGroundLink, RegenerateJointSolution(), and RegenerateLinkSolution().

Referenced by GetLinkTransformsFromSolutionPoint(), MoveWorld(), PrintWorldAxes(), RegenerateWorldOriginalPoint(), RegenerateWorldSolutionPoint(), and WorldSample2DOF().

void RegenerateMechanismBox ( Tparameters p,
TCuikSystem cs,
Tbox b,
Tmechanism m 
)

This is the same as RegenerateMechanismSolution but it works in solution boxes instead of on solution points (i.e. it is interval-based instead of floating point based).

Parameters
pThe set of parameters.
csThe cuik system on which the solutions are defiened. It is used to, given the name of the variables corresponding the reference frame of the given link, retrive its numerical identifiers, i.e., the number of range of the box to use to instantiate each variable.
bThe solution box with the values for the system variables. At the end of the function, this box also has values for the link-related dummy variables.
mThe mechanism.

Definition at line 267 of file mechanism.c.

References CT_REPRESENTATION, GetMechanismJoint(), GetMechanismLink(), GetMechanismNJoints(), GetMechanismNLinks(), GetParameter(), IsGroundLink, RegenerateJointBox(), RegenerateLinkBox(), and REP_JOINTS.

void GetMechanismDOFsFromTransforms ( Tparameters p,
THTransform tl,
double *  dof,
Tmechanism m 
)

Obtains the value of the degrees of freedom given the poses for all links.

Parameters
pThe set of parameters.
tlHomogeneous transform giving the pose of the link in global coordinates.
dofThe space where to store the computed dof.
mThe mechanism to query.

Definition at line 298 of file mechanism.c.

References GetJointDOF(), GetJointDOFValues(), GetMechanismJoint(), GetMechanismNJoints(), JointFromID(), and JointToID().

Referenced by GetSolutionPointFromLinkTransforms(), and WorldSample2DOF().

void MechanismPrintAtoms ( FILE *  f,
THTransform tl,
Tmechanism m 
)

Stores the centers of the atoms in a mechanism.

This is used only whent the world represents a molecule and we want to store the atom (i.e., the sphere) positions into a file.

Parameters
fThe file where to store the atom centers.
tlArray of transforms giving the global pose for each link.
mThe mechanism to process.

Definition at line 320 of file mechanism.c.

References GetMechanismLink(), GetMechanismNLinks(), and LinkPrintAtoms().

Referenced by WorldPrintAtoms().

void MechanismStoreRigidAtoms ( FILE *  f,
THTransform tl,
Tmechanism m 
)

Auxiliary function for WorldStoreRigidGroups. It basically stores the spheres giving its center and radius.

Parameters
fThe file where to store the atom centers.
tlArray of transforms giving the global pose for each link.
mThe mechanism to process.

Definition at line 335 of file mechanism.c.

References GetMechanismLink(), GetMechanismNLinks(), IsGroundLink, LinkNAtoms(), and LinkStoreAtoms().

Referenced by WorldStoreRigidGroups().

void MoveMechanismFromTransforms ( Tparameters pr,
Tplot3d pt,
THTransform tl,
Tmechanism m 
)

Displaces a mechanism previously added to a 3d scene to a given solution piont.

Parameters
prThe set of parameters. Only used for debug.
ptThe 3d scene where the apply the displacement.
tlHomogeneous transform giving the pose of the link in global coordinates.
mThe mechanism to move.

Definition at line 372 of file mechanism.c.

References Close3dBlock(), GetJointDOF(), GetMechanismJoint(), GetMechanismLink(), GetMechanismNJoints(), GetMechanismNLinks(), JointFromID(), JointToID(), MoveJointFromTransforms(), MoveLinkFromTransform(), and Start3dBlock().

Referenced by MoveWorld(), and MoveWorldDOF().

void PrintMechanism ( FILE *  f,
char *  path,
char *  prefix,
Tmechanism m 
)

Stores the link/joint information into a file in the format valid to be read by InitWorldFromFile.

Parameters
fThe file where to store the information.
pathThe working folder.
prefixPrefix to add to the sub-files generated to describe the mechanisms (i.e., files with the geometry, mainly).
mThe mechanism with the links/joints to store.

Definition at line 414 of file mechanism.c.

References GetMechanismJoint(), GetMechanismLink(), GetMechanismNJoints(), GetMechanismNLinks(), PrintJoint(), and PrintLink().

Referenced by PrintWorld().

void DeleteMechanism ( Tmechanism m)

Deletes the information stored in a mechanism and frees the allocated memory.

Parameters
mThe mechanism to delete.

Definition at line 441 of file mechanism.c.

References DeleteJoint(), DeleteLink(), DeleteVector(), GetMechanismJoint(), GetMechanismLink(), GetMechanismNJoints(), GetMechanismNLinks(), Tmechanism::joints, and Tmechanism::links.

Referenced by DeleteWorld().