How does internally the code limits or sets the voltage for the motors?
Let’s say my power supply is set to 33V, but I want to set the max to 30V? Is it possible? How does it work in the driver internally? It limits the max PWM? Does it measure the real voltage?
Yes, this is correct - the voltage output to the motor phases is modulated using the PWM signals to the driver. So by limiting the PWM duty cycle we can set a voltage limit in software.
No, not unless you add your own code to do so. So if the actual PSU voltage differs from the configuration of the driver, all voltages calculated by SimpleFOC will be wrong in proportion to this difference.
Your power-supply voltage is basically the “wall-voltage” as the motor system sees it. E.g. your motor system is supplied by a usb-c PD supply, negotiated to 20V, and so the motor systems lives on 20V. in The BLDCDriver class, you would set voltage_power_supply to 20
…however, you want to limit your motor to 13V, and so you set BLDCDriver::voltage_limit to 13.
So: a 100% duty cycle is always-on 20V, but you have specified that 100% rated voltage to 13. The end result is 100% rated power maps to a 65% duty cycle, resulting in pwm period averages to no more than 13V.
So your system as a whole needs to be able to handle up to 20V everywhere, but for the parts that are PWM modulated, if their max is 13V operational, they need to be able to handle that in terms of PWM’d 20V with up-to 65% duty cycle.
Have I got that correct?
One source of confusion for me: Both BLDCDriver and FOCMotor have a voltage_limit field. is this a duplication? or does this have different meaning in these different classes?