#1
|
|||
|
|||
External Trigger via LabJack
Hi,
I wanna trigger a Vizard-function via an external trigger (via LabJack). How do I do that? I wrote the following code using 'vizact.waitsignal': ############################## import viz viz.go() import u12 d = u12.U12() ############################## Trigg = d.eAnalogIn(0) #Create the signal object sig = vizact.signal(Trigg > 0) #Create an action to wait on the signal waitsig = vizact.waitsignal(sig) def ExtTrigg(waitsig) ### add SOUND song = viz.add('Beethoven.wma') song.loop(viz.OFF) #viz.callback(viz.Event,ExtTrigg) ##? viz.callback(viz.ACTION_BEGIN_EVENT,ExtTrigg) ##? ############################## Thanks! |
#2
|
|||
|
|||
You could use vizact.onupdate to check every frame if the trigger has occurred and then either do something there or call another function
Code:
def checkTrigger(): trigg = d.eAnalogIn(0) if trigg > 0: ExtTrigg() vizact.onupdate(0, checkTrigger) |
#3
|
|||
|
|||
Thanks!
And the callback function is ok or do I have to callback also the 'checkTrigger' function? ############################## #Create the signal object sig = vizact.signal(Trigg > 0) #Create an action to wait on the signal waitsig = vizact.waitsignal(sig) def ExtTrigg(waitsig) ### add SOUND song = viz.add('Beethoven.wma') song.loop(viz.OFF) ###+++++++++++++++++++++++++++ def checkTrigger(): trigg = d.eAnalogIn(0) if trigg > 0: ExtTrigg() vizact.onupdate(0, checkTrigger) viz.callback(viz.ACTION_BEGIN_EVENT,ExtTrigg) ############################## |
#4
|
|||
|
|||
The line of code
Code:
vizact.onupdate(0, checkTrigger) |
#5
|
|||
|
|||
Hi
I tried it like that to keep it simple: ############################## import viz viz.go() import u12 d = u12.U12() trigg = d.eAnalogIn(0) # AI0 ############################## def ExtTrigg(): print trigg ###+++++++++++++++++++++++++++ def checkTrigger(): if trigg > 2.0: ExtTrigg() vizact.onupdate(0, checkTrigger) ############################## But it gives me this output (ever and ever again; regardless if I change my if-condition to 2.0, what should call the ExtTrigg-function): {'overVoltage': 0, 'idnum': 0, 'voltage': 1.4208984375} I can't read in a external voltage into AI0 (a ramp 0V-5V-0V produced by a battery). My output in Vizard is always unchanged by 1.42...V. Do I also have to address my output like ' if trigg{3} > 2.0' or similar? I tried that, but it didn't seem to work with either [] nor () or {}. I just have some background in Matlab, so I don't have a clue, what I could try next in Python... |
#6
|
|||
|
|||
Please use the code tags when you post code to preserve the indentation. This line
Code:
trigg = d.eAnalogIn(0) # AI0 |
#7
|
|||
|
|||
The problem still remains...
Code:
def ExtTrigg(): print 'trigger > 2.0' ###+++++++++++++++++++++++++++ def checkTrigger(): trigg = d.eAnalogIn(0) # AI0 if trigg > 2.0: ExtTrigg() vizact.onupdate(0, checkTrigger) Why does it not work to feed in a voltage? |
#8
|
|||
|
|||
What do you get if you try the following? This should print out the voltage once a second. Do you notice any errors in Vizard's input/output window?
Code:
def checkTrigger(): trigg = d.eAnalogIn(0) # AI0 print trigg['voltage'] vizact.ontimer(1, checkTrigger) |
#9
|
|||
|
|||
Hi,
I can now feed in 'my' voltage from the external source and print just the voltage output. So, that works fine, thanks. But it prints the result still every second, so the if-condition does not seem to work properly... Code:
def ExtTrigg(): print 'trigger > 2.0' ###+++++++++++++++++++++++++++ def checkTrigger(): trigg = d.eAnalogIn(0) # AI0 if trigg > 2.0: ExtTrigg() print trigg['voltage'] vizact.ontimer(1, checkTrigger) |
#10
|
|||
|
|||
Ok, I see, that the if-condition work fine, if I address the voltage output...
Code:
if trigg['voltage'] > 0.2: |
#11
|
|||
|
|||
Sorry, I figured it out...
Code:
vizact.ontimer(.01, checkTrigger) |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Implement LabJack | ursi | Vizard | 4 | 01-07-2010 04:14 PM |
Updating viewpoint via external computer | Rachel | Vizard | 1 | 02-04-2008 07:23 PM |
labjack plugin | Jerry | Vizard | 1 | 03-14-2007 05:36 PM |
collision events trigger | Eunice | Vizard | 1 | 01-03-2006 11:39 AM |
A hotspot id of -1 will never trigger. | jrodman | Vizard | 1 | 01-27-2004 04:22 PM |