Ouch! That’s one motor demo I didn’t enjoy so much as most
I would also read it in the way that it would use FOC at lower speeds, but who knows? I’m not saying it isn’t possible to do at 40kRPM, just that it would be very hard, and not something that would “just work” with our library. And this isn’t so much a problem of the code as of the speed of Arduino hardware, the sensors available, etc…
I think it would probably work.
I’m not sure this would be so simple. Your intuition is correct that the current would have to be sensed very quickly to switch the driver off in time to prevent damage.
You need 3 current sensors, on in series with each phase. Or you could place a single sensor in the path from the driver to the GND, that should work too. Then the MCU would continuously monitor the current sensor, but how would it limit the current? You’d essentially need a huge buck-converter to dynamically change the voltage, or some other very fast-reacting but high-current capable switch…
Normally the current is controlled by the driver stage itself, its the natural place to do it.
That said, you might be able to find a power-supply that just limits the current for you in the desired way. Not sure what’s out there in that department…