Is it possible to calibrate the compass?

birnesoft

Active Member
Licensed User
Longtime User
The compass of my milestone2 is sometimes +-45° wrong
When I start a other Compass that can calibrate it'S ok.

But is there a Way to calibrate the compass with b4a?

in Java it looks like this

import icommand.nxt.comm.NXTProtocol;

public class CompassSensor extends I2CSensor {


private final static byte BEGIN_CALIBRATION = 0x43;
private final static byte END_CALIBRATION = 0x44;
private final static byte COMMAND = 0x41;


/**
* Begins calibrating the compass sensor resulting in more accurate measurements. Rotate compass
* at least two times, taking at least 20 seconds per rotation. Issue stopCalibration() when done.
* NOTE: Once the compass is calibrated, you do not have to recalibrate even when the NXT is
* turned off. The calibration settings are stored in internal non-volatile memory on the NXT.
*
*/

public void startCalibration() {
super.sendData(COMMAND, BEGIN_CALIBRATION);
}

public void stopCalibration() {
super.sendData(COMMAND, END_CALIBRATION);
}

Gruss Björn
 

birnesoft

Active Member
Licensed User
Longtime User
I think it's not only the Offset, the b4a compass give me really exact
angle in all directions after calibration.

In this java class it is possible to send the calibration commands to the compass.

http://code.google.com/p/bot-commander/source/browse/android/src/icommand/nxt/CompassSensor.java
I2CSensor.java - bot-commander - Remote control Lego NXT robots from Android. - Google Project Hosting

startCalibration:

I2CSensor1.sendData(0x41,0x43);

is there a way to integrade this in the b4a produced java code?

thanks Björn
 
Last edited:
Upvote 0

jsanchezc

Member
Licensed User
Longtime User
I don't think that this code affects the built-in compass.
You can calibrate built-in compass:
start compass app or gps app that shows compass information.

take your phone with one hand.
put it horizontal then "draw" a horizontal half circle
after this draw a vertical half circle above your head.
and put your phone vertical and roll one circle

order is not important, but after do this compass sensor is calibrated.

look this: it works on my samsung galaxy mini
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
public class CompassSensor extends I2CSensor

The above line is referencing I2C which is a protocol to communicate with firmware
embedded into hardware components.. this indicates to me that the code is sending
hardware-specific commands to the MCU part that's responsible for managing the
compass.

My two cents.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Yes it looks to be a hardware specific piece of code, the source code states:

Currently supports Mindsensors.com Compass V1.1 and 2.0 (CMPS-Nx) and HiTechnic compass sensors.
Auto-detects appropriate model.

So it's not generic code that can be used on all devices, no doubt it'll cause an exception on devices that don't have the supported hardware.

Martin.
 
Upvote 0
Top