PDA

View Full Version : Vizard scheduler vs Python scheduler


jelly
05-17-2016, 07:21 AM
I have some code that is scheduling beeps respective to the onset of the script, but it seems to run everything before Vizard can load and I think that is because Vizard may not understand the scheduler?

How can I use the viztask_schedule to achieve a comparable result, after Vizard loaded the environment?

import schedule
import time
from functools import partial
import viztask

viz.go()

## Cue sound ###
cue = viz.addAudio('cues\dong.wav')
cueDuration = cue.getDuration()

# my specified list of timings
times = [1.76493425, 3.10174059, 4.49576803, 10.99379224, 18.84178369]

# get the starting time
start = time.time()

# define a job, i.e. play beep sound and print smth
def job(t, start):
cue.play()
print ('cue', ' - timing: ', t, ' - now: ', time.time()- start)
# pop the job right away from schedule.jobs, so it runs only once
return schedule.CancelJob

def main():

# for each time add what to do
for t in times:
# using partial so i can pass arguments to job
schedule.every(t).seconds.do(partial(job, t, start))
# and run it inside a lop
while True:
schedule.run_pending()
# schedule.jobs is just a list of jobs
if not schedule.jobs:
break


viztask.schedule(main())

Jeff
05-20-2016, 02:25 AM
The viztask library is designed to control program flow. You can wait for time to elapse, an action, event, etc. before executing more code. If you have not done so yet, take a look at the viztask (http://docs.worldviz.com/vizard/#VizTask_basics.htm) documentation in the reference section and the creating a task (http://docs.worldviz.com/vizard/#Tutorial__Tasks.htm) tutorial. Use the waittime (http://docs.worldviz.com/vizard/#commands/viztask/waitTime.htm) command to wait for a set time.