WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-07-2008, 12:51 PM
timbo timbo is offline
Member
 
Join Date: Jun 2008
Posts: 16
Wink two continuous sockets

I am doing a reaching task experiment with vizard using 1 socket for hand data and a separate socket for target data. I use viz.director() in a while loop to call the hand position and the same for the target position (in different functions). This seems to work well except when ever the target data is called the hand data stops then starts up again. Is there any way I can run both sockets without having one interupt the other?


def handmove():
global S, X, Y, Z
try:
data, addr = S.recvfrom(30)
component = data.split(',')

X = float(component[0])
Y = float(component[1])
Z = float(component[2])
except:
pass

def targmove():
global T, A, B, C
for n in (1,2):
if n < 2:
data, addr = T.recvfrom(30)
status = data
else:
data, addr = T.recvfrom(30)
comp = data.split(',')
A = float(comp[0])
B = float(comp[1])
C = float(comp[2])

ball2.translate(A, B, C)

###################################
MAIN LOOP
###################################

def hand():
global loopy, X, Y, Z
while loopy:
handmove()
ball1.translate(X,Y,Z)

viz.director(hand)

def targ():
global loopy
while loopy:
targmove()

viz.director(targ)
Reply With Quote
  #2  
Old 07-07-2008, 12:54 PM
timbo timbo is offline
Member
 
Join Date: Jun 2008
Posts: 16
oops, it didnt recognize my indentations. Hopefully you get the point...
Reply With Quote
  #3  
Old 07-07-2008, 02:45 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Please use the [code][/code] tags when posting Python code. It preserves the indentation which is essential for running Python code.

Also, I don't really understand your problem. What do you mean by 'the hand data stops then starts up again'?
Reply With Quote
  #4  
Old 07-07-2008, 03:18 PM
timbo timbo is offline
Member
 
Join Date: Jun 2008
Posts: 16
The hand data is continuously updating with the sensor in the while loop (approximately every 16 ms). The target data updates only when it changes its position. So everytime the target location changes, which is like every 15 seconds, the hand data stops being recieved for a moment and the target data is updated. I want these two to be able to run at the same time without effecting eachother. I belive this happens because of the viz.director call but I dont know how else to do it. Does this clarify my question?
Reply With Quote
  #5  
Old 07-08-2008, 11:48 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Without proper formatting, I can't really tell what your code is doing. Are you getting any error messages in your script? I notice you have a try...except clause, but you silently ignore the message. Try removing the try..except and allow exceptions to be printed.
Reply With Quote
  #6  
Old 07-08-2008, 12:37 PM
Gladsomebeast Gladsomebeast is offline
Member
 
Join Date: Mar 2005
Location: Isla Vizta, CA
Posts: 397
I think the problem here is the blocking nature of the socket calls in the director functions combined with the sudo threaded nature of director functions.

My theory: Vizard allocates some CPU time to director functions every frame. Because only one thread/director function can access the Python interpriter at a time, if a director function takes all the time Vizard allocates for director functions in a frame, the other director functions will not get executed in that frame.

The solution is to make you director function call non-blocking (aka faster) network functions, or bust some C code to use real threads.

Farshizzo, does this make sense?

Maybe all you need is to add a viz.waitframe() call in the while loops to yield CPU to other director functions?

As a side note, multi-threading really messes with my mind.
__________________
Paul Elliott
WorldViz LLC
Reply With Quote
  #7  
Old 07-09-2008, 10:16 AM
timbo timbo is offline
Member
 
Join Date: Jun 2008
Posts: 16
Adding the viz.waitframe() minimized the lag to a reasonable value. Thank you both for your input.
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


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


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