Subject:
|
Re: Need help with my program
|
Newsgroups:
|
lugnet.robotics.rcx.nqc
|
Date:
|
Sun, 13 Aug 2000 20:20:52 GMT
|
Viewed:
|
1827 times
|
| |
| |
Your program is pretty difficult for me to follow...way too many tasks
starting and stoping one another. For something as simple as the
algorithm you described, you can probably take care of all the light
seeking in a single task. If you still want to break out separate
sub-functions (checking the light, etc) then use functions rather than
tasks. Functions run synchronously to completion, then control returns
to the caller. This makes things a lot easier to follow and debug.
Here's a rough sketch of how the program could work..
task main()
{
SetSensor(SENSOR_3,SENSOR_LIGHT);
while(true)
{
forward();
find_darker();
}
}
void forward()
{
OnFwd(OUT_A + OUT_C);
Wait(200); // 2 seconds
Off(OUT_A + OUT_C);
}
void find_darker()
{
int old = SENSOR_3;
int new;
while(true)
{
// turn a little
OnFwd(OUT_A);
OnRev(OUT_C);
Wait(50); // 0.5 seconds
Off(OUT_A + OUT_C);
new = SENSOR_3;
if (new < old) return;
// use this next line only if you need the new reading to be
// darker than the previous one. If you want it to be
// darker than the original, then eliminate the line
old = new;
}
}
-----
Taking care of the bumper is probably a good candidate for a second task
since it must happen in parallel with finding darkness.
Hope this helps.
Dave
In article <39903946.913805@lugnet.com>, yellow5guy@prodigy.net
(Michael Camilleri) wrote:
> On Tue, 8 Aug 2000 16:29:09 GMT, yellow5guy@prodigy.net (Michael
> Camilleri) wrote:
>
> > I just started with NQC and attempted to make a light-seeking program.
> > It
> > is supposed to go forward for a wile and them stop and then turn a
> > little,
> > check the light level, turn again, check again and keep doing it until
> > it
> > gets darker then the last level, and then go forward. The problem is
> > that
> > once it starts turning it won't stop. Could you please help me? This is
> > one of my first programs and I really would like some help.
> >
> > Yank You!
> > --Mike
>
>
> Oops I forgot the code.
> Here it is.
>
> #define RUNTIME 100
> #define REVERSTIME 30
> #define TURNTIME 100
> #define BUMPTURNTIME 100
> #define STOPTIME 25
>
> int lastlevel;
>
> // STARTUP TASK
> task main()
> {
> SetSensor(SENSOR_1,SENSOR_TOUCH);
> SetSensor(SENSOR_3,SENSOR_LIGHT);
> start drive;
> start bumper;
> }
>
> // DRIVES CAR
> task drive()
> {
> while(true)
> {
> OnFwd(OUT_A+OUT_C);
> Wait(RUNTIME);
> Off(OUT_A+OUT_C);
> Wait(STOPTIME);
> start checklight;
> }
> }
>
> // CHECKS LIGHT SENSOR
> task checklight()
> {
> stop drive;
> OnFwd(OUT_A); OnRev(OUT_C);
> Wait(TURNTIME);
> Off(OUT_A+OUT_C);
> Wait(STOPTIME);
> start _checklight;
> }
>
> task _checklight()
> {
> stop drive;
> lastlevel = SENSOR_3;
> if (SENSOR_3 >= lastlevel);
> {
> start reset1;
> }
> if (SENSOR_3 < lastlevel);
> {
> OnFwd(OUT_C); OnRev(OUT_C);
> Wait(TURNTIME);
> Off(OUT_A+OUT_C);
> Wait(STOPTIME);
> start reset2;
> }
> }
>
> task reset1()
> {
> stop checklight;
> stop _checklight;
> start checklight;
> }
>
> task reset2()
> {
> stop checklight;
> stop _checklight;
> start drive;
> }
>
>
> // WATCHES BUMPER
> task bumper()
> {
> while (true)
> {
> if (SENSOR_1 == 1)
> {
> stop drive;
> stop checklight;
> OnRev(OUT_A+OUT_C); Wait(REVERSTIME);
> OnFwd(OUT_A); Wait(BUMPTURNTIME);
> Off(OUT_A+OUT_C);
> Wait(STOPTIME);
> start drive;
> }
> }
> }
>
>
>
>
--
reply to: dbaum at enteract dot com
|
|
Message has 1 Reply:
Message is in Reply To:
| | Re: Need help with my program
|
| (...) Oops I forgot the code. Here it is. #define RUNTIME 100 #define REVERSTIME 30 #define TURNTIME 100 #define BUMPTURNTIME 100 #define STOPTIME 25 int lastlevel; // STARTUP TASK task main() { SetSensor(SENSOR_1,S...OR_TOUCH); (...) (24 years ago, 8-Aug-00, to lugnet.robotics.rcx.nqc)
|
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
|
|
|
|