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 / 22703
22702  |  22704
Subject: 
Re: Competitive MINDSTORMS: Now in a store near you!
Newsgroups: 
lugnet.robotics
Date: 
Mon, 23 Aug 2004 15:07:37 GMT
Viewed: 
1086 times
  
In lugnet.robotics, Brian Davis wrote:
   On pg37 of bonus chapter 2, you have some code including the line of code and
a highlighted box below it:

   until(LBump<100&RBump==1);

   "Notice the ampersand (&) in this task. This is the AND operator
    in NQC. Here is another example... There are two types of AND:
    & and &&. The former, the one we use in this program, is called
    bitwise AND and has no restraints on the types of arguments that
    can be used with it. The latter example is called logical AND
    and is constrained to constants only (such as 5, 27, OUT_A)."

First, while the above code seems to work, it would seem this is only due to the
order of precedence (relational operators being slightly higher in precedence
than the various flavors of ANDs and ORs). Second, using a logical AND here
works just fine, as (a) it is comparing two constants (both experssions
'LBump<100' and 'RBump==1' are evaluated to either the constant 'true' or
'false', and this will be done before any AND comparision), and (b) at least as
of NQC 2.5a4, any AND or OR operators have no restraints on argument types.
   So, why use a bitwise AND here? You seem to do this throughout, even though
I've never had a problem using logical AND within control commands (or in lots
of other places, like variable assignments).

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.

   Another thing that confused me was in bonus chapter 1. On pg36, you give the
listing of the task 'crash'. What 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, or stops the counter-rotating wheels. Where is this - what have I missed?

The trick is, 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.

   I do like the trick of using ACQUIRE_USER_1 instead of ACQUIRE_OUT_A (or
similar) which would stop the wheels. That's a technique I may "borrow" for Sumo
6 in Ann Arbor.

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

Thanks,

David J. Perdue

www.davidjperdue.com

www.davidjperdue.com/competitivemindstorms



Message has 1 Reply:
  Re: Competitive MINDSTORMS: Now in a store near you!
 
(...) Given what you say in the boxed text, do you ever use logical AND in a program? (...) Well, here's the code in question. I've removed blank lines, but the spacing & punctuation is preserved: task Crash() { SetPriority(1); while(true) { (...) (20 years ago, 23-Aug-04, to lugnet.robotics)

Message is in Reply To:
  Re: Competitive MINDSTORMS: Now in a store near you!
 
(...) I finally downloaded and read the bonus chapters as well, and (of course) got confused. I've only been using NQC for a little over a year, so it could be my inexperience, but I knew C for several years prior to using NQC, so I'm not a complete (...) (20 years ago, 22-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