EASY-ROBâ„¢ Kernel  v8.606
Static Public Member Functions | List of all members
ERK_CAPI_SIM_COLLISION Class Reference

Method class for collision, tolerances, etc. More...

#include <erk_capi.h>

Inheritance diagram for ERK_CAPI_SIM_COLLISION:
ERK_CAPI_SIM ERK_CAPI

Static Public Member Functions

static DLLAPI int ER_STDCALL erColl_BeginModel (ER_COLLISION_HND *er_coll_hnd, long n_tris)
 Creates a collision handle for one Model and preallocate memory for n_tris triangles. More...
 
static DLLAPI int ER_STDCALL erColl_AddTri (ER_COLLISION_HND er_coll_hnd, double *p1, double *p2, double *p3, long id)
 Adds a triangle to a Model.
call erColl_BeginModel() once to create a new unique model handle. More...
 
static DLLAPI int ER_STDCALL erColl_EndModel (ER_COLLISION_HND er_coll_hnd)
 Stop building a Model. More...
 
static DLLAPI int ER_STDCALL erColl_ChkCollision (ER_COLLISION_HND er_coll_hnd_1, DFRAME *iT_1, ER_COLLISION_HND er_coll_hnd_2, DFRAME *iT_2, long query_type=ER_COLL_QUERY_TYPE_COLLIDE, long contact_type=ER_COLL_FIRST_CONTACT, double rel_err=0, double abs_err=0, double tolerance=0)
 Perform the collision check of two Models.
See also erColl_ChkCollision_res() to get the collision results immediately
The query type query_type can be one of the following values.
0: ER_COLL_QUERY_TYPE_UNDEF skip collision checks
1: ER_COLL_QUERY_TYPE_COLLIDE detects collision between two Models
2: ER_COLL_QUERY_TYPE_DISTANCE computes the distance between two Models
3: ER_COLL_QUERY_TYPE_TOLERANCE checks if distance between Models is <= tolerance
The contact type contact_type is used for query type ER_COLL_QUERY_TYPE_COLLIDE and can be one of the following values.
1: ER_COLL_ALL_CONTACTS , the erColl_GetResults_Collide() contains an array with all colliding triangle pairs ER_CollideResult.
2: ER_COLL_FIRST_CONTACT , the erColl_GetResults_Collide() array will only get the first colliding triangle pair found.
Collide
Detects collsion. This is the fastest method.
Distance
Computes minimum distance between two Models. This method takes the most time !!!
Tolerances
Specify tolerance for query type ER_COLL_QUERY_TYPE_DISTANCE or ER_COLL_QUERY_TYPE_TOLERANCE
Checks if distance between Models is <= tolerance.
Remarks
If erColl_ChkCollision() returns with ER_COLL_DETECTED call, depending on the query type, one of the collision result functions erColl_GetResults_Collide(), erColl_GetResults_Distance() or erColl_GetResults_Tolerance() to receive more detailed information about the collision status. More...
 
static DLLAPI int ER_STDCALL erColl_ChkCollision_res (ER_COLLISION_HND er_coll_hnd_1, DFRAME *iT_1, ER_COLLISION_HND er_coll_hnd_2, DFRAME *iT_2, long query_type=ER_COLL_QUERY_TYPE_COLLIDE, long contact_type=ER_COLL_FIRST_CONTACT, double rel_err=0, double abs_err=0, double tolerance=0, void *pres=NULL)
 Perform the collision check of two Models.
Collision results returned immediately by parameter pres compared to erColl_ChkCollision()
The query type query_type can be one of the following values.
0: ER_COLL_QUERY_TYPE_UNDEF skip collision checks
1: ER_COLL_QUERY_TYPE_COLLIDE detects collision between two Models
2: ER_COLL_QUERY_TYPE_DISTANCE computes the distance between two Models
3: ER_COLL_QUERY_TYPE_TOLERANCE checks if distance between Models is <= tolerance
The contact type contact_type is used for query type ER_COLL_QUERY_TYPE_COLLIDE and can be one of the following values.
1: ER_COLL_ALL_CONTACTS , the erColl_GetResults_Collide() contains an array with all colliding triangle pairs ER_CollideResult.
2: ER_COLL_FIRST_CONTACT , the erColl_GetResults_Collide() array will only get the first colliding triangle pair found.
Collide
Detects collsion. This is the fastest method.
Distance
Computes minimum distance between two Models. This method takes the most time !!!
Tolerances
Specify tolerance for query type ER_COLL_QUERY_TYPE_DISTANCE or ER_COLL_QUERY_TYPE_TOLERANCE
Checks if distance between Models is <= tolerance.
Remarks
If erColl_ChkCollision_res() returns with ER_COLL_DETECTED, get more detailed information about the collision status by parameter pres. More...
 
static DLLAPI int ER_STDCALL erColl_ChkCollision_res_free (long query_type, void *pres)
 Frees allocated memory for Collision results for parameter pres
The query type query_type can be one of the following values.
0: ER_COLL_QUERY_TYPE_UNDEF skip operation
1: ER_COLL_QUERY_TYPE_COLLIDE frees allocated data in ER_CollideResult
2: ER_COLL_QUERY_TYPE_DISTANCE frees allocated data in ER_DistanceResult
3: ER_COLL_QUERY_TYPE_TOLERANCE frees allocated data in ER_ToleranceResult
Remarks
Note that the allocated memory in the Collision results structures must be administrated by the Kernel and not in the host application. More...
 
static DLLAPI int ER_STDCALL erColl_UnloadModel (ER_COLLISION_HND *er_coll_hnd)
 Unload a Model. Free all allocated memory. More...
 
static DLLAPI int ER_STDCALL erColl_GetResults_Collide (ER_CollideResult *er_cres)
 Get Collision result for query ER_COLL_QUERY_TYPE_COLLIDE. Remarks
Call erColl_ChkCollision() first, brfore calling this function. More...
 
static DLLAPI int ER_STDCALL erColl_GetResults_Distance (ER_DistanceResult *er_dres)
 Get Collision result for query ER_COLL_QUERY_TYPE_DISTANCE. Remarks
Call erColl_ChkCollision() first, before calling this function. More...
 
static DLLAPI int ER_STDCALL erColl_GetResults_Tolerance (ER_ToleranceResult *er_tres)
 Get Collision result for query ER_COLL_QUERY_TYPE_TOLERANCE. Remarks
Call erColl_ChkCollision() first, brfore calling this function. More...
 

Additional Inherited Members

- Static Public Attributes inherited from ERK_CAPI_SIM
static ERK_CAPI_SIM_COLLISION erk_capi_sim_collision
 Method class for collision, tolerances, etc. More...
 
- Static Public Attributes inherited from ERK_CAPI
static ERK_CAPI_ADMIN erk_capi_admin
 Method class to administrate this Robotics Simulation Kernel. More...
 
static ERK_CAPI_DEVICES erk_capi_devices
 Method class to create, attach, update devices, for kinematics calculations and for motion planning and -execution. More...
 
static ERK_CAPI_SIM erk_capi_sim
 Method class for simulation settings. More...
 
static ERK_CAPI_AUTOPATH erk_capi_autopath
 Method class for collision free path planning. More...
 
static ERK_CAPI_TARGETS erk_capi_targets
 Method class for paths and tags. More...
 
static ERK_CAPI_GEO erk_capi_geo
 Method class to handle 3D Geometry Data. More...
 
static ERK_CAPI_SYS erk_capi_sys
 Method class for mathematical calculations, simulation status, units. More...
 

Detailed Description

Method class for collision, tolerances, etc.

Member Function Documentation

◆ erColl_AddTri()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_AddTri ( ER_COLLISION_HND  er_coll_hnd,
double *  p1,
double *  p2,
double *  p3,
long  id 
)
static

Adds a triangle to a Model.
call erColl_BeginModel() once to create a new unique model handle.

Parameters
[in]er_coll_hnda valid unique Collision handle ER_COLLISION_HND
[in]p11st point of triangle
[in]p22nd point of triangle
[in]p33rd point of triangle
[in]idunique identifier for this triangle
Return values
0- ER_COLL_OK - OK
1- ER_COLL_ERROR - Error, kernel not initialized
2- ER_COLL_HND_INVALID - Collision handle invalid

◆ erColl_BeginModel()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_BeginModel ( ER_COLLISION_HND er_coll_hnd,
long  n_tris 
)
static

Creates a collision handle for one Model and preallocate memory for n_tris triangles.

Parameters
[out]er_coll_hndunique Collision handle ER_COLLISION_HND
[in]n_trisnumber of model triangles
Return values
0- ER_COLL_OK - OK
1- ER_COLL_ERROR - Error, kernel not initialized
2- ER_COLL_HND_INVALID - Collision handle invalid
-1- ER_COLL_ERR_MODEL_OUT_OF_MEMORY - not enough memory

◆ erColl_ChkCollision()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_ChkCollision ( ER_COLLISION_HND  er_coll_hnd_1,
DFRAME iT_1,
ER_COLLISION_HND  er_coll_hnd_2,
DFRAME iT_2,
long  query_type = ER_COLL_QUERY_TYPE_COLLIDE,
long  contact_type = ER_COLL_FIRST_CONTACT,
double  rel_err = 0,
double  abs_err = 0,
double  tolerance = 0 
)
static

Perform the collision check of two Models.
See also erColl_ChkCollision_res() to get the collision results immediately
The query type query_type can be one of the following values.
0: ER_COLL_QUERY_TYPE_UNDEF skip collision checks
1: ER_COLL_QUERY_TYPE_COLLIDE detects collision between two Models
2: ER_COLL_QUERY_TYPE_DISTANCE computes the distance between two Models
3: ER_COLL_QUERY_TYPE_TOLERANCE checks if distance between Models is <= tolerance
The contact type contact_type is used for query type ER_COLL_QUERY_TYPE_COLLIDE and can be one of the following values.
1: ER_COLL_ALL_CONTACTS , the erColl_GetResults_Collide() contains an array with all colliding triangle pairs ER_CollideResult.
2: ER_COLL_FIRST_CONTACT , the erColl_GetResults_Collide() array will only get the first colliding triangle pair found.
Collide
Detects collsion. This is the fastest method.
Distance
Computes minimum distance between two Models. This method takes the most time !!!
Tolerances
Specify tolerance for query type ER_COLL_QUERY_TYPE_DISTANCE or ER_COLL_QUERY_TYPE_TOLERANCE
Checks if distance between Models is <= tolerance.
Remarks
If erColl_ChkCollision() returns with ER_COLL_DETECTED call, depending on the query type, one of the collision result functions erColl_GetResults_Collide(), erColl_GetResults_Distance() or erColl_GetResults_Tolerance() to receive more detailed information about the collision status.

// Example:
// Collision Model
//
// A Collision Model stores geometry to be used in a proximity query.
// The geometry is loaded with a call to erColl_BeginModel(), at least one call to
// erColl_AddTri(), and then a call to erColl_EndModel().
//
// create a two triangle models
//
ER_COLLISION_HND er_coll_hnd_1 = NULL; // unique Collision handle for the 1st Model
ER_COLLISION_HND er_coll_hnd_2 = NULL; // unique Collision handle for the 2nd Model
ER_COLLISION_HND *er_coll_hnd; // points to er_coll_hnd_1 or er_coll_hnd_2
long id; // tri identifier
long number_of_tris_1 = 6; // number of tris for the 1st Model
long number_of_tris_2 = 4; // number of tris for the 2nd Model
//~~~~~~~~~~~~~~~~~~~~~~~~~
// erColl_BeginModel
//~~~~~~~~~~~~~~~~~~~~~~~~~
// 1st Model
er_coll_hnd = &er_coll_hnd_1;
ret=erColl_BeginModel(er_coll_hnd,number_of_tris_1);
// 2nd Model
er_coll_hnd = &er_coll_hnd_2;
ret=erColl_BeginModel(er_coll_hnd,number_of_tris_2);
//~~~~~~~~~~~~~~~~~~~~~~~~~
// erColl_AddTri
//~~~~~~~~~~~~~~~~~~~~~~~~~
// define 5 points for a pyramide
double p1[ER_DIM] = { 0.5, 0, 0.0};
double p2[ER_DIM] = { 0.0, 0.5, 0.0};
double p3[ER_DIM] = {-0.5, 0.0, 0.0};
double p4[ER_DIM] = { 0.0,-0.5, 0.0};
double p5[ER_DIM] = { 0.0, 0.0, 0.5};
// 1st Model
er_coll_hnd = &er_coll_hnd_1;
id=0;
ret=erColl_AddTri(*er_coll_hnd,p1,p2,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p2,p3,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p3,p4,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p4,p1,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p1,p4,p3,id++); // with a bottom
ret=erColl_AddTri(*er_coll_hnd,p3,p2,p1,id++); // with a bottom
if (ret==ER_COLL_OK)
erColl_EndModel(*er_coll_hnd);
// 2nd Model
er_coll_hnd = &er_coll_hnd_2;
id=0;
ret=erColl_AddTri(*er_coll_hnd,p1,p2,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p2,p3,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p3,p4,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p4,p1,p5,id++);
if (ret==ER_COLL_OK)
erColl_EndModel(*er_coll_hnd);
//~~~~~~~~~~~~~~~~~~~~~~~~~
// erColl_ChkCollision
//~~~~~~~~~~~~~~~~~~~~~~~~~
long collision = 0; // ER_COLL_DETECTED- collision, 0- no collision
DFRAME T_1; // location of 1st Model
DFRAME T_2; // location of 2nd Model
// translate 2nd Model to z=1.5 and rotate about y-axis by 180 deg
erMath_PxyzRxyzToFrame( 0.1, 0.1, 1.5, 0.0, 180.0*ER_RAD, 0.0, &T_2);
long query_type = ER_COLL_QUERY_TYPE_DISTANCE; // or one of ER_COLL_QUERY_TYPE_COLLIDE , ER_COLL_QUERY_TYPE_DISTANCE, ER_COLL_QUERY_TYPE_TOLERANCE
long contact_type = ER_COLL_ALL_CONTACTS; // or one of ER_COLL_FIRST_CONTACT, if query_type is ER_COLL_QUERY_TYPE_COLLIDE
// if query_type is one of ER_COLL_QUERY_TYPE_DISTANCE, ER_COLL_QUERY_TYPE_TOLERANCE
double rel_err = 0; // the relative error margin from actual distance
double abs_err = 0; // the absolute error margin from actual distance
double tolerance = 100 * ER_mm2m; // 100 [mm]
collision = erColl_ChkCollision(
er_coll_hnd_1, // unique Collision handle for the 1st Model
&T_1, // location of 1st object
er_coll_hnd_2, // unique Collision handle for the 2nd Model
&T_2, // location of 2nd object
query_type, // ER_COLL_QUERY_TYPE_COLLIDE, ER_COLL_QUERY_TYPE_DISTANCE, ER_COLL_QUERY_TYPE_TOLERANCE
contact_type, // ER_COLL_FIRST_CONTACT, ER_COLL_ALL_CONTACTS
rel_err, // the relative error margin from actual distance
abs_err, // the absolute error margin from actual distance
tolerance // Tolerance [m]
);
//~~~~~~~~~~~~~~~~~~~~~~~~~
// Get collision results
//~~~~~~~~~~~~~~~~~~~~~~~~~
if (collision==ER_COLL_DETECTED ||
{
switch (query_type) {
// ....
break;
// ....
break;
// ....
break;
};
}
// ....
Parameters
[in]er_coll_hnd_1unique Collision handle for the 1st Model ER_COLLISION_HND
[in]iT_1a location of the 1st Model w.r.t. inertia DFRAME
[in]er_coll_hnd_2unique Collision handle for the 2nd Model ER_COLLISION_HND
[in]iT_2a location of the 2nd Model w.r.t. inertia DFRAME
[in]query_typecollision query type
[in]contact_typecollision contact type
[in]rel_errrelative error margin from actual distance
[in]abs_errabsolute error margin from actual distance
[in]toleranceTolerance value
Return values
3- ER_COLL_DETECTED - Collision detected
1- ER_COLL_ERROR - Error, kernel not initialized
2- ER_COLL_HND_INVALID - Collision handle invalid

◆ erColl_ChkCollision_res()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_ChkCollision_res ( ER_COLLISION_HND  er_coll_hnd_1,
DFRAME iT_1,
ER_COLLISION_HND  er_coll_hnd_2,
DFRAME iT_2,
long  query_type = ER_COLL_QUERY_TYPE_COLLIDE,
long  contact_type = ER_COLL_FIRST_CONTACT,
double  rel_err = 0,
double  abs_err = 0,
double  tolerance = 0,
void *  pres = NULL 
)
static

Perform the collision check of two Models.
Collision results returned immediately by parameter pres compared to erColl_ChkCollision()
The query type query_type can be one of the following values.
0: ER_COLL_QUERY_TYPE_UNDEF skip collision checks
1: ER_COLL_QUERY_TYPE_COLLIDE detects collision between two Models
2: ER_COLL_QUERY_TYPE_DISTANCE computes the distance between two Models
3: ER_COLL_QUERY_TYPE_TOLERANCE checks if distance between Models is <= tolerance
The contact type contact_type is used for query type ER_COLL_QUERY_TYPE_COLLIDE and can be one of the following values.
1: ER_COLL_ALL_CONTACTS , the erColl_GetResults_Collide() contains an array with all colliding triangle pairs ER_CollideResult.
2: ER_COLL_FIRST_CONTACT , the erColl_GetResults_Collide() array will only get the first colliding triangle pair found.
Collide
Detects collsion. This is the fastest method.
Distance
Computes minimum distance between two Models. This method takes the most time !!!
Tolerances
Specify tolerance for query type ER_COLL_QUERY_TYPE_DISTANCE or ER_COLL_QUERY_TYPE_TOLERANCE
Checks if distance between Models is <= tolerance.
Remarks
If erColl_ChkCollision_res() returns with ER_COLL_DETECTED, get more detailed information about the collision status by parameter pres.

// Example
//
// Erk_CollisionResult_Init(...) to initialize collision result structures depending on query_type
// Erk_CollisionResult_Output(...) to store collision results into file stream 'fp'
// Erk_Do_Collisions() performe collision check of two Models
//
int Erk_CollisionResult_Init(long query_type, void *pres)
// Initialize collision result structures depending on query_type
// Note that the Kernel will administrate the memory for p->pairs, p->p1, p->p2
// Make sure that these pointers are set to NULL here
{
if (!pres)
return 1;
switch (query_type) {
{
p->num_pairs = 0;
p->pairs = NULL;
}
break;
{
p->rel_err = 0;
p->abs_err = 0;
p->distance = 0;
p->p1 = NULL;
p->p2 = NULL;
}
break;
{
p->tolerance = 0;
p->distance = 0;
p->p1 = NULL;
p->p2 = NULL;
}
break;
};
return 0;
}
int Erk_CollisionResult_Output(long collision, long query_type, int step, void *pres)
// Store collision results into file stream 'fp'
// Pointer 'pres' points to one collision result structure: ER_CollideResult, ER_DistanceResult or ER_ToleranceResult
{
if (!pres)
return 1;
if (collision==ER_COLL_DETECTED ||
{
switch (query_type) {
{
fprintf(fp,"i=%d erColl_GetResults_Collide() num_pairs_alloced %d num_pairs %ld time %.6lf\n",step,
DFRAME *pT = &p->m1Tm2;
out_frame(fp,"m1Tm2",pT);
ER_CollisionPair *pa = p->pairs; // is NULL if no num_pairs
for (int j=0;j<p->num_pairs;j++)
{
fprintf(fp," pairs[%d] id ( %d , %d )\n",j,pa->id1,pa->id2);
pa++;
}
}
break;
{
fprintf(fp,"i=%d erColl_GetResults_Distance() rel_err %.3lf abs_err %.3lf distance %.3lf time %.6lf\n",step,
p->rel_err*100,
DFRAME *pT = &p->m1Tm2;
out_frame(fp,"m1Tm2",pT);
if (p->distance>0)
{
double *v;
v = p->p1;
fprintf(fp," p1 %.3lf %.3lf %.3lf\n",v[0]*ER_m2mm,v[1]*ER_m2mm,v[2]*ER_m2mm);
v = p->p2;
fprintf(fp," p2 %.3lf %.3lf %.3lf\n",v[0]*ER_m2mm,v[1]*ER_m2mm,v[2]*ER_m2mm);
}
}
break;
{
fprintf(fp,"i=%d erColl_GetResults_Tolerance() closer_than_tolerance %s tolerance %.3lf distance %.3lf time %.6lf\n",step,
DFRAME *pT = &p->m1Tm2;
out_frame(fp,"m1Tm2",pT);
if (p->distance>0)
{
double *v;
v = p->p1;
fprintf(fp," p1 %.3lf %.3lf %.3lf\n",v[0]*ER_m2mm,v[1]*ER_m2mm,v[2]*ER_m2mm);
v = p->p2;
fprintf(fp," p2 %.3lf %.3lf %.3lf\n",v[0]*ER_m2mm,v[1]*ER_m2mm,v[2]*ER_m2mm);
}
}
break;
};
}
return 0;
}
int Erk_Do_Collisions()
// do some collisions
{
// Collision Model
//
// A Collision Model stores geometry to be used in a proximity query.
// The geometry is loaded with a call to erColl_BeginModel(), at least one call to
// erColl_AddTri(), and then a call to erColl_EndModel().
//
// create a two triangle models
//
int ret=ER_COLL_OK;
long collision = ER_COLL_OK; // ER_COLL_DETECTED - collision, ER_COLL_OK - no collision
//~~~~~~~~~~~~~~~~~~~~~~~~~
// erColl_BeginModel
//~~~~~~~~~~~~~~~~~~~~~~~~~
ER_COLLISION_HND er_coll_hnd_1 = NULL; // unique Collision handle for the 1st Model
ER_COLLISION_HND er_coll_hnd_2 = NULL; // unique Collision handle for the 2nd Model
ER_COLLISION_HND *er_coll_hnd; // points to er_coll_hnd_1 or er_coll_hnd_2
long id; // tri identifier
long number_of_tris_1 = 6; // number of tris for the 1st Model
long number_of_tris_2 = 4; // number of tris for the 2nd Model
// 1st Model
er_coll_hnd = &er_coll_hnd_1;
ret=erColl_BeginModel(er_coll_hnd,number_of_tris_1);
// 2nd Model
er_coll_hnd = &er_coll_hnd_2;
ret=erColl_BeginModel(er_coll_hnd,number_of_tris_2);
//~~~~~~~~~~~~~~~~~~~~~~~~~
// erColl_AddTri
//~~~~~~~~~~~~~~~~~~~~~~~~~
// define 5 points for a pyramide
double p1[ER_DIM] = { 0.5, 0, 0.0};
double p2[ER_DIM] = { 0.0, 0.5, 0.0};
double p3[ER_DIM] = {-0.5, 0.0, 0.0};
double p4[ER_DIM] = { 0.0,-0.5, 0.0};
double p5[ER_DIM] = { 0.0, 0.0, 0.5};
// 1st Model
er_coll_hnd = &er_coll_hnd_1;
id=0;
ret=erColl_AddTri(*er_coll_hnd,p1,p2,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p2,p3,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p3,p4,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p4,p1,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p1,p4,p3,id++); // bottom
ret=erColl_AddTri(*er_coll_hnd,p3,p2,p1,id++); // bottom
if (ret==ER_COLL_OK)
erColl_EndModel(*er_coll_hnd);
// 2nd Model
er_coll_hnd = &er_coll_hnd_2;
id=0;
ret=erColl_AddTri(*er_coll_hnd,p1,p2,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p2,p3,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p3,p4,p5,id++);
ret=erColl_AddTri(*er_coll_hnd,p4,p1,p5,id++);
if (ret==ER_COLL_OK)
erColl_EndModel(*er_coll_hnd);
//~~~~~~~~~~~~~~~~~~~~~~~~~
// erColl_ChkCollision
//~~~~~~~~~~~~~~~~~~~~~~~~~
DFRAME T_1; // location of 1st Model
DFRAME T_2; // location of 2nd Model
// translate 2nd Model to z=1.5 and rotate about y-axis by 180°
erMath_PxyzRxyzToFrame( 0.1, 0.1, 1.5, 0.0, 180.0*ER_RAD, 0.0, &T_2);
// Choose query_type
long query_type = ER_COLL_QUERY_TYPE_DISTANCE; // or one of ER_COLL_QUERY_TYPE_COLLIDE , ER_COLL_QUERY_TYPE_DISTANCE, ER_COLL_QUERY_TYPE_TOLERANCE
// Set contact_type
// Note: Only relevant for query_type = ER_COLL_QUERY_TYPE_COLLIDE
long contact_type = ER_COLL_ALL_CONTACTS; // or one of ER_COLL_FIRST_CONTACT, if query_type is ER_COLL_QUERY_TYPE_COLLIDE
// Set rel_err, abs_err and tolerance
// Note: Only relevant for query_type = ER_COLL_QUERY_TYPE_DISTANCE or ER_COLL_QUERY_TYPE_TOLERANCE
double rel_err = 0; // the relative error margin from actual distance
double abs_err = 0; // the absolute error margin from actual distance
double tolerance = 100 * ER_mm2m; // 100 [mm]
// Initialize collision result structures
// depending on query_type
void *pres=NULL;
pres = query_type==ER_COLL_QUERY_TYPE_COLLIDE ? (void *)&er_cres :
query_type==ER_COLL_QUERY_TYPE_DISTANCE ? (void *)&er_dres :
query_type==ER_COLL_QUERY_TYPE_TOLERANCE ? (void *)&er_tres :
NULL;
// Initialize collision result structures depending on query_type
Erk_CollisionResult_Init(query_type,pres);
// make some collision tests,
// while moving 2nd Model down by 100 mm step
for (int i=0;ret==ER_COLL_OK && i<20;i++)
{
T_2.p[2] -= 100 * ER_mm2m; // move 2nd Model in -z direction
er_coll_hnd_1, // unique Collision handle for the 1st Model
&T_1, // location of 1st object
er_coll_hnd_2, // unique Collision handle for the 2nd Model
&T_2, // location of 2nd object
query_type, // ER_COLL_QUERY_TYPE_COLLIDE, ER_COLL_QUERY_TYPE_DISTANCE, ER_COLL_QUERY_TYPE_TOLERANCE
contact_type, // ER_COLL_FIRST_CONTACT, ER_COLL_ALL_CONTACTS
rel_err, // the relative error margin from actual distance
abs_err, // the absolute error margin from actual distance
tolerance, // Tolerance [m]
pres // pres collision result depending on query type is ::ER_CollideResult, ::ER_DistanceResult or ::ER_ToleranceResult
);
fprintf(fp,"i=%d erColl_ChkCollision() T_2.p[2]=%.5lf , collision = %ld\n",i,T_2.p[2],collision);
if (collision==ER_COLL_ERROR || collision==ER_COLL_HND_INVALID)
{
}
//~~~~~~~~~~~~~~~~~~~~~~~~~
// Output of collision results
//~~~~~~~~~~~~~~~~~~~~~~~~~
if (pres) // Pointer 'pres' points to one collision result structure: ER_CollideResult, ER_DistanceResult or ER_ToleranceResult
Erk_CollisionResult_Output(collision,query_type,i,pres); // Store collision results into file stream 'fp'
else
{
//~~~~~~~~~~~~~~~~~~~~~~~~~
// Get collision results
// Using
// erColl_GetResults_Collide()
// erColl_GetResults_Distance()
// erColl_GetResults_Tolerance()
//~~~~~~~~~~~~~~~~~~~~~~~~~
switch (query_type) {
pres = (void*) &er_cres;
break;
pres = (void*) &er_dres;
break;
pres = (void*) &er_tres;
break;
};
if (pres)
Erk_CollisionResult_Output(collision,query_type,i,pres); // Store collision results into file stream 'fp'
}
}
//~~~~~~~~~~~~~~~~~~~~~~~~~
// Free collision result structures depending on query_type
//~~~~~~~~~~~~~~~~~~~~~~~~~
if (pres)
//~~~~~~~~~~~~~~~~~~~~~~~~~
// erColl_UnloadModel
//~~~~~~~~~~~~~~~~~~~~~~~~~
// 1st Model
er_coll_hnd = &er_coll_hnd_1;
erColl_UnloadModel(er_coll_hnd);
// 2nd Model
er_coll_hnd = &er_coll_hnd_2;
erColl_UnloadModel(er_coll_hnd);
return 0;
}
// ....
Parameters
[in]er_coll_hnd_1unique Collision handle for the 1st Model ER_COLLISION_HND
[in]iT_1a location of the 1st Model w.r.t. inertia DFRAME
[in]er_coll_hnd_2unique Collision handle for the 2nd Model ER_COLLISION_HND
[in]iT_2a location of the 2nd Model w.r.t. inertia DFRAME
[in]query_typecollision query type
[in]contact_typecollision contact type
[in]rel_errrelative error margin from actual distance
[in]abs_errabsolute error margin from actual distance
[in]toleranceTolerance value query_type
[out]prespointer to collision result structure ER_CollideResult, ER_DistanceResult or ER_ToleranceResult, depending on query type
Return values
3- ER_COLL_DETECTED - Collision detected
1- ER_COLL_ERROR - Error, kernel not initialized
2- ER_COLL_HND_INVALID - Collision handle invalid

◆ erColl_ChkCollision_res_free()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_ChkCollision_res_free ( long  query_type,
void *  pres 
)
static

Frees allocated memory for Collision results for parameter pres
The query type query_type can be one of the following values.
0: ER_COLL_QUERY_TYPE_UNDEF skip operation
1: ER_COLL_QUERY_TYPE_COLLIDE frees allocated data in ER_CollideResult
2: ER_COLL_QUERY_TYPE_DISTANCE frees allocated data in ER_DistanceResult
3: ER_COLL_QUERY_TYPE_TOLERANCE frees allocated data in ER_ToleranceResult
Remarks
Note that the allocated memory in the Collision results structures must be administrated by the Kernel and not in the host application.

// Example
//
// Erk_CollisionResult_Exit(...) to frees collision result structures depending on query_type
//
int Erk_CollisionResult_Exit(long query_type, void *pres)
// frees collision result structures depending on query_type
{
if (!pres)
return ER_COLL_ERROR;
long ret = erColl_ChkCollision_res_free(query_type,pres);
return ret;
}
// ....
Parameters
[in]query_typecollision query type
[out]prespointer to collision result structure ER_CollideResult, ER_DistanceResult or ER_ToleranceResult, depending on query type
Return values
0- ER_COLL_OK - Ok, free memory done
1- ER_COLL_ERROR - Error, kernel not initialized

◆ erColl_EndModel()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_EndModel ( ER_COLLISION_HND  er_coll_hnd)
static

Stop building a Model.

Parameters
[in]er_coll_hnda valid unique Collision handle ER_COLLISION_HND
Return values
0- ER_COLL_OK - OK
1- ER_COLL_ERROR - Error, kernel not initialized
2- ER_COLL_HND_INVALID - Collision handle invalid

◆ erColl_GetResults_Collide()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_GetResults_Collide ( ER_CollideResult er_cres)
static

Get Collision result for query ER_COLL_QUERY_TYPE_COLLIDE. Remarks
Call erColl_ChkCollision() first, brfore calling this function.

Parameters
[out]er_crescollide results ER_CollideResult
Return values
0- OK
1- Error, kernel not initialized

◆ erColl_GetResults_Distance()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_GetResults_Distance ( ER_DistanceResult er_dres)
static

Get Collision result for query ER_COLL_QUERY_TYPE_DISTANCE. Remarks
Call erColl_ChkCollision() first, before calling this function.

Parameters
[out]er_dresdistance results ER_DistanceResult
Return values
0- OK
1- Error, kernel not initialized

◆ erColl_GetResults_Tolerance()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_GetResults_Tolerance ( ER_ToleranceResult er_tres)
static

Get Collision result for query ER_COLL_QUERY_TYPE_TOLERANCE. Remarks
Call erColl_ChkCollision() first, brfore calling this function.

Parameters
[out]er_trestolerance results ER_ToleranceResult
Return values
0- OK
1- Error, kernel not initialized

◆ erColl_UnloadModel()

static DLLAPI int ER_STDCALL ERK_CAPI_SIM_COLLISION::erColl_UnloadModel ( ER_COLLISION_HND er_coll_hnd)
static

Unload a Model. Free all allocated memory.

Parameters
[in]er_coll_hnda valid unique Collision handle ER_COLLISION_HND
Return values
0- ER_COLL_OK - OK
1- ER_COLL_ERROR - Error, kernel not initialized
2- ER_COLL_HND_INVALID - Collision handle invalid

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