36 #include "DTrackSDK.hpp" 46 static void output_to_console();
47 static bool data_error_to_console();
48 static void messages_to_console();
54 int main(
int argc,
char** argv )
58 std::cout <<
"Usage: example_communicating <server host> <data port>" << std::endl;
62 std::istringstream portstream( argv[ 2 ] );
66 if ( portstream.fail() )
68 std::cout <<
"invalid port '" << argv[ 2 ] <<
"'" << std::endl;
74 dt =
new DTrackSDK( (
const char *)argv[ 1 ], port );
78 std::cout <<
"DTrackSDK init error" << std::endl;
82 std::cout <<
"connected to ATC '" << argv[ 1 ] <<
"', listening at local data port " << dt->
getDataPort() << std::endl;
90 std::cout <<
"Full access to ATC required!" << std::endl;
91 data_error_to_console();
92 messages_to_console();
100 bool isOk = dt->
getParam(
"config",
"active_config", par );
103 std::cout <<
"Reading parameter failed!" << std::endl;
104 data_error_to_console();
105 messages_to_console();
109 std::cout <<
" active configuration: '" << par <<
"'" << std::endl;
115 std::cout <<
"Measurement start failed!" << std::endl;
116 data_error_to_console();
117 messages_to_console();
123 while ( count++ < 1000 )
131 data_error_to_console();
132 messages_to_console();
135 if ( count % 100 == 1 )
136 messages_to_console();
140 messages_to_console();
150 static void output_to_console()
152 std::cout.precision( 3 );
153 std::cout.setf( std::ios::fixed, std::ios::floatfield );
173 std::cout <<
"DTrackSDK fatal error: invalid body id " << i << std::endl;
179 std::cout <<
"bod " << body->
id <<
" not tracked" << std::endl;
183 std::cout <<
"bod " << body->
id <<
" qu " << body->
quality 184 <<
" loc " << body->
loc[ 0 ] <<
" " << body->
loc[ 1 ] <<
" " << body->
loc[ 2 ]
185 <<
" rot " << body->
rot[ 0 ] <<
" " << body->
rot[ 1 ] <<
" " << body->
rot[ 2 ]
186 <<
" " << body->
rot[ 3 ] <<
" " << body->
rot[ 4 ] <<
" " << body->
rot[ 5 ]
187 <<
" " << body->
rot[ 6 ] <<
" " << body->
rot[ 7 ] <<
" " << body->
rot[ 8 ]
191 std::cout <<
"bod " << body->
id <<
" quatw " << quat.
w 192 <<
" quatxyz " << quat.
x <<
" " << quat.
y <<
" " << quat.
z << std::endl;
200 if ( flystick == NULL )
202 std::cout <<
"DTrackSDK fatal error: invalid Flystick id " << i << std::endl;
208 std::cout <<
"fly " << flystick->
id <<
" not tracked" << std::endl;
212 std::cout <<
"flystick " << flystick->
id <<
" qu " << flystick->
quality 213 <<
" loc " << flystick->
loc[ 0 ] <<
" " << flystick->
loc[ 1 ] <<
" " << flystick->
loc[ 2 ]
214 <<
" rot " << flystick->
rot[ 0 ] <<
" " << flystick->
rot[ 1 ] <<
" " << flystick->
rot[ 2 ]
215 <<
" " << flystick->
rot[ 3 ] <<
" " << flystick->
rot[ 4 ] <<
" " << flystick->
rot[ 5 ]
216 <<
" " << flystick->
rot[ 6 ] <<
" " << flystick->
rot[ 7 ] <<
" " << flystick->
rot[ 8 ]
221 for (
int j = 0; j < flystick->
num_button; j++ )
223 std::cout <<
" " << flystick->
button[ j ];
228 std::cout <<
" " << flystick->
joystick[ j ];
230 std::cout << std::endl;
237 if ( meatool == NULL )
239 std::cout <<
"DTrackSDK fatal error: invalid Measurement tool id " << i << std::endl;
245 std::cout <<
"mea " << meatool->
id <<
" not tracked" << std::endl;
249 std::cout <<
"mea " << meatool->
id <<
" qu " << meatool->
quality 250 <<
" loc " << meatool->
loc[ 0 ] <<
" " << meatool->
loc[ 1 ] <<
" " << meatool->
loc[ 2 ]
251 <<
" rot " << meatool->
rot[ 0 ] <<
" " << meatool->
rot[ 1 ] <<
" " << meatool->
rot[ 2 ]
252 <<
" " << meatool->
rot[ 3 ] <<
" " << meatool->
rot[ 4 ] <<
" " << meatool->
rot[ 5 ]
253 <<
" " << meatool->
rot[ 6 ] <<
" " << meatool->
rot[ 7 ] <<
" " << meatool->
rot[ 8 ]
259 std::cout <<
" radius " << meatool->
tipradius << std::endl;
265 for (
int j = 0; j < meatool->
num_button; j++ )
267 std::cout <<
" " << meatool->
button[ j ];
269 std::cout << std::endl;
277 if ( mearef == NULL )
279 std::cout <<
"DTrackSDK fatal error: invalid Measurement reference id " << i << std::endl;
285 std::cout <<
"mearef " << mearef->
id <<
" not tracked" << std::endl;
289 std::cout <<
"mearef " << mearef->
id <<
" qu " << mearef->
quality 290 <<
" loc " << mearef->
loc[ 0 ] <<
" " << mearef->
loc[ 1 ] <<
" " << mearef->
loc[ 2 ]
291 <<
" rot " << mearef->
rot[ 0 ] <<
" " << mearef->
rot[ 1 ] <<
" " << mearef->
rot[ 2 ]
292 <<
" " << mearef->
rot[ 3 ] <<
" " << mearef->
rot[ 4 ] <<
" " << mearef->
rot[ 5 ]
293 <<
" " << mearef->
rot[ 6 ] <<
" " << mearef->
rot[ 7 ] <<
" " << mearef->
rot[ 8 ]
302 if ( marker == NULL )
304 std::cout <<
"DTrackSDK fatal error: invalid marker index " << i << std::endl;
308 std::cout <<
"mar " << marker->
id <<
" qu " << marker->
quality 309 <<
" loc " << marker->
loc[ 0 ] <<
" " << marker->
loc[ 1 ] <<
" " << marker->
loc[ 2 ]
319 std::cout <<
"DTrackSDK fatal error: invalid FINGERTRACKING id " << i << std::endl;
325 std::cout <<
"hand " << hand->
id <<
" not tracked" << std::endl;
329 std::cout <<
"hand " << hand->
id <<
" qu " << hand->
quality 330 <<
" lr " << ( ( hand->
lr == 0 ) ?
"left" :
"right") <<
" nf " << hand->
nfinger 331 <<
" loc " << hand->
loc[ 0 ] <<
" " << hand->
loc[ 1 ] <<
" " << hand->
loc[ 2 ]
332 <<
" rot " << hand->
rot[ 0 ] <<
" " << hand->
rot[ 1 ] <<
" " << hand->
rot[ 2 ]
333 <<
" " << hand->
rot[ 3 ] <<
" " << hand->
rot[ 4 ] <<
" " << hand->
rot[ 5 ]
334 <<
" " << hand->
rot[ 6 ] <<
" " << hand->
rot[ 7 ] <<
" " << hand->
rot[ 8 ]
337 for (
int j = 0; j < hand->
nfinger; j++ )
339 std::cout <<
" fi " << j
345 std::cout <<
" fi " << j
358 std::cout <<
"no human model data" << std::endl;
366 std::cout <<
"DTrackSDK fatal error: invalid human model id " << i << std::endl;
372 std::cout <<
"human " << human->
id <<
" not tracked" << std::endl;
376 std::cout <<
"human " << human->
id <<
" num joints " << human->
num_joints << std::endl;
381 std::cout <<
"joint " << human->
joint[ j ].
id <<
" not tracked" << std::endl;
394 std::cout << std::endl;
400 std::cout <<
"no inertial body data" << std::endl;
406 if ( inertial == NULL )
408 std::cout <<
"DTrackSDK fatal error: invalid hybrid body id " << i << std::endl;
412 std::cout <<
" inertial body " << inertial->
id <<
" st " << inertial->
st <<
" error " << inertial->
error << std::endl;
415 std::cout <<
" loc " << inertial->
loc[ 0 ] <<
" " << inertial->
loc[ 1 ] <<
" " << inertial->
loc[ 2 ]
416 <<
" rot " << inertial->
rot[ 0 ] <<
" " << inertial->
rot[ 1 ] <<
" " << inertial->
rot[ 2 ]
417 <<
" " << inertial->
rot[ 3 ] <<
" " << inertial->
rot[ 4 ] <<
" " << inertial->
rot[ 5 ]
418 <<
" " << inertial->
rot[ 6 ] <<
" " << inertial->
rot[ 7 ] <<
" " << inertial->
rot[ 8 ]
426 std::cout <<
"no system status data" << std::endl;
431 if ( status == NULL )
433 std::cout <<
"DTrackSDK fatal error: invalid system status" << std::endl;
438 std::cout <<
"status gen nc " << status->
numCameras 447 for (
int i = 0; i < status->
numCameras; i++ )
449 std::cout <<
"status cam " << status->
cameraStatus[ i ].idCamera
451 <<
" nu " << status->
cameraStatus[ i ].numReflectionsUsed
452 <<
" mi " << status->
cameraStatus[ i ].maxIntensity << std::endl;
464 static bool data_error_to_console()
472 std::cout <<
"--- timeout while waiting for tracking data" << std::endl;
476 std::cout <<
"--- error while receiving tracking data" << std::endl;
480 std::cout <<
"--- error while parsing tracking data" << std::endl;
490 std::cout <<
"--- timeout while waiting for Controller command" << std::endl;
494 std::cout <<
"--- error while receiving Controller command" << std::endl;
498 std::cout <<
"--- error while parsing Controller command" << std::endl;
511 static void messages_to_console()
double getTimeStamp() const
Get timestamp since midnight.
int getNumFlyStick() const
Get number of calibrated Flysticks.
double loc[3]
Location (in [mm])
const DTrackFlyStick * getFlyStick(int id) const
Get Flystick data.
const DTrackMeaTool * getMeaTool(int id) const
Get Measurement Tool data.
int getNumBody() const
Get number of calibrated standard bodies (as far as known).
bool receive()
Receive and process one tracking data packet.
bool isStatusAvailable() const
Returns if system status data is available.
double rot[9]
Rotation matrix (column-wise)
double loc[3]
Location (in [mm])
unsigned short getDataPort() const
Get UDP data port where tracking data is received.
int numOtherWarningMessages
Number of other warning messages (since booting)
int lr
Left (0) or right (1) hand.
bool isCommandInterfaceFullAccess()
Returns if TCP connection has full access for DTrack2/DTRACK3 commands.
double loc[3]
Location (in [mm])
Single marker data (3DOF).
double x
Quaternion component x.
double quality
Quality (0.0 <= qu <= 1.0, no tracking if -1.0)
int getNumHand() const
Get number of calibrated A.R.T. FINGERTRACKING hands (as far as known).
A.R.T. Flystick data (6DOF + buttons).
Hybrid (optical-inertial) body data (6DOF).
double error
Drift error estimate (only during inertial tracking, in [deg])
bool isTracked() const
Returns if joint is currently tracked.
std::vector< DTrackCameraStatus > cameraStatus
Camera status.
double quality
Quality of joint (0.0 <= qu <= 1.0, no tracking if -1.0)
A.R.T. FINGERTRACKING hand data (6DOF + fingers).
int numInfoMessages
Number of info messages (since booting)
int num_joints
Number of joints.
int numTrackedBodies
Number of currently tracked 6DOF bodies.
const DTrackBody * getBody(int id) const
Get standard body data.
bool isTracked() const
Returns if Measurement Tool reference is currently tracked.
struct DTrackSDK_Datatypes::DTrackHuman::DTrackJoint joint[DTRACKSDK_HUMAN_MAX_JOINTS]
Joint data.
double y
Quaternion component y.
int numCameras
Number of cameras.
int nfinger
Number of fingers (maximum 5)
double quality
Quality (0.0 <= qu <= 1.0, no tracking if -1.0)
double rot[9]
Rotation matrix of outermost phalanx (column-wise)
double loc[3]
Location of tip (in [mm])
const DTrackMeaRef * getMeaRef(int id) const
Get Measurement Tool reference data.
bool getParam(const std::string &category, const std::string &name, std::string &value)
Get DTrack2/DTRACK3 parameter.
DTrack SDK main class derived from DTrackParser.
int id
ID number (starting with 1)
const DTrackMarker * getMarker(int index) const
Get single marker data.
unsigned int getLatencyUsec() const
Get latency (delay between exposure and sending UDP data in Controller).
int getNumMeaRef() const
Get number of calibrated Measurement Tool references.
double anglephalanx[2]
Angle between phalanxes (order: outermost, innermost; in [deg])
int st
State of hybrid body (0: not tracked, 1: inertial tracking, 2: optical tracking, 3: inertial and opti...
bool isTracked() const
Returns if body is currently tracked.
std::string getMessageStatus() const
Get status of last DTrack2/DTRACK3 event message.
int numCameraWarningMessages
Number of camera-related warning messages (since booting)
int id
ID number of joint (starting with 0)
int numOtherErrorMessages
Number of other error messages (since booting)
double lengthphalanx[3]
Length of phalanxes (order: outermost, middle, innermost; in [mm])
int getNumMarker() const
Get number of tracked single markers.
double loc[3]
Location of joint (in [mm])
unsigned int getFrameCounter() const
Get frame counter.
double rot[9]
Rotation matrix (column-wise)
unsigned int getTimeStampUsec() const
Get timestamp since Unix epoch (1970-01-01 00:00:00), microseconds.
int id
ID number (starting with 0)
const DTrackHuman * getHuman(int id) const
Get ART-Human model data.
int id
ID number (starting with 0)
Errors getLastServerError() const
Get last error at exchanging commands with Controller (command transmission).
bool isCommandInterfaceValid() const
Returns if TCP connection for DTrack2/DTRACK3 commands is active.
double quality
Quality (0.0 <= qu <= 1.0, no tracking if -1.0)
double quality
Quality (0.0 <= qu <= 1.0, no tracking if -1.0)
unsigned int getTimeStampSec() const
Get timestamp since Unix epoch (1970-01-01 00:00:00), seconds.
double loc[3]
Location of back of the hand (in [mm])
std::string getMessageMsg() const
Get message text of last DTrack2/DTRACK3 event message.
const DTrackHand * getHand(int id) const
Get A.R.T. FINGERTRACKING hand data.
double quality
Quality (0.0 <= qu <= 1.0)
int num_joystick
Number of joystick values.
int id
ID number (starting with 0)
int id
ID number (starting with 0)
Error while parsing command.
int num_button
Number of buttons.
bool isDataInterfaceValid() const
Returns if UDP socket is open to receive tracking data on local machine.
double rot[9]
Rotation matrix of joint (column-wise) in relation to room coordinate system.
bool getMessage()
Get DTrack2/DTRACK3 event message from the Controller.
const DTrackInertial * getInertial(int id) const
Get hybrid (optical-inertial) data.
Errors getLastDataError() const
Get last error at receiving tracking data (data transmission).
int numCameraErrorMessages
Number of camera-related error messages (since booting)
int getNumInertial() const
Get number of calibrated hybrid (optical-inertial) bodies.
int button[DTRACKSDK_FLYSTICK_MAX_BUTTON]
Button state (1 pressed, 0 not pressed): 0 front, 1..n-1 right to left.
bool stopMeasurement()
Stop measurement.
bool startMeasurement()
Start measurement.
const DTrackStatus * getStatus() const
Get system status data.
bool isTracked() const
Returns if human model is currently tracked.
double rot[9]
Rotation matrix of back of the hand (column-wise)
Measurement Tool reference data (6DOF).
double w
Quaternion component w.
double z
Quaternion component z.
double rot[9]
Rotation matrix (column-wise)
struct DTrackSDK_Datatypes::DTrackHand::DTrackFinger finger[DTRACKSDK_HAND_MAX_FINGER]
Finger data (order: thumb, index finger, middle finger, ...)
DTrackQuaternion getQuaternion() const
Returns rotation as quaternion.
bool isTracked() const
Returns if Flystick is currently tracked.
double radiustip
Radius of tip (in [mm])
double rot[9]
Rotation matrix (column-wise)
int getNumHuman() const
Get number of calibrated ART-Human models.
bool isTracked() const
Returns if hand is currently tracked.
int numTrackedMarkers
Number of currently found additional 3DOF markers.
double loc[3]
Location (in [mm])
Standard body data (6DOF).
double loc[3]
Location (in [mm])
double joystick[DTRACKSDK_FLYSTICK_MAX_JOYSTICK]
Joystick value (-1.0 <= joystick <= 1.0); 0 horizontal, 1 vertical.
bool isTracked() const
Returns if body is currently tracked.
int id
ID number (starting with 0)
int id
ID number of human model (starting with 0)
ART-Human model (joints (6DOF) including optional Fingertracking).
int getNumMeaTool() const
Get number of calibrated Measurement Tools.