single_device.cpp

Simple example of single-device programming.

////////////////////////////////////////////////////////////////////////////////
//
// This example implements a simple gravity compensation loop for a single
// haptic device.
//
////////////////////////////////////////////////////////////////////////////////
// C++ library headers
#include <iostream>
#include <iomanip>
// project headers
#include "dhdc.h"
////////////////////////////////////////////////////////////////////////////////
int main(int argc,
char* argv[])
{
// get device count
if (dhdGetDeviceCount() <= 0)
{
std::cout << "error: " << dhdErrorGetLastStr() << std::endl;
return -1;
}
// open the first available device
if (dhdOpen() < 0)
{
std::cout << "error: " << dhdErrorGetLastStr() << std::endl;
return -1;
}
// haptic loop
while (true)
{
// apply a null force to put the device in gravity compensation
if (dhdSetForce(0.0, 0.0, 0.0) < 0)
{
std::cout << "error: " << dhdErrorGetLastStr() << std::endl;
break;
}
// exit the haptic loop on button press
if (dhdGetButton(0))
{
break;
}
}
// close the connection to the device
if (dhdClose() < 0)
{
std::cout << "error: " << dhdErrorGetLastStr() << std::endl;
}
return 0;
}
DHD header file.
int __SDK dhdClose(char ID=-1)
Definition: dhdc.cpp:443
int __SDK dhdGetDeviceCount()
Definition: dhdc.cpp:226
int __SDK dhdGetButton(int index, char ID=-1)
Definition: dhdc.cpp:1182
const char *__SDK dhdErrorGetLastStr()
Definition: dhdError.cpp:197
int __SDK dhdSetForce(double fx, double fy, double fz, char ID=-1)
Definition: dhdc.cpp:1697
int __SDK dhdOpen()
Definition: dhdc.cpp:265