Go to Post Too often teams forget that pretty isn't always good. - Al Skierkiewicz [more]
Home
Go Back   Chief Delphi > Technical > Programming > NI LabVIEW
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-10-2010, 13:13
Itamar's Avatar
Itamar Itamar is offline
Registered User
FRC #1943 (NeatTeam) & FRC #4590 (GreenBlitz)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Israel
Posts: 83
Itamar is an unknown quantity at this point
How do I use interrupts?

Hello,
For the past few days I have been searching the web for an explanation how to use interrupts. I didn't find anything useful.
All the code bits I have seen untill now talked about a timed loop.
Is it possible to use interrupts to execute a certain VI the second a microswitch is clicked? If so, please tell me how.

Many thanks,
Itamar.
Reply With Quote
  #2   Spotlight this post!  
Unread 18-10-2010, 14:50
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Itamar View Post
Is it possible to use interrupts to execute a certain VI the second a microswitch is clicked? If so, please tell me how.
You don't want the interrupt service routine to run your VI if it contains any delays or a non-trivial amount of code. You will mess up the system's latency.

You want to let the RTOS (vxworks) handle asynchronous events that require non-trivial amounts of processing.

Can you describe in more detail what you are trying to accomplish, and why it can't wait 20ms for the next teleop iteration?



Reply With Quote
  #3   Spotlight this post!  
Unread 19-10-2010, 05:26
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Is it possible to use interrupts to execute a certain VI the second a microswitch is clicked?
You probably don't really mean the same second, as in within a second, but what time do you mean?

If you open the Periodic Timing VI, there is a loop that defaults to run once every 100ms and another that defaults to run every 10ms. You can add more loops or change those to run faster, if that is what you need.

As a way to bound the problem, calculate how far the thing your are measuring will move in a millisecond. Use that to scale your timing needs.

As for actually using interrupts, I didn't see an example, but it looks like you'd bundle together the Digital info for the digital channel monitoring the switch, then loop handling the interrupts as they are returned, then cleanup at the end. Determin if this is the correct transition for your digital line, or if you want to interrupt on both open and close and update the Booleans on Open accordingly. Note that the attached image doesn't have the rest of the framework or the watchdog in place and assumes that you will incorporate this into the framework.
Attached Thumbnails
Click image for larger version

Name:	Clipboard 1.png
Views:	61
Size:	11.7 KB
ID:	9359  
Reply With Quote
  #4   Spotlight this post!  
Unread 19-10-2010, 10:05
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Greg McKaskle View Post
If you open the Periodic Timing VI, there is a loop that defaults to run once every 100ms and another that defaults to run every 10ms. You can add more loops or change those to run faster, if that is what you need.
... or just put it in teleop (20ms), if that is fast enough and it doesn't need to run concurrently with your other teleop code.

Is the 2011 FRC LabVIEW Framework still under development? If so, would it be possible to add support for event handlers? That way, folks who ask about interrupts could be directed to the event-handler feature of the Framework instead, where the OS could provide the proper priority and concurrency management.



Reply With Quote
  #5   Spotlight this post!  
Unread 19-10-2010, 16:54
Greg McKaskle Greg McKaskle is offline
Registered User
FRC #2468 (Team NI & Appreciate)
 
Join Date: Apr 2008
Rookie Year: 2008
Location: Austin, TX
Posts: 4,751
Greg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond reputeGreg McKaskle has a reputation beyond repute
Re: How do I use interrupts?

Since you had already mentioned the teleop timing, I didn't cover it. I listed ways to get other timing values that aren't driven by the FRC protocol and how to connect to the interrupts raised by the FPGA.

Can you give more info as to what OS event handling or Framework event handling means to you?

Do you want to use the LV event structure? Registered callbacks? Asynchronous VIs that wait for a condition?

What is the concurrency management that you refer to?

Basically, can you give more info on what you have in mind.
Greg McKaskle
Reply With Quote
  #6   Spotlight this post!  
Unread 19-10-2010, 17:52
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

An event handler, as I was using the phrase, is application-level code that gets executed when an external asynchronous hardware event occurs. The execution of this code is "managed" by LabVIEW/vxworks in the sense that resources are allocated to the handler based on time-sharing and priority of other tasks concurrently competing for resources.

The 2010 FRC LabVIEW Framework had explicit support for periodic tasks. These periodic tasks are time-based, not event-based. You could put code in there to poll for an external event of interest. You could even change the default 10ms task to 1ms, although that would waste CPU resources if the event you're polling for occurs much less frequently than that.

I don't know what "Asynchronous VIs that wait for a condition" are, but that sure sounds like what I have in mind when I use the phrase "event handler". Perhaps the 2011 Framework could include a shell or template for something like that, as was done for the periodic tasks, to make it more accessible.

I make a distinction between "interrupt service" code and "event handler" code. To me, "interrupt service" is what happens from the time the interrupt occurs until the code ACKs the interrupt (if required by the hardware) and re-enables global interrupts. During this period everything else is locked out: There is no concurrency management (time sharing) because there is no concurrency. I'll go out on a limb here and say that for the purposes of FRC programming, interrupts should be serviced ONLY by LabVIEW/vxworks/FPGA: There should be NO need for teams to be writing their own interrupt service code.

So when I see a poster asking "how to use interrupts" two thoughts come to mind: 1) what is this team doing that is so time-critical that it cannot properly be handled in a fast periodic task, and 2) do they really mean they want to write an interrupt service routine, or do they want to write an event handler.





Last edited by Ether : 20-10-2010 at 14:23.
Reply With Quote
  #7   Spotlight this post!  
Unread 19-10-2010, 18:28
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,795
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: How do I use interrupts?

Would the LabVIEW Event Structure fit what you're looking for? It's available on the Programming->Structures palette and would use robot-side events rather than front panel events.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 20-10-2010 at 13:30.
Reply With Quote
  #8   Spotlight this post!  
Unread 19-10-2010, 22:24
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Mark McLeod View Post
Would the LabVIEW Event Structure fit what you're looking for?
Yes and no.

This part sounds good:

Quote:
When your OS detects that an event has occurred, it notifies applications so they can react by executing any code written specifically for that event.
But this part not so much:

Quote:
the event structure responds to every registered event detected by the OS and executes those responses synchronously in the order the events occurred.
In LabVIEW, periodic tasks can be prioritized, and tasks with the same priority can run concurrently via time-slicing. Is there a way in LabVIEW to treat event handlers the same way?



Reply With Quote
  #9   Spotlight this post!  
Unread 20-10-2010, 12:13
Itamar's Avatar
Itamar Itamar is offline
Registered User
FRC #1943 (NeatTeam) & FRC #4590 (GreenBlitz)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2010
Location: Israel
Posts: 83
Itamar is an unknown quantity at this point
Re: How do I use interrupts?

To tell you the truth, I'm a bit lost with all of your comments... After reading Ether's comment, I'm pretty sure that what I need is an event handler.
So... is there an option to use events for a microswitch?
Reply With Quote
  #10   Spotlight this post!  
Unread 20-10-2010, 12:32
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Itamar View Post
To tell you the truth, I'm a bit lost with all of your comments... After reading Ether's comment, I'm pretty sure that what I need is an event handler.
So... is there an option to use events for a microswitch?
Can you tell us what function the microswitch serves? What activates the switch, and what do you want to happen when the switch is activated?



Reply With Quote
  #11   Spotlight this post!  
Unread 20-10-2010, 12:42
Alan Anderson's Avatar
Alan Anderson Alan Anderson is offline
Software Architect
FRC #0045 (TechnoKats)
Team Role: Mentor
 
Join Date: Feb 2004
Rookie Year: 2004
Location: Kokomo, Indiana
Posts: 9,112
Alan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond reputeAlan Anderson has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Itamar View Post
To tell you the truth, I'm a bit lost with all of your comments... After reading Ether's comment, I'm pretty sure that what I need is an event handler.
So... is there an option to use events for a microswitch?
For really quick response to a digital input, interrupts are likely the simplest choice, but the rest of the context is also important to finding the "right" solution. What do you intend to make happen when the switch activates?
Reply With Quote
  #12   Spotlight this post!  
Unread 20-10-2010, 13:13
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,563
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Ether View Post
An event handler, as I was using the phrase, is application-level code that gets executed when an external asynchronous hardware event occurs. The execution of this code is "managed" by LabVIEW/vxworks in the sense that resources are allocated to the handler based on time-sharing and priority of other tasks concurrently competing for resources.
I had assumed that the code the Greg posted worked this way and not that everything in side the while loop was running inside the ISR.
Reply With Quote
  #13   Spotlight this post!  
Unread 20-10-2010, 13:28
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Joe Ross View Post

Quote:
Originally Posted by Ether
An event handler, as I was using the phrase, is application-level code that gets executed when an external asynchronous hardware event occurs. The execution of this code is "managed" by LabVIEW/vxworks in the sense that resources are allocated to the handler based on time-sharing and priority of other tasks concurrently competing for resources.
I had assumed that the code the Greg posted worked this way and not that everything in side the while loop was running inside the ISR.
Perhaps Greg could confirm?

If so, back to my original suggestion: the 2010 Framework had "placeholders" for periodic tasks. Perhaps doing the same in the 2011 Framework for event handlers would be helpful. Users asking about "interrupts" could then be directed to the Framework's support for event handlers.




Last edited by Ether : 20-10-2010 at 14:20.
Reply With Quote
  #14   Spotlight this post!  
Unread 20-10-2010, 14:09
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,065
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Itamar View Post
I'm pretty sure that what I need is an event handler.
So... is there an option to use events for a microswitch?
Yes, you could use an event handler http://en.wikipedia.org/wiki/Event_handler to respond to the microswitch.

Using LabVIEW, you can set up the circuitry connected to the microswitch to generate an interrupt http://en.wikipedia.org/wiki/Interrupts when the switch closes (or opens, or both). When the interrupt occurs, the operating system immediately responds and queues up your event handler for execution.

The 2010 Framework doesn't contain any template or example code for event handlers. See Greg's and Mark's earlier posts for suggestions how to do this.

Before you do that though, if you tell us what you are trying to accomplish http://www.chiefdelphi.com/forums/sh...0&postcount=10 there might be a better way to handle it.







Last edited by Ether : 20-10-2010 at 14:14.
Reply With Quote
  #15   Spotlight this post!  
Unread 20-10-2010, 14:31
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,795
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: How do I use interrupts?

There are some dangers to beware of when using the Interrupt palette.

P.S. Since this is for use with a mechanical switch, it can be done, but you'll get pretty erratic results until you learn how to debounce a switch.
What will happen is you'll get multiple interrupts all within a fraction of a second, as the switch makes and breaks contact several times before settling down to a firm contact. In the example attached, throwing a delay into "React" will effectively debounce the switch, but releasing the switch will probably cause the action all over again.
Mechanical switches also operate slowly enough for polling to be a possibly more effective alternative.

Quote:
Originally Posted by LV Help
...the robot program might hang if no interrupts occur when you shut down the robot. Instead, specify a finite time for the CompactRIO device to wait for an interrupt. When the CompactRIO device times out, check if the robot is shutting down. If the robot is not shutting down, return to the Wait VI.
This issue is probably moot in normal operation, because your robot program is typically shutdown by powering off the robot. Let's see an interrupt handler survive that!


on the other hand...
Quote:
Originally Posted by LV Help
Specifying a finite time to wait for an interrupt can introduce jitter into the interrupt handling process. The CompactRIO device might be handling a timeout at the same time an actual interrupt occurs. Therefore, the CompactRIO device takes longer to recognize and handle the interrupt. The smaller the Timeout (ms), the greater the likelihood of introducing jitter.
There appears to be a limit of 8 of these interrupts available for use by us.

I've attached a variation of Greg's interrupt example that puts it in terms of the 2010 framework.
You can use an Analog Trigger instead of a Digital Input if you'd rather.
Attached Thumbnails
Click image for larger version

Name:	InterruptExample.jpg
Views:	60
Size:	24.9 KB
ID:	9362  
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 21-10-2010 at 13:25.
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

vB 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
Interrupts, Interrupts, and more Interrupts! dcbrown Programming 14 06-03-2008 23:12
How many interrupts is too many interrupts? Madison Programming 14 08-02-2008 12:09
How to use motors xmarufx Motors 9 02-08-2005 00:22
How to use Generate_Pwms() ? steven Robotics Education and Curriculum 0 01-04-2005 11:43
How did you learn how to use Inventor? Greg McCoy Inventor 26 24-05-2003 01:55


All times are GMT -5. The time now is 10:05.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi