WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Movement Question (https://forum.worldviz.com/showthread.php?t=1248)

Elittdogg 10-18-2007 08:37 AM

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?

farshizzo 10-18-2007 09:54 AM

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)

Elittdogg 11-26-2007 12:45 PM

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?

farshizzo 11-26-2007 12:52 PM

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.

Elittdogg 11-26-2007 12:58 PM

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.

Elittdogg 11-26-2007 01:04 PM

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?

farshizzo 11-26-2007 01:06 PM

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


Elittdogg 11-26-2007 01:10 PM

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?

farshizzo 11-26-2007 01:42 PM

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.

Elittdogg 11-27-2007 01:11 PM

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?

farshizzo 11-27-2007 05:13 PM

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))

Elittdogg 11-27-2007 06:18 PM

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?

Elittdogg 11-28-2007 08:47 AM

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?

farshizzo 11-28-2007 09:15 AM

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.

Elittdogg 11-28-2007 10:05 AM

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.

Elittdogg 11-28-2007 10:16 AM

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.

farshizzo 11-28-2007 10:36 AM

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?

Elittdogg 11-28-2007 01:09 PM

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 "", 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?

farshizzo 11-28-2007 01:14 PM

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.

Elittdogg 11-28-2007 02:57 PM

I'm using 2.5. Can't upgrade to 3.0.

Elittdogg 11-29-2007 08:36 AM

And this may be completely obvious and I may be completely clueless but where are the tags?

farshizzo 11-29-2007 08:56 AM

You can manually type the tags and place the code in between.

Elittdogg 12-03-2007 10:22 AM

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.

farshizzo 12-04-2007 10:26 AM

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)

Elittdogg 12-04-2007 10:52 AM

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

Elittdogg 12-04-2007 11:27 AM

What type of system are you running on?

Elittdogg 12-04-2007 11:42 AM

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?

farshizzo 12-04-2007 06:45 PM

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?

Elittdogg 12-05-2007 08:46 AM

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)).


All times are GMT -7. The time now is 05:53 AM.

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