Beginner help Space Mouse Programming

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

Moderator: Moderators

Post Reply
sm_demon
Posts: 7
Joined: Tue Jan 20, 2015 12:52 pm

Beginner help Space Mouse Programming

Post by sm_demon »

Hi all,

I am new to space mouse environment and trying to build a project where want to control different motors for different input axis.

I am a mechanical engineer by profession so have limited skills when it comes to expertly coding an application but have experience in electronics and hardware. After lot of research I found that C++ (Java is out of my skills) seems to be ideal way to proceed ahead.
Right now I am stuck at getting signals out from space mouse, quick search showed that each message is 7 bytes = Rotation or Translation, Tx,Ty,Tz, Rx,Ry,Rz.

Any suggestions on how to approach the problem in a manner that's easy for a beginner like me. I have the windows SDK, going through the functions implemented but I'm all over the place. If I may have missed a post before or you guys feel another post answers my concerns feel free to direct me there.

Hope to hear from you soon, once I finish my project(hopefully), I will myself write a short intro for someone starting out.

thanks
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: Beginner help Space Mouse Programming

Post by jwick »

There is a demo in our SDK, 3DxTest, the just gets the data from the device and prints it to a window. You can hack that to do whatever you want.
You can also ask the driver to handle the data for your process in any custom way you like, but that is for later.

For now you need to have a window (the 3DxTest window is a good starting point).

When you get the data you need to send it to your motor interface.
You will get +/- 350 values as you push left/right, in/out, twist, etc (2 directions along 6 axes). When you release pressure on the cap you will get zeroes.
I'm assuming you can convert these values in to something useful for the motors.

Start with just one axis at a time.
You will probably get data way faster than your motors can respond.

IMO, it is not useful to try to use all 6 axes at once unless you can map the movement of the 3D mouse cap to the movement of some point in 3D space. E.g., a robot end-effector. Randomly assigning 6 axes to 6 random motors will be impossible to control.
sm_demon
Posts: 7
Joined: Tue Jan 20, 2015 12:52 pm

Re: Beginner help Space Mouse Programming

Post by sm_demon »

jwick,

thanks for pointing me in right direction, it did help me somewhat to understand a bit, I am no expert in win api handling so some functions took time to understand with multiple structs within structs didn't make it easier.

I played around a bit and wrote a small code that just takes the value in the direction as user thinks to move is ( 6 axes split into 6 discrete values, so if someone tilts fwd/bkwd, output is only in Rx), all other axes are set to zero. This is intuitively how we wish to use the motors, will utilize the data effectively to mould into motor values.

Next step, you mentioned something about handling at driver level (maybe ready for that), also I will search myself too but still, any good way to import data being spit onto window somewhere else?

Thanks for the quick reply though

P.S. - the code could use some re-touches, I do things in mathematical way so not the best implementer of beautiful code...

Regards,

Code: Select all

/*----------------------------------------------------------------------
* Function: SbMotionEvent()
*
* Description:
*    This function receives motion information and prints out the info 
*    on screen.
*    
*
* Args:
*    SiSpwEvent *pEvent   Containts Data from a 3D mouse Event
*
* Return Value:
*    NONE
*
*----------------------------------------------------------------------*/
void SbMotionEvent(SiSpwEvent *pEvent)
{	
  TCHAR buff0[30];                            /* text buffer for TX */
  TCHAR buff1[30];                            /* text buffer for TY */
  TCHAR buff2[30];                            /* text buffer for TZ */
  TCHAR buff3[30];                            /* text buffer for RX */
  TCHAR buff4[30];                            /* text buffer for RY */
  TCHAR buff5[30];                            /* text buffer for RZ */ 
  TCHAR buff6[30];                            /* text buffer for Period */ 
  



  int len0,len1,len2,len3,len4,len5,len6;	   /* length of each buffer */


  /* put the actual ball data into the buffers */
  len0= _stprintf( buff0, _T("TX: %d         "), pEvent->u.spwData.mData[SI_TX] );
  len1= _stprintf( buff1, _T("TY: %d         "), pEvent->u.spwData.mData[SI_TY] );
  len2= _stprintf( buff2, _T("TZ: %d         "), pEvent->u.spwData.mData[SI_TZ] );
  len3= _stprintf( buff3, _T("RX: %d         "), pEvent->u.spwData.mData[SI_RX] );
  len4= _stprintf( buff4, _T("RY: %d         "), pEvent->u.spwData.mData[SI_RY] );
  len5= _stprintf( buff5, _T("RZ: %d         "), pEvent->u.spwData.mData[SI_RZ] );
  len6= _stprintf( buff6, _T(" P: %d         "), pEvent->u.spwData.period);
     
  // choosing abs value to decide which motion excecuted

  int aTx = abs(len0);
  int aTy = abs(len1);
  int aTz = abs(len2);
  int aRx = abs(len3);
  int aRy = abs(len4);
  int aRz = abs(len5);

  
	// getting max out of the list
  
	int Nbrs[6] = { aTx, aTy, aTz, aRx, aRy, aRz };
	int Maximum = Max(Nbrs, 6);
	 

	 // Once max decided, evrything else set to zero, only 1 axis activated
	
	 if (Maximum == aTx){
		 len1 = len2 = len3 = len4 = len5 = 0;
	 }
	 if (Maximum == aTy){
		 len0 = len2 = len3 = len4 = len5 = 0;
	 }
	 if (Maximum == aTz){
		 len0 = len1 = len3 = len4 = len5 = 0;
	 }
	 if (Maximum == aRx){
		 len0 = len1 = len2 = len4 = len5 = 0;
	 }
	 if (Maximum == aRy){
		 len0 = len1 = len2 = len3 = len5 = 0;
	 }
	 if (Maximum == aRz){
		 len0 = len1 = len2 = len3 = len4 = 0;
	 }
	

	 /* get handle of our window to draw on */
	 hdc = GetDC(hWndMain);


  /* print buffers */
  TCHAR *buf = _T("Motion Event              ");
  TextOut(hdc,  0 ,   0, buf, (int)_tcslen(buf));
  TextOut(hdc,  0 ,  20, devicename, (int)_tcslen(devicename));
  TextOut(hdc, 15 , 100, buff0, len0);
  TextOut(hdc, 15 , 120, buff1, len1);
  TextOut(hdc, 15 , 140, buff2, len2);
  TextOut(hdc, 15 , 160, buff3, len3);
  TextOut(hdc, 15 , 180, buff4, len4);
  TextOut(hdc, 15 , 200, buff5, len5);
  TextOut(hdc, 15 , 220, buff6, len6);

  /* Dump to debugger output buffer to get a running log */
  _RPT3(_CRT_WARN,"%S %S %S",  buff0, buff1, buff2);
  _RPT3(_CRT_WARN," %S %S %S", buff3, buff4, buff5);
  _RPT1(_CRT_WARN," %S\n", buff6);

  // Also dump to stdout for a searchable log
  printf("%d %d %d %d %d %d\n",
    pEvent->u.spwData.mData[SI_TX],
    pEvent->u.spwData.mData[SI_TY],
    pEvent->u.spwData.mData[SI_TZ],
    pEvent->u.spwData.mData[SI_RX],
    pEvent->u.spwData.mData[SI_RY],
    pEvent->u.spwData.mData[SI_RZ]);

  /*release our window handle */ 
  ReleaseDC(hWndMain,hdc);
}
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: Beginner help Space Mouse Programming

Post by jwick »

The driver will do that filter for you. It has many filters, but the "Dominant" filter will do what you have done here.

You can define a function in a DLL or an executable/script for the driver to call when something happens (e.g., the user moves the cap or presses a button). In that code, you can use whatever communication mechanism is convenient for you to talk to your motor interface. All this is doing is moving the code around. You still have to write the code to communicate with the motor interface.

You can see DLL functions being used in the winword.xml file. If this is of interest, I can provide more details.

The driver can also output joystick information. Sometimes people have software that already works with joysticks.
sm_demon
Posts: 7
Joined: Tue Jan 20, 2015 12:52 pm

Re: Beginner help Space Mouse Programming

Post by sm_demon »

Yes, I would like to know more about it because I couldn't locate the file in SDK (maybe I'm wrong)

And since you might have had this question in the future, which interface do you recommend for a beginner like me to adopt while communicating to the motors?

Thanks
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: Beginner help Space Mouse Programming

Post by jwick »

That depends on what means you have available to communicate with the motor interfaces. There are plenty of options (PC board, parallel port, USB, wifi, BT, ...). The motor hardware will decide.

I would approach it as using 3DxTest as a starting point to develop a GUI for the motors. Having a piece of code in there allows you to do a lot of tweaking to the data which may be required. If you are using motors to move something in the real world, you will definitely want to give a lot of thought to handling error conditions and feedback....so you don't hurt someone or something.
sm_demon
Posts: 7
Joined: Tue Jan 20, 2015 12:52 pm

Re: Beginner help Space Mouse Programming

Post by sm_demon »

I meant to ask between USB and Serial connection, which would be easier to adopt to 3D connexion SDK?
Also about that winword.xml, where do i find it?

We will have a micro-controller board in between, was searching before and saw that USB and serial both are adopted with that, wanna try on a small system first and then scale it up (in regards to your concern, safety of others and mine is of prime importance).
Since I have not done this before, some of questions will be vague but all my expertise will come from the supreme power of the internet!
jwick
Moderator
Moderator
Posts: 3331
Joined: Wed Dec 20, 2006 2:25 pm
Location: USA
Contact:

Re: Beginner help Space Mouse Programming

Post by jwick »

USB or serial to talk to the ucontroller board? It makes no difference. Whichever the ucontroller board vendor recommends. They will provide libraries and samples, just like we did. Your job is to stitch the two together. Probably some of the samples will be easier to use than the others.

The only practical difference between them is that vendors are starting to not putting serial ports on machines. USB might be faster but the speed of the interface is not your controlling factor.

That end of it makes no difference as far as the 3D mouse is concerned.

winword.xml is in the 3DxWinCore/Cfg dir. It isn't relevant to your project at this time.
Post Reply