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 / 12899
12898  |  12900
Subject: 
RE: NQC with C++ header file
Newsgroups: 
lugnet.robotics
Date: 
Wed, 25 Oct 2000 14:06:58 GMT
Viewed: 
810 times
  
Well, yes - but that doesn't always do you much good.

  355/113 = 3

...in integer math - and that's a an error of about 1 in 10!

Well, not exactly. I guess I should elaborate. These rations are commonly
used for scaling results. Of course if you do the division in integer
you get 3, but what if you had an intermediate result that was 32 bits
long. That's how Forth avoids overflows. Here's an example, and it hinges
on picking reasonable ranges for your numbers.

You have a circle you want to navigate around. The radius rnages from
10 to 100 units, with a precision of 1 unit. The diameter of the circle
is 2*pi*radius. Stay with me here...

2*radius*355/113 gives you an approximation to the diameter within the precision
of your measurement!

10 units of radius =  62 units of diameter
100 units of radius = 628 units of diameter

If you want more precision, scale up the radius. The key is the 32 bit internal
precision of the scaling operator, which Forth has built in.

It's called */ which takes three parameters on the stack as follows:

*/ ( n1 n2 n3 -- n1*n2/n3 )

By the way, there's a discussion on fixed point math in my pbForth chapters
in the new Extreme Mindstorms book. And I think Luis has some info on
floats using legOS

Sure, you *can* use fixed-point - but with only 16 bit integers, it's
hard going!

Like us embedded guys say, if you need flots, you don't understand the problem
well enough :-)

Doing something like sin() in NQC would definitely be 'challenging'.

Probably, the best bet would be something like a lookup-table
implemented as a giant 'switch' statement - perhaps with some
interpolation to keep the code size down to something manageable.

In fact, this is an excellent way of doing it. The Cordic method John
alluded to is even better.

NQC is *great* - but I can certainly see that I'll outgrow it
and progress to LegOS and gcc *real-soon-now*. (I'm a C++ enthusiast,
so LegOS/g++ looks VERY attractive!)

If you want to compile right on the RCX, give pbForth a try too!

Cheers,

Ralph Hempel - P.Eng

--------------------------------------------------------------------
Check out pbFORTH for LEGO Mindstorms at:
<http://www.hempeldesigngroup.com/lego/pbForth>

Buy "Extreme Mindstorms: an Advanced Guide to Lego Mindstorms"
<http://www.amazon.com/exec/obidos/ASIN/1893115844/hempeldesigngrou>
--------------------------------------------------------------------
Reply to:      rhempel at bmts dot com
--------------------------------------------------------------------



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    
Active threads in Robotics

 
Verified and Trusted Team of Hackers
14 hours ago
Custom Search

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