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 / 24533
24532  |  24534
Subject: 
Re: Basic NQC Problem
Newsgroups: 
lugnet.robotics
Date: 
Sun, 13 Nov 2005 13:24:29 GMT
Viewed: 
1945 times
  
In lugnet.robotics, Ralph Toepper wrote:

Cameron Hooper wrote:

The problem is stopping is delayed until control returns to
the top of the while(){} control structure. I want it to stop
as soon as the sensor is pressed.

   There's a couple of ways to fix it. One is as Raplph said - have the first
task start up a dedicated second task that does nothing more than look for a
touch in a very tight loop. Very roughly, it would work something like this:

task watch_sensor()
{
   while(true)
   {
      while(SENSOR_1 == UNTOUCHED);
      stop walking;
      // do whatever it is you need to if touched - stop motors,
      // beep, whatever
      start walking;
   }
}

task walking()
{
   while(true)
   {
      // walk back and forth
   }
}

task main()
{
   start walking;
   start watch_sensor;
}

   The other way is to use what the RIS software does, which is events. You can
define an event (like "sensor pressed"), and then have a section of code
run while the firmware does all the sensor-watching for you:

task main()
{
   // setup sensors etc.

   SetEvent(MY_EVENT, SENSOR_1, EVENT_TYPE_PRESSED);

   while(true)
   {
      monitor(EVENT_MASK(MY_EVENT))
      {
         // have the walking back and forth stuff in here;
         // the moment the touch sensor is pressed, the
         // code will jump to the "catch" routine below,
         // without waiting for this stuff to loop back
      }
      catch
      {
         // put you code for handling the touch sensor being
         // pressed in here
      }
      // any code placed here will execute after the catch
      // routines are done, or after a "normal" exit (if any
      // from the monitor routines (like if they weren't an
      // infinite loop).
   }
}

Personally, I now find the second method to be the way to do it, but I've also
used tasks stopping and starting each other all over the place. There's actually
a third way of doing this as well using the NQC "acquire" command (very similar
in some respects to the "monitor" command).

    while(0 == 0) { // you might find a better construct

   I find while(true) to be useful here, as it makes it readable, is short, and
the NQC compiler crunches it right down to an infinite loop (no conditional
check, so it's faster).

a better RCX firmware exists, that is much faster. Its called
the "Dick Swan Firmware".

   True the Swan firmware is faster, but for something like this it's not
needed. At 3 ms per bytecode, the standard firmware can do an awful lot (if not
everything).

--
Brian Davis



Message has 1 Reply:
  Re: Basic NQC Problem
 
Thanks to both Brian and Ralph. Your responses were very detailed and helpful. I've played around with the suggested code and learnt a lot. Are events relatively new in NQC? I purchased a second hand copy of David Baum's Definite Guide (1st ed). I (...) (19 years ago, 15-Nov-05, to lugnet.robotics)

Message is in Reply To:
  Re: Basic NQC Problem
 
(...) Big place to ask your questions here. I'll try to answer it, best i can. (...) You should switch of the motors and StopAllTasks in the check_sensor() task, if the bumper is hit. The main task does not furthermore look like that algorithmic as (...) (19 years ago, 12-Nov-05, to lugnet.robotics)

5 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
    
Active threads in Robotics

 
Contact Recovery Nerd for Speedy USDT / BTC Recovery
9 hours ago
 
Different Sensors Available...
23 hours ago
Custom Search

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