To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 885
884  |  886
Subject: 
Re: Event dispatch
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Sun, 17 Dec 2000 21:30:50 GMT
Viewed: 
1772 times
  
In article <G5q4F2.3vF@lugnet.com>, "Thomas Zapf-Schramm"
<Thomas.Zapf-Schramm@home.ivm.de> wrote:


But what about the event dispatch? Is somethig like this possible?

task LightWatcher() {
    do while true() {
        monitor (EVENT_MASK(GLOOMY) |
                 EVENT_MASK(DULL) |
                 EVENT_MASK(INTENSE) ) {
            / do something
        }
        catch {
            switch ( ?????)  {    / What should be the expression?
                GLOOMY:
                      / perform GLOOMY action
                DULL:
                      / perform DULL action
                INTENSE:
                      / perform INTENSE action
                default:
            }
        }
    }
}


How can I react in LightWatcher to the correct triggering event?
Do I have to write a separate monitorong task  for each event I want do
to
handle in a specific way?


I think the choice of whether to have a single task waiting on multiple
events or multiple tasks each servicing a single event depends on the
following questions:

1) Is there a single activity that should be happening that gets
interrupted by ANY event?  If yes, this would be a strong indicator for
using a single task since the body of the monitor statement would be the
activity to be interrupted.

2) Is there a need for multiple events to be responded to concurrently?
If yes, this is a strong indicator for multiple tasks since each task
could respond in the catch clause and several of these could be running
concurrently.

If both questions are "no", then it comes down to personal preference,
and perhaps if you're running out of tasks and minor performance issues.
If both questions are "yes", then I things get complicated...either a
single monitor task starts multiple response tasks or multiple monitor
tasks have to coordinate (perhaps through acquire or killing a separate
task) the single activity that needs to be interrupted.

Or can I distinguish between events using EvenState() somehow?
What are the EventStates of Events of  Boolean Events (0/1 or 0/2)?

ActiveEvents(n) can be used to determine the event that triggered a
catch where n is the task number (main is always 0).  TLG added a
special variation - ActiveEvents(10) - that returns the event triggered
for the currently running task (only valid for recent versions of the
RCX2 firmware - 0328 should be fine).  I've already added a more
convenient call in the API, which should appear in the next NQC release:

   #define CurrentEvents() ActiveEvents(10)

That lets you do something like this

monitor(EVENT_MASK(1) | EVENT_MASK(2))
{

}
catch
{
  if (CurrentEvents() & EVENT_MASK(1))
  {
  }
  else
  {
  }
}


At some point (now that ActiveEvents(10) is possible) I'll probably add
multiple catch clauses into the compiler...

monitor(EVENT_MASK(1) | EVENT_MASK(2))
{
}
catch (EVENT_MASK(1))
{
  // when event 1 is triggered
}
catch
{
  // any other events
}



What happens if we are in a handler and the same or another event fires
again?


I haven't tested this at all.  Ideally the new event is pending and upon
exit from the catch() the new one would be triggered.  Unfortunately, I
don't think this happens...after the catch events are implicitly not
being monitored, and the next time event monitoring is entered I believe
the "pending" events get cleared.  Just a guess, though.

If anyone has some comprehensive tests on this please let me know.  I'd
like to make the simulator accurate in this respect.

Dave Baum

--
reply to: dbaum at enteract dot com



Message has 1 Reply:
  Re: Event dispatch
 
(...) Meanwhile I found this out too. (...) I think I never would have found this feature. (...) I like the new features in 2.3a1! (I'll try them tonight). TZS (24 years ago, 18-Dec-00, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  Event dispatch
 
In the SDK2 documentation for the new Lego-Scripting language events are used as follows: sensor Opto on 2 Opto is light as percent event gloomy when Opto is 0..20 event dull when Opto is 30 .. 40 event intense when Opto is 80 .. 100 main { start (...) (24 years ago, 17-Dec-00, to lugnet.robotics.rcx.nqc)

3 Messages in This Thread:

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

This Message and its Replies on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

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