Is calibration necessary?

I found in every startup there is only the sensor alignment but no any sensor calibration, right? Does it necessary to perform sensor calibration after setting up the hardware to compensate the mis-aligned sensor assembly?

It depends on your sensor and how performant you need to be. Often times they will work off-axis somewhat well but you pay a cost in linearity over a full rotation. Considering FOC is mostly concerned with electrical revolution which is much several times smaller than a physical rev, it generally does not cause issues. I do usually run a calibration once and then store that data after a board is assembled, just because it does not take time, but it’s not necessary by any means.

Yes, it works most of the time without calibration, until I tried a stepper motor. Its behavior is quite strange and I don’t know how to describe. How did you calibrate? Have SimpleFOC had the calibration implementation already?

It might be worth describing what you mean by the word calibrate, there are several meanings in this context and I’m not sure which you’re talking about.

Yes, there may be confusion between sensor calibration and sensor alignment and don’t think there is a third situation. I am talking about sensor calibration not sensor alignment. Do you know what I am talking about?

Calibrating a magnetic sensor for runout on the magnet or decenter of the sensor as it’s installed?

I think some of the sensor drivers support sending commands to the sensor to start/stop such a calibration, but it’s specific to the sensor and driver, and isn’t really part of the base library.

Yes, that is the calibration means.

The sensor driver should be no such calibration command, because it must works with power driver that drive the shaft moves and record the relation between electronic angle and sensor angle.

It depends on your sensor, I think that for some encoders (MT6835) there may be some calibration command implemented in the driver (check simplefoc drivers lib) but it is trivial to do yourself if you read the datasheet for your specific sensor.

I am using a MT6816 sensor, it seems no such command. You said you performed that calibration and stored the data, did you do that by yourself? and how simplefoc uses that data?

Sorry, I think I fell into the same mistake as @Copper280z here.
You don’t mean an actual encoder calibration, you are meaning here you want to avoid doing the little turn when starting simpleFOC?
In that case, do the motor.initFOC() once, then read motor.electric_zero_angle and store in flash. THere are various arduino libraries for this. Then when you start the application, check if that was written anywhere, and then provide that value in motor.initFOC(your_angle), then it will skip the little dance.

It seems that in terms of linearity calibration, MT6816 does not have any sort of self-calibration or external calibration.

no no no no, I did mean the actual encoder calibration, that is why I asked you about how you stored the calibration data, and how simplefoc uses those data.

Hi @zhangzq71 , it is a good question you ask!

We have had a contribution from one of our member with code to calibrate the sensor non-linearity: Arduino-FOC-drivers/src/encoders/calibrated at master · simplefoc/Arduino-FOC-drivers · GitHub
You can try this code, but it might be hard to get working, not sure.

This is for non-linearity across a full rotation of the motor, so it is used for example to correct the problem of off-centre mounting of the sensor.

The reports were also that it does not have a big impact on performance, and you need a very large misalignment of the magnet/sensor on the shaft to really see an improvement through calibration.

This code stores the calibration data in-memory, so you also need a MCU with enough memory for it.

The MT6835 has a calibration function in the sensor - you need to move the motor at a constant speed (details are in the datasheet for the sensor) and then start the calibration. The sensor stores the calibration values internally, so the MCU does not need to keep them in memory.
At the moment it is the only sensor I know of that has this kind of function.

You can also calibrate the sensor for motor cogging - this is a different process, requiring far more data points. At the moment we do not have code for this as far as I know.

Great, I tried that code,


because I am using Stepper motor the _NPP is 50, n_ticks = 128*50 = 6400, the MCU must has no such large memory to run this code. I try another ways to do this.

I think there are several sensors that let you put in the geometric offsets is the sensor to magnet, but I don’t think it works like the MT6835 where you can either have it self calibrate or give it a high resolution lookup table. I think the ma730 allows this, and suggests you could use it to mount the encoder next to the magnet instead of coaxial to it.

Runger said MT6835 is the only sensor that has the self-calibration function. I have build a driver that the sensor was assembled in the board, so glue the magnet to the shaft is the only way.


I will try to the LUT by myself following that CalibratedSensor.cpp.

1 Like