RPI and 10 DOF IMU

Moderators: adafruit_support_bill, adafruit

Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/
Locked
User avatar
xyzones
 
Posts: 3
Joined: Fri Oct 10, 2014 7:11 pm

RPI and 10 DOF IMU

Post by xyzones »

Hello,

i have a B+ with arch linux and installed all required i2c tools. I am using Adafruit_I2C python library and wrote my own LSM303. I just wonder if is that good to have magneto sensors X Y Z between a range of 0-65K but no negative numbers at all.

Code: Select all

		raw_mag = self.mag.readList(self.LSM303_REGISTER_MAG_OUT_X_H_M, 6)
		magnetometerVector = self.obj3d(x=0,y=0,z=0)
		magnetometerVector.x = ((raw_mag[0] << 8) + raw_mag[1])
		magnetometerVector.z = ((raw_mag[2] << 8) + raw_mag[3])
		magnetometerVector.y = ((raw_mag[4] << 8) + raw_mag[5])
Another question, where i am or I will use the rpi with the sensor there is a declination between +3° 59' EAST and +4° 14' EAST. When calculating the tilt compensated heading where do I add these, how to get the best precision for the heading?

I am building a sailboat computer, why precision is important.

Thanks,

Attila

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPI and 10 DOF IMU

Post by adafruit_support_mike »

The values returned from the magnetic sensor are 16-bit signed integers in twos-complement notation. Only the lowest 15 bits contain magnitude information. The highest bit indicates the sign.

To convert twos-complement to a signed integer value, you need something like this:

Code: Select all

if ( value & 0x8000 ):
	value = ( value & 0x7fff ) - 0x8000

User avatar
xyzones
 
Posts: 3
Joined: Fri Oct 10, 2014 7:11 pm

Re: RPI and 10 DOF IMU

Post by xyzones »

Hello Mike,

That seems to be better now thanks.

Code: Select all

		xla = self.accel.readS8(self.LSM303_REGISTER_ACCEL_OUT_X_L_A)
		xha = self.accel.readS8(self.LSM303_REGISTER_ACCEL_OUT_X_H_A)
		yla = self.accel.readS8(self.LSM303_REGISTER_ACCEL_OUT_Y_L_A)
		yha = self.accel.readS8(self.LSM303_REGISTER_ACCEL_OUT_Y_H_A)
		zla = self.accel.readS8(self.LSM303_REGISTER_ACCEL_OUT_Z_L_A)
		zha = self.accel.readS8(self.LSM303_REGISTER_ACCEL_OUT_Z_H_A)

		a.x = xha << 8 | xla
		a.y = yha << 8 | yla
		a.z = zha << 8 | zla
when the IMU is on my desk no movement at all i have the below 0.5 seconds responses for the above code

Code: Select all

-16 -48 -15792
-16 -16 -80
-256 -32 -80
-208 -48 -96
-240 -224 -48
-256 -240 -96
-208 -240 -128
-64 -96 -15808
-192 -240 -15792
-224 -32 -15760
-224 -32 -80
-224 -16 -15776
-240 -32 -15776
-240 -32 -80
-240 -48 -96
-208 -16 -80
-32 -32 -96
-240 -224 -15600
-240 -240 -64
-32 -240 -64
-192 -256 -48
-192 -32 -64
-16 -240 -96
-208 -32 -32
-240 -32 -80
-240 -256 -112
-224 -240 -112
-240 -240 -96
-240 -224 -80
-32 -64 -96
-32 -16 -48
-240 -224 -80
-256 -192 -16
-48 -240 -64
-224 -16 -112
-32 -64 -96
-208 -208 -16
-256 -240 -64
-32 -32 -128
-240 -16 -112
-224 -32 -15616
-16 -96 -96
-240 -256 -48
-16 -224 -64
-240 -48 -64
-16 -16 -112
-256 -80 -48
-16 -256 -48
-16 -224 -48
-240 -32 -48
-160 -256 -96
-240 -16 -64
-256 -80 -128
-256 -224 -48
-256 -240 -80
-16 -256 -48
-224 -48 -15584
-256 -48 -16
-208 -96 -96
-208 -16 -48
-224 -48 -80
-48 -256 -80
-240 -224 -32
-32 -256 -64
-256 -48 -112
-16 -48 -96
-240 -256 -112
-32 -16 -64
-64 -48 -112
-32 -256 -80
-32 -240 -80
-256 -64 -80
-224 -32 -112
-32 -224 -64
-16 -256 -64
-208 -256 -32
-176 -32 -112
-32 -16 -80
-208 -256 -112
-208 -16 -96
-16 -64 -16
-256 -32 -32
-224 -32 -48
-256 -48 -15600
-256 -224 -64
-208 -256 -80
-16 -240 -128
-16 -240 -128
-240 -48 -80
-16 -64 -128
-16 -16 -32
-224 -48 -112
-48 -256 -32
-48 -240 -64
-32 -256 -15584
-16 -48 -80
-208 -224 -48
-16 -256 -112
-32 -16 -48
-16 -256 -80
-224 -240 -128
-80 -240 -112
-64 -16 -128
-48 -64 -96
-224 -64 -128
-240 -256 -16
-48 -16 -80
-256 -208 -112
-16 -16 -32
-16 -96 -32
-256 -256 -16
-256 -32 -128
-16 -64 -15552
-16 -240 -15616
-208 -32 -96
-240 -16 -80
-224 -64 -15808
-240 -32 -112
-240 -32 -96
-256 -48 -64
-208 -48 -80
-240 -256 -48
-16 -48 -128
-32 -48 -15760
-32 -80 -48
-224 -64 -15776
-224 -256 -15616
-208 -224 -96
-240 -176 -16
-224 -224 -64
-192 -32 -80
-16 -48 -15600
-256 -256 -128
-32 -256 -80
-240 -16 -80
-224 -16 -96
-240 -240 -32
-240 -64 -80
-224 -224 -128
-256 -224 -48
-112 -16 -112
-16 -48 -128
-240 -64 -32
-208 -16 -15760
-32 -224 -48
-240 -48 -128
-16 -32 -128
-240 -16 -96
-256 -256 -80
-208 -256 -112
BANNED results are showing almost 0 movement.

Code: Select all

21 80 80
21 80 80
22 80 79
22 79 79
22 79 78
22 79 80
22 80 79
22 80 79
23 80 80
22 79 79
22 80 78
21 79 79
22 79 79
22 80 78
22 80 79
22 79 79
22 79 79
21 80 80
22 79 79
22 79 80
22 81 80
23 79 79
22 80 80
what am i doing wrong?

LSM303_REGISTER_ACCEL_CTRL_REG1_A is set to 0x47
LSM303_REGISTER_ACCEL_CTRL_REG4_A is set to 0x08

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: RPI and 10 DOF IMU

Post by adafruit_support_mike »

I'm not sure what's happenining there.. post the complete code you're using and we'll see if that gives us any clues.

Locked
Forum rules
Talk about Adafruit Raspberry Pi® accessories! Please do not ask for Linux support, this is for Adafruit products only! For Raspberry Pi help please visit: http://www.raspberrypi.org/phpBB3/

Return to “Adafruit Raspberry Pi® accessories”