#1
|
|||
|
|||
Incoming floating point values
Thanks for your help last week setting up a socket to write from an external machine. That is working, and I'm able to communicate with Vizard, but there are a few behaviors I don't understand. I'm using an external computer to send position data simultaneously to a motion base and to Vizard. The goal is to syncronize the viewpoint in Vizard with the excursions of the motion base. Three things are troubling me.
1. I want to send Vizard floating point values. I'm sending from Matlab running on another machine. When I send using an "fwrite" command, which writes binary text to an instrument, the data Vizard displays (when I ask for it using the print command) isn't what was intended. If I send a 5, it displays ENQ. If I send a 1, it displays SOH. But, if I send from Matlab using "fprintf", which writes text to an instrument, I get the 5 and the 1. If I call the incoming position values "data" and say: data = float(data) and send Vizard a list of -2, -4, -2, -4, it is received as -2.0, -4.0, -2.0, -4.0, which is fine. But if I send it a +2, it reports an "invalid literal for STX" (how it reads a 2) Vizard does okay using this fprintf workaround as long as I don't send an integer or a zero. Any value with decimals seems to work. But, I'd like to find a way to get them there using "fwrite" instead of "fprintf", because I sometimes get float errors on the Vizard side and I think if the data were coming in via the "fwrite" command, as binary data instead of text, things might go better. My question is, am I misusing the float command? Should I do something else to make sure I get a 2 and not STX, for example? 2. A follow-on question is whether there is a way to determine how fast Vizard is reading incoming data. I know how fast I'm sending from Matlab, but can I verify how fast Vizard is reading it in? The reason I ask is... 3. The position data (sinusoidal) sent to the motion base and to Vizard is the same. But, the base is starting the motion at a center point whereas Vizard is starting at the left extreme. So, when viewed together, it looks like there is a 90 degree phase shift, or it's as if the base is moving as a sine wave and the Vizard viewpoint is moving as a cosine wave. Any idea why that might be? As always, my sincere appreciation for your time and input. Rachel |
#2
|
|||
|
|||
1) If you want to read in binary numbers in Python you will need to use the struct module. Have a look at the Python documentation for detailed info. Here is a basic usage that will read in 4 binary floating point values from a data string:
Code:
import struct . . . #Read data from socket s = InSocket.recv(PACKET_SIZE) #Unpack binary data into 4 floating point numbers data = struct.unpack('ffff',s) #Print floating point list print data Code:
recv_time = viz.tick() . . . #Code that should be called when data is received global recv_time now = viz.tick() print '%.2f ms between packets' % (now-recv_time)*1000.0 recv_time = now |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
data glove navigation | arielasso | Vizard | 6 | 10-24-2007 03:15 PM |
Floating license server problems | jrodman | Vizard | 2 | 10-30-2006 11:39 AM |
looking at a point | vadrian | Vizard | 5 | 06-07-2005 06:43 PM |