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 / 22704
22703  |  22705
Subject: 
Re: Competitive MINDSTORMS: Now in a store near you!
Newsgroups: 
lugnet.robotics
Date: 
Mon, 23 Aug 2004 16:38:06 GMT
Viewed: 
1308 times
  
In lugnet.robotics, David Perdue wrote:

Yes, from what you say, both logical and bitwise AND would
work.

   Given what you say in the boxed text, do you ever use logical AND in a
program?

I don't understand is why ever time through the while(true)
loop here, it starts by starting the counter-rotating wheels
and starting up the task Spin... but I must have missed the
code that stops the task Spin...

there isn't code that stops the counter-rotating wheels or
task Spin! They are turned on just once, and then are never
turned off again. This also means that the program goes through
the while(true) loop in task Crash only once.

   Well, here's the code in question. I've removed blank lines, but the spacing
& punctuation is preserved:

task Crash()
{
   SetPriority(1);
   while(true)
   {
      OnFwd(Front);
      start Spin;
      until(Timer(1)>TOUCH);
         acquire(ACQUIRE_USER_1)
         {
            Win();
            PlaySound(SOUND_CLICK);
         }
   }
}

It seems to me that upon starting the task it falls into an infinite loop
(while(true)). That (A) starts up the front wheels and monitoring task, (B)
waits until the watchdog timer is exceeded, (C) grabs control, reverses briefly
& "rams" forward (for those without the listing, that's what the in-line
function Win() is suppossed to do), (D) releases control, and then restarts the
loop, which begins with (A).
   Again, this would certainly work, but it seems a strange way to code it. Why
not just put the OnFwd and start Spin commands just ahead (& outside) of the
while(true) loop? Or for even cleaner code, have Spin do it's own housecleaning
(i.e.- make the first line of Spin an OnFwd command).
   Also, is there a reason that the acquire statement is indented (it is in the
original code as well)? It would seem that it follows, not is controled by, the
until statement, yes? I just fear some of this could be slightly confusing.

I'm glad you liked it - borrowing techniques is highly encouraged.

   Yes, I sometimes wonder if anything I'm doing is actually my own - just ask
some of the people I've competed with!

--
Brian Davis



Message has 1 Reply:
  Re: Competitive MINDSTORMS: Now in a store near you!
 
(...) Truthfully, I rarely use any type of AND, so I can't really say! :) (...) Excellent observation! I guess, when I was creating the code, I just decided to put that code in with the Crash task. You can however, place it elsewhere where it won't (...) (20 years ago, 23-Aug-04, to lugnet.robotics)

Message is in Reply To:
  Re: Competitive MINDSTORMS: Now in a store near you!
 
(...) Yes, from what you say, both logical and bitwise AND would work. My book is only a guide, so although I use bitwise, you can feel free to use logical. (...) The trick is, there isn't code that stops the counter-rotating wheels or task Spin! (...) (20 years ago, 23-Aug-04, to lugnet.robotics)

29 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