how to check if specified number of targets are in proximity sensor?
Hey there! Can anyone tell me what's the best way to check, if a specified number of targets are inside a proximity sensor?
I have an experiment in which a person is required to move a specified number of targets into a proximity sensor in order to continue. On top of that, this should be done within a specified time, e.g. 5 seconds. I tried something like: Code:
... |
Hi Vaquero ,
You might be looking for this Call these methods as per logic: 1) 2) Thank You!!! |
Thank you for your reply. I already use manager.getActiveTargets(sensor=targetSensor) in my code sample above. So unfortunately your reply doesn't provide any logic to the problem of how to check for 5 seconds long if at least 3 targets occupy a sensor at the same time, and if not, start the next trial.
|
One way to do this is create a custom event that's triggered when 3 targets are inside a sensor. Write a function that's called every frame, checks to see how many targets are in the sensor, and sends the event. In the viztask function, use the viztask.waitAny command to wait for either the custom event or 5 seconds:
Code:
waitTargets = viztask.waitEvent(THREE_TARGETS_EVENT) |
Thanks Jeff, that brought me closer to a solution, but I can't get it to work.
In each trial there's another sensor that needs to trigger the event, but whatever I do, I can't seem to get the functions/events recognize the newly chosen sensor. First I thought, well, I would only need to check for the number of targets in the sensor, if a target enters the sensor. Here's some pseudo-code: Code:
TRIGGER_ACTIVATED_EVENT = viz.getEventID('TRIGGER_ACTIVATED_EVENT') Now I tried using checkingTrigger = vizact.onupdate(0,checkTrigger,manager,triggerSens or) and using checkingTrigger.setEnabled(viz. Could you please give a more complete, working example? |
It works by doing the checkingTrigger = vizact.onupdate(0,checkTrigger,manager,triggerSens or) part inside the loop after triggerSensor = random.choice(sensors) was called, and removing the EventFunction at the end of the loop.
|
Concurrency?
There's another requirement for the task I need to implement, but can't figure out how to accomplish it. All the targets shall reach the given sensor concurrently (within tolerance) to count as a success.
So there's, for example, a 5 seconds time limit in which the sensor must be reached, but within that time limit the targets must reach the sensor within a shorter amount of time, e.g. 1 second. For now, the user should be able to try this within the time limit until she succeeds. I guess I should utilize starttimer, so I'd have to start it, when the first target enters the sensor and before it elapses, all targets should have followed. If one target exits the sensor before the timer elapsed, it should be stopped (killtimer). But if I put the starttimer in the on_enter function of the sensor, then each target starts a new timer. I suppose there should be an event that marks a success only when the TRIGGER_ACTIVATED_EVENT occured while the timer event did not yet occur. I tried setting a global variable to true and false, but since each onEnter-call sets it to true, it's useless. Here's a condensed debug version of my script so far: Code:
import viz |
I think I got it. I just check for the boolean status of the timer before I start a new one AND make sure, there are not already other targets in the sensor.
Code:
def enter_sensor(e): |
Unfortunately, when 2 targets arrive at the exact same time at the sensor, the timer isn't started because numtargets > 1. I didn't think it was possible or probable, but it is. So my solution is still not good enough.
|
All times are GMT -7. The time now is 02:09 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC