CHAI3D plugin for V-REP

Shared library for use by V-REP (from Coppelia Robotics). More...

Classes

struct  State
 Data structure that contains an object state. More...
 
struct  Device
 Data structure that contains a haptic device handle and related state information. More...
 
class  Object
 Data structure that contains an object of type ObjectType used to generate haptic feedback. More...
 

Macros

#define CONCAT(x, y, z)   x y z
 
#define strConCat(x, y, z)   CONCAT(x,y,z)
 
#define LUA_START_COMMAND   "simExtCHAI3D_start"
 
#define LUA_RESET_COMMAND   "simExtCHAI3D_reset"
 
#define LUA_ADD_SHAPE_COMMAND   "simExtCHAI3D_addShape"
 
#define LUA_ADD_CONSTRAINT_POINT_COMMAND   "simExtCHAI3D_addConstraintPoint"
 
#define LUA_ADD_CONSTRAINT_SEGMENT_COMMAND   "simExtCHAI3D_addConstraintSegment"
 
#define LUA_ADD_CONSTRAINT_PLANE_COMMAND   "simExtCHAI3D_addConstraintPlane"
 
#define LUA_UPDATE_SHAPE_COMMAND   "simExtCHAI3D_updateShape"
 
#define LUA_UPDATE_CONSTRAINT_COMMAND   "simExtCHAI3D_updateConstraint"
 
#define LUA_REMOVE_OBJECT_COMMAND   "simExtCHAI3D_removeObject"
 
#define LUA_READ_POSITION_COMMAND   "simExtCHAI3D_readPosition"
 
#define LUA_READ_FORCE_COMMAND   "simExtCHAI3D_readForce"
 
#define LUA_READ_BUTTONS_COMMAND   "simExtCHAI3D_readButtons"
 

Enumerations

enum  ObjectType { SHAPE, CONSTRAINT_POINT, CONSTRAINT_SEGMENT, CONSTRAINT_PLANE }
 Types of haptic objects. More...
 

Functions

int addObject (Object *object)
 Add generic object to the scene. More...
 
bool updateShape (int objectID, float pos[3], float rot[3], float stiffnessFactor)
 Update the parameters of a SHAPE haptic object. More...
 
bool updateConstraint (int objectID, float pos[3], float dir[3], float Kp, float Kv, float Fmax)
 Update the parameters of a constraint haptic object. More...
 
bool removeObject (int objectID)
 Safely remove an object from the object list. More...
 
bool removeObject (Object *object)
 Safely remove an object from the object list. More...
 
void hapticLoop ()
 Main haptic loop. More...
 
void hapticStart ()
 Start the haptic loop. More...
 
void hapticStop ()
 Stop the haptic loop. More...
 
bool hapticConnect (int deviceIndex, float toolRadius, float workspaceRadius)
 
bool hapticDisconnect (int index)
 Disconnect from haptic device. More...
 
void hapticReset ()
 Clean up the scene. More...
 
void LUA_START_CALLBACK (SLuaCallBack *p)
 Connect to a haptic device. More...
 
void LUA_RESET_CALLBACK (SLuaCallBack *p)
 Disconnect from a haptic device and reset the scene. More...
 
void LUA_ADD_SHAPE_CALLBACK (SLuaCallBack *p)
 Add a SHAPE object to the scene. More...
 
void LUA_ADD_CONSTRAINT_POINT_CALLBACK (SLuaCallBack *p)
 Add a CONSTRAINT_POINT object to the scene. More...
 
void LUA_ADD_CONSTRAINT_SEGMENT_CALLBACK (SLuaCallBack *p)
 Add a CONSTRAINT_SEGMENT object to the scene. More...
 
void LUA_ADD_CONSTRAINT_PLANE_CALLBACK (SLuaCallBack *p)
 Add a CONSTRAINT_PLANE object to the scene. More...
 
void LUA_UPDATE_SHAPE_CALLBACK (SLuaCallBack *p)
 Update the parameters of a SHAPE haptic object. More...
 
void LUA_UPDATE_CONSTRAINT_CALLBACK (SLuaCallBack *p)
 Update the parameters of a constraint haptic object. More...
 
void LUA_REMOVE_OBJECT_CALLBACK (SLuaCallBack *p)
 Safely remove an object from the object list. More...
 
void LUA_READ_POSITION_CALLBACK (SLuaCallBack *p)
 Retrieve the current position of a haptic device (identified by its deviceIndex) in the scene. More...
 
void LUA_READ_FORCE_CALLBACK (SLuaCallBack *p)
 Retrieve the force currently displayed by a haptic device (identified by its deviceIndex). More...
 
void LUA_READ_BUTTONS_CALLBACK (SLuaCallBack *p)
 Retrieve a haptic device (identified by its deviceIndex) end-effector buttons status. More...
 
VREP_DLLEXPORT unsigned char v_repStart (void *reservedPointer, int reservedInt)
 V-REP shared library initialization. More...
 
VREP_DLLEXPORT void v_repEnd ()
 V-REP shared library disconnect. More...
 
VREP_DLLEXPORT void * v_repMessage (int message, int *auxiliaryData, void *customData, int *replyData)
 V-REP shared library message processing callback. More...
 

Variables

bool SimulationRunning
 Haptic thread control flag. More...
 
cThread * HapticThread
 Haptic thread handle. More...
 
cMutex * SimulationLock
 Haptic thread stop synchronization lock. More...
 
cMutex * SceneLock
 Haptic scene synchronization lock. More...
 
cMutex * ObjectLock
 Haptic objects synchronization lock. More...
 
vector< Object * > Objects
 Haptic objects list. More...
 
cHapticDeviceHandler * DeviceHandler
 CHAI3D haptic device handler. More...
 
cWorld * World
 Haptic scene container. More...
 
map< int, cGenericHapticDevicePtr > Devices
 CHAI3D haptic device list. More...
 
map< int, Device * > Cursors
 Haptic device list. More...
 
cPrecisionClock Clock
 
double BiggestRadius = 0.0
 
double LowestStiffness = -1.0
 
LIBRARY vrepLib
 
const int inArgs_START []
 
const int inArgs_RESET []
 
const int inArgs_ADD_SHAPE []
 
const int inArgs_ADD_CONSTRAINT_POINT []
 
const int inArgs_ADD_CONSTRAINT_SEGMENT []
 
const int inArgs_ADD_CONSTRAINT_PLANE []
 
const int inArgs_UPDATE_SHAPE []
 
const int inArgs_UPDATE_CONSTRAINT []
 
const int inArgs_REMOVE_OBJECT []
 
const int inArgs_READ_POSITION []
 
const int inArgs_READ_FORCE []
 
const int inArgs_READ_BUTTONS []
 

Detailed Description

Please refer to the introduction for more information on how to use the CHAI3D plugin for V-REP.

Macro Definition Documentation

#define CONCAT (   x,
  y,
  z 
)    x y z
#define strConCat (   x,
  y,
  z 
)    CONCAT(x,y,z)
#define LUA_START_COMMAND   "simExtCHAI3D_start"
#define LUA_RESET_COMMAND   "simExtCHAI3D_reset"
#define LUA_ADD_SHAPE_COMMAND   "simExtCHAI3D_addShape"
#define LUA_ADD_CONSTRAINT_POINT_COMMAND   "simExtCHAI3D_addConstraintPoint"
#define LUA_ADD_CONSTRAINT_SEGMENT_COMMAND   "simExtCHAI3D_addConstraintSegment"
#define LUA_ADD_CONSTRAINT_PLANE_COMMAND   "simExtCHAI3D_addConstraintPlane"
#define LUA_UPDATE_SHAPE_COMMAND   "simExtCHAI3D_updateShape"
#define LUA_UPDATE_CONSTRAINT_COMMAND   "simExtCHAI3D_updateConstraint"
#define LUA_REMOVE_OBJECT_COMMAND   "simExtCHAI3D_removeObject"
#define LUA_READ_POSITION_COMMAND   "simExtCHAI3D_readPosition"
#define LUA_READ_FORCE_COMMAND   "simExtCHAI3D_readForce"
#define LUA_READ_BUTTONS_COMMAND   "simExtCHAI3D_readButtons"

Enumeration Type Documentation

enum ObjectType

Each Object in the scene must be assigned one of the following types.

Enumerator
SHAPE 

Arbitrary 3D mesh object.

CONSTRAINT_POINT 

Constraint that holds the haptic device at a given point. The point is defined by State::Pos.

CONSTRAINT_SEGMENT 

Constraint that holds the haptic device on a given segment. The segment is defined by a point (State::Pos) and a vector (State::Dir).

CONSTRAINT_PLANE 

Constraint that holds the haptic device on a given plane. The plane is defined by a point (State::Pos) and a normal direction (State::Dir).

Function Documentation

int addObject ( Object *  object)
Parameters
objectHaptic Object to add to the scene.
Returns
A unique identifier for the object if successful, -1 otherwise.
bool updateShape ( int  objectID,
float  pos[3],
float  rot[3],
float  stiffnessFactor 
)
Parameters
objectIDobject identifier (returned by addObject).
posnew target SHAPE target position, expressed in m.
rotnew target SHAPE orientation in the scene, expressed as ZYX extrinsic Euler angles.
stiffnessFactornew target object stiffness factor (between 0.0 and 1.0).
Returns
true on success, false otherwise.
bool updateConstraint ( int  objectID,
float  pos[3],
float  dir[3],
float  Kp,
float  Kv,
float  Fmax 
)
Parameters
objectIDobject identifier (returned by addObject).
posnew constraint position in the scene, expressed in m.
dirnew constraint direction, as defined in ObjectType.
Kpnew constraint stiffness factor (between 0.0 and 1.0).
Kvnew constraint viscosity factor (between 0.0 and 1.0).
Fmaxnew constraint max force for Kp, expressed in N.
Returns
true on success, false otherwise.
bool removeObject ( int  objectID)
Parameters
objectIDobject identifier (returned by addObject).
Returns
true on success, false otherwise.
bool removeObject ( Object *  object)
Parameters
objectpointer to object to remove.
Returns
true on success, false otherwise.
void hapticLoop ( )

The haptic loop runs in the background (with high priority) and renders all Objects haptically to all devices in the scene. Use hapticStart() to start the haptic loop, and hapticReset() to stop it.

Note
The hapticLoop is started and stopped automatically by hapticConnect() and hapticDisconnect(), according to the number of devices connected.
void hapticStart ( )
void hapticStop ( )
bool hapticConnect ( int  deviceIndex,
float  toolRadius,
float  workspaceRadius 
)

\brief Connect to a haptic device and add it to the scene.

If successful, the device is added to the device list and will be controlled by the hapticLoop().

Parameters
deviceIndexindex of the device to open in the list of devices detected by the operating system. This is guaranteed to be the same between executions as long as no hardware changes occur.
toolRadiusradius of the haptic device proxy (tool) in the simulated scene, expressed in m.
workspaceRadiusradius of the simulated workspace that the physical device workspace must be scaled to, expressed in m.
Returns
true on success, false otherwise.
bool hapticDisconnect ( int  index)

This will remove all objects associated with this particular device, and will remove the device from the scene.

Parameters
indexindex of the device to disconnect. This should be the same as the index given to hapticConnect().
Returns
true on success, false otherwise.
void hapticReset ( )

This function disconnects all devices and removes all objects from the scene.

void LUA_START_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for hapticConnect().
The arguments parsed from the p buffer are passed on to hapticConnect(int deviceIndex, float toolRadius, float workspaceRadius).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 number simExtCHAI3D_start(number deviceIndex, number toolRadius, number workspaceRadius)
Returns
1 on success, -1 otherwise.
void LUA_RESET_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for hapticReset().

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_reset()
void LUA_ADD_SHAPE_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for addObject() and Object::Object().
The arguments parsed from the p buffer are passed on to Object::Object(float pos[3], float rot[3], vector<float>vertices, vector<int> indices, float stiffnessFactor).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_addShape(table_3 pos, table_3 rot, table vertices, table indices, number stiffnessFactor)
void LUA_ADD_CONSTRAINT_POINT_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for addObject() and Object::Object().
The arguments parsed from the p buffer are passed on to Object::Object(ObjectType constraintType, int device, float pos[3], float dir[3], float Kp, float Kv, float Fmax).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_addConstraintPoint(number deviceIndex, table_3 pos, number Kp, number Kv, number Fmax)
void LUA_ADD_CONSTRAINT_SEGMENT_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for addObject() and Object::Object().
The arguments parsed from the p buffer are passed on to Object::Object(ObjectType constraintType, int device, float pos[3], float dir[3], float Kp, float Kv, float Fmax).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_addConstraintSegment(table_3 posA, table_3 posB, number Kp, number Kv, number Fmax)
void LUA_ADD_CONSTRAINT_PLANE_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for addObject() and Object::Object().
The arguments parsed from the p buffer are passed on to Object::Object(ObjectType constraintType, int device, float pos[3], float dir[3], float Kp, float Kv, float Fmax).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_addConstraintPlane(table_3 pos, table_3 normal, number Kp, number Kv, number Fmax)
void LUA_UPDATE_SHAPE_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for updateShape().
The arguments parsed from the p buffer are passed on to updateShape(int objectID, float pos[3], float rot[3], float stiffnessFactor).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_updateShape(number objectID, table_3 pos, table_3 rot, number stiffnessFactor)
void LUA_UPDATE_CONSTRAINT_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for updateShape().
The arguments parsed from the p buffer are passed on to updateConstraint(int objectID, float pos[3], float dir[3], float Kp, float Kv, float Fmax).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_updateConstraint(number objectID, table_3 pos, table_3 dir, number Kp, number Kv, number Fmax)
void LUA_REMOVE_OBJECT_CALLBACK ( SLuaCallBack *  p)

This LUA callback is a wrapper for removeObject().
The arguments parsed from the p buffer are passed on to removeObject(int objectID).

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 simExtCHAI3D_removeObject(number objectID)
void LUA_READ_POSITION_CALLBACK ( SLuaCallBack *  p)
Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 table_3 simExtCHAI3D_readPosition(number deviceIndex)
Returns
An array containing the XYZ position Cartesian coordinates of the device end-effector in the simulated scene.
void LUA_READ_FORCE_CALLBACK ( SLuaCallBack *  p)
Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 table_3 simExtCHAI3D_readForce(number deviceIndex)
Returns
An array containing the XYZ Cartesian force component at the device end-effector.
void LUA_READ_BUTTONS_CALLBACK ( SLuaCallBack *  p)

The buttons are returned in the form of an array of bit. A bit state of 1 indicates that the button at the given bit array index is pressed, 0 means it is not.

Parameters
pSLuaCallBack I/O buffer.

The corresponding LUA function is:

1 table_3 simExtCHAI3D_readButtons(number deviceIndex)
Returns
An array of bits containing the buttons state for the given device.
VREP_DLLEXPORT unsigned char v_repStart ( void *  reservedPointer,
int  reservedInt 
)
VREP_DLLEXPORT void v_repEnd ( )
VREP_DLLEXPORT void* v_repMessage ( int  message,
int *  auxiliaryData,
void *  customData,
int *  replyData 
)

Variable Documentation

bool SimulationRunning
cThread* HapticThread
cMutex* SimulationLock
cMutex* SceneLock
cMutex* ObjectLock
vector<Object*> Objects
cHapticDeviceHandler* DeviceHandler
cWorld* World
map<int,cGenericHapticDevicePtr> Devices
map<int,Device*> Cursors
double BiggestRadius = 0.0
double LowestStiffness = -1.0
LIBRARY vrepLib
const int inArgs_START[]
Initial value:
= {
3,
sim_lua_arg_int, 0,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0,
}
const int inArgs_RESET[]
Initial value:
= {
0
}
const int inArgs_ADD_SHAPE[]
Initial value:
= {
5,
sim_lua_arg_float|sim_lua_arg_table, 9,
sim_lua_arg_int|sim_lua_arg_table, 3,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float, 0
}
const int inArgs_ADD_CONSTRAINT_POINT[]
Initial value:
= {
5,
sim_lua_arg_int, 0,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0
}
const int inArgs_ADD_CONSTRAINT_SEGMENT[]
Initial value:
= {
6,
sim_lua_arg_int, 0,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0
}
const int inArgs_ADD_CONSTRAINT_PLANE[]
Initial value:
= {
6,
sim_lua_arg_int, 0,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0
}
const int inArgs_UPDATE_SHAPE[]
Initial value:
= {
4,
sim_lua_arg_int, 0,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float, 0
}
const int inArgs_UPDATE_CONSTRAINT[]
Initial value:
= {
6,
sim_lua_arg_int, 0,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float|sim_lua_arg_table, 3,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0,
sim_lua_arg_float, 0
}
const int inArgs_REMOVE_OBJECT[]
Initial value:
= {
1,
sim_lua_arg_int, 0
}
const int inArgs_READ_POSITION[]
Initial value:
= {
1,
sim_lua_arg_int, 0
}
const int inArgs_READ_FORCE[]
Initial value:
= {
1,
sim_lua_arg_int, 0
}
const int inArgs_READ_BUTTONS[]
Initial value:
= {
1,
sim_lua_arg_int, 0
}