View Single Post
  #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