WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rating: Thread Rating: 10 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-16-2013, 05:24 AM
chris2307 chris2307 is offline
Member
 
Join Date: Nov 2013
Posts: 36
Unexpected Avatar lookAt() behavior when using yield statements

Hi,

I have an encountered some unexpected behavior in my Vizard application which I cannot work out. I should stress that I am relatively new to Python and the use of Yield statements. My problem may or may not be directly caused by the use of them.

The application I am creating uses two differing scenarios; the first scenario requires the user to follow an avatar and the second scenario requires the user to retrace the route that they went on when they followed the avatar.

I have created two classes (one for each scenario). Within the main.py file, I call a main functionbusing viztask.schedule(). I have used an (rather un-elegant) if statement that queries the state of the program which determines which scenario to run.

At the end of following the avatar, the visibility of the avatar is disabled. The scenario returns and the next scenario is played out where the user retraces the route. When this has finished, we re-initialise the following avatar scenario which includes placing the avatar back in the start position and setting the orientation to what ever direction it needs to go.

However, I call the lookAt() function to do this but it doesn't seem to take any effect. I used debug statements everywhere to try and find out why this wasn't working and found that actually, lookAt() was doing what it was supposed to do but at some other point, the avatar orientation was put back to where it was facing before calling the lookAt() function.

I am going to put some code down now. Sorry for the long explanation (finding this difficult to word!)

Code:
def runExperiment():
	
	while True:
		
		if(programState.isInitExperiment()):

			# Code related to setting up an experiment
			yield followAvatar.setUpExperiment(experiment.returnCurrentExperimentRoute(), experiment.returnFailureCoordinates())

			print "1a:",followAvatar.returnAvatarEuler()
			followAvatar.setAvatarEuler()
			print "1b:",followAvatar.returnAvatarEuler()
			
			programState.setTrainingInstructions()
			
			print "2a:",followAvatar.returnAvatarEuler()
			followAvatar.setAvatarEuler()
			print "2b:",followAvatar.returnAvatarEuler()
			
		elif(programState.isTrainingInstructions()):
			
			# Code related to displaying the introduction screen should go here
			yield message.displayMessage("Follow Avatar\nThis is a test message and not to be used in final version of the application")
			if(win32api.GetAsyncKeyState(win32con.VK_SPACE)):
				yield programState.setTrainingPhase()
				yield message.removeMessage()
		
		elif(programState.isTrainingPhase()):
			
			# Code related to the running the training phase should go here
			
			yield followAvatar.runExperiment()
			if (followAvatar.experimentEnded):
				yield programState.setInitTest()
				
		elif(programState.isInitTest()):
			
			# Code related to initialising the testing phase
			
			yield retraceRoute.setUpExperiment(experiment.returnCurrentExperimentRoute(), experiment.returnFailureCoordinates())
			yield programState.setTestInstructions()
				
		elif(programState.isTestInstructions()):
			
			# Code related to displaying the test instructions to go here
			
			yield message.displayMessage("Retrace the route\nThis is a test message and not to be used in the final version of the application")
			if(win32api.GetAsyncKeyState(win32con.VK_SPACE)):
				yield programState.setTestingPhase()
				yield message.removeMessage()
				#TODO - Somehow block movement
			
		elif(programState.isTestingPhase()):
			
			yield retraceRoute.runExperiment()
			
			if(retraceRoute.returnResult() == 1): 			# Passed Testing
				
				if (experiment.nextExperiment() == True): 	# Is there another experiment?
					yield programState.setInitExperiment() 	# Initiate that experiment
				else:										# If not...
					yield programState.setTestingComplete()	# Testing Complete
					
			elif(retraceRoute.returnResult() == 2): 		# Failed Testing
				
				if(experiment.experimentFailed() == True): 	# All tries used up?
					yield programState.setTestingComplete()	# Testing Complete
				else:										# If not...
					yield programState.setInitTest()		# Initiate the testing again

		elif(programState.isTestingComplete()):
			
			# Code to run once ALL testing have been completed to go here			
			print "Testing Complete"
			yield viz.quit()

viztask.schedule(runExperiment())
This is the bit I think is important:

Code:
		if(programState.isInitExperiment()):

		# Code related to setting up an experiment
		yield followAvatar.setUpExperiment(experiment.returnCurrentExperimentRoute(), experiment.returnFailureCoordinates())

		print "1a:",followAvatar.returnAvatarEuler()
		followAvatar.setAvatarEuler()
		print "1b:",followAvatar.returnAvatarEuler()
		
		programState.setTrainingInstructions()
		
		print "2a:",followAvatar.returnAvatarEuler()
		followAvatar.setAvatarEuler()
		print "2b:",followAvatar.returnAvatarEuler()
			
		elif(programState.isTrainingInstructions()):
			
		# Code related to displaying the introduction screen should go here
		yield message.displayMessage("Follow Avatar\nThis is a test message and not to be used in final version of the application")
		if(win32api.GetAsyncKeyState(win32con.VK_SPACE)):
			yield programState.setTrainingPhase()
			yield message.removeMessage()
Where you see the followAvatar.setUpExperiment() function called, we initialise the experiment and move the avatar to the start position and orientate it so it faces the direction of intended travel. (I'll paste this method below).

The next line prints out the avatar euler to the console. I've also identified this with a number so you can clearly see the output. When I first return the euler, it is not how I set it within the method. The euler has returned to (not how it was when first loaded in to Vizard at the very beginning) but how it was before I called the .lookAt() function.

So I then call a method to reset this. This method does nothing but call the lookAt() function on the avatar from within the same class. Then, returning the euler, I can see it is correct.

Where it gets really puzzling for me, I then set the state of application (sounds simple enough). If I put a yield statement in front of this line, I see the same behavior. The avatar oritentation returns to how it was in the previous experiment (ignoring the last two times I called .lookAt(). If I take out the yield statement, as shown in the code example, I do not see this behavior. To try and show you what I mean, here is what I see in the output window with and without the yield statement before the line: "programState.setTrainingInstructions()"

With Yield Statement

1a: [-89.52449798583984, -0.0, 0.0]
1b: [0.0, 0.0, 0.0]
2a: [-89.52449798583984, -0.0, 0.0]
2b: [0.0, 0.0, 0.0]

Without Yield Statement

1a: [-89.53038787841797, -0.0, 0.0]
1b: [0.0, 0.0, 0.0]
2a: [0.0, 0.0, 0.0]
2b: [0.0, 0.0, 0.0]

None of this really matters anyway because when I move down the code to call a function that displays the message I want, I must use a yield statement else Vizard gets blocked and the the avatar orientation goes back to [-89.53038787841797, -0.0, 0.0].

I am very sorry for the long-winded post. I had trouble describing the problem I am seeing. Hopefully someone can help me out. Please ask if there is something I have missed out.

Thanks
Reply With Quote
 

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
avatar walkto interrupt Meneer_Aart Vizard 6 04-09-2013 02:41 PM
lookat and threads status Philippe Vizard 3 08-12-2010 03:01 AM
Looking through the eyes of an avatar Frank Verberne Vizard 2 04-01-2008 05:52 AM
How to make avatar's eyes to blink when speaking michelcm3 Vizard 12 01-15-2008 08:48 AM


All times are GMT -7. The time now is 07:13 PM.


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