WorldViz User Forum Movement Question
 User Name Remember Me? Password
 Register FAQ Search Today's Posts Mark Forums Read

 Thread Tools Rating: Display Modes
#1
10-18-2007, 09:37 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
Movement Question

So I'm trying to move an object (a picture) forward and backward a certain distance for a certain period of time. What I can't get it to do in this case is to move some fixed amount (e.g. 2 m) for X amount of seconds. In this example in the following code, I need to it to be able to go 2 m forward for .01 s then 2 m backward for .01 and do that sequence for 1 min (which is why I have "60/freq." Because I thought that would give me how many time .01 s went into 60 s. After a minute I want it to change to move 2 m forward for 2 seconds and 2 m backward for 2 seconds and to do that "60/freq" times (i.e. 30 times). ETC ETC ETC. Then I have the whole sequence looping 5 times (so it'll go through (.01, 2, .03, .0, .05, .06) a total of 5 times).

def WriteFlag():
print "Movement Transition Made"

movefreq = [.01, 2, .03, .04, .05, .06]
sequences = []
for freq in movefreq:
MoveRoom = vizact.sequence(vizact.move(0,0,2,freq), vizact.move(0,0,-2,freq), 60/freq)
sequences.append(MoveRoom)
sequences.append( vizact.call( WriteFlag ) )
MovingRoom = vizact.sequence(sequences, 5)

Here's my problem. I can't get it to move X distance for Y seconds. If I switch it so the code looks like "vizact.move(0,0,freq,2). Then it'll move the specified distance in 2 seconds. But I can't get it to do the other thing that I want (above). I was thinking that maybe I'm specifying it to move for too short of an amount of time????? Or maybe I need it to move too far too quickly? I mean, asking something to move 2m in .01 seconds is kind of quick. Is there some threshold that I need to be above?

Also I was wondering how I could make them both vairable (i.e. how far the picture moves and for how long). I was thinking about creating two lists in that case "dist and freq" and then having something like vizact.move(0,0, dist, freq). Would that work or am I missing something?

Last edited by Elittdogg; 10-18-2007 at 09:46 AM.
#2
10-18-2007, 10:54 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
With the vizact.move() command you specify the velocity to move with, and the amount of time to move at that velocity. So your code should look something like this:
Code:
`MoveRoom = vizact.sequence(vizact.move(0,0,2.0/freq,freq), vizact.move(0,0,-2.0/freq,freq), 60/freq)`
#3
11-26-2007, 01:45 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
The problem with this is that it makes the transitions very very very quickly if I put decimals in the list "movetime."

movetime = [.05, .25, .75, 1, 2]
sequences = []
for time in movetime:
MoveRoom = vizact.sequence(vizact.move(0,0,(0.12/time),time), vizact.move(0,0,(-0.12/time),time), (30/time))
sequences.append(MoveRoom)
sequences.append( vizact.call( WriteFlag ) )
MovingRoom = vizact.sequence(sequences, 1)

If I make the code:
MoveRoom = vizact.sequence(vizact.move(0,0,(0.5/time),time), vizact.move(0,0,(-0.5/time),time), (30/time))

and I make movetime [1, 2, 3, 4, etc] then it'll move .5 m/s for 1 second and then .25 m/s for 2 seconds...etc....all of the movements will result in moving .5 meters for a total of 1 minute. But when I have the above (if I want it to move .12 meters in .05 seconds or .25 seconds, etc.) it moves really fast for a second and then moves on to the next number in the list. It doesn't perform what I want it to and it doesn't do it for 1 minute either. Is there some problem with decimals? Am I making a wrong conversion? I tried changing the end (instead of 30/time to 600/time but that didn't change anything--if anything it made it transition faster. Am I missing something?
#4
11-26-2007, 01:52 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
Then don't put decimals in your movetime list. Keep in mind that dividing two integers in Python will yield another integer that is the floor of the division. Example:
Code:
```print 1 / 2 #prints 0
print 1 / 2.0 #prints 0.5```
So you will need to either use floating point values in your movetime list or use floating point values for your distance.
#5
11-26-2007, 01:58 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
what's a floating point value?

Like if I want it to move .12 meters in .5 seconds how would I code that?

I'm not familiar with floating point values.

Even if I make it 1/20.0 instead of .05 it doesn't work. It still moves really fast and transitions WAY before a minute has passed.

Last edited by Elittdogg; 11-26-2007 at 02:01 PM.
#6
11-26-2007, 02:04 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
Also, even if I make it 1/2.0 it goes really fast and doesn't last one minute. Maybe I'm just confusing myself?
#7
11-26-2007, 02:06 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
In most programming languages, non-fractional numbers are referred to as integers and fractional numbers are referred to as floats or floating point values. For example the following are integers:
Code:
```1
2
3
4```
and the following are floats
Code:
```1.0
2.1
3.89
4.43509876```
#8
11-26-2007, 02:10 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
So 0.5 should be a floating point if I'm understanding correctly. And my desired distance is already "0.12" which would also be a floating point. Yet it is still not working for me. Am I missing something?
#9
11-26-2007, 02:42 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
What exactly is not working? According to your example code, the longest move action will last 2 seconds. None of the values in the movetime list are specifying anything close to a minute.
#10
11-27-2007, 02:11 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
Ok. So what I originally had was:

movetime = [1,2,3,4,5,6]
sequences = []
for time in movetime:
MoveRoom = vizact.sequence(vizact.move(0,0,(0.5/time),time), vizact.move(0,0,(-0.5/time),time), (30/time))
sequences.append(MoveRoom)
sequences.append( vizact.call( WriteFlag ) )
MovingRoom = vizact.sequence(sequences, 1)

This made it so that the picture moved .5m/s forward for 1 second and .5m/s backward for 1 second (it did that a total of 30 times which added up to 60 seconds). The second iteration it moved .25m/s (.5/2) for 2 seconds forward and backward and it did that 15 times (30/2) for a total of 60 seconds. The third iteration it moved .167m/s (.5/3) forward and backward for 3 seconds and it did this 10 times (30/3) for a total of 60 seconds. ETC ETC ETC ETC In each case it was moving a total of .5 meters forward and backward it was just doing it at a slower velocity over a longer period of time.

Now I need to keep it semi-proportional to that. Namely, I need it to move .12m forward for .05 seconds and .12m backward for .05 seconds and to do that for a minute. (Just like above I need it to move a total of .12 meters (in this case) forward and backward and do it at a faster velocity over a shorter period of time.

So I need my movetime list to be like: movetime = [.05, .25, .75, 1, 2]. So it should start off moving very fast over a short distance and then gradually move slower over that same short distance. And each "iteration" needs to be a minute long. I know I'm missing something/my formula/equation is off/wrong, but I can't figure it out. If I'm dividing 30 by .05 that equals 600. So it should do that iteration 600 times which would end up being 60 seconds long. But it doesn't. It only does it a couple of times (which ends up being 2.4 seconds long).

Does that make sense?
#11
11-27-2007, 06:13 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
I think the problem in this case is that you need to convert the repeat count to an integer when passing it to the vizact.sequence command. Try the following instead:

MoveRoom = vizact.sequence(vizact.move(0,0,(0.5/time),time), vizact.move(0,0,(-0.5/time),time), int(30/time))
#12
11-27-2007, 07:18 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
and would that work if I change .5 to .12???

MoveRoom = vizact.sequence(vizact.move(0,0,(0.12/time),time), vizact.move(0,0,(-0.12/time),time), int(30/time))

Would it then run each iteration for a minute?
#13
11-28-2007, 09:47 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
When I added "int" before (30/time) it made it run longer than 2 seconds, but each iteration was running for approximately 90 seconds instead of 60. Am I making a mathematical error? Or am I missing something else?
#14
11-28-2007, 10:15 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
Which values are you using? I tested it out and it ran for exactly 60 seconds, as long as the number is a multiple of 30.
#15
11-28-2007, 11:05 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
Here's my movetime list:

movetime = [1/20.0, 1/4.0, 1/2.0, 1, 2]

and the code:
MoveRoom = vizact.sequence(vizact.move(0,0,((3/25.0)/time),time), vizact.move(0,0,((-3/25.0)/time),time), int(30/time))

or I could convert those fractions to floating points so it looks like:
movetime = [.05, .25, .5, 1, 2]
MoveRoom = vizact.sequence(vizact.move(0,0,(0.12/time),time), vizact.move(0,0,(0.12/time),time), int(30/time))

Either way it should work. But I have a timer set up to tell me every 60 seconds that 60 seconds had elapsed. And another timer to indicate when a movement transition has occured (i.e. when it shifts between interations--.05-->.25-->.5-->etc.)
Those should line up identically but they weren't for some reason.
#16
11-28-2007, 11:16 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
Here's the printed output from running it for a bit:

Elapsed time: 60.0057702864 seconds
Movement Transition Made
Elapsed time: 60.0058499055 seconds
Movement Transition Made
Elapsed time: 60.0067419183 seconds
Movement Transition Made
Elapsed time: 60.0055750102 seconds
Movement Transition Made

The time between elapsed time 1 and Movement transition made 1 is about 20 seconds. The time between ET2 and MTM2 is about 25 seconds. The time between ET3 and MTM3 is about 30 seconds. And time between ET4 and MTM4 is about 35 seconds. Granted I'm using a stopwatch so of course there is a little human error delay, but nonetheless it's not even close to being the same.
#17
11-28-2007, 11:36 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
I tried those time values and they seem to work fine. Here is the script I used:
Code:
```import viz
viz.go()

ball = viz.add('ball.wrl',pos=(0,1,5))

def WriteFlag():
global startTime
now = viz.tick()
print now - startTime
startTime = now

movetime = [.05, .25, .5, 1, 2]
for time in movetime:
MoveRoom = vizact.sequence(vizact.move(0,0,(0.12/time),time), vizact.move(0,0,(-0.12/time),time), int(30/time))
ball.addAction(MoveRoom)
ball.addAction(vizact.call( WriteFlag ))

startTime = viz.tick()```
And here is the output I got:
Code:
```60.0330525563
60.032436376
60.032417561
60.0325621751
60.0324703632```
I also manually timed it with a clock and it was correct.

Is your framerate very low?
#18
11-28-2007, 02:09 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
This is the code I have: (Oh and by the way...I don't know how to make it into the [code]/[code] thing...to make it come out like it shows up in Vizard).

import viz
import math
import whrandom
import string

viz.go(viz.PROMPT)

# Get subject number from prompt box
promptMesg = viz.get(viz.INITMESG)
if promptMesg == "":
Subnum = 999
Trial = 100

else:
text = string.split(promptMesg)
Subnum = int(text[0])
Trial = int(text[1])

print "Subnum =", Subnum
print "Trial =", Trial

tex1 = viz.add('3d-room.jpg')
quad = viz.add(viz.TEXQUAD)
quad.texture(tex1)
quad.translate(0,1.1,12)
quad.scale(12.8, 10.24)

def WriteFlag():
# write the flag in the data file
print "Movement Transition Made"

movetime = [0.05, 0.25, 0.5, 1, 2]
sequences = []
for time in movetime:
MoveRoom = vizact.sequence(vizact.move(0,0,(0.12/time),time), vizact.move(0,0,(-0.12/time),time), int(30/time))
sequences.append(MoveRoom)
sequences.append( vizact.call( WriteFlag ) )
sequences.append( vizact.call( WriteFlag3) )

MovingRoom = vizact.sequence(sequences, 1)

def WriteFlag2():
#write the flag2 in the data file
print "Participant Noticed Movement"
vizact.onkeydown('n',WriteFlag2)

def timer1():
print 'Elapsed time:',viz.elapsed(), 'seconds'

def onkeydown(key):
if key == ' ':
quad.add(MovingRoom)
vizact.ontimer(60,timer1)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)

And the computer's frame rate is 60Hz.

So with the object that I'm using I can't use the viz.tick; I get this error message:
Traceback (most recent call last):
File "<string>", line 12, in ?
File "MOVING ROOM (FINAL).py", line 51, in ?
startTime = viz.tick()
AttributeError: 'module' object has no attribute 'tick'

Anyway, I ran it again, but it still doesn't come out to every minute. I don't know. Maybe I'm doing something wrong elsewhere in the code?
#19
11-28-2007, 02:14 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
To post code on the forum, place the code between the [code][/code] tags.

Which version of Vizard are you using. It seems you have a pretty old version. I highly suggest upgrading to 3.0 if possible.
#20
11-28-2007, 03:57 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
I'm using 2.5. Can't upgrade to 3.0.
#21
11-29-2007, 09:36 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
And this may be completely obvious and I may be completely clueless but where are the tags?
#22
11-29-2007, 09:56 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
You can manually type the tags and place the code in between.
#23
12-03-2007, 11:22 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
Here is my code:

Code:
```import viz
import math
import whrandom
import string

viz.go(viz.PROMPT)

# Get subject number from prompt box
promptMesg = viz.get(viz.INITMESG)
if promptMesg == "":
Subnum 	= 999
Trial	= 100

else:
text = string.split(promptMesg)
Subnum = int(text[0])
Trial = int(text[1])

print "Subnum =", Subnum
print "Trial =", Trial

tex1 = viz.add('3d-room.jpg')
quad = viz.add(viz.TEXQUAD)
quad.texture(tex1)
quad.translate(0,1.1,12)
quad.scale(12.8, 10.24)

def WriteFlag():
# write the flag in the data file
print "Movement Transition Made"

movetime = [.05, .25, .5, 1, 2]
sequences = []
for time in movetime:
MoveRoom = vizact.sequence(vizact.move(0,0,(0.12/time),time), vizact.move(0,0,(-0.12/time),time), int(30/time))
sequences.append(MoveRoom)
sequences.append(vizact.call( WriteFlag ))

MovingRoom = vizact.sequence(sequences, 1)

def WriteFlag2():
#write the flag2 in the data file
print "Participant Noticed Movement"
vizact.onkeydown('n',WriteFlag2)

def timer1():
print 'Elapsed time:',viz.elapsed(), 'seconds'

def onkeydown(key):
if key == ' ':
quad.add(MovingRoom)
vizact.ontimer(60,timer1)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)```

So far it hasn't worked. When I run the first iteration the timer lets me know when 60 seconds has passed but the first movement transition doesn't occur until about 80 seconds have passed. And subsequent iterations are not paired with the 60 second timer either. I don't know what i'm doing wrong.
#24
12-04-2007, 11:26 AM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
I ran your script and had it print out the current time whenever a movement transition was made and I got the following output:
Code:
```Movement Transition Made 3.42844253975e-006
Movement Transition Made 63.9694971806
Movement Transition Made 125.937294339
Movement Transition Made 186.970923251
Movement Transition Made 247.520842059```
I'm getting about 2 seconds of error per transition. I'm not sure why you are getting such large timing errors. What are the specs on your computer? (processor speed, RAM, graphics card)
#25
12-04-2007, 11:52 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
How did you get it to print out the time when a movement transition occurs???

processor ~1395 MHz, Total RAM 512MB (Available 235.29MB), Graphics: Radeon 7500 series
#26
12-04-2007, 12:27 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
What type of system are you running on?
#27
12-04-2007, 12:42 PM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
I ran it again, and here's the times that I got:

Elapsed time: 60.0142129796 seconds
Movement Transition Made: Elapsed time = 101.746000051
Elapsed time: 60.0369736936 seconds
Movement Transition Made: Elapsed time = 174.59100008
Elapsed time: 60.0066273786 seconds
Elapsed time: 60.0072808136 seconds
Movement Transition Made: Elapsed time = 243.891000032
Elapsed time: 60.0356240807 seconds
Movement Transition Made: Elapsed time = 312.269000053
Elapsed time: 60.0056311626 seconds
Movement Transition Made: Elapsed time = 379.265000105

I DUNNO?
#28
12-04-2007, 07:45 PM
 farshizzo WorldViz Team Member Join Date: Mar 2003 Posts: 2,849
I used the time module to print out the current time. Example:
Code:
```from time import clock
.
.
.
def WriteFlag():
# write the flag in the data file
print "Movement Transition Made",clock()```
Your system specs seem reasonable. I even tried artificially reducing my framerate, but I still got similar values. Have you tried running the script on another machine?
#29
12-05-2007, 09:46 AM
 Elittdogg Member Join Date: Aug 2007 Posts: 77
This is the only machine with the program and space to run on (I'm pretty sure...I'd have to double check, but I'm pretty sure we can't run on another system (even if we copied the program to another unit)).

 Thread Tools Display Modes Rate This Thread Linear Mode Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Announcements Vizard Precision Position Tracker (PPT) Plug-in development

All times are GMT -7. The time now is 06:21 PM.

 Contact Us - WorldViz Home - Archive - Top

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