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 / 969
968  |  970
Subject: 
Re: Q: Multitasking, and reacting to sensors
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Tue, 6 Feb 2001 13:12:00 GMT
Viewed: 
1816 times
  
Hej Tobias!

Tobias Möller <tobias.moller@telia.com> writes:

In NQC, I've tried to use the "If" statement, but it doesn't work
correctly... It doesn't react to the sensor!

Does this kind of procedure need to involve multitasking to work right?
I put the if statement inside task main{} or whatever it's called.

No, rather you need a While or Until loop.
Normal programming languages are different from the RCX code.
In RCX code the watchers are running all the time, in NQC
you need to program the repetition yourself.
A program for simple rover could look like this:

#define BUMPER   SENSOR_1

task main()
{
  SetSensor(BUMPER, SENSOR_TOUCH);

  while(true){
    // go forward
    OnFwd(OUT_A+OUT_C);

    // wait for bumper
    until(BUMPER==1);

    // back up and turn
    OnRev(OUT_A+OUT_C);
    Wait(50);
    OnFwd(OUT_A);
    Wait(50);
  }
}

(no guarantees for correctness, I just wrote it without any testing)

This leads me to the second question...
Although I already may have the answer...
Could someone give me a simple example of multitasking? I've read the
documentation, I know what it does, I just don't know how to use it.

If you have to things that should be done simultaneously and
are rather independent (e.g. one task to drive around and
one to operate a complicated sensor like a light scanner)
then it is best to use separate tasks.
If tasks need to communicate you can use global variables.

Can I define a task in the beginning of the program, then run it only
under certain circumstances (like light reading <50),

No, it runs all the time (in RCX2 there are events that can
do this, but they are more complicated to use).
You just need to use a loop to wait for the circumstances,
then do what you want to do.

or at a certain point in the program?

This is what function or subroutines are good for.


Hoppas det hjälper

Jürgen

--
Jürgen Stuber <stuber@loria.fr>
http://www.loria.fr/~stuber/



Message has 1 Reply:
  Re: Q: Multitasking, and reacting to sensors
 
(...) Sorry Juergen, but that's not quite right. You can start and stop tasks as often as you wish to do. like this int do_s_s = 0; int condition = 0; task main() { while (1) { if (condition && !do_s_s) { start do_something_special; do_s_s = 1; } if (...) (24 years ago, 6-Feb-01, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  Q: Multitasking, and reacting to sensors
 
I've downloaded NQC, and got it running. I have been able to make the motors run, to make them run backwards, then forward, etc. However... I can't get the sensor thing to work right. I want to make a program for a robot that backs up and turns when (...) (24 years ago, 5-Feb-01, to lugnet.robotics.rcx.nqc)

9 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