Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in C

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
gfcwfzkm
 
Posts: 16
Joined: Thu Aug 07, 2014 12:49 pm

Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in C

Post by gfcwfzkm »

I got some Problems with the LSM9DS0 Breakout and (maybe) with the Library. I rewrote the Library to use it in Atmel Studio with C but it looks
like it doesnt calcuclate the gyro correctly.
Unbenannt1.JPG
Unbenannt1.JPG (65.57 KiB) Viewed 1129 times
After initialising and configuring it for 245DPS the Registers for the Gyro are: CTRL_REG1_G: 0x0F, CTRL_REG4_G: 0x00

To calculate the data, i read the 6 Registers (Xl,Xh,Yl,Yh,Zl,Zh) and multiply it with 0.08F but it always says that the device is moving.

Is the Calibration wrong or could be the calculation wrong?

~gfc

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by adafruit_support_bill »

Is the Calibration wrong
How did you calibrate it? Calibrating a gyro requires subjecting it to known rotation rates are reading the output. The differences between the output values and the known rate are you calibration correction factors.

The two primary types of error in MEMS devices like the gyro are zero offset (which looks like what you are seeing) and scale. .

User avatar
gfcwfzkm
 
Posts: 16
Joined: Thu Aug 07, 2014 12:49 pm

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by gfcwfzkm »

I didnt calibrated it by myself yet but it was an idea that this could be wrong (and the reason for the results).

You said that the error could be a zero-offset. But how can i fix it?
In the Library you use Float-Numbers for the different ranges to calculate the degrees per second. Could these numbers be wrong?
Like in your Library i use 0.061 for 2G (for high precision) and with that number it calculates the degrees per second.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by adafruit_support_bill »

Zero offset errors are typical for MEMS sensors like your Gyro. You fix it in software by subtracting the zero offset error from the reading.

http://www.digikey.com/en/articles/tech ... ms-sensors
Zero-rate level (some vendors call this the offset calibration error) is the output generated even if there is no rotation. The previously-mentioned LY3100ALH is specified at 1.5 volts, far in excess of the device’s 1.1 mV/dps sensitivity. Clearly this must be nullified by the designer. VTI Technologies’ CMR3000 has a ±2000 dps range, but the zero-rate error, at ±200 dps, is fully ten percent of the unit’s range. As mentioned, for absolute measurements one must calibrate the sensor.

User avatar
gfcwfzkm
 
Posts: 16
Joined: Thu Aug 07, 2014 12:49 pm

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by gfcwfzkm »

Thank you, that solved my Gyro-Problem.

I came to one of your tutorials to get AHRS-Data (For Pitch and Roll). I tried to use it but sadly i get very strange values back.
Unbenannt.JPG
Unbenannt.JPG (49.84 KiB) Viewed 942 times
I rewrote it to use it in AtmelStudio-C. Im giving it the calculated Accleration-Values (That you see in the screenshot, the 'Accel'-Line(s))

Could i have a Library problem or am i giving it the wrong values? Thats what im using.

Code: Select all

// Compute orientation based on accelerometer and magnetometer data.
void getOrientation(lsm9ds0_sensor* accel_event, lsm9ds0_sensor* mag_event)
{
	float const PI_F = 3.14159265F;
	float pitch;
	// roll: Rotation around the X-axis. -180 <= roll <= 180
	// a positive roll angle is defined to be a clockwise rotation about the positive X-axis
	//
	// y
	// roll = atan2(---)
	// z
	//
	// where: y, z are returned value from accelerometer sensor
	float roll = (float)atan2(accel_event->y, accel_event->z);
	// pitch: Rotation around the Y-axis. -180 <= roll <= 180
	// a positive pitch angle is defined to be a clockwise rotation about the positive Y-axis
	//
	// -x
	// pitch = atan(-------------------------------)
	// y * sin(roll) + z * cos(roll)
	//
	// where: x, y, z are returned value from accelerometer sensor
	if (accel_event->y * sin(roll) + accel_event->z * cos(roll) == 0)
	{
		pitch = accel_event->x > 0 ? (PI_F / 2) : (-PI_F / 2);
	}
	else
	{
		pitch = (float)atan(-accel_event->x / (accel_event->y * sin(roll) + accel_event->z * cos(roll)));
	}
	// heading: Rotation around the Z-axis. -180 <= roll <= 180
	// a positive heading angle is defined to be a clockwise rotation about the positive Z-axis
	//
	// z * sin(roll) - y * cos(roll)
	// heading = atan2(--------------------------------------------------------------------------)
	// x * cos(pitch) + y * sin(pitch) * sin(roll) + z * sin(pitch) * cos(roll))
	//
	// where: x, y, z are returned value from magnetometer sensor
	float heading = (float)atan2(mag_event->z * sin(roll) - mag_event->y * cos(roll), \
	mag_event->x * cos(pitch) + \
	mag_event->y * sin(pitch) * sin(roll) + \
	mag_event->z * sin(pitch) * cos(roll));
	// Convert angular data to degree
	roll = roll * 180 / PI_F;
	pitch = pitch * 180 / PI_F;
	heading = heading * 180 / PI_F;
	
	sprintf(buffer, "\n\rRoll: %d     Pitch: %d        Heading: %d", roll, pitch, heading);
	uart_puts_all(buffer);
}
I didnt changed much. Just renamed the variables (accel_event, mag_event and replaced orientation->roll to float roll...)

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by adafruit_support_bill »

In your sprintf format string you are using %d. It is trying to interpret your floating point values as integers.

User avatar
gfcwfzkm
 
Posts: 16
Joined: Thu Aug 07, 2014 12:49 pm

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by gfcwfzkm »

^^ fail, now i see it.

Thanks, that solved my last problem.

~gfc

User avatar
kcparker
 
Posts: 3
Joined: Sat May 07, 2016 5:05 pm

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by kcparker »

Could you elaborate on which number is the zero offset? My tilt sensor is also off and I'd like to fix this.

Thank you

User avatar
Franklin97355
 
Posts: 23912
Joined: Mon Apr 21, 2008 2:33 pm

Re: Gyro Calibration of the LSM9DS0 with the ATMEGA1284P in

Post by Franklin97355 »

@kcparker. If you are having a problem start a thread, explain your problem, tell us what you have tried to resolve it and perhaps we can help.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”