Hey @nikolaewich1988!
So many interesting issues, I love it.
You are using the encoder right?
What is the velocity you are trying to run your motor on?
Electric angle of the motor should not change, at all. Especially not 0.6 rad (35 degrees). This is not possible. So SimpleFOC does not support adding two different electric zero offsets simply because there is only one.
However, if you are trying to spin your motor at very high velocities, you will definitely see some strange behaviors. For example if the electric angle is wrong by a small postive number, your motor will spin faster in the posititve side and if the electrical angle is wrong by a small negative number your motor will spin faster in the negative side.
If you are using the closed loop control for relatively normal range of velocities there will be no differences.
If you are going to the velocities of >200 rad/s then you will start seeing the issues. There are multiple facters that come to play and electrical angle is only one of them:
- loop time is becoming comparable to the motor electrical rotation period and that means that your the microcontroller is not able to set the phase voltages fast enough. Your rotor will no longer be exactly at 90 degrees from the vector of the magnetic filed because the mcu takes too much time to calculate and set the appropriate phase voltages.
- Not measuring the phase current. If youโre not measuring the phase current, you assume that the phase current is proportional to the phase voltage
I=U/R
which is only true for low velocitites. The higher the velocity the less this relationship is true, and the higher the misalignment. - Finally having evena small error in the electric angle offset estimation will lead to the issues on very high velocities. The maximal velocity on one side will be slower than on the other and the motor can even become unstable.
In most cases, we have to deal with a combination of all of these issues at once.
Fortunately there is a simple fix to help avoid issues 1 and 2 using the zero electric angle 3.
It is called field weakening and the simplest way to implement is to change the electric zero angle depending on the velocity direction you are spinning your motor with.
In you Arduino program you can add a new variable zero_angle_toremember
to remember the zero angle found by the library. Then in the loop function you can change the zero_electric_angle
proportional to the velocity.
float zero_angle_toremember;
void setup(){
....
motor.initFOC();
...
zero_angle_toremember= motor.zero_electric_angle; // remember the zero angle
}
float gain= 0.001; // a gain factor - to try out
float delta_angle_max = 0.3; // something to try, but I would not go much higher than 0.3-0.4
void loop(){
// calculate the field weakening delta angle
float delta_el_angle = _constrain(motor.shaft_velocity*gain, -delta_angle_max ,delta_angle_max );
// set the new angle
motor.zero_electric_angle = zero_angle_toremember+ delta_el_angle ;
...
motor.loopFOC();
motor.move();
}