cancel
Showing results for 
Search instead for 
Did you mean: 

MotionTL calibration fails

KHeye.1
Associate III

Hi,

I am currently trying to calibrate a LSM6DSL using the MotionTL calibration but it keeps failing. There must be something I am doing wrong, but I have not been able to find it while comparing my code to the mems examples.

  MTL_acc_cal_t calibration_values;
  MTL_cal_result_t calibration_result;
  calibration_result = MotionTL_SetCalValues(&calibration_values);
  float accel_values[3];
 
  int orientation, sample, i;
  for(orientation = 0; orientation < 6; orientation++){
	  // calibrate for 6 different orientations
	  // read new value to first to get good values
	  readIMUData(&dev_ctx, accel_values);
	  float samples[sample_size][3];
	  for(sample = 0; sample < sample_size; sample++){
		  // get data
		  readIMUData(&dev_ctx, accel_values);
		  HAL_Delay(3);
		  for(i = 0; i < 3; i++)
			  samples[sample][i] = accel_values[i];
 
	  }
 
	  // add to motiontl
	  switch(orientation){
	  case 0:
		  MotionTL_CalibratePosition(samples, sample_size, X_UP);
		  break;
	  case 1:
		  MotionTL_CalibratePosition(samples, sample_size, X_DOWN);
		  break;
	  case 2:
		  MotionTL_CalibratePosition(samples, sample_size, Y_UP);
		  break;
	  case 3:
		  MotionTL_CalibratePosition(samples, sample_size, Y_DOWN);
		  break;
	  case 4:
		  MotionTL_CalibratePosition(samples, sample_size, Z_UP);
		  break;
	  case 5:
		  MotionTL_CalibratePosition(samples, sample_size, Z_DOWN);
		  break;
	  }
 
  }
 
  calibration_result = MotionTL_GetCalValues(&calibration_values);

Please let me know what I am doing wrong.

Cheers,

Kevin

5 REPLIES 5
Eleon BORLINI
ST Employee

Hi Kevin @KHeye.1​ ,

a hardware level, are you using this library with STM32 boards or with a custom board?

From a firmware / software side, are you able to read the data out of the device?

And did you check the example code in the UM2277 user manual? Especially regarding the library configuration phase.

[…]
#define VERSION_STR_LENG 35
[…]
/*** Initialization ***/
char lib_version[VERSION_STR_LENG];
char acc_orientation[3];
acc_orientation[0] = 'n';
acc_orientation[1] = 'w';
acc_orientation[2] = 'u';
/* Tilt API initialization function */
MotionTL_manager_init(ACCELERO_handle);
MotionTL_SetOrientation_Acc(acc_orientation);
/* OPTIONAL */
/* Get library version */
 MotionTL_manager_get_version(lib_version, &lib_version_len);
[…]

You could also improve the accuracy of the output running the MotionAC accelerometer calibration library before the MotionTL, especially if the device is facing post-soldering offsets (you could check them just reading the dataout in rest position and see if the axis are far from 0g, 0g, and 1g.

-Eleon

Hi Eleon,

This is a custom board, and I am able to read the data from the LSM and get valid tilt angles out of MotionTL.

I have looked at the example code in UM227 and LSM6DSL_TiltDetection in X-CUBE-MEMS1. My initialization of MotionTL is:

MotionTL_Initialize();
MotionTL_SetOrientation_Acc("neu"); 

As for using MotionAC, Miroslav Batek posted on this question that he recommends using the calibration on MotionTL. Because of his comment, I was going to try the MotionTL calibration first and then try MotionAC if needed. If you recommend otherwise I will try MotionAC calibration first.

Cheers,

Kevin

Hi Kevin @KHeye.1​ ,

please follow Miroslav suggestion, he is more expert than me on this topic.

Did you already have the possibility to try it?

-Eleon

Hi Eleon @Eleon BORLINI​ ,

I did get MotionAC to work, but it did not compensate for misalignment (which is what I ended up needing). I implemented a 6 point tumble calibration myself which did compensate for misalignment.

Maybe I did something wrong with the 6 point calibration in MotionAC, but it would always just return zeros for each of the 6 cross axis gains.

Cheers,

Kevin

Eleon BORLINI
ST Employee

Hi Kevin,

>> I implemented a 6 point tumble calibration myself which did compensate for misalignment.

Is your solution working well now? If so, could you briefly describe it for the Community? Not the detailed algorithm, just a few hints.

Thanks,

-Eleon