Odd results from HiTechnic compass sensor

This is where you talk about the NXJ hardware related topics such as the brick, sensors, LEGO pieces, etc.

Moderators: 99jonathan, roger, imaqine

Odd results from HiTechnic compass sensor

Postby Rickz2020 » Sat Jun 18, 2011 4:05 pm

Hi all.

I have the compass sensor and for some reason when facing within 10deg of North, I get readings like 1.0.0 up to 9.0.0... these should be 1 or 2 or 3 ....9.

What is going on? It's messing up my navigation!

Regards,

Rich.
Rickz2020
Active User
 
Posts: 121
Joined: Thu Feb 10, 2011 5:47 pm
Location: London, Earth.

Re: Odd results from HiTechnic compass sensor

Postby gloomyandy » Sat Jun 18, 2011 4:12 pm

Hi,
I'm sorry I don;t really understand the description of your problem. Can you post a short test program along with details of what the output is that you are seeing and the details of what version of leJOS you are using (and are you running your program on the NXT or on a PC)...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4083
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Odd results from HiTechnic compass sensor

Postby Rickz2020 » Sat Jun 18, 2011 4:21 pm

Hi Andy,

Code: Select all

   public double getCompassDirection() {
        double compassDirection = 0.0;
        compassDirection = compass.getDegrees();   
        return compassDirection;
    }

   public void correctCourse(double cLat, double cLon) {
        int bearing = (int) getBearing(cLat, cLon);

        int robotFacing = (int) getCompassDirection();
        int rotation = 0;
        int direction = 0;

        if (robotFacing != bearing) {
            rotation = bearing - robotFacing;
            if (rotation > 0 && rotation < 180) {
                direction = 1; //left
            } else {
                direction = 0; //right
            }
            if (rotation > 180) {
                swapDirection(direction);
            }
            if (rotation < -180) {
                swapDirection(direction);
            }
        } else {
            //move.moveForward(100);
            Sound.twoBeeps();
            move.stopTurning();
        }
        rotate(direction);

        LCD.drawString("rotation: " + rotation, 0, 5);
        LCD.drawString("rf: " + getCompassDirection(), 0, 6);
        rotation = 0;
    }


rf or RobotFacing should always be between 360 and 0, right? But for some reason instead of showing 1.0 or 2.0 up to 9.0 and then the usual 10.0 to 360.0, it shows 1.0.0, 2.0.0, 3.0.0 ect... up till 10.0 and then its normal again.

I'm running this on my nxt brick.

Iv'e got no idea why it would be returning something like 1.0.0.

Rich.
Last edited by Rickz2020 on Sat Jun 18, 2011 4:32 pm, edited 1 time in total.
Rickz2020
Active User
 
Posts: 121
Joined: Thu Feb 10, 2011 5:47 pm
Location: London, Earth.

Re: Odd results from HiTechnic compass sensor

Postby Rickz2020 » Sat Jun 18, 2011 4:29 pm

Even

Code: Select all
public class myGPS {

    public static void main(String[] args) {

        CompassSensor compass = new CompassSensor(SensorPort.S1);
        do {
            LCD.drawString("direction " + compass.getDegrees(), 0, 5);
        } while (!Button.ENTER.isPressed());
    }
}


gives me the same strange results. Try rotate to 350 and then move it back to +- 3degrees, very slowly.
Rickz2020
Active User
 
Posts: 121
Joined: Thu Feb 10, 2011 5:47 pm
Location: London, Earth.

Re: Odd results from HiTechnic compass sensor

Postby gloomyandy » Sat Jun 18, 2011 4:35 pm

Hi,
You are not clearing the LCD screen when you display new results. This means that if you display say 300.0 and 3.0 then the display for the 3.0 will actually look like 3.0.0 this is because the final .0 will have been left from displaying the 300.0... Try either adding a LCD.clear() call or erase the individual lines to spaces before you display the result...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4083
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: Odd results from HiTechnic compass sensor

Postby Rickz2020 » Sat Jun 18, 2011 5:03 pm

gloomyandy wrote:Hi,
You are not clearing the LCD screen when you display new results. This means that if you display say 300.0 and 3.0 then the display for the 3.0 will actually look like 3.0.0 this is because the final .0 will have been left from displaying the 300.0... Try either adding a LCD.clear() call or erase the individual lines to spaces before you display the result...

Andy



OMG!

Thanks so much Andy! I guess this is the reason we should take breaks during coding...bangs head on desk.

Cheers!

Rich.
Rickz2020
Active User
 
Posts: 121
Joined: Thu Feb 10, 2011 5:47 pm
Location: London, Earth.


Return to NXJ Hardware

Who is online

Users browsing this forum: No registered users and 0 guests

more stuff