10 #include "PlusConfigure.h" 15 #include <HDU/hduVector.h> 16 #include <HDU/hduError.h> 20 #include <vtkMatrix4x4.h> 21 #include <vtkTransform.h> 34 , DeviceName(
"Default Device")
35 , toolTransform(vtkSmartPointer<vtkTransform>::New())
36 , rotation(vtkSmartPointer<vtkTransform>::New())
37 , velMatrix(vtkSmartPointer<vtkMatrix4x4>::New())
38 , buttonMatrix(vtkSmartPointer<vtkMatrix4x4>::New())
39 , toolMatrix(vtkSmartPointer<vtkMatrix4x4>::New())
53 ss << HD_VERSION_MAJOR_NUMBER <<
"." << HD_VERSION_MINOR_NUMBER <<
"." << HD_VERSION_BUILD_NUMBER;
62 LOG_ERROR(
"vtkPlusOpenHapticsDevice::Probe should not be called while the device is already initialized");
68 LOG_INFO(
"vtkPlusOpenHapticsDevice::Probe found OpenHaptics Device");
73 LOG_ERROR(
"vtkPlusOpenHapticsDevice::Probe failed to connect to device");
84 hdScheduleSynchronous(positionCallback,
this, HD_MAX_SCHEDULER_PRIORITY);
93 HDErrorInfo errorFlush;
94 while(HD_DEVICE_ERROR(errorFlush = hdGetError())) {}
96 this->DeviceHandle = hdInitDevice(this->
DeviceName.c_str());
99 if(HD_DEVICE_ERROR(error = hdGetError()))
101 LOG_ERROR(
"Failed to initialize Phantom Omni " << this->
DeviceName);
102 this->DeviceHandle = -1;
107 hdEnable(HD_FORCE_OUTPUT);
108 hdEnable(HD_FORCE_RAMPING);
110 LOG_DEBUG(
"Phantom initialized: " << this->
DeviceName)
120 hdDisableDevice(DeviceHandle);
129 XML_READ_STRING_ATTRIBUTE_REQUIRED(
DeviceName, deviceConfig);
137 trackerConfig->SetAttribute(
"DeviceName", this->
DeviceName.c_str());
146 LOG_INFO(
"No force input has been provided");
152 LOG_INFO(
"Multiple input channels present. Only first channel will be checked for force data");
157 LOG_INFO(
"No Force tool in input channel. Forces will not be available");
164 HDCallbackCode HDCALLBACK
165 vtkPlusOpenHapticsDevice::positionCallback(
void* pData)
169 HHD handle = client->DeviceHandle;
171 const double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
189 vtkSmartPointer<vtkMatrix4x4> forceMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
191 force[0] = forceMatrix->GetElement(0, 3);
192 force[1] = forceMatrix->GetElement(1, 3);
193 force[2] = forceMatrix->GetElement(2, 3);
197 LOG_ERROR(
"OpenHaptics Force data tool is not valid")
202 LOG_ERROR(
"OpenHaptics Force data tool info not recevied")
207 LOG_TRACE(
"No force data tool has been provided");
214 HDint buttonVals = 0;
215 HDboolean inkwell = 0;
216 hdBeginFrame(handle);
217 hdMakeCurrentDevice(handle);
218 hdGetDoublev(HD_CURRENT_TRANSFORM, tfm);
219 hdGetDoublev(HD_CURRENT_POSITION, pos);
220 hdGetDoublev(HD_CURRENT_VELOCITY, vel);
221 hdSetDoublev(HD_CURRENT_FORCE, force);
222 hdGetIntegerv(HD_CURRENT_BUTTONS, &buttonVals);
223 hdGetBooleanv(HD_CURRENT_INKWELL_SWITCH, &inkwell);
232 client->toolTransform->Identity();
233 client->toolTransform->Translate(pos);
234 client->rotation->SetMatrix(tfm);
235 client->rotation->GetOrientation(orient);
236 client->toolTransform->RotateX(-1 * orient[0] + 180);
237 client->toolTransform->RotateY(orient[1]);
238 client->toolTransform->RotateZ(orient[2]);
239 client->velMatrix->SetElement(0, 3, vel[0]);
240 client->velMatrix->SetElement(1, 3, vel[1]);
241 client->velMatrix->SetElement(2, 3, vel[2]);
243 client->toolMatrix = client->toolTransform->GetMatrix();
249 client->buttonMatrix->SetElement(0, 0, 0);
250 client->buttonMatrix->SetElement(1, 1, 0);
251 client->buttonMatrix->SetElement(2, 2, 0);
252 client->buttonMatrix->SetElement(0, 0, (
bool)(buttonVals & HD_DEVICE_BUTTON_1));
253 client->buttonMatrix->SetElement(1, 0, (
bool)(buttonVals & HD_DEVICE_BUTTON_2));
254 client->buttonMatrix->SetElement(2, 0, (
bool)(buttonVals & HD_DEVICE_BUTTON_3));
255 client->buttonMatrix->SetElement(3, 0, (
bool)(buttonVals & HD_DEVICE_BUTTON_4));
256 client->buttonMatrix->SetElement(0, 1, (
int)inkwell);
273 return HD_CALLBACK_DONE;
ToolStatus GetStatus() const
Device interface for Open Haptics devices.
vtkStandardNewMacro(vtkPlusOpenHapticsDevice)
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_WRITING(deviceConfig, rootConfigElement)
ChannelContainer InputChannels
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
PlusStatus InternalUpdate()
bool RequirePortNameInDeviceSetConfiguration
virtual std::string GetSdkVersion()
vtkPlusOpenHapticsDevice()
virtual PlusStatus ReadConfiguration(vtkXMLDataElement *config)
PlusStatus NotifyConfigured()
PlusStatus GetToolByPortName(const char *aPortName, vtkPlusDataSource *&aSource)
PlusStatus GetMatrix(vtkMatrix4x4 *outputMatrix)
~vtkPlusOpenHapticsDevice()
#define XML_FIND_DEVICE_ELEMENT_REQUIRED_FOR_READING(deviceConfig, rootConfigElement)
virtual ItemStatus GetLatestStreamBufferItem(StreamBufferItem *bufferItem)
bool StartThreadForInternalUpdates
PlusStatus InternalDisconnect()
virtual PlusStatus WriteConfiguration(vtkXMLDataElement *config)
PlusStatus InternalConnect()
Interface to a 3D positioning tool, video source, or generalized data stream.