Basic data output for SDK 2.0

Post questions, comments and feedback to our 3Dconnexion Windows Development Team.

Moderator: Moderators

Post Reply
wpence
Posts: 5
Joined: Tue Jan 05, 2010 7:32 am
Location: Tampa, FL

Basic data output for SDK 2.0

Post by wpence »

Hello, after reading through the documentation for SDK 2.0 using siapp.lib and spwmath.lib, I created the following simple test program to attempt to just get some sample data from my Spaceball 4000 FLX and print it out to the console:

#include <stdio>
#include <math>
#include <windows>
#include <float>
#include <stdlib>
#include <iostream>
#include <windows>

#include "spwmacro.h" /* Common macros used by SpaceWare functions. */
#include "si.h" /* Required for any SpaceWare support within an app.*/
#include "siapp.h" /* Required for siapp.lib symbols */

using namespace std;

int main ()
{
SiHdl devHandle; //Spaceball device handle
SiOpenData oData;
SiGetEventData pData;
SiSpwEvent pEvent;
double tx=0, ty=0, tz=0, rx=0, ry=0, rz=0;

SiInitialize (); //Initializes the spaceball libraries

devHandle = SiOpen ("application", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData);

for (int i=0; i<10; i++)
{
SiGetEvent (devHandle, 0, &pData, &pEvent); //Get data

//Put data into local variables
pEvent.u.spwData.mData[0] = tx;
pEvent.u.spwData.mData[1] = ty;
pEvent.u.spwData.mData[2] = tz;
pEvent.u.spwData.mData[3] = rx;
pEvent.u.spwData.mData[4] = ry;
pEvent.u.spwData.mData[5] = rz;

//Print it all out for each iteration
cout << endl << "Iteration " << i << endl;
cout << "TX " << tx << endl;
cout << "TY " << ty << endl;
cout << "TZ " << tz << endl;
cout << "RX " << rx << endl;
cout << "RY " << ry << endl;
cout << "RZ " << rz << endl;
}

return 0;
}

The code compiles and runs just fine, but it does not output any data from the Spaceball, it only just outputs a bunch of 0's. I am using Visual Studio C++ 2008 to build and am just running the application in command prompt. Am I missing something? Thanks!
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

I don't see that you are initializing your oData structure. That must be done with a valid window handle.

You are also not processing any events. Your app will be sent device events via the Windows event mechanism to the handle you specify in oData. You need to filter out 3Dx events from that event stream.

It is far easier to take one of the demos from the SDK and hack out what you don't need, than start from scratch as you are trying to do here.
wpence
Posts: 5
Joined: Tue Jan 05, 2010 7:32 am
Location: Tampa, FL

Post by wpence »

Thank you for the tips. I have modified the code and read through more of the documentation and I still can't get my code to output anything; I am including it below. This is being developed and compiled in Visual Studio 2008 in C++. We have a wheelchair-mounted robotic arm project that we have developed code for, so in essence what we're trying to do is get the spaceball to give us the translations and rotations (tx, ty, tz, rx, ry, rz) through the console so that we can include code into our current code that calculates the movements for each of the joints. All of the sample code seems to involve simply outputting this information to a window, which is not useful for our purposes since we are doing nothing GUI-related. Should I be coming at this from a different angle? Thanks,

#include <stdio>
#include <math>
#include <windows>
#include <float>
#include <stdlib>
#include <iostream>
#include <windows>
#include "spwmacro.h" /* Common macros used by SpaceWare functions. */
#include "si.h" /* Required for any SpaceWare support within an app.*/
#include "siapp.h" /* Required for siapp.lib symbols */

using namespace std;

int main ()
{
SiHdl devHandle; //Handle for spaceball device
SiSpwEvent Event; //Event object to read the translations and rotations from spaceball
SiOpenData oData; //Data object to get data from spaceball
SiGetEventData EData; //Data object for SiGetEventWinInit()
//double tx, ty, tz, rx, ry, rz; //Translations and rotations
int foo=0;
MSG msg;
HWND hWnd;

if (SiInitialize() == SPW_ERROR)
{
cerr << "Error initializing the spaceball. Program will exit." << endl;
SiTerminate();
exit(1);
}

SiOpenWinInit(&oData, hWnd);
SiSetUiMode(devHandle, SI_UI_NO_CONTROLS);

//Intitialize spaceball
devHandle = SiOpen ("application", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &oData);

//Initializes library for calling getEvent in Windows
SiGetEventWinInit(&EData, msg.message, msg.wParam, msg.lParam);

cout << "Spaceball has been initialized." << endl;

while (foo==0)
{
cout << "In while" << endl;
//Get event data from the spaceball
if (SiGetEvent (devHandle, 0, &EData, &Event) == SI_IS_EVENT)
{
cout << "In for" << endl;
//Print it all out for each motion event
cout << "TX " << Event.u.spwData.mData[SI_TX] << endl;
cout << "TY " << Event.u.spwData.mData[SI_TY] << endl;
cout << "TZ " << Event.u.spwData.mData[SI_TZ] << endl;
cout << "RX " << Event.u.spwData.mData[SI_RX] << endl;
cout << "RY " << Event.u.spwData.mData[SI_RY] << endl;
cout << "RZ " << Event.u.spwData.mData[SI_RZ] << endl;
}
Sleep(1000);
}

return 0;
}
jwick
Moderator
Moderator
Posts: 3341
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Post by jwick »

You aren't initializing that hwnd to anything. You need a window to use this API.

If you truly don't have a window, and are not going to have one, I suggest you use a different API, like HID. That API doesn't require a window. There are examples on our ftp site.

These other APIs only work with USB devices. I suggest you switch to a USB device. The Spaceball 4000FLX was discontinued ages ago. You shouldn't waste time developing support for a device that your end users won't even be able to buy.
Post Reply