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.
Moderators: roger, 99jonathan, imaqine
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;
}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());
}
}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
Users browsing this forum: No registered users and 0 guests