In the functions Roll1_vel() and Roll2_vel() the following code is supposed to keep the phase index in the interval 0 to 2*pi:
//RESET PHASE INDEX AFTER 2PI
if (phaseindex1 >= 2*pi) { //Reset phaseindex_U1 once it completes 2*180o in phase.
phaseindex1 = 0;
}
else if (phaseindex1 <= 0){
phaseindex1 = 2*pi - phaseindex1;
}
For the case of phaseindex1 <= 0, I believe is should really be phaseindex1 = 2*pi + phaseindex1; rather than phaseindex1 = 2*pi - phaseindex1;. For the case of phaseindex1 >= 2*pi, it's not really wrong, but setting it to 0 could cause a small speed inconsistency. It would be better to use phaseindex1 = phaseindex1 - 2*pi;.
All together, I would propose the following code:
//RESET PHASE INDEX AFTER 2PI
if (phaseindex1 >= 2*pi) { //Reset phaseindex_U1 once it completes 2*180o in phase.
phaseindex1 -= 2*pi;
}
else if (phaseindex1 < 0){
phaseindex1 += 2*pi;
}
The reason I found this was that I experienced that the motor got stuck after rotating just a little bit at certain speeds. I believe this is due to the controller getting stuck in an infinite loop jumping between the edge cases. It only seems to happen at certain negative speeds, which I think is due to floating point imprecision.
In the functions
Roll1_vel()andRoll2_vel()the following code is supposed to keep the phase index in the interval 0 to 2*pi:For the case of
phaseindex1 <= 0, I believe is should really bephaseindex1 = 2*pi + phaseindex1;rather thanphaseindex1 = 2*pi - phaseindex1;. For the case ofphaseindex1 >= 2*pi, it's not really wrong, but setting it to 0 could cause a small speed inconsistency. It would be better to usephaseindex1 = phaseindex1 - 2*pi;.All together, I would propose the following code:
The reason I found this was that I experienced that the motor got stuck after rotating just a little bit at certain speeds. I believe this is due to the controller getting stuck in an infinite loop jumping between the edge cases. It only seems to happen at certain negative speeds, which I think is due to floating point imprecision.