WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-08-2013, 10:04 AM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
Inconsisten movement speed of the viewport

Hello all,

we are designing experiments in Vizard that include both automated movement as well as manual movement (joystick, keyboard) of the viewport through an environment.
Here, we have come across an interesting problem: Whenever we have manual movement, the movement speed is inconsistent. This means it is a) dependent on the loaded environment and b) dependent on the desired speed that is set.

a) More complex scenarios produce higher deviations in movement speed (but only for manual movement! The automated movement works flawlessly)
b) Higher speeds produce higher deviations (at 10m/s it is about 0.5m/s slower, at 30m/s about 1.5m/s slower)

We are realising the joystick and/or keyboard movement with the following code:

Code:
if math.fabs(jy) > joyDeadzone and -zoneX < jx < zoneX: 	# translation
	if jy > 0:	# backward
		view.move(0,0,viz.elapsed()*-joyMovSpeed) 
	if jy < 0:	# forward
		view.move(0,0,viz.elapsed()*joyMovSpeed)
elif math.fabs(jx) > joyDeadzone and -zoneY < jy < zoneY:	# rotation
	if  jx < 0: 	# left
		view.setEuler([joyRotSpeed*jx*viz.elapsed(),0,0],viz.HEAD_ORI,viz.REL_PARENT)
		if  jx > 0: 	# right
		view.setEuler([joyRotSpeed*jx*viz.elapsed(),0,0],viz.HEAD_ORI,viz.REL_PARENT)
else: 
	pass
Could it be that the function viz.elapsed() is causing the deviation in movement speed?

All the best and thank you!
Reply With Quote
  #2  
Old 07-08-2013, 12:08 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Does the framerate vary in your different applications?
Reply With Quote
  #3  
Old 07-08-2013, 01:13 PM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
Hello Jeff,

thanks for your reply! No, the framerate is fixed at 60fps, and it stays there at all times (already checked it with the gpu info box overlay).
Reply With Quote
  #4  
Old 07-08-2013, 05:21 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Can you post a complete example with navigation and how you calculate the error?
Reply With Quote
  #5  
Old 07-09-2013, 07:35 AM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
I did some more research today and I found out the cause, which is quite interesting:

When I use one of the envorinments provided by Vizard (i.e. ground_grass.osgb), everyworks fine and the movement speed is correct, both automatically and manual. Also, the viz.collision setting has no impact on the speed.

Whe I use one of our own environment (also just a simple ground plane with a tube around it to create an arena) and I have viz.collision turned OFF, everything is working fine.
However, if I turn viz.collision ON in our environment, the movement speed while moving with the keyboard or the joystick if off by about 0.5m/s for a speed of 10m/s. When I move automatically in this setting, everything works fine.

Jeff, I have send you a private message with a minimum example. In the first phase, the viewport will move automatically for 100m. Then, the viewport is reset and you can move forward for 100m with the key '3'. The position and time is logged in a separate .txt file.
In the first lines, you can switch the collsion on and off as well as change the environment from a standard one to the one that is provided with the .rar file.

Thanks for your help!
Reply With Quote
  #6  
Old 07-10-2013, 01:53 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
Are there any framerate drops when collision is enabled? Even an occasional drop may affect your calculations. I took a look at your example. I would suggest that you simplify that to the minimum code possible, perhaps just have forward movement in manual mode. I'm not immediately able to see from the log file what the speed or error is. Unless you don't want to publicly post your model, it's best to post everything here so other users can help as well.
Reply With Quote
  #7  
Old 07-15-2013, 05:07 AM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
Hello Jeff,

thanks for your reply and the time you invest in helping me.

As far as I can tell, there are no framerate drops during the scene. I am using the info-panel to assess framerate and it looks constant. Also, the problem is persistent in every run and only if I am moving via keyboard or joystick. If there is a problem with dropping framerates, shouldn't it be also while moving automatically? Also, we tested it on 3 quite capable machines - all showed the error.

I have stripped down the code a little and uploaded it here:
https://www.dropbox.com/s/d3b4rpfw9u...minExample.rar
Also, I will post my code here. But without the example scene, it won't reproduce the error.

Please enable the collision, run the trial with my arena supplied in the .rar. Afterwards, you should see that it takes exactly 10 seconds to move 100m automatically. If I do it manually with the keyboard, it takes me 10.453 seconds.

Here are the relevant lines from my log-file:

Automatic movement:
13:57:31:410,0:00:10.015,[0.000,1.800,99.913],[-0.000]
13:57:31:425,0:00:10.030,[0.000,1.800,100.000],[-0.000]
---> 10.015 seconds for 100m

Keyboard movement:
13:57:43:890,0:00:10.468,[0.000,1.820,99.997],[-0.000]
13:57:43:905,0:00:10.483,[0.000,1.820,100.156],[-0.000]
---> 10.47 seconds for 100m

If I disable collision OR run the program with a standard scene (e.g. ground_grass.osgb), the time need will both times be 10seconds.

Finally the code:

Code:
# ----------------------------------------------------------
# 	Preamble
#	
#
#
#
#
#
# ----------------------------------------------------------	



# --------
# Librarys
# --------

from __future__ import division
import viz
import vizact
import vizinput
import vizshape
import vizproximity
import vizdlg
import viztask
import random
import vizjoy
import os
import datetime
import math

# -------
# Options
# -------

fs = 50
joyMovSpeed = 10
autoMovSpeed = 10
buttonMap = {'left': '1', 'right': '2', 'forward': '3', 'backward':'4'}	# button map
startPoint = 0
desiredEndpoint = 100

view = viz.MainView

view.collision(viz.ON)			
arena = viz.addChild('arena_dm250_urban.osgb')

#court = viz.addChild('ground_grass.osgb')
#court.setScale([5,1,5])

# ---------------------------
# Joystick & Movement related
# ---------------------------

joystick = vizjoy.add() # add joystick variable


def updateMovement(inputDevice = 'joystick'):
	
	if inputDevice == 'joystick':
		# subject movement related
		[jx,jy,jz] = joystick.getPosition() # continously get joystick axis position
			
		if math.fabs(jy) > joyDeadzone: 
			if jy > 0:	# backward
				view.move(0,0,viz.elapsed()*-joyMovSpeed) 	# viz. elapsed() allows movement, as long as joystick axes are moved
			if jy < 0:	# forward
				view.move(0,0,viz.elapsed()*joyMovSpeed)
	
		if  math.fabs(jx) > joyDeadzone:		# rotation
			if  jx < 0: 	# left
				view.setEuler([joyRotSpeed*jx*viz.elapsed(),0,0],viz.HEAD_ORI,viz.REL_PARENT)
			if  jx > 0:  	# right
				view.setEuler([joyRotSpeed*jx*viz.elapsed(),0,0],viz.HEAD_ORI,viz.REL_PARENT)

	
	if inputDevice == 'keyboard':
		
	
			if viz.key.isDown(buttonMap['left']):
				view.setEuler([-joyRotSpeed*viz.elapsed(),0,0],viz.HEAD_ORI,viz.REL_PARENT)
			if viz.key.isDown(buttonMap['right']):
				view.setEuler([joyRotSpeed*viz.elapsed(),0,0],viz.HEAD_ORI,viz.REL_PARENT)
			if viz.key.isDown(buttonMap['forward']):
				view.move(0,0,viz.elapsed()*joyMovSpeed) 	
			if viz.key.isDown(buttonMap['backward']):
				view.move(0,0,viz.elapsed()*-joyMovSpeed)


# ------
# Timing
# ------

class myTimer():

	def __init__(self,number,dateFormat,timeFormat):
		
		self.nr = number
		self.dateFormat = dateFormat
		self.timeFormat = timeFormat
	
	# timer methods to calculate time differences
	def start(self):
		
		self.startTime = datetime.datetime.now()
	
	def end(self):
		
		self.endTime = datetime.datetime.now()
		
	def deltaNow(self):
		
		self.curDeltaNowTime = datetime.datetime.now() - self.startTime
		self.curDeltaNowTime= str(self.curDeltaNowTime)[:-3] 
		return self.curDeltaNowTime
	
	# timer methods to get current date or time
	def date(self):
		
		self.curDateTime = datetime.datetime.now()
		self.curDate = self.curDateTime.strftime(self.dateFormat)
		return self.curDate
		
	def time(self):
		
		self.curDateTime = datetime.datetime.now()
		self.curTime = self.curDateTime.strftime(self.timeFormat)
		if self.timeFormat == '%H:%M:%S:%f':
			self.curTime = self.curTime[:-3]
		return self.curTime

# -----------------
# Globals & Statics
# -----------------

# timer classes
logTime = myTimer(1,'%d.%m.%Y','%H:%M:%S:%f')	# init log timer instance


# open output log file	
file = open('movementTest.txt', 'w')	# open log file	
file.write('Timestamp,Time since restart of timer,Position [x,y,y],View angle [Euler]\n')
# -------------------
# Procedual functions
# -------------------

def autoMovement():
	
	view.setEuler(0,0,0)
	view.setPosition(0,1.8,startPoint)

	logTime.start()
	logTimer = vizact.ontimer((1/fs),posLogger)	# start the logging of position and view angle at frequency specified by fs
	
	yield viztask.waitTime(1)
	
	logTime.start()
	yield viztask.addAction(view, vizact.moveTo([0,1.8,desiredEndpoint],speed = autoMovSpeed))
	yield viztask.waitTime(0.5)
	writeLog('Auto movement ended')
	viztask.schedule(manualMovement)
	
	
def manualMovement():
	
	global movementTimer
	
	# set start position and view angle
	view.setEuler(0,0,0)
	view.setPosition(0,1.8,startPoint)

	logTime.start()
	yield viztask.waitTime(1)
	
	#yield viztask.waitAny([waitJoyAxis])
	yield viztask.waitKeyDown('3')
	movementTimer = vizact.ontimer(0,updateMovement,inputDevice = 'keyboard') 
	logTime.start()
	
# -----------------------------------------
# Resource Functions & Classes during trial
# -----------------------------------------

# logging position and view angle	

def posLogger():
	
	global movementTimer
	
	timestamp = logTime.time()
	timeDelta = logTime.deltaNow()
	curAngle = view.getEuler()
	curPos = view.getPosition()
	curJoyPos = joystick.getPosition()
	
	file.write('%s,%s,[%0.3f,%0.3f,%0.3f],[%0.3f]\n' % 
	(timestamp,timeDelta,curPos[0],curPos[1],curPos[2],curAngle[0]))
	
	if curPos[2] > desiredEndpoint: # halt movement
		movementTimer.remove()
	
def writeLog(text):
	
	file.write(logTime.time() + ',EVENT: ' + text + '\n')
	print(text)
	
# -----
# Start
# -----

viz.mouse.setOverride(viz.ON)
viz.window.setSize(1280, 960)
viz.go()
viz.window.setFrameRate(viz.NICE)

viztask.schedule(autoMovement())
Reply With Quote
  #8  
Old 07-22-2013, 07:56 AM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
I am still trying to figure out what the cause of the reduced movement speed in our experiments is.

Jeff, what exactly is the 'Update' time of the renderer? This is the only value that varies during the test runs and also seems to be dependent on the collision:

In the test model of the minimum example I provided, I get update times up to 2 when I enable collision and the movement is slower than it is supposed to be. It stays at 0.1 if I disable collision and the movement speed is correct.
In a standard vizard model (like the one in the minimum example), it is well below 0.3, regardless of collision on or off and the movement speed is correct.
Reply With Quote
  #9  
Old 07-23-2013, 03:38 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,471
If you're updating the viewpoint every frame, try:
Code:
viz.getFrameElapsed() * SPEED
instead of:
Code:
viz.elapsed() * SPEED
Reply With Quote
  #10  
Old 07-24-2013, 12:02 AM
mape2k mape2k is offline
Member
 
Join Date: Mar 2013
Posts: 60
Hello Jeff,

thank you very much! That solved the problem. The movement speed of the viewport is now consistent throughout all of our environments.

What do you think was the problem? Is there a variation in frame draw times that depends on the current environment? If I am using viz.elapsed(), than I would not take this deviation into account, right?
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
Temporal delay on movement westbyb Vizard 5 05-23-2013 06:06 PM
Varying rotation speed with spinTo mape2k Vizard 2 03-22-2013 07:48 AM
Object + InteriaCube + Viewport problem Gekitatsu Vizard 1 02-22-2012 10:55 AM
random speed and associated coding Saz Vizard 1 05-20-2010 04:03 AM
Calculating Speed with sensor durf Vizard 1 03-13-2009 10:25 AM


All times are GMT -7. The time now is 03:22 PM.


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