7 #include "PlusConfigure.h" 11 #include "vtkMatrix4x4.h" 13 #include "vtkObjectFactory.h" 23 this->OrientationSensorToTracker = vtkMatrix4x4::New();
24 this->OrientationSensorTool = NULL;
30 this->OrientationSensorToTracker->Delete();
31 this->OrientationSensorToTracker = NULL;
37 LOG_TRACE(
"vtkPlusMicrochipTracker::Connect");
42 this->OrientationSensorTool = NULL;
49 LOG_TRACE(
"vtkPlusMicrochipTracker::Disconnect");
54 this->OrientationSensorTool = NULL;
62 igsioLockGuard<vtkIGSIORecursiveCriticalSection> updateMutexGuardedLock(this->
Mutex);
64 std::string textReceived;
65 double unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
69 double startTime = vtkIGSIOAccurateTimer::GetSystemTime();
72 unfilteredTimestamp = vtkIGSIOAccurateTimer::GetSystemTime();
75 if (vtkIGSIOAccurateTimer::GetSystemTime() - startTime > maxReadTimeSec)
82 if (this->OrientationSensorTool != NULL)
86 double rotationQuat[4] = {1, 0, 0, 0};
92 double rotationMatrix[3][3] = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
93 vtkMath::QuaternionToMatrix3x3(rotationQuat, rotationMatrix);
94 for (
int row = 0; row < 3; row++)
96 for (
int col = 0; col < 3; col++)
98 this->OrientationSensorToTracker->Element[row][col] = rotationMatrix[row][col];
104 unsigned long frameNumber = this->OrientationSensorTool->GetFrameNumber() + 1 ;
105 ToolTimeStampedUpdate(this->OrientationSensorTool->GetId(), this->OrientationSensorToTracker, TOOL_OK, frameNumber, unfilteredTimestamp);
117 if (textReceived.size() < 35)
119 LOG_ERROR(
"Failed to parse message: " << textReceived <<
" (expected longer message)")
122 rotationQuat[1] = atof(textReceived.substr(2, 6).c_str());
123 rotationQuat[2] = atof(textReceived.substr(11, 6).c_str());
124 rotationQuat[3] = atof(textReceived.substr(20, 6).c_str());
125 rotationQuat[0] = atof(textReceived.substr(29, 6).c_str());
~vtkPlusMicrochipTracker()
virtual PlusStatus ToolTimeStampedUpdate(const std::string &aToolSourceId, vtkMatrix4x4 *matrix, ToolStatus status, unsigned long frameNumber, double unfilteredtimestamp, const igsioFieldMapType *customFields=NULL)
PlusStatus InternalConnect()
Interface for acquiring data from a Microchip MM7150 motion module.
PlusStatus GetToolByPortName(const char *aPortName, vtkPlusDataSource *&aSource)
PlusStatus InternalUpdate()
vtkStandardNewMacro(vtkPlusMicrochipTracker)
PlusStatus InternalConnect()
unsigned int GetNumberOfBytesAvailableForReading() const
vtkSmartPointer< vtkIGSIORecursiveCriticalSection > Mutex
virtual PlusStatus InternalDisconnect()
virtual PlusStatus InternalDisconnect()
virtual PlusStatus ReceiveResponse(std::string &textReceived, ReplyTermination acceptReply=REQUIRE_LINE_ENDING)
PlusStatus ParseMessage(std::string &textReceived, double *rotationQuat)
vtkPlusMicrochipTracker()