PDA

View Full Version : saving proximity events (onEnter,onExit) to file


Vaquero
08-25-2016, 06:47 PM
Hey!
I've scripted an experiment based on the experiment framework (http://docs.worldviz.com/vizard/#examples/experimentDesign.htm) in the examples. I have set up my sensor and targets and added them to the manager. Now I want to save the onEnter and onExit events to a file only when the experiment is in the testphase , but I'm lost on how to do that.


def EnterSensor(e):
print 'Enter',e.sensor.name, contactManager.getActiveTargets(sensor=e.sensor) #DEBUG

def ExitSensor(e):
print 'Exit',e.sensor.name, contactManager.getActiveTargets(sensor=e.sensor) #DEBUG

manager.onEnter(sensor, EnterSensor)
manager.onExit(sensor, ExitSensor)


Can I just move this code inside the experiment definition ( def experiment(): ) just before yielding the testphase? And instead of printing to console saving to a file that I opened in the experiment function before? I can only test it when I'm back in the lab and on a tight schedule.

Jeff
08-26-2016, 07:43 AM
You could add a global variable that keeps track of which phase is currently active and check against that. Or you could create two proximity managers and enable one during the initial phases and the other during the test phase:

manager1.setEnabled(viz.OFF)
manager2.setEnabled(viz.ON)

The event object passed to the callback function for the proximity event stores which manager was involved.

Vaquero
08-30-2016, 11:55 AM
Thanks, Jeff, I'll try the second approach. I have another question:
Is there a way to give targets a custom name and retrieve this name with manager.getActiveTargets(sensor=e.sensor)?

Right now this gives me a list like this:

[Target(source=LinkableSource(linkable=__builtin__. _VrpnTracker(2), flag=0)), Target(source=LinkableSource(linkable=__builtin__. _VrpnTracker(1), flag=0))]


But I'd like to get names for the targets like 'right hand' and 'left hand'. I know I can get the source object of a target, but I haven't found one that has a name attribute.

Jeff
08-31-2016, 04:24 AM
You can add a custom name attribute to the node:

target.name = 'right_hand'

and get this name in the proximity event callback:

e.target.name