Go to Post We're not disappointed if we don't achieve excellence, so long as we did everything we could in our pursuit of it. - JVN [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
  #16   Spotlight this post!  
Unread 20-10-2010, 16:07
Jon236's Avatar
Jon236 Jon236 is offline
Registered User
AKA: Jon Mittelman
FRC #2648 (Infinite Loop)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Windsor, Maine
Posts: 741
Jon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond repute
Re: How do I use interrupts?

Mark, if you handle the interrupt with the Event Case inside the While Loop, doesn't the Interrupt Wait vi handle the interrupt reset for you while you do whatever you want in the Event Case? I would think you would just want to write to a FGV or Global to allow a parallel process actually DO something.
__________________
Jon Mittelman

Senior Judge Advisor New England & Israel 2014-2015
Infinite Loop Mentor 2011-2015
TechnoTicks Mentor 2000-2011
Championship Chairman's Award 2009 Team236 TechnoTicks
Judge 2010-2015 Championships
Senior Judge Advisor New England District Championship 2014-2015
Judge Advisor Tel Aviv Regional 2007-2015
Judge Advisor Pine Tree Regional 2013
Maine Regional Planning Committee
New England District Planning Committee
Lead Inspector Microsoft Tel Aviv Regional 2006-2008
Judge & Lead Inspector GM/Technion Tel Aviv Regional 2006
Judge UTC Hartford Regional 2006
Reply With Quote
  #17   Spotlight this post!  
Unread 20-10-2010, 19:21
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,906
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?

Quote:
Originally Posted by Jon236 View Post
Mark, if you handle the interrupt with the Event Case inside the While Loop, doesn't the Interrupt Wait vi handle the interrupt reset for you while you do whatever you want in the Event Case? I would think you would just want to write to a FGV or Global to allow a parallel process actually DO something.
This depends on what you're trying to do and the time you have to accomplish it. The answer gets back to the question Ether asked, "What is the application?"

In a traditional Interrupt Service Handler (ISR) what you say is very true. You do want to get out of it just as fast as possible, usually by simply setting a flag or incrementing a counter, and then leaving further processing up to some independent polling task or triggered process.
A traditional example would be an encoder where interrupts come fast and furious and you must make sure they are all captured and counted. In this case the reset/repeat elapsed time is much too fast to waste time process when you could be missing subsequent interrupts.

I may be reading too much between the lines here...
but this doesn't sound like a rapid-fire response ISR though. This sounds like an event trigger.

This application, what little we know of it, is a micro-switch which is quite a slow (& noisy) device, especially when you take into account the debouncing delay that will probably be required (and that you have to add). An interrupt is not usually a good solution for a mechanical switch, because of all the false interrupts that get generated when a switch makes contact just once. Your code will probably run several times in a row on a single switch press. It probably won't matter which edge you chose as you'll most likely get both rising and falling edges at the same time, whether the switch is being pushed or released.

So, I'm imagining that they just want to react to the switch getting hit just as fast as computerly possible, with a relatively long (for the cRIO) delay afterwards to do whatever it is they plan to do.
Say the switch is just intended to trigger an event like "kick a ball" when it hits the switch, then that's a slow process that could do all it's processing in the interrupt handler. Primarily because you don't want it to happen again until the mechanism has recycled/reloaded. Code has to be added to delay long enough to debounce the switch anyway.

When designing your code you need to take into account how fast you need to be able to repeat the process, whether the process is locked until recycled, etc.

P.S.
I don't think this Interrupt function stores events. I think it will only "hear" interrupts that occur while Interrupt Wait is active. So the entire time spent in the React case will be deaf to further interrupts.
__________________
"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:46. Reason: Simplifying a tiny bit.
Reply With Quote
  #18   Spotlight this post!  
Unread 20-10-2010, 20:31
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,756
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?

To answer some, hopefully all of the questions. The Wait for Interrupt is a somewhat high level, but relatively low jitter way to respond to an FRC specific interrupt raised by the FPGA.

Notice that Interrupt Open lets you specify specific FRC related I/O triggers. In the general FPGA tool, you write the FPGA to poll, calculate, or do whatever you want at 40MHz or less. The FPGA code you write can raise the one of N interrupts on the PPC (32 interrupts I believe, but it could be less). The lower level library let you determine whether the acknowledge will take place after your code or before. For FRC, it is hidden and set to ack first.

To be honest, I haven't used the interrupt stuff a ton, but unlike many other libraries where close is pretty foolproof, you may want to ensure that you close resources or you may find some odd behaviors. If so, reboot the cRIO.

Another comment on the interrupt stuff, keep in mind that the heavy protection and isolation you associate with OSes is far thinner and sometimes nonexistent on RT systems such as VXWorks. Newer versions of VXWorks have different configurations which support more user protection and isolation, but the version on the cRIO has high I/O throughput, but less isolation, in fact very little.

I don't believe that the event structure works on RT, at least much of it doesn't work there since the event structure is primarily for UI operations. It is certainly not setup to handle interrupts. The event structure also deals with user events which can be used much like queues.

If you need to set priorities, and I highly doubt that you do, you can set different subVI priorities and put each of them to wait on different interrupts.

Greg McKaskle
Reply With Quote
  #19   Spotlight this post!  
Unread 20-10-2010, 22:08
Jon236's Avatar
Jon236 Jon236 is offline
Registered User
AKA: Jon Mittelman
FRC #2648 (Infinite Loop)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Windsor, Maine
Posts: 741
Jon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond repute
Re: How do I use interrupts?

Quote:
Originally Posted by Greg McKaskle View Post

If you need to set priorities, and I highly doubt that you do, you can set different subVI priorities and put each of them to wait on different interrupts.

Greg McKaskle
Thank you for clarifying the use of the event structure. As far as priorities, I would want to use them to determine machine behavior based on sensed events. I think my takeaway from your discussion is that I should use a state machine based on the sensor inputs. My concern would be how to truly interrupt a process such as raising an arm when an imminent collision is sensed. Even if the entire state machine (say, for raising an arm) is contained inside another case statement (collision imminent, true or false), if you are executing state machine logic within the 'collision false' case, wouldn't there be a significant delay (20 ms) before switching to the 'collision true' case?
__________________
Jon Mittelman

Senior Judge Advisor New England & Israel 2014-2015
Infinite Loop Mentor 2011-2015
TechnoTicks Mentor 2000-2011
Championship Chairman's Award 2009 Team236 TechnoTicks
Judge 2010-2015 Championships
Senior Judge Advisor New England District Championship 2014-2015
Judge Advisor Tel Aviv Regional 2007-2015
Judge Advisor Pine Tree Regional 2013
Maine Regional Planning Committee
New England District Planning Committee
Lead Inspector Microsoft Tel Aviv Regional 2006-2008
Judge & Lead Inspector GM/Technion Tel Aviv Regional 2006
Judge UTC Hartford Regional 2006
Reply With Quote
  #20   Spotlight this post!  
Unread 21-10-2010, 13: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,906
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?

Quote:
Originally Posted by Jon236 View Post
My concern would be how to truly interrupt a process such as raising an arm when an imminent collision is sensed.
We have one example of how to do this in the Framework handling of Autonomous Independent.vi.
At the end of Autonomous mode the vi gets killed no matter what it is doing at the moment.

I think the more standard approach will be to do what we do now and design checks like limit switches into our code or use the CAN Jaguar limit switches.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Reply With Quote
  #21   Spotlight this post!  
Unread 21-10-2010, 19:29
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,113
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 Jon236 View Post
...I think my takeaway from your discussion is that I should use a state machine based on the sensor inputs. My concern would be how to truly interrupt a process such as raising an arm when an imminent collision is sensed.
The answer seems obvious to me. Make "imminent collision sensed" one of the states your machine can be in, and use the sensor inputs to put it into that state when appropriate.
Reply With Quote
  #22   Spotlight this post!  
Unread 21-10-2010, 21:26
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
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 Jon236 View Post
Even if the entire state machine (say, for raising an arm) is contained inside another case statement (collision imminent, true or false), if you are executing state machine logic within the 'collision false' case, wouldn't there be a significant delay (20 ms) before switching to the 'collision true' case?
Yes, if you are running the state machine at 50Hz. You can't achieve the immediate response you are seeking simply by changing the design of the state machine.

Quote:
My concern would be how to truly interrupt a process such as raising an arm when an imminent collision is sensed.
In the design you are referring to, would it suffice to simply remove power from the motor as quickly as possible to "interrupt the process", and then allow the next 20ms iteration to handle it from there?

If so, you could use the example Mark provided here and put your "event handler" code (to depower the motor) where the "react" note is in the diagram. You could also set a flag (like a global variable) that your state machine could read, to keep it from un-doing the motor depower. One possible way would be to test this flag after every motor command in the state machine, and depower the motor if the flag is set.

You could experiment with putting a small capacitor across the microswitch to help de-bounce it.



Reply With Quote
  #23   Spotlight this post!  
Unread 21-10-2010, 21:47
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,906
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?

Adding to Ether's idea, you might encapsulate the Motor speed command in a subvi all by itself that everyone calls to set that motor speed. With an optional input for the emergency stop flag.

Then the interrupt handler calls it to set the emergency stop flag (& speed to zero), while the state machine calls it for normal operation. The subvi only allows one caller at a time, so you avoid the race condition of setting the speed in two different places near-simultaneously.
In the subvi if the emergency stop flag is set, only an explicit reset allows non-zero motor speeds.
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle
Reply With Quote
  #24   Spotlight this post!  
Unread 21-10-2010, 22:12
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,125
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
Adding to Ether's idea, you might encapsulate the Motor speed command in a subvi all by itself that everyone calls to set that motor speed. With an optional input for the emergency stop flag.

Then the interrupt handler calls it to set the emergency stop flag (& speed to zero), while the state machine calls it for normal operation.
Thanks Mark, that is a MUCH cleaner approach. I like it.



Reply With Quote
  #25   Spotlight this post!  
Unread 21-10-2010, 22:30
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,756
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?

Perhaps the previous robot architecture is influencing the thinking process.

The teleop code is indeed limited to 20ms start gaps, but that limit need not leak into the rest of the robot code. You can have loops running at the rate appropriate to the sensors or mechanism. Often that just means to build a loop and place a Wait or Wait ms Multiple inside. If you find that a loop is running quite fast, you may choose to switch to the timed loop. It has multiple clocks you can choose from, and you can choose very small delays and different delay and scheduling policies. The timed loop is rich in possibilities, which also means it can be confusing if you dive in and then wonder why your app behaves the way it does. I'd encourage you to look at examples and read up on it a bit and perhaps even experiment with it first. And I'll state again that priorities are a tricky tool, and don't be too careless with them or you will starve out other tasks, perhaps even starving the teleop itself.

If your app's loops need to coordinate, but not be placed into the same loop, look at using the RTFIFO to send notifications/events between them. You can even use the timeout to combine a periodic and event driven response.

If you are interested in going to the next level in LV RT, I'd encourage you to look at examples based on those two concepts, RT FIFOs and Timed loops and think about how your scheduling for sensor loops and state machines is built from those. The cool thing is that rather than having one event mechanism that is interleaved, you can have as many as you like with much finer grained multitasking.

Greg McKaskle
Reply With Quote
  #26   Spotlight this post!  
Unread 22-10-2010, 09:50
Jon236's Avatar
Jon236 Jon236 is offline
Registered User
AKA: Jon Mittelman
FRC #2648 (Infinite Loop)
Team Role: Mentor
 
Join Date: Jan 2004
Rookie Year: 2000
Location: Windsor, Maine
Posts: 741
Jon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond reputeJon236 has a reputation beyond repute
Re: How do I use interrupts?

Greg, thank you for that explanation and suggested directions.
__________________
Jon Mittelman

Senior Judge Advisor New England & Israel 2014-2015
Infinite Loop Mentor 2011-2015
TechnoTicks Mentor 2000-2011
Championship Chairman's Award 2009 Team236 TechnoTicks
Judge 2010-2015 Championships
Senior Judge Advisor New England District Championship 2014-2015
Judge Advisor Tel Aviv Regional 2007-2015
Judge Advisor Pine Tree Regional 2013
Maine Regional Planning Committee
New England District Planning Committee
Lead Inspector Microsoft Tel Aviv Regional 2006-2008
Judge & Lead Inspector GM/Technion Tel Aviv Regional 2006
Judge UTC Hartford Regional 2006
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:59.

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