//=========================================================================== int cDeltaDevice::open() { // check if the system is available if (!m_systemAvailable) return (-1); // if system is already opened then return if (m_systemReady) return (0); // try to open the device int result = dhdOpenID(m_deviceID); // update device status if (result == 0) { m_systemReady = true; } else { m_systemReady = false; return (-1); } // read the device type m_deviceType = dhdGetSystemType(m_deviceID); switch (m_deviceType) { // default values are set to the omega m_halfSizeWorkspace = OMEGA_DEVICE_WORKSPACE_HALF_SIZE; m_maximumForces = OMEGA_DEVICE_MAXIMUM_FORCE; // delta devices case (DHD_DEVICE_3DOF): case (DHD_DEVICE_6DOF): case (DHD_DEVICE_6DOF_500): { m_halfSizeWorkspace = DELTA_DEVICE_WORKSPACE_HALF_SIZE; m_maximumForces = DELTA_DEVICE_MAXIMUM_FORCE; } break; // omega devices case (DHD_DEVICE_OMEGA): case (DHD_DEVICE_OMEGA3): case (DHD_DEVICE_OMEGA33): case (DHD_DEVICE_OMEGA331): { m_halfSizeWorkspace = OMEGA_DEVICE_WORKSPACE_HALF_SIZE; m_maximumForces = OMEGA_DEVICE_MAXIMUM_FORCE; } break; } return (result); }
int main (int argc, char **argv) { int i; int done = 0; int enc[DHD_MAX_ENC]; int encCount; // message int major, minor, release, revision; dhdGetAPIVersion (&major, &minor, &release, &revision); printf ("Force Dimension - Encoder Reading Example %d.%d.%d.%d\n", major, minor, release, revision); printf ("(C) 2010 Force Dimension\n"); printf ("All Rights Reserved.\n\n"); // open the first available device if (dhdOpen () < 0) { printf ("error: cannot open device (%s)\n", dhdErrorGetLastStr()); return -1; } // identify device printf ("%s device detected\n\n", dhdGetSystemName()); // identify number of encoders to report based on device type switch (dhdGetSystemType ()) { case DHD_DEVICE_3DOF: case DHD_DEVICE_3DOF_USB: case DHD_DEVICE_OMEGA: case DHD_DEVICE_OMEGA3: default: encCount = 3; break; case DHD_DEVICE_6DOF: case DHD_DEVICE_6DOF_500: case DHD_DEVICE_6DOF_USB: case DHD_DEVICE_OMEGA33: case DHD_DEVICE_OMEGA33_LEFT: encCount = 6; break; case DHD_DEVICE_OMEGA331: case DHD_DEVICE_OMEGA331_LEFT: encCount = 7; break; case DHD_DEVICE_CONTROLLER: case DHD_DEVICE_CONTROLLER_HR: encCount = 8; break; } // display instructions printf ("press BUTTON or 'q' to quit\n\n"); // configure device dhdEnableExpertMode(); // loop while the button is not pushed while (!done) { // read all available encoders if (dhdGetEnc (enc) < 0) { printf ("error: cannot read encoders (%s)\n", dhdErrorGetLastStr ()); done = 1; } // print out encoders according to system type for (i=0; i<encCount; i++) { printf ("%06d ", enc[i]); } printf (" \r"); // limit to kHz and check for exit condition dhdSleep (0.001); if (dhdGetButton(0)) done = 1; if (dhdKbHit()) { if (dhdKbGet() == 'q') done = 1; } } // close the connection dhdClose (); // happily exit printf ("\ndone.\n"); return 0; }