CompassSensor cartezian bug

This is where you talk about the NXJ software itself, installation issues, and programming talk.

Moderators: 99jonathan, roger, imaqine

CompassSensor cartezian bug

Postby vladra » Sun Jan 27, 2008 11:28 am

CompassSensor calculation of cartezian degrees is wrong.
For example let's assume:
compass.getDegrees() -> 278
compass.getDegreesCartesian() -> 82

it's ok.

then execute compass.resetCartesianZero()
compass.getDegrees() -> 278
compass.getDegreesCartesian() -> 164

I think degreesCartesian should be zero after resetCartesianZero, isn't it?

First line of CompassSensor.getDegreesCartesian() is invalid. This should be the following:
Code: Select all
float degrees = 360 - getDegrees() + cartesianCalibrate;

plus cartesianCalibrate, not minus
vladra
New User
 
Posts: 24
Joined: Fri Nov 16, 2007 6:18 pm
Location: Russia

Postby roger » Thu Jan 31, 2008 7:03 am

You are right. The correction will be in the next release.
Roger
roger
Moderator
 
Posts: 350
Joined: Fri Jun 01, 2007 4:31 am
Location: Berkeley, CA

Postby kirkpthompson » Thu Jan 31, 2008 1:25 pm

While your at it, here is code that returns the higher resolution values from a Mindsensors:

Constructor:
Code: Select all
        // Put the Mindsensors compass into integer mode
        if (isMindsensors) {
            int retVal;
            byte[] buf = new byte[1];
            buf[0] = 0x49; // set to 2 byte integer mode for reading headings
            retVal = sendData(0x41, buf, 1);
            if (retVal!=0) {
                // TODO do something with the error
                throw new IllegalStateException();
            }
        }

getDegrees():
Code: Select all
        if(isMindsensors) { // Check if this is mindsensors
            int iHeading = (0xFF & buf[0]) | (0xFF00 & buf[1] << 8);
           
            return iHeading / 10.0f ;
        } else {
            return ((buf[0] & 0xff)<< 1) + buf[1];
        }

-K
User avatar
kirkpthompson
leJOS Team Member
 
Posts: 304
Joined: Wed Dec 05, 2007 1:27 am
Location: New Mexico, USA


Return to NXJ Software

Who is online

Users browsing this forum: No registered users and 3 guests

more stuff