Hey, quick question as I try to implement the above approach: the docs all say the relative angle for mechanical position of the rotor and the electrical angle should be 90 degrees.
I assume I multiply the mechanical angle of the rotor - detected sensor angle minus the zero electrical angle (to compensate for the random installed position of the sensor’s magnet relative to the rotor’s magnets) - by seven (7 pole pairs for this motor), then go modulo division of that figure by 2pi. That should give me the “mechanical angle” in terms of the position of the magnets between the poles? In radians.
And then add 90 degrees i.e. pi/2 radians, to give the desired electrical angle in simplefoc?
I’m trying to write a simple program that starts the motor in open loop mode, checks the mechanical angle (as described above) and then immediately checks the electrical angle using simplefoc’s methods/functions. I assume no practical time delay between these two measurements. I do this ten times per second. Then I calculate the difference.
Then I do some very basic PID controller stuff with floating point numbers, also every tenth of second or so, to adjust the open loop velocity, in order to regulate the difference between the two angles to pi/2.
Thus, I close the loop, but in a way that allows for much higher RPM. It is not suitable for other kinds of motion, but it should work for a fan. Reversing direction, and acceleration will be tackled after getting this going.
Does that make sense? I don’t quite see why this 90 degrees angle gives optimal torque. One thing I can do is run it in open loop mode and print out the relative angle, then adjust the power supply to reduce current flow, until efficiency is optimal (which is at the same point that current is minimal and yet the fan keeps turning), or rather just before (so I have a little safety margin against the motor “skipping steps”, same as a stepper motor would). I can verify experimentally that my assumptions/this wisdom about the angle being 90 degrees is correct. Pretty clownerific I know, compared to actually understanding the math, but none of the articles I can find about FOC want to actually answer on the ground questions like this.
You can’t change the acceleration too fast or it will loose track and the pid controller will take a while to reduce the velocity and get the fan turning again, but that’s fine. I can implement acceleration logic in the master microcontroller, the raspberry pi pico. Or I could implement it later, or maybe even just set the PID controller gains accordingly. I know to do integral wind up limits and stuff with the controller logic. It will be a pain to tune the pid, I will have to compile and recompile it with different values because I don’t know enough C to make efficient work of getting the values over serial or whatever. Whatever.