To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1497
1496  |  1498
Subject: 
Re: Problems with NQC and math operations
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Mon, 3 Feb 2003 08:31:13 GMT
Viewed: 
5084 times
  
In lugnet.robotics.rcx.nqc, Jeff Merrick writes:
Hi-

I'm currently working on a project to get a dead-reckoning navigation system
to work with NQC and the RCX.  Right now I have a compass sensor and a
rotation sensor hooked up and the idea is that with an angle and a distance,
I can get an x and y position.  Of course, this involves sines and cosines
which NQC is incapable of doing.  So to solve this problem I used Taylor
series polynomials to approximate sine and cosine...this seems to work fine,
and I get values that are pretty close to what the actual values should be.
I later ran into another problem which was that the robot was giving me
incorrect x and y positions because in the middle of the operation, it would
divide by a large number and then end up truncating the result to zero.
This
problem was solved by multiplying by 10000 before the operation and then
dividing by 10000 at the end.  This is the point at which I ran into a
really strange problem.  I would test to see if the robot was doing the
operations correctly by simply replacing the places where I used variables
with numbers where I knew what the correct result would be.  When I was
convinced that it was doing the operations correctly, I just replaced the
numbers I had used to test, with the variables again.  Logically, everything
should work the same...but it didn't...it returned 0 every time...for some
reason using variables in my expression doesn't work.  Here's a little bit
of the code...
Rotation is the rotation sensor value, Direction is the compass sensor value
and current x and current y were both initialized as 0 (the robot assumes it
starts at (0,0).

       D = abs(Rotation);
        theta = Direction * 18/5;  //since the compass sensor uses 0-100 I
have to convert to the standard 0-360
        oldx = currentx;
        oldy = currenty;
        if (theta >= 0 && theta <= 90) //this is only the portion of the
code if the robot is moving in the direction of the first quadrant
        {
             theta = 90 - theta;
             currentx = (10000 * 3 * theta / 180 * D) / 10000;
             currenty = (10000 * D - theta * theta * 125 * D/ 81)/10000;
//(1 - (10 * (theta * theta))/64800) * D;
         }

So if I simply replace theta with 51 and D with 15 the robot returns the
correct value of
12 for current x and 8 for current y.

But when I use the variables...either point the robot in the right direction
and right number of rotations, or even initialize them at 51 and 15...the
robot returns 0 for currentx and currenty...

This really has me puzzled as I can't see any logical explanation for it...I
hope I'm overlooking something simple...

Anybody have any idea what's going on here?
Thanks for your help!

Jeff


Did you considered that the RCX has only integer variables. So, the allowed
operation range is -32768  32767. If at any stage of your operation you
exceed these limits, the result will be corrupted.

For the use of sine and cosine with integer variables have a look at:

http://www.restena.lu/convict/Jeunes/Math/Sine_Cosine.htm

See yah,

Claude



Message is in Reply To:
  Problems with NQC and math operations
 
Hi- I'm currently working on a project to get a dead-reckoning navigation system to work with NQC and the RCX. Right now I have a compass sensor and a rotation sensor hooked up and the idea is that with an angle and a distance, I can get an x and y (...) (22 years ago, 2-Feb-03, to lugnet.robotics.rcx.nqc)

6 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