To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.handyboardOpen lugnet.robotics.handyboard in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / Handy Board / 1335
1334  |  1336
Subject: 
Re: IC loop
Newsgroups: 
lugnet.robotics.handyboard
Date: 
Sun, 26 Jan 1997 00:11:33 GMT
Original-From: 
Richard Vannoy <[richardv@]spamless[abac.com]>
Reply-To: 
richardv@abac.com&spamcake&
Viewed: 
1147 times
  
I am now wanting to
put a loop in the code so that it will continue for a certain length of time
or count.  I think I should probably use the while expression but I am not
sure how to do this.  Can anyone help me out.  I am just beginning to pick
up on the IC code

There are a number of ways to do this in C.  If you get the code that
comes with the Handyboard, they have msleep(500L);  which sleeps for 500
milliseconds (L for LONG Integer) and then returns to the calling
program.  My code is at work, but I'm sure it is just a simple loop or
time compare.  Examples of the two are:

for(i=1; i<1000; i++);

will just count to 1000 and then go on.  The best part is that it is
easy, but you need to test it and see how long 1,000 is.  Also on
different machines with different CPU clock times the times vill vary,
so that isn't very "elegant".

More on the elegant side would be to measure the time and look for a
differential.  Most all systems have a clock() function that returns
seconds or milliseconds.  I don't have my handyboard code here, but here
is the idea...

delay(long desired_delay)
{
   Old_Time = clock();     // Returns the number of milliseconds since
startup
   while(1)    //  Loop forever
   {
      New_Time = clock
      if( New_Time - Old_Time > desired_delay)
         break;            // Out o here
   }
}

...so    delay(250);  in the code would produce a 1/4 second delay.
This has the advantage that it works correctly on any machine since it
uses milliseconds or seconds.



Message is in Reply To:
  IC loop
 
Hope someone can help, I have just written my first code for my bot. All I have done so far is make my bot go forward in about a 4 foot square area. I am now wanting to put a loop in the code so that it will continue for a certain length of time or (...) (28 years ago, 23-Jan-97, to lugnet.robotics.handyboard)

3 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