12-13-2010 09:04 PM
Thanks to all who posted. Omar II's reply was selected as the solution because he actually posted code that worked. Johnsold got a kudo for proposing the correct property that made it work.
I already knew how to read a joystick button in a loop; I really did need to know how to use that to trigger an event.
Thanks again,
Ed
12-13-2010 09:11 PM
Then you should mark Lynn's (johnsold) message as the solution to your question.
12-13-2010 11:09 PM
Ravens Fan,
I felt that Omar II's response was the one that solved the problem for me--I already had the idea that the Value (Signaling) property was what I needed (it was in the subject of the post), but I didn't know how to apply it. Omar II gave me that, so he got the Solution. Lynn got a kudo for telling me I was on the right track, and that what I wanted to do wasn't impossible.
To my way of thinking, posting code is a more useful solution than telling me that I can read the Help. I've been reading the Help for the past three days without learning what I wanted to know.
Anyhow, after more experimentation, I realized that Omar II's code, although showing me what I needed, had an undesirable behavior--it triggered the event on button down AND button up (if the time between pressing and releasing the button was longer than the Wait in the loop). So I created a new version that only triggers the event on button down (attached below).
Once again, thank you all for your help.
Ed
12-14-2010 02:42 AM
12-14-2010 09:10 AM
GerdW,
I hate to display my ignorance (I don't why, I should be used to it by now ) but what is the symbol on the inverting input to the And gate? I am happy to find any way to streamline the code, because my next step will be to expand this to read several buttons and an axis on the joystick.
Thanks,
Ed
12-14-2010 09:23 AM
It's a Feedback Node, which is like a shift register except it does not need to be contained inside a loop. It's storing the previous value, making for a quick comparison to see if the value has changed.
12-14-2010 10:32 AM
OK, thanks. I should have known that. I'll try it with the joystick tonight.
Ed
12-14-2010 10:44 AM - edited 12-14-2010 10:45 AM
OK, I still don't know why you need an event structure at all, because whatever you do in the event case could be done in the original case structure of the polling loop. Don't overcomplicate things!
To trigger on a TRUE->FALSE transition, use implies from the boolean palette.
Here's a quick rewrite.
Some extra comments to your original code:
12-14-2010 11:12 AM
altenbach,
I'll have to consider your extra comments this evening, when I can try them along with my hardware. There are clearly a more elegant ways to compare the new value with the old value than what I posted, and I appreciate the recommendations. I've never used Implies before, so I will need to look at that one.
As to why I need an event structure: the joystick capability is being added to an existing program which uses the Producer/Consumer (Events) architecture to control an ROV. There are two Consumer loops, so that I can trigger each without waiting for the other to complete--for instance, I want to steer the vehicle without waiting for the last Drive Forward command to complete. Or I want to Stop the vehicle without waiting for the Steer command to complete. I wrote the original program using Producer/Consumer (Events) because I wanted to learn how to use that architecture and it seems ideal for the application. I am studying (and gaining experience) toward the CLD exam, maybe next year, so I give myself assignments which use the architectures I might need for that exam.
But I didn't want to post the entire ROV .vi just to ask a question about triggering an event. I already knew how to read the joystick in a loop, and I can think of a few ways to read multiple buttons to control a State Machine, but my goal was to learn how to trigger events with non-UI inputs.
Ed
12-15-2010 01:16 AM
Okay, I tried some of the recommended techniques. I like the Feedback Node--it's a nice easy to read method that does what my two shift registers were doing. I will use that.
I couldn't get the "Implies" function to work for me--I think because it is basically an Or function, it was continuously triggering the event, and the LED was blinking. Not exactly what I wanted. But I did relocate the Stop control to the joystick read loop; that is much cleaner.
Thanks a lot to all; I've learned a lot.
Ed