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 / 692
691  |  693
Subject: 
Re: Need help with my program
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Tue, 8 Aug 2000 16:48:17 GMT
Viewed: 
1938 times
  
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;
    }
  }
}



Message has 1 Reply:
  Re: Need help with my program
 
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 (...) (24 years ago, 13-Aug-00, to lugnet.robotics.rcx.nqc)

Message is in Reply To:
  Need help with my program
 
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 (...) (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
    

Custom Search

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