Whoa, lot of stuff in this thread, I’m afraid we might all loose track. At some point a summary should be drawn up and a new thread started with an OP that summarizes the conclusions/poses the most pertinent questions.
One option for some people in some contexts would be to use a battery pack which can be connected in either series or parallel to some degree.
For braking, you would capture the energy, or some of it, but connecting the cells in parallel rather than series, reducing the battery voltage to lower than the output of the motor.
Aside from that I think fundamentally you need a boost converter. What I would probably do is that Simplefoc continues to operate the mosfets that drive the motor in exactly the same way, using the angle sensor. If the driver does this, if the battery voltage is higher than the back voltage produced at the input to the inverter, energy flows from the battery to the motor. If it’s higher, energy flows from the motor to battery. In other words it mimics a brushed dc motor basically. There would be no need to PWM the mosfets in the inverter, you would would use somethign more like 6 step commutation, not sine wave, during braking.
Then you need a dc dc boost converter (buck means step down I think). I think honestly there is probably no way around voltage boosting, energy has to be concentrated on a smaller number of electrons. There has to be an active mechanism to do this, which produces waste heat, or is it the third or second law of thermodynamics that would be violated. Energy can’t be concentrated on a smaller number of particles without an active pumping system, which is never 100 percent efficient. I know that’s a distortion, but I think that is a corrollary that I remember from the fundamentals.
Also the voltage booster would ideally have maximum power point tracking type algorithm because there is an optimum voltage and current draw from the motor that leads to maximal energy return. Draw too much current and a lot of the energy gets dissipated in the motor as heat.
However I think the energy available from all this is very small. Braking is a good idea, there is already active braking by setting torque negative, which you need for a servo motor.
However generators are also useful so basic function to do generator stuff might make sense, if built into SimpleFOC.
Actually I just thought of something, if you measure the back voltage that could be a good way to calibrate the angle sensor too, that’s actually a good idea as it does not get distorted by the loading the way the existing open loop drive approach does.
Maybe measuring the voltage on the output of the inverters is useful, then, for that. Also has applications in sensorless drive.