11-30-2008 09:54 PM
I'm a labview newbie, and i've been scratching my head about a particular problem.
I want to use a joystick (11button, 3 axis) to operate 2 PI microscope stages in tandem. I am thinking about the best solution to this problem:
the joystick buttons provide latched booleans: they are only true while the button is held down. once the button is released, the boolean becomes false again.
I want to take this toggle and produce a true boolean the first time the button is pressed, and change that boolean to a false when the button is subsequently pressed.
My current idea is to try and construct something with either an occurance structure or notifier structure, or even something like a boolean to integer conversion then modulo-2 division.
Can anyone give me some pointers here?
thanks!
Solved! Go to Solution.
12-01-2008 07:11 AM
Hi zipmanx,
Thanks for your post and I hope your well today.
You want,
1st press --> LED = TRUE
2nd press --> LED = FALSE
3rd press --> LED = TRUE
I would sugget using a shift reigistor to remember the number of times the switch has been pressed. Then if the number of presses = 0 and the Switch is high then LED is = true, then in all other cases LED = False. For this you could use a case structure or logic, up to you.
I hope this helps,
Kind Regards,
James.
12-01-2008 01:52 PM
I think you really want an output to toggle every time the button is pressed:
1st press = TRUE
2nd press = FLASE
3rd press = TRUE
4th press = FALSE
and so on.
If this is so then all you need is an event structure with shift register and a boolean NOT function. See attached vi.
12-01-2008 02:11 PM
One alternative i have that works is to read the latched bool, convert to int, mod2, reconvert to bool, all in a while loop with a shift register. It seems pretty bulky
From a programming standpoint, which is better to use? an event handler as trob has suggested, or something like an occurance or a notifier?
Here's another one: can you do a bitwise shift in labview?
12-01-2008 02:27 PM
zipmanx wrote:the joystick buttons provide latched booleans: they are only true while the button is held down. once the button is released, the boolean becomes false again.
I want to take this toggle and produce a true boolean the first time the button is pressed, and change that boolean to a false when the button is subsequently pressed.
You got the LabVIEW definition of "latched" wrong. In LabVIEW, a latched button turns true until it's value is read by the code (no matter how long that takes). Once the value is read, it automatically reverts to false again.
What you are describing is "switch until released". (Similar to the horn on your car).
You certainly don't need two CPU burner loops, local variables, integers, mod, and trimmings. What is your LabVIEW version and how are you reading the switches?
12-01-2008 03:05 PM - edited 12-01-2008 03:05 PM
zipmanx wrote:From a programming standpoint, which is better to use? an event handler as trob has suggested, or something like an occurance or a notifier?
Here's another one: can you do a bitwise shift in labview?
Since you are reading hardware, you probably need to poll it, so an event is out.
Yes, you ca do bitwise shifts in LabVIEW. Look in the "numeric...data manipulation" palette.
Here's one possibility to solve your problem (LabVIEW 8.5). There are many other ways to do this, but you dfefinitely don't need any blue wires for the logic. :).
12-03-2008 08:17 PM
altenbach wrote:What is your LabVIEW version and how are you reading the switches?
We have labview 8.2, 8.5, and 8.6. by default we're now coding in 8.6
You are correct about the nomenclature error i have made, the joystick buttons are switch until released. I will read the axes of the joystick and the buttons from the directinput based labview subvi.
In my case will use labview globals to provide communication to dependencies, as the joystick operation subvi PI provides contains a while loop with a long cycle time. The joystick polling will have to be in a separate loop as it will not be uniquely operating this subvi, but more than one, simultaneously.
Would an occurance be better suited to this?
12-03-2008 08:51 PM
altenbach wrote:Here's one possibility to solve your problem (LabVIEW 8.5). There are many other ways to do this, but you dfefinitely don't need any blue wires for the logic. :).
This is better than what i coded before. In fact, i see that what i've coded is flawed with a switch when released behaviour. Another improvement on my algorithm is that you're only carrying 2 bits in memory for the loop iteration rather than 16 or 8 for the integer. The integer to bool array to array index, can be replaced by a bit rotation with a carry as the boolean indicator; but as you have stated, this is not a latch situation.
I would be quite interested to see what other alternate ways you have in mind are.
thanks altenbach.