To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 19174
19173  |  19175
Subject: 
events or infinite loops... which is better?
Newsgroups: 
lugnet.robotics
Date: 
Fri, 11 Oct 2002 21:32:09 GMT
Viewed: 
958 times
  
Hi Everyone,
I just recently learned how to use event monitoring, and I really like it.
My question is whether or not this method is more efficient than infinite
loops. I always used to check for sensor readings using an infinite loop
something like this:
while(true)
{
  if(SENSOR_1 >= 50)
  {
    //do something here...
  }
}
The thing that bothered me is that the program has to hang in the loop for
it to work. Then I found out about event monitoring, and wondered if these
were equivalent to interrupts. Using interrupts to respond to sensor
readings would be much better, since the program can do something else in
the meantime, and basically ignores the sensors until an interrupt is
triggered. Using event monitoring would look something like this:
SetEvent(0,SENSOR_1,EVENT_TYPE_HIGH);
SetUpperLimit(0,50);
monitor(EVENT_MASK 0)
{
   until(false);
}
catch(EVENT_MASK 0)
{
   //do something here
}

So, are these two methods essentially equivalent? I realize you can 'do
something else' with the first method by having your infinite loop in one
task, and work on something else in another task. But, you are really just
jumping between tasks quickly. If events are actually interrupts, then I
think it would be more efficient this way, since the cpu can spend its time
doing other things, and only pauses when the interrupt line is triggered.
Can anyone more knowledgable offer some feedback on this?
Rob



Message has 2 Replies:
  Re: events or infinite loops... which is better?
 
(...) Events are generally going to be more efficient since no bytecodes need to be executed to continually check for a condition. However, efficiency is not always the most important factor. I don't think either one is necessarily "better". A lot (...) (22 years ago, 12-Oct-02, to lugnet.robotics)
  nqc adapt project : nqc easier
 
Hello I've created a langage for RCX that use nqc. It's a langage that is very easier than nqc. It use nqc cause it translate word into nqc command. You can also integrate nqc code. a little example : begin go_fordward wait 5 /* all time in second (...) (22 years ago, 13-Oct-02, to lugnet.robotics)

8 Messages in This Thread:




Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR