Need a quick intro on using the com port

For general discussion related FlowStone
Post Reply
Asbjørn
Posts: 45
Joined: Thu Sep 16, 2010 11:51 am

Need a quick intro on using the com port

Post by Asbjørn »

I got myself an old serial SpaceBall 4000FLX because it doesnt seem like Flowstone will get support for the 3DConnexxion Space Navigator USB.

I found a document describing the protocol it uses, but I have no experience with the com port. I would really appreciate it if you could make me a small example using one or two of the commands in this document so I can understand how it works.

http://lists.unc.edu/read/attachment/1682004/5/a4_public.1.20.doc

Thanks!
Embedded
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

Re: Need a quick intro on using the com port

Post by Embedded »

Here you go!

The only thing you need to set is the correct Com port number. On some OS only Com 1-8 work, so you might have to force the comport number in this range in the device manager.

I have added the Beep command and the Data Enable so that the device will send positional data etc.

Let me know if it works?
Attachments
SpaceBall Test.fsm
(508 Bytes) Downloaded 1516 times
Asbjørn
Posts: 45
Joined: Thu Sep 16, 2010 11:51 am

Re: Need a quick intro on using the com port

Post by Asbjørn »

It works perfectly! Thank you! :D
Now I'll try to get the different buttons on the device working, and then try to decode the positional data from the ball. I'll post the result.

If anyone else needs a 6 DOF 3D "mouse", they are really cheap on ebay: http://shop.ebay.com/i.html?_from=R40&_trksid=p5197.m570.l1313&_nkw=spaceball+4000&_sacat=See-All-Categories
Asbjørn
Posts: 45
Joined: Thu Sep 16, 2010 11:51 am

Re: Need a quick intro on using the com port

Post by Asbjørn »

Ok, I got all of the buttons and the send packets working! It's not perfect, it freaks out if more than one button is pressed at the same time, and it could probably be done with less components than I used.

I started working on the ball data, that's the difficult part. I figured out how to separate the different axes, but the data is confusing.

The protocol document says this about ball data:

Code: Select all

4.2.2   Ball Data
Description:   Whenever the ball is moved, a packet is generated by the Spaceball.  This packet contains data about the movement data for the Spaceball.
In order to receive a data packet, the “Enable Data” packet has to be sent first.
Packet Header:   D (0x44)
Packet Data:   Dppxxyyzzrruuvv (each letter stands for 1 byte)
Data Format:   pp   Period of data.  This is the number of 1/16th milliseconds since the last ball data packet.
   xx…zz   Translational forces.
   rr…vv   Rotational forces (torque).
      Actual force and torque values are 16-bit signed integers.
The first byte is the higher significant byte of the 16 bit signed integer, the second byte is the lower significant byte. Decoding to a 16bit signed integer can be done like this:
signed int ForceX = ( packet[3] << 8) | (packet[4]);

The resolution is 160 mNm and 4.4mNm for force and torque.  This results in a force and torque range of +/- 20.48 N and +/- 0.5632 mNm.  Positive x is to the right, +y is up and +z is upwards.  Positive torque values are clockwise as viewed from the center of the ball out along the positive force axes. 


Period of data: What do I need this for?

I need help dumbing down this: "Decoding to a 16bit signed integer can be done like this:
signed int ForceX = ( packet[3] << 8) | (packet[4]);"
Attachments
SpaceBall Test 2.fsm
(100.13 KiB) Downloaded 1523 times
Asbjørn
Posts: 45
Joined: Thu Sep 16, 2010 11:51 am

Re: Need a quick intro on using the com port

Post by Asbjørn »

I think i understand it a little better now, I have a 16 bit unsigned integer I need to convert to a 16 bit signed integer. How can I do this with flowstone?
DSP
Posts: 150
Joined: Fri May 14, 2010 10:55 pm

Re: Need a quick intro on using the com port

Post by DSP »

You normally just subtract the zero offset.

16 Bit Unsigned Integer = 0 to 65536

16 Bit Signed Integer = +32768 to -32768

So just subtract 32768 !
Asbjørn
Posts: 45
Joined: Thu Sep 16, 2010 11:51 am

Re: Need a quick intro on using the com port

Post by Asbjørn »

DSP wrote:You normally just subtract the zero offset.

16 Bit Unsigned Integer = 0 to 65536

16 Bit Signed Integer = +32768 to -32768

So just subtract 32768 !


Thanks but I don't think it's that easy, the x-axis output after converting string to integer is 0 when the ball is in the middle. If I move the ball to the right, the value climbs to 65536, if I move it to the left it seems to start at 65536 and decrease the further to the left I move it.

Confused :|

I'm probably doing something wrong.
DSP
Posts: 150
Joined: Fri May 14, 2010 10:55 pm

Re: Need a quick intro on using the com port

Post by DSP »

Looking at the manual the ball data isn't positional information anyway it's force xx,yy,zz,rr,uu,vv, the period is so that you can calculate acceleration :

>>
4.2.2 Ball Data
Description: Whenever the ball is moved, a packet is generated by the Spaceball. This packet contains data about the movement data for the Spaceball.
In order to receive a data packet, the “Enable Data” packet has to be sent first.
Packet Header: D (0x44)
Packet Data: Dppxxyyzzrruuvv (each letter stands for 1 byte)
Data Format: pp Period of data. This is the number of 1/16th milliseconds since the last ball data packet.
xx…zz Translational forces.
rr…vv Rotational forces (torque).
Actual force and torque values are 16-bit signed integers.
The first byte is the higher significant byte of the 16 bit signed integer, the second byte is the lower significant byte. Decoding to a 16bit signed integer can be done like this:
signed int ForceX = ( packet[3] << 8) | (packet[4]);

The resolution is 160 mNm and 4.4mNm for force and torque. This results in a force and torque range of +/- 20.48 N and +/- 0.5632 mNm. Positive x is to the right, +y is up and +z is upwards. Positive torque values are clockwise as viewed from the center of the ball out along the positive force axes.

<<

So the data is already a signed 16bit Int so you just need to convert it from 16bit to 32bit for FlowStone. To do this you need to detect the sign bit (bit 16) and then subtract 32768 when it's negative (ie > 32768).

Here's a FS project that should work for you:
Attachments
Signed 16bit Int.fsm
Signed 16 bit int to 32bit conversion
(9.09 KiB) Downloaded 1601 times
Asbjørn
Posts: 45
Joined: Thu Sep 16, 2010 11:51 am

Re: Need a quick intro on using the com port

Post by Asbjørn »

Thanks DSP, looks like that took care of one problem.

I think there might be something wrong with the data comming from the device, it's jumping all over the place. I'll do some testing..
Asbjørn
Posts: 45
Joined: Thu Sep 16, 2010 11:51 am

Re: Need a quick intro on using the com port

Post by Asbjørn »

Ok, I'm back! ;)

I put my Spaceball 4000 on the shelf and started working on my Spaceball 5000 which uses a different protocol, hopefully with some more success!

When the ball returns to the zero position, I should be getting:

dH000H000H000H000H000H000

However, I'm getting:

dà€à€à€à€à€à€

I need help to figure out how I can convert à€ to H000
Post Reply