WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-12-2008, 02:46 PM
Rachel Rachel is offline
Member
 
Join Date: Feb 2008
Posts: 3
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
Reply With Quote
  #2  
Old 02-12-2008, 03:09 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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
2)At what frequency are you sending data in MATLAB. If you send data faster than it can be read, then some packets might be lost. Vizard's graphics loop runs at your monitor refresh rate, which is usually 60Hz. Either way, you can save the time when a packet is received and compare it to the previous receive time. This will give you a rough estimate on the time between packets. Example:
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
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
data glove navigation arielasso Vizard 6 10-24-2007 02:15 PM
Floating license server problems jrodman Vizard 2 10-30-2006 10:39 AM
looking at a point vadrian Vizard 5 06-07-2005 05:43 PM


All times are GMT -7. The time now is 08:23 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC