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 / 966
965  |  967
Subject: 
Re: Q: Multitasking, and reacting to sensors
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Mon, 5 Feb 2001 19:10:15 GMT
Viewed: 
1856 times
  
In lugnet.robotics.rcx.nqc, Tobias Möller writes:
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 it hits a wall. In RCX code I'd use
a sensor block.

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


Did you define the sonsors correctly ?
For example :

#define BUTTON SENSOR_2
#define DETECT_LEFT SENSOR_1
#define DETECT_RIGHT SENSOR_3
#define MOTOR_LEFT OUT_A
#define MOTOR_RIGHT OUT_C

task main()
{
SetSensor(BUTTON, SENSOR_TOUCH);
SetSensor(DETECT_LEFT, SENSOR_TOUCH);
SetSensor(DETECT_RIGHT, SENSOR_TOUCH);
SetPower(MOTOR_LEFT,7);
SetPower(MOTOR_RIGHT,7);
SetDirection(MOTOR_LEFT,OUT_REV);
SetDirection(MOTOR_RIGHT,OUT_REV);
On(MOTOR_LEFT);
while(DETECT_LEFT == 0);
Off(MOTOR_LEFT);
On(MOTOR_RIGHT);
while(DETECT_RIGHT == 0);
Off(MOTOR_RIGHT);

This works fine for me in the main task (no other tasks running)

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.

Should I instead make one task main, where I run the motors, and one
task bump or something, where I put the if statement?

No, you don't need to.

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.

I send you an example i did to your e-mail adress.

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

Any help appreciated.

--Tobias



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
    

Custom Search

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