Subject:
|
Re: Basic NQC Problem
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Sat, 12 Nov 2005 22:05:10 GMT
|
Viewed:
|
2102 times
|
| |
| |
In lugnet.robotics Cameron Hooper wrote:
> Hi
>
> I'm new to Mindstorms and this mailing list. I have a very basic question
> about NQC. I hope such questions are not inappropriate here.
Big place to ask your questions here. I'll try to answer it, best i can.
> I am basically following the Missions that come with the kit. I want to use
> NQC rather than RCX code. One mission involves building a 'GuardBot', a
> robot that patrols back and forth and stops when touched. I've included my
> attempt below. 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. I can understand why my program does not work, (condition
> only tested every 7.08 seconds), but now how to fix it.
>
> Any help appreciated.
>
> Cameron
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 you invented it, if you do so.
Your program now might look like this:
// guardbot2.nqc
#define BUMP SENSOR_2
#define LEFT OUT_A
#define RIGHT OUT_C
#define FWD_TIME 500
#define SPIN_TIME 208
task main() {
SetSensor(BUMP, SENSOR_TOUCH);
// start going forward
On(LEFT+RIGHT);
start check_sensor;
while(0 == 0) { // you might find a better construct
Wait(FWD_TIME);
Rev(LEFT);
Wait(SPIN_TIME);
Fwd(LEFT);
}
}
task check_sensor() {
until(BUMP == 1);
Off(LEFT+RIGHT);
StopAllTasks();
}
You see, the desired algorithmic action is now devided between the main and the
check_sensor task. StopAllTasks is an available NQC command, stopping the
current NQC program.
Experience in using tasking in a case like that teaches, that it is (may i say
"dammed") slow. You will see your bot hitting the bumper, and he takes time you
can recognise, before he shuts down. Of course, you would not expect any time
notifyable.
As i have learned earlier in this mailing list, a better RCX firmware exists,
that is much faster. Its called the "Dick Swan Firmware". It claims to be much
faster and not only in this case. You should try it, if your investigations are
seriously.
Remember, that NQC does not compile to machine code. NQC compiles to a code
interpreted by a virtual machine, housed in the firmware of the RCX.
Ralph
|
|
Message has 1 Reply: | | Re: Basic NQC Problem
|
| (...) 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 (...) (19 years ago, 13-Nov-05, to lugnet.robotics)
|
5 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
Active threads in Robotics
|
|
|
|