Hi,
I studied the encoder offset calibration algorithm recently.
I know the calibration algorithm has 3 steps:
-
Align encoder angle
shadow_count_
to alpha axis. -
Accumulate encoder angle and
num_steps
during turning rotor forward and backward.
i.e.
encvaluesum += shadow_count_
num_steps++
-
Calculate
phase_offset
andphase_offset_residual
.
config_.phase_offset = encvaluesum / num_steps;
int32_t residual = encvaluesum - ((int64_t)config_.phase_offset * (int64_t)num_steps);
config_.phase_offset_float = (float)residual / (float)num_steps + 0.5f; // add 0.5 to center-align state to phase
then the electrical angle is corrected in 3 steps:
-
Calculate corrected encoder angle.
int32_t corrected_enc = count_in_cpr_ - config_.phase_offset;
-
Interpolate encoder angle.
float interpolated_enc = corrected_enc + interpolation_;
whereinterpolation_
is 0.0, 0.5 or 1.0 is depended on moving. -
Calculate electrical angle.
float ph = elec_rad_per_enc * (interpolated_enc - config_.phase_offset_float);
My questions are below:
-
Why just accumulate encoder angle and num_steps?
And could I treat the encoder angle aligned to the alpha axis as phase_offset?
Or accumulate the difference between the encoder angle and electrical angle * pole pairs then take average. -
Why calculate phase_offset_float?
And could I ignore it?
Because I don’t think the residual divided by steps is a large number. -
Why add 0.5 to phase_offset_float?
I can’t understand the meaning ofadd 0.5 to center-align state to phase
.
Is the 0.5 value for interpolating? -
Why interpolate the encoder angle?
There are many questions.
I will vary much appreciate if someone reply me.