Systems, Man & Cybernetics - January 2016 - 19

Supplementary
Part I: Sample Code for the Demonstration of Function Templates Conversion
Below is a segment of C++ code from the proposed
framework to demonstrate part of the templates and the

if (count > 0){
string EncoderCounts[8], ADC[8];

conversion procedure on getting the positions of multiple

Encoder[0] = (buf[0]<<24) + (buf[1]<<16) + (buf[2]<<8)

HIPs from the customized controller function template.

+ (buf[3]);

Here, we have a customized controller where its driver

if(Encoder[0] < 0 ) Encoder[0] = 0;

provides the following functions related to getting positions

Encoder[1] = (buf[4]<<24) + (buf[5]<<16) + (buf[6]<<8) +

for its HIPs:

(buf[7]);

int HID_API_EXPORT HID_API_CALL hid_read(hid_device
*device, unsigned char *data, size_t length);
int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_
device *device, int nonblock);

if(Encoder[1] > 0 ) Encoder[1] = 0;}
else return -1;
//Position calculation for the specific controller
this->getPosShift(m_localMainPosShift);
this->getScale(m_localMainDeviceScale);
double armLength = 100.0 * 10;

While in the proposed framework, the following function

double theta = 3.1415926/4/3000;

template is used to get a three-dimensional position vector
for a specific HIP:

l o c a l L e f t Po s . z = l o c a l R i g h t Po s . z = z = 0 + m _
localMainPosShift.z;

int getPosition(cVector3d& a_position, int iHIPID);

l o c a l L e f t Po s. x = l o c a l R i g h t Po s. x = x = 0 + m _
localMainPosShift.x;

The conversion procedure for the getPosition() function
looks like this:

y = 0 + m_localMainPosShift.y;
localLeftPos.y = armLength * sin (Encoder[1] * theta)/1000

//Function Conversion Preparation

+ m_localMainPosShift.y;

MPH_hid_read = (int (__stdcall*)(hid_device *device,

localRightPos.y = armLength * sin (Encoder[0] *

unsigned char *data, size_t length))

theta)/1000 + m_localMainPosShift.y;

GetProcAddress(hdCISR_MPH_Driver_DLL, "hid_read");
a_position.set(x,y,z);
MPH_hid_set_nonblocking = (int (__stdcall*)(hid_device

estimateLinearVelocity(a_position);

*device, int nonblock))
GetProcAddress(hdCISR_MPH_Driver_DLL, "hid_set_
nonblocking");

//Finished converting controller functions into a function
template usable within the proposed framework
return 0;}

//Actual Function Conversion
int cMyCustomDevice::getPosition(cVector3d& a_position,
int iHIPID) {

This conversion procedure needs to be done only once
per device configuration. After this, the customized device

//Local variables declaration

will be recognized by the framework as a standard MPH,

double x,y,z;

with all essential interaction functions implemented. Haptic

unsigned char buf[MAX_BYTES];

application programmers will be able to write examples for the

char hval, lval;

MPHs similar to what they used to work with other SDKs such as

int count, Encoder[2];

CHAI3D. In the example above, only the function getPosition()

cVector3d m_localMainPosShift;

will be called in MPH applications for the customized controller.

double m_localMainDeviceScale;
Part II: Details of Data Throughput Comparison
//Calling functions from the customised controller and
retrieve device data

Tests Among Different SDKs
For each configuration, we test exactly 100,000 data I/O

memset(buf, 0, sizeof(buf));

throughputs on position (input data from device to system) and

MPH_hid_set_nonblocking(iHIPID, 1);

force (output data from system to device), which ideally should

count = MPH_hid_read(iHIPID, buf, MAX_BYTES);

take 100 s to finish for a single HIP. To avoid any computational
overheads during the force calculation procedure, the

//Data conversion procedure, this part will be different for
different controllers

input force vectors are simply set as the opposite of the
position vectors.
(continued)

Ja nu a r y 2016

IEEE SyStEmS, man, & CybErnEtICS magazInE

19



Table of Contents for the Digital Edition of Systems, Man & Cybernetics - January 2016

Systems, Man & Cybernetics - January 2016 - Cover1
Systems, Man & Cybernetics - January 2016 - Cover2
Systems, Man & Cybernetics - January 2016 - 1
Systems, Man & Cybernetics - January 2016 - 2
Systems, Man & Cybernetics - January 2016 - 3
Systems, Man & Cybernetics - January 2016 - 4
Systems, Man & Cybernetics - January 2016 - 5
Systems, Man & Cybernetics - January 2016 - 6
Systems, Man & Cybernetics - January 2016 - 7
Systems, Man & Cybernetics - January 2016 - 8
Systems, Man & Cybernetics - January 2016 - 9
Systems, Man & Cybernetics - January 2016 - 10
Systems, Man & Cybernetics - January 2016 - 11
Systems, Man & Cybernetics - January 2016 - 12
Systems, Man & Cybernetics - January 2016 - 13
Systems, Man & Cybernetics - January 2016 - 14
Systems, Man & Cybernetics - January 2016 - 15
Systems, Man & Cybernetics - January 2016 - 16
Systems, Man & Cybernetics - January 2016 - 17
Systems, Man & Cybernetics - January 2016 - 18
Systems, Man & Cybernetics - January 2016 - 19
Systems, Man & Cybernetics - January 2016 - 20
Systems, Man & Cybernetics - January 2016 - 21
Systems, Man & Cybernetics - January 2016 - 22
Systems, Man & Cybernetics - January 2016 - 23
Systems, Man & Cybernetics - January 2016 - 24
Systems, Man & Cybernetics - January 2016 - 25
Systems, Man & Cybernetics - January 2016 - 26
Systems, Man & Cybernetics - January 2016 - 27
Systems, Man & Cybernetics - January 2016 - 28
Systems, Man & Cybernetics - January 2016 - 29
Systems, Man & Cybernetics - January 2016 - 30
Systems, Man & Cybernetics - January 2016 - 31
Systems, Man & Cybernetics - January 2016 - 32
Systems, Man & Cybernetics - January 2016 - 33
Systems, Man & Cybernetics - January 2016 - 34
Systems, Man & Cybernetics - January 2016 - 35
Systems, Man & Cybernetics - January 2016 - 36
Systems, Man & Cybernetics - January 2016 - 37
Systems, Man & Cybernetics - January 2016 - 38
Systems, Man & Cybernetics - January 2016 - 39
Systems, Man & Cybernetics - January 2016 - 40
Systems, Man & Cybernetics - January 2016 - 41
Systems, Man & Cybernetics - January 2016 - 42
Systems, Man & Cybernetics - January 2016 - 43
Systems, Man & Cybernetics - January 2016 - 44
Systems, Man & Cybernetics - January 2016 - Cover3
Systems, Man & Cybernetics - January 2016 - Cover4
https://www.nxtbook.com/nxtbooks/ieee/smc_202110
https://www.nxtbook.com/nxtbooks/ieee/smc_202107
https://www.nxtbook.com/nxtbooks/ieee/smc_202104
https://www.nxtbook.com/nxtbooks/ieee/smc_202101
https://www.nxtbook.com/nxtbooks/ieee/smc_202010
https://www.nxtbook.com/nxtbooks/ieee/smc_202007
https://www.nxtbook.com/nxtbooks/ieee/smc_202004
https://www.nxtbook.com/nxtbooks/ieee/smc_202001
https://www.nxtbook.com/nxtbooks/ieee/smc_201910
https://www.nxtbook.com/nxtbooks/ieee/smc_201907
https://www.nxtbook.com/nxtbooks/ieee/smc_201904
https://www.nxtbook.com/nxtbooks/ieee/smc_201901
https://www.nxtbook.com/nxtbooks/ieee/smc_201810
https://www.nxtbook.com/nxtbooks/ieee/smc_201807
https://www.nxtbook.com/nxtbooks/ieee/smc_201804
https://www.nxtbook.com/nxtbooks/ieee/smc_201801
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_1017
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0717
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0417
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0117
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_1016
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0716
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0416
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0116
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_1015
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0715
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0415
https://www.nxtbook.com/nxtbooks/ieee/systems_man_cybernetics_0115
https://www.nxtbookmedia.com