Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #include "DHDDriver.hpp"
00009
00010 #include <dhdc.h>
00011 #include <telekyb_defines/telekyb_defines.hpp>
00012
00013 #include <boost/foreach.hpp>
00014
00015
00016 namespace TELEKYB_NAMESPACE
00017 {
00018
00019 DHDDriver::DHDDriver()
00020 : controllerLoader("tk_haptics_base", std::string( TELEKYB_NAMESPACE_STRING ) + "::HapticDeviceController")
00021 {
00022 dhdInit();
00023 }
00024
00025 DHDDriver::~DHDDriver()
00026 {
00027
00028 BOOST_FOREACH(DHDDevice* d, devices) {
00029 delete d;
00030 }
00031 }
00032
00033
00034 void DHDDriver::dhdInit()
00035 {
00036 int api_major, api_minor, api_release, api_revision;
00037 dhdGetAPIVersion(&api_major, &api_minor, &api_release, &api_revision);
00038
00039 if (dhdGetDeviceCount() != 0) {
00040 for ( int i = 0; i < dhdGetDeviceCount(); ++i) {
00041 dhdOpenID(i);
00042 ROS_INFO_STREAM("Device " << i << ": " << dhdGetSystemName(i));
00043
00044 if (dhdGetSystemType(i) == DHD_DEVICE_NONE) {
00045 ROS_ERROR("Device with ID %d recognized, but unsupported in DHD %d.%d.%d.%d",i, api_major, api_minor, api_release, api_revision);
00046 dhdClose(i);
00047 } else {
00048 devices.insert(new DHDDevice(i, true));
00049 }
00050 }
00051 }
00052
00053
00054 if (devices.empty()) {
00055 ROS_ERROR("No Devices found!");
00056 }
00057
00058 }
00059
00060 void DHDDriver::start()
00061 {
00062 if (devices.empty()) {
00063 return;
00064 }
00065
00066
00067 ROS_INFO("Loading Controllers for devices.");
00068 BOOST_FOREACH(DHDDevice* d, devices) {
00069 d->loadController(controllerLoader);
00070 }
00071
00072 ROS_INFO("Creating threads for devices.");
00073
00074 BOOST_FOREACH(DHDDevice* d, devices) {
00075 d->startThread();
00076 }
00077
00078
00079 BOOST_FOREACH(DHDDevice* d, devices) {
00080 d->joinThread();
00081 }
00082 }
00083
00084 }