#1
|
|||
|
|||
Proximity Manager - How to implement delay
Hello,
I have a timing issue in my script, as I am not sure how to implement a delay, in that when the proximity sensor is entered, a variable (handstate) changes only after 2 seconds have elapsed. That variable change triggers a certain action in a different function, but to keep it simple, I have copied below the proximity function I have: Code:
def EnterProximity_IndexFinger(e): # decide what happens on sensor entry global handstate e.sensor == SensorIndexFinger handstate = 1 print "sensor A entered" print condition manager.onEnter(SensorIndexFinger,EnterProximity_IndexFinger) Code:
def Change(): global handstate yield viztask.waitTime(2) handstate = 1 def EnterProximity_IndexFinger(e): # decide what happens on sensor entry global handstate e.sensor == SensorIndexFinger print "sensor A entered" yield Change() manager.onEnter(SensorIndexFinger,EnterProximity_IndexFinger) I reckon it must not be too tricky to achieve this - in essence I just want a 2 second delay after proximity sensor was entered before my action is triggered. But I am not sure how to achieve this. I would be very happy to receive some ideas or help! Best, J |
#2
|
|||
|
|||
Use the vizproximity.waitEnter command within a task function:
Code:
import viztask def proximityTask(): yield vizproximity.waitEnter(SensorIndexFinger) print 'entered sensor' yield viztask.waitTime(2) print 'two seconds elapsed' viztask.schedule(proximityTask()) |
#3
|
|||
|
|||
Dear Jeff,
thank you for the help, this seems like the way to go! But I have some problems with it: I noticed that adding the line Code:
viztask.schedule(proximityTask()) My question would be how do I make it happen everytime, like it was the case when I used Code:
manager.onEnter(SensorIndexFinger,EnterProximity_IndexFinger) Code:
SensorIndexFinger = vizproximity.Sensor(vizproximity.Box([0.03,0.03,0.03],center=[0,0,0]),IndexFinger) manager.addSensor(SensorIndexFinger) def proximityTask(): global handstate yield vizproximity.waitEnter(SensorIndexFinger) print 'entered sensor' yield viztask.waitTime(2) print 'two seconds elapsed' handstate = 1 print 'change hand' def EnterProximity_IndexFinger(e): # decide what happens on sensor entry global handstate e.sensor == SensorIndexFinger print "activate proximityTask" manager.onEnter(SensorIndexFinger,proximityTask()) I would be very happy to hear if you had any suggestions on how to call the action (with delay) every time the sensor was entered, as I can't seem to find a way to implement it |
#4
|
|||
|
|||
You can add a loop inside the task function:
Code:
def proximityTask(): while True: yield vizproximity.waitEnter(SensorIndexFinger) print 'entered sensor' yield viztask.waitTime(2) print 'two seconds elapsed' viztask.schedule(proximityTask()) |
#5
|
|||
|
|||
Thank you so much, Jeff, this works perfectly!
|
Tags |
proximity, proximity sensor, timing |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Proximity Sensing Using Kinect | JamesCakes | Vizard | 6 | 06-24-2016 05:52 AM |
Orientation selective (Viewing Vector) Proximity Sensor | lmGehrke | Vizard | 2 | 03-17-2015 12:31 PM |
Proximity Sensor Problem | kmkm | Vizard | 3 | 03-04-2014 11:54 AM |
Phase Space and Proximity Sensors | snovob93 | Vizard | 3 | 06-13-2012 12:32 PM |
Packager manager | Chapre | Vizard | 1 | 04-29-2011 09:16 AM |