# Imu temp calibration

Source: https://forum.modalai.com/topic/3264/imu-temp-calibration
Category: VOXL 2 and VOXL 2 Mini (https://forum.modalai.com/category/26/voxl-2-and-voxl-2-mini)
Tags: voxl-2-mini
Posted: 2024-03-27 00:50:11 UTC by mkriesel
Replies: 5 · Views: 1326

## mkriesel · 2024-03-27 00:50:11 UTC

Hello, I have a voxl2 mini that I'm doing development on and I'm running in to issues with the temperature calibration on the imu, mostly that I can't get it to work. When I try to run the calibration it doesn't complete and says "not enough samples, need at least 3" It feels like I'm missing something obvious but I've tried it a few times to the same result. Any help or guidance is appreciated.

![Screenshot from 2024-03-26 17-45-59.png](https://forum.modalai.com/assets/uploads/files/1711500423509-screenshot-from-2024-03-26-17-45-59.png)

## Reply by Alex Kushleyev (ModalAI staff) · 2024-03-27 03:24:24 UTC

@mkriesel , 

the source code is [here](https://gitlab.com/voxl-public/voxl-sdk/services/qrb5165-imu-server/-/blob/master/clients/voxl-calibrate-imu-temp.c)

You can run in debug mode to get more info, but it seems the temperature of the IMU has not really changed from the start (34C vs 31C). The cpu stressing may not be enough. You should check output of `top` while the stressing of CPU is running (the application just burns cpu cycles in order to heat up the cpu, which will heat up the IMU to help with temperature calibration). How long did the procedure run before it stopped?

## Reply by mkriesel · 2024-03-27 18:22:47 UTC (in reply to Alex Kushleyev)

@Alex-Kushleyev
it runs for about a minute and it seems to be stressing the cpu but not enough to raise the temp significantly, in my setup the voxl is sitting in a metal housing so does it just not get hot enough for it to run the calibration properly?
 ![Screenshot from 2024-03-27 11-19-43.png](https://forum.modalai.com/assets/uploads/files/1711563658456-screenshot-from-2024-03-27-11-19-43.png)

## Reply by Alex Kushleyev (ModalAI staff) · 2024-03-27 19:52:10 UTC (in reply to mkriesel)

@mkriesel , yes, i believe your conclusion is correct. Something must be cooling down the board (enclosure).

It tested this myself and have a small tip for you: setting cpu mode to performance helps to burn more power in the cpu (run this right before starting the temp calibration):

```
voxl-set-cpu-mode perf
```

Also you should start the calibration when the board is a bit colder, maybe room temp 20-25C

Try it!

## Reply by Alex Kushleyev (ModalAI staff) · 2024-03-27 20:02:31 UTC (in reply to Alex Kushleyev)

we can also the stress function for the cpu, to make it consume more power. i will follow up about it a bit later.

## Reply by Alex Kushleyev (ModalAI staff) · 2024-03-27 21:15:29 UTC (in reply to Alex Kushleyev)

If you need the cpu stress function to generate more heat, here is something that works. you can replace the current function with this one. It adds a memcpy() operation which uses a lot of power. You can tune `do_memcpy_every_nth` to control more or less heat (decreasing the number will use heat up cpu more).

Original function is [here](https://gitlab.com/voxl-public/voxl-sdk/services/qrb5165-imu-server/-/blob/master/clients/voxl-calibrate-imu-temp.c#L168)

```
#define STRESS_ARRAY_SIZE (128*1024)
static void* _stress_function(__attribute__((unused)) void* arg)
{
    uint8_t * _stress_array  = malloc(sizeof(uint8_t)*STRESS_ARRAY_SIZE);
    
    uint32_t cntr = 0;
	while(stress_running){
	    cntr++;
		volatile double s = sqrt(rand()); //this helps slow down the while loop
		
		const int do_memcpy_every_nth = 50; //do not perform memcpy every loop because cpu can get hot very quickly
		if ((cntr % do_memcpy_every_nth) == 0){            
		    memcpy(_stress_array,_stress_array+STRESS_ARRAY_SIZE/2,sizeof(uint8_t)*STRESS_ARRAY_SIZE/2);
		}
	}
	//printf("stress thread exiting\n");
	
	free(_stress_array);
	return NULL;
}
```
