To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 1017
     
   
Subject: 
NQC Code
Newsgroups: 
lugnet.robotics
Date: 
Wed, 2 Dec 1998 20:36:09 GMT
Original-From: 
John Donaldson <jdonaldson@+stopspam+ghg.net>
Viewed: 
2613 times
  

  I got two questions.

1. How do you use the timer() function under NQC?
2. What is best way to determine if bot is stuck in corner make it turn
180 deg to get out?

John A. Donaldson

   
         
     
Subject: 
Re: NQC Code
Newsgroups: 
lugnet.robotics
Date: 
Thu, 3 Dec 1998 04:12:34 GMT
Viewed: 
4464 times
  

In article <3665A4B9.861224B6@ghg.net>, lego-robotics@crynwr.com (John
Donaldson) wrote:

I got two questions.

1. How do you use the timer() function under NQC?
2. What is best way to determine if bot is stuck in corner make it turn
180 deg to get out?

John A. Donaldson

I'm going from memory here - sorry if I goof something up....

There are three timers (0, 1, and 2).  They are free running at 10Hz
(100ms per tick).  They do not run while the RCX is "off", but they do
retain their count.  You can clear a timer with ClearTimer(n), where n is
0, 1 or 2.  You an retrive the current timer value with Timer(n).

This can be a good way to repeat a certain series of steps for a certain
amount of time.  I've appended a sample program I used for a line follower
robot.  There's a loop in the follow() subroutine where the program turns
until it either hits a line or a timeout expires.

Dave

---------------

/* tracker.nqc
* written by Dave Baum for nqcc 0.5 b1
*
* This is a more complex program for a line-following robot.
* As usual, outputs A and C drive right and left tank treads,
* while input 1 is a light sensor at the front of the robot.
*
* The follow() subroutine follows a thin line until in
* encounters a very dark spot, at which point the robot
* stops.  When following a line, the robot runs forward
* until the light sensor reading exceeds a given value,
* at which point it starts turning right (or left) a bit
* looking for the rest of the line.  It continues to
* oscillate left and right until it finds the line, then
* continues forward.  The program remembers the direction
* previously used to find the line, so it can start turning
* the same way next time it loses the line.
*
* The main program follows a line until it reaches the end (a
* dark spot), then beeps, turns around, and follows the line
* back to the start.  The "test" surface should be white with
* a thin black line (1/8 inch thick) which can turn and curve
* as you desire.  Solid dark "endpoint" should be at both ends
* of the line - 1" wide black squares work well.
*
*/

#define EYE IN_1
#define LEFT   OUT_C
#define RIGHT  OUT_A

#define NORMAL_SPEED 6
#define TURN_SPEED 2
#define DELAY  20

#define CUTOFF 55
#define STOP   48


int direction, time, eye;

#define INITIAL_TIME 2

task main
{
   Sensor(EYE, IN_LIGHT);


   direction = 1;
   time = INITIAL_TIME;

   follow();
   PlaySound(5);

   turn_around();
   follow();
}


sub turn_around
{
   Fwd(LEFT, TURN_SPEED);
   Rev(RIGHT, TURN_SPEED);

   wait(EYE > CUTOFF);
   Sleep(25);
   wait(EYE < CUTOFF);

   Off(LEFT+RIGHT);
}


sub follow
{
   Fwd(LEFT+RIGHT, NORMAL_SPEED);
   while(true)
   {
      eye = EYE;
      if (eye < STOP) break;
      if (eye <= CUTOFF) continue;

      {
         ClearTimer(0);
         if (direction == 1)
         {
            Fwd(RIGHT, TURN_SPEED);
            Rev(LEFT, TURN_SPEED);
         }
         else
         {
            Fwd(LEFT, TURN_SPEED);
            Rev(RIGHT, TURN_SPEED);
         }

         while(true)
         {
            if (EYE < CUTOFF)
            {
               time = INITIAL_TIME;
               break;
            }

            if (Timer(0) > time)
            {
               direction *= -1;
               time *= 2;
               break;
            }
         }

         Fwd(RIGHT+LEFT, NORMAL_SPEED);
      }
   }

   Off(RIGHT+LEFT);
}

--
reply to: dbaum at enteract dot com

    
          
     
Subject: 
Re: NQC Code
Newsgroups: 
lugnet.robotics
Date: 
Wed, 9 Dec 1998 19:03:54 GMT
Original-From: 
John Donaldson <jdonaldson@ghg*nomorespam*.net>
Viewed: 
1434 times
  

Dave,

  Sorry for not getting back sooner. Been out of town. Anyway, thanks
for
the reply. This is what I am looking for. I am going to combine this
wirh another routine. Basicly

  1. Right Touch Sensor hits object.
   RCount += 1;
   IF RCount >= 2
   {
     RCount = 1;
   }

  2. Same for Left Touch Sensor

  IF RCount = 1 && LCount = 1
  // Stuck in Corner
  {
    RevMotor(AC);
    Sleep(500);
    FwdMotor(C);
    Sleep(500);
    Fwdmotor(A);
    RCount = 0;
    LCount = 0;
  }

  This way if one sensor countinues to hit then it is the same wall or
mabey a curved wall.
  If both sensors have a count of one (1) then means it first hit on
one side of the wall and then one the other side of the wall. With both
a count one (1), it reverses and the turns around.
  The timer function will also be used to backup the count by loking for
certain values too.

John D.



Dave Baum wrote:

In article <3665A4B9.861224B6@ghg.net>, lego-robotics@crynwr.com (John
Donaldson) wrote:

I got two questions.

1. How do you use the timer() function under NQC?
2. What is best way to determine if bot is stuck in corner make it turn
180 deg to get out?

John A. Donaldson

I'm going from memory here - sorry if I goof something up....

There are three timers (0, 1, and 2).  They are free running at 10Hz
(100ms per tick).  They do not run while the RCX is "off", but they do
retain their count.  You can clear a timer with ClearTimer(n), where n is
0, 1 or 2.  You an retrive the current timer value with Timer(n).

This can be a good way to repeat a certain series of steps for a certain
amount of time.  I've appended a sample program I used for a line follower
robot.  There's a loop in the follow() subroutine where the program turns
until it either hits a line or a timeout expires.

Dave

---------------

/* tracker.nqc
* written by Dave Baum for nqcc 0.5 b1
*
* This is a more complex program for a line-following robot.
* As usual, outputs A and C drive right and left tank treads,
* while input 1 is a light sensor at the front of the robot.
*
* The follow() subroutine follows a thin line until in
* encounters a very dark spot, at which point the robot
* stops.  When following a line, the robot runs forward
* until the light sensor reading exceeds a given value,
* at which point it starts turning right (or left) a bit
* looking for the rest of the line.  It continues to
* oscillate left and right until it finds the line, then
* continues forward.  The program remembers the direction
* previously used to find the line, so it can start turning
* the same way next time it loses the line.
*
* The main program follows a line until it reaches the end (a
* dark spot), then beeps, turns around, and follows the line
* back to the start.  The "test" surface should be white with
* a thin black line (1/8 inch thick) which can turn and curve
* as you desire.  Solid dark "endpoint" should be at both ends
* of the line - 1" wide black squares work well.
*
*/

#define EYE IN_1
#define LEFT   OUT_C
#define RIGHT  OUT_A

#define NORMAL_SPEED 6
#define TURN_SPEED 2
#define DELAY  20

#define CUTOFF 55
#define STOP   48

int direction, time, eye;

#define INITIAL_TIME 2

task main
{
   Sensor(EYE, IN_LIGHT);

   direction = 1;
   time = INITIAL_TIME;

   follow();
   PlaySound(5);

   turn_around();
   follow();
}

sub turn_around
{
   Fwd(LEFT, TURN_SPEED);
   Rev(RIGHT, TURN_SPEED);

   wait(EYE > CUTOFF);
   Sleep(25);
   wait(EYE < CUTOFF);

   Off(LEFT+RIGHT);
}

sub follow
{
   Fwd(LEFT+RIGHT, NORMAL_SPEED);
   while(true)
   {
      eye = EYE;
      if (eye < STOP) break;
      if (eye <= CUTOFF) continue;

      {
         ClearTimer(0);
         if (direction == 1)
         {
            Fwd(RIGHT, TURN_SPEED);
            Rev(LEFT, TURN_SPEED);
         }
         else
         {
            Fwd(LEFT, TURN_SPEED);
            Rev(RIGHT, TURN_SPEED);
         }

         while(true)
         {
            if (EYE < CUTOFF)
            {
               time = INITIAL_TIME;
               break;
            }

            if (Timer(0) > time)
            {
               direction *= -1;
               time *= 2;
               break;
            }
         }

         Fwd(RIGHT+LEFT, NORMAL_SPEED);
      }
   }

   Off(RIGHT+LEFT);
}

--
reply to: dbaum at enteract dot com

   
         
   
Subject: 
Re: NQC Code
Newsgroups: 
lugnet.robotics
Date: 
Fri, 4 Dec 1998 05:53:17 GMT
Original-From: 
Nancy Evelyn Gold <nancyg@sgi*StopSpammers*.com>
Viewed: 
2708 times
  

John Donaldson wrote:

  I got two questions.

1. How do you use the timer() function under NQC?
2. What is best way to determine if bot is stuck in corner make it turn
180 deg to get out?

Based on the first question I would think you're on the right track.
Counting the number of turns in a given time period is key. It
impressed the hell out of the folks at the office when the rover
would back out of a corner and turn around.

The below code includes some crude semaphore code. The sound
was for debugging.

No rude comments, this was my first NQC code and the first C code
I've written in two years. :-)

--- Nancy

Some sample code:

#define FUTILE_INT      200
#define FUTILE          1
#define FUTILE_THRESH   4

task corner_detect
{
    while (true)
    {
// I added the OR while playing with the code, not sure why
//
        if ( (Timer(FUTILE) > FUTILE_INT) || (turns > FUTILE_THRESH) )
            {
            if (turns > FUTILE_THRESH)
                    {
                        while (lock_turn != 0) Sleep(1);
                        lock_turn = 1;
                        stall = 1;
                        PlaySound(3);
                        timed_reverse();
                        about_face();
                        lock_turn = 0;
                        stall = 0;
                    }
            turns = 0;
            ClearTimer(FUTILE);
            }
    }
}


--
Nancy Evelyn Gold (nancyg@sgi.com)
1993 BMW K1100LT "Chloe" - DoD# 1184 - BMWMOA
++ Only Open DVD Delivers! Just say no to DIVX. ++

   
         
   
Subject: 
Re: NQC Code
Newsgroups: 
lugnet.robotics
Date: 
Wed, 9 Dec 1998 19:01:12 GMT
Original-From: 
John Donaldson <jdonaldson@ghg.STOPSPAMnet>
Viewed: 
956 times
  

Nancy,
  Sorry for not getting back sooner. Been outof town. Anyway, thanks for
the reply. This is what I am looking for. I am going to combine this
wirh another routine. Basicly

  1. Right Touch Sensor hits object.
   RCount += 1;
   IF RCount >= 2
   {
     RCount = 1;
   }

  2. Same for Left Touch Sensor

  IF RCount = 1 && LCount = 1
  // Stuck in Corner
  {
    RevMotor(AC);
    Sleep(500);
    FwdMotor(C);
    Sleep(500);
    Fwdmotor(A);
    RCount = 0;
    LCount = 0;
  }

  This way if one sensor countinues to hit then it is the same wall or
mabey a curved wall.
  If both sensors have a count of one (1) then means it first hit on
one side of the wall and then one the other side of the wall. With both
a count one (1), it reverses and the turns around.
  The timer function will also be used to backup the count by loking for
certain values too.

John D.

Nancy Evelyn Gold wrote:

John Donaldson wrote:

  I got two questions.

1. How do you use the timer() function under NQC?
2. What is best way to determine if bot is stuck in corner make it turn
180 deg to get out?

Based on the first question I would think you're on the right track.
Counting the number of turns in a given time period is key. It
impressed the hell out of the folks at the office when the rover
would back out of a corner and turn around.

The below code includes some crude semaphore code. The sound
was for debugging.

No rude comments, this was my first NQC code and the first C code
I've written in two years. :-)

--- Nancy

Some sample code:

#define FUTILE_INT      200
#define FUTILE          1
#define FUTILE_THRESH   4

task corner_detect
{
    while (true)
    {
        // I added the OR while playing with the code, not sure why
        //
        if ( (Timer(FUTILE) > FUTILE_INT) || (turns > FUTILE_THRESH) )
            {
            if (turns > FUTILE_THRESH)
                    {
                        while (lock_turn != 0) Sleep(1);
                        lock_turn = 1;
                        stall = 1;
                        PlaySound(3);
                        timed_reverse();
                        about_face();
                        lock_turn = 0;
                        stall = 0;
                    }
            turns = 0;
            ClearTimer(FUTILE);
            }
    }
}

--
Nancy Evelyn Gold (nancyg@sgi.com)
1993 BMW K1100LT "Chloe" - DoD# 1184 - BMWMOA
++ Only Open DVD Delivers! Just say no to DIVX. ++

 

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