WorldViz User Forum  

Go Back   WorldViz User Forum > Plug-in development

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1  
Old 01-15-2010, 10:53 AM
ursi ursi is offline
Member
 
Join Date: Dec 2009
Posts: 11
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!
Reply With Quote
  #2  
Old 01-15-2010, 03:11 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
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)
Reply With Quote
  #3  
Old 01-18-2010, 11:04 AM
ursi ursi is offline
Member
 
Join Date: Dec 2009
Posts: 11
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)
##############################
Reply With Quote
  #4  
Old 01-18-2010, 05:06 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
The line of code
Code:
vizact.onupdate(0, checkTrigger)
already registers the checkTrigger function and that will be called every frame. Have you tried running that on it's own without the code you added?
Reply With Quote
  #5  
Old 01-19-2010, 04:17 PM
ursi ursi is offline
Member
 
Join Date: Dec 2009
Posts: 11
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...
Reply With Quote
  #6  
Old 01-20-2010, 09:42 AM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
Please use the code tags when you post code to preserve the indentation. This line
Code:
trigg = d.eAnalogIn(0) # AI0
should be inside your checkTrigger function if you want to be continuously checking it.
Reply With Quote
  #7  
Old 01-20-2010, 12:06 PM
ursi ursi is offline
Member
 
Join Date: Dec 2009
Posts: 11
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)
How can I address the 'right' output to be checked?
Why does it not work to feed in a voltage?
Reply With Quote
  #8  
Old 01-20-2010, 04:40 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,448
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)
Reply With Quote
  #9  
Old 01-21-2010, 09:39 AM
ursi ursi is offline
Member
 
Join Date: Dec 2009
Posts: 11
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)
Another question: can I chance the code, so that the frequence for checking the trigger would be higher than once a second?
Reply With Quote
  #10  
Old 01-21-2010, 10:55 AM
ursi ursi is offline
Member
 
Join Date: Dec 2009
Posts: 11
Ok, I see, that the if-condition work fine, if I address the voltage output...

Code:
if trigg['voltage'] > 0.2:
So, the last question that remains is the higher frequency for checking the trigger?
Reply With Quote
  #11  
Old 01-21-2010, 10:57 AM
ursi ursi is offline
Member
 
Join Date: Dec 2009
Posts: 11
Sorry, I figured it out...

Code:
vizact.ontimer(.01, checkTrigger)
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Implement LabJack ursi Vizard 4 01-07-2010 03:14 PM
Updating viewpoint via external computer Rachel Vizard 1 02-04-2008 06:23 PM
labjack plugin Jerry Vizard 1 03-14-2007 04:36 PM
collision events trigger Eunice Vizard 1 01-03-2006 10:39 AM
A hotspot id of -1 will never trigger. jrodman Vizard 1 01-27-2004 03:22 PM


All times are GMT -7. The time now is 09:00 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC