43 #include "DTrackSDK.hpp" 49 #if defined( _WIN32 ) || defined( WIN32 ) || defined( _WIN64 ) 50 #define OS_WIN // for MS Windows 52 #define OS_UNIX // for Unix (Linux) 58 #if defined( OS_UNIX ) 65 static const int NUMBER_OF_FINGERS = 3;
66 static std::vector< double > strength( NUMBER_OF_FINGERS, 0.0 );
68 static const unsigned int REPEAT_PERIOD = 1000;
69 static unsigned int lastTimeMs;
72 static bool doTactile(
int flystickId,
int handId );
73 static bool data_error_to_console();
74 static void messages_to_console();
75 static unsigned int getTimeMs();
86 int main(
int argc,
char** argv )
90 std::cout <<
"Usage: example_tactile_flystick [<server host/ip>:]<data port> <Flystick id> <hand id>" << std::endl;
94 std::istringstream is( argv[ 2 ] );
98 if ( is.fail() || ( flystickId < 0 ) )
100 std::cout <<
"invalid Flystick ID '" << argv[ 2 ] <<
"'" << std::endl;
109 if ( is.fail() || ( handId < 0 ) )
111 std::cout <<
"invalid hand id '" << argv[ 3 ] <<
"'" << std::endl;
117 dt =
new DTrackSDK( (
const char *)argv[ 1 ] );
121 std::cout <<
"DTrackSDK init error" << std::endl;
125 std::cout <<
"connected to ATC '" << argv[ 1 ] <<
"', listening at local data port " << dt->
getDataPort() << std::endl;
135 std::cout <<
"Full access to ATC required!" << std::endl;
136 data_error_to_console();
137 messages_to_console();
143 lastTimeMs = getTimeMs();
151 std::cout <<
"Measurement start failed!" << std::endl;
152 data_error_to_console();
153 messages_to_console();
168 std::cout <<
"Flystick ID or Hand ID doesn't exist!" << std::endl;
172 if ( ! doTactile( flystickId, handId ) )
177 data_error_to_console();
182 messages_to_console();
190 messages_to_console();
205 static bool doTactile(
int flystickId,
int handId )
210 std::cout <<
"DTrackSDK fatal error: invalid Flystick id " << flystickId << std::endl;
214 if ( fly->
button[ 0 ] != 0 )
219 std::vector< double > newStrength( NUMBER_OF_FINGERS, 0.0 );
221 for (
int i = 0; i < NUMBER_OF_FINGERS; i++ )
223 if ( fly->
button[ i + 1 ] != 0 )
224 newStrength[ i ] = 0.5;
230 newStrength[ 0 ] = joy;
232 else if ( joy < 0.0 )
234 newStrength[ 2 ] = -joy;
240 newStrength[ 1 ] = joy;
246 for (
int i = 0; i < NUMBER_OF_FINGERS; i++ )
248 if ( fabs( newStrength[ i ] - strength[ i ] ) >= 0.01 )
250 strength[ i ] = newStrength[ i ];
255 unsigned int timeMs = getTimeMs();
256 if ( timeMs - lastTimeMs >= REPEAT_PERIOD )
277 static bool data_error_to_console()
285 std::cout <<
"--- timeout while waiting for tracking data" << std::endl;
289 std::cout <<
"--- error while receiving tracking data" << std::endl;
293 std::cout <<
"--- error while parsing tracking data" << std::endl;
303 std::cout <<
"--- timeout while waiting for Controller command" << std::endl;
307 std::cout <<
"--- error while receiving Controller command" << std::endl;
311 std::cout <<
"--- error while parsing Controller command" << std::endl;
324 static void messages_to_console()
338 static unsigned int getTimeMs()
340 #if defined( OS_WIN ) 341 return (
unsigned int )timeGetTime();
343 #if defined( OS_UNIX ) 346 clock_gettime( CLOCK_MONOTONIC, &ts );
348 return (
unsigned int )ts.tv_sec * 1000u + (
unsigned int )ts.tv_nsec / 1000000u;
int getNumFlyStick() const
Get number of calibrated Flysticks.
const DTrackFlyStick * getFlyStick(int id) const
Get Flystick data.
bool receive()
Receive and process one tracking data packet.
unsigned short getDataPort() const
Get UDP data port where tracking data is received.
bool isCommandInterfaceFullAccess()
Returns if TCP connection has full access for DTrack2/DTRACK3 commands.
int getNumHand() const
Get number of calibrated A.R.T. FINGERTRACKING hands (as far as known).
A.R.T. Flystick data (6DOF + buttons).
DTrack SDK main class derived from DTrackParser.
std::string getMessageStatus() const
Get status of last DTrack2/DTRACK3 event message.
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.
std::string getMessageMsg() const
Get message text of last DTrack2/DTRACK3 event message.
Error while parsing command.
bool isDataInterfaceValid() const
Returns if UDP socket is open to receive tracking data on local machine.
bool getMessage()
Get DTrack2/DTRACK3 event message from the Controller.
Errors getLastDataError() const
Get last error at receiving tracking data (data transmission).
bool tactileHandOff(int handId, int numFinger)
Send tactile FINGERTRACKING command to turn off tactile feedback on all fingers of a specific hand...
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.
double joystick[DTRACKSDK_FLYSTICK_MAX_JOYSTICK]
Joystick value (-1.0 <= joystick <= 1.0); 0 horizontal, 1 vertical.
bool tactileHand(int handId, const std::vector< double > &strength)
Send tactile FINGERTRACKING command to set tactile feedback on all fingers of a specific hand...