Support for Field Weakening in SimpleFOC

Hello

I am exploring ways to implement field weakening control using SimpleFOC to achieve higher speeds in my motor applications. Currently; SimpleFOC handles FOC well within the nominal voltage range but I haven’t found a straightforward way to extend the speed range by dynamically adjusting the d-axis current. :upside_down_face:

Has anyone experimented with modifying the library to support field weakening? Would it be possible to integrate this feature into future releases? :thinking: I’d love to hear if others have found workarounds or if there are plans to include native support. :innocent: I have checked https://docs.simplefoc.com guide for reference .

Any guidance or discussion on potential implementations would be greatly appreciated. Looking forward to hearing your thoughts!

Thank you ! :slightly_smiling_face:

1 Like

You can easily inherit from BLDCMotor class by creating a class like:

class MyMotor: public BLDC Motor {

/*...*/

public:

	// Redefining setPhaseVoltage method
	void setPhaseVoltage(float Uq, float Ud, float angle_el) override
	{
		// Example: field weaking
		Ud -= 1.0f;
		
		// Example: HFSI
		Ud += hfsi_voltage*sinf(2 * PI * hfsi_frequency * (micros() / 1e6));
		
		// Example: anticogging
		Uq += cogging_table[getCoggingTableIdForAngle(mechanical_angle)];

		// Invoking the original method for applying voltages to phases
		BLDCMotor::setPhaseVoltage(Uq, Ud, angle_el);
	}
/*...*/
};