DHD-API 3.2.2 documentation
 

single_device.cpp

Simple example of single-device programming.

#include <stdio.h>
#include "dhdc.h"



int
main (int  argc,
      char **argv)
{
  int done = 0;

  // get device count
  if (dhdGetDeviceCount () <= 0) {
    printf ("error: no device found (%s)\n", dhdErrorGetLastStr ());
    return 0;
  }

  // open the first available device
  if (dhdOpen () < 0) {
    printf ("error: %s\n", dhdErrorGetLastStr ());
  }

  // haptic loop
  while (!done) {

    // apply a null force to put the device in gravity compensation
    if (dhdSetForce (0.0, 0.0, 0.0) < 0) {
      printf ("error: %s\n", dhdErrorGetLastStr ());
      done = 1;
    }

    // detect button click to quit the haptic loop
    if (dhdGetButton (0)) {
      printf ("exiting...\n");
      done = 1;
    }
  }

  // close the connection to the device
  if (dhdClose () < 0) {
    printf ("error: %s\n", dhdErrorGetLastStr ());
  }


  return 0;
}


DHD-API 3.2.2 documentation
Please address any questions to support@forcedimension.com
(C) 2001-2010 - Force Dimension
All Rights Reserved.