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 / 1491
1490  |  1492
Subject: 
Re: Problems with NQC and math operations
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Sun, 2 Feb 2003 19:45:26 GMT
Viewed: 
5625 times
  
Jeff,

Your problem is with the 16 bit integer size that NQC uses.  All integers
are in the range -32768 to 32767.  Using 10000 to simulate fixed point math
operations is killing you.  Everything works when you replace theta and D
with constants because the compiler evaluates the equation and replaces it
with a constant.

Dean

       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...



Message has 1 Reply:
  Re: Problems with NQC and math operations
 
Dean, Well, that was the problem...changing the 10000 to 100 makes me get a value back, however I think the error is too big for the robots to navigate effectively..I'll probably have to learn legOS so I can use floating-point and get more precise (...) (22 years ago, 2-Feb-03, to lugnet.robotics.rcx.nqc)

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

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