This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Where to modify the PID parameters

Hello,

I would like to know what is the best place of the code to set the current PID parameters. I know initialy it gets set to some small default parameters and later on it calculates some proper ones based on the motor parameters. However if instead of using those PID parameters I want to use some I have tweaked by hand, where should I make the changes?

So far what I have been doing is:

if(EST_getState(obj->estHandle) != EST_State_OnLine){
// Proportional gain for the PID current loop
gMotorVars.Kp_Idq = _IQ(Kp_Gain_Idq) ;

// Integral gain for the PID current loop
gMotorVars.Ki_Idq = _IQ(Ki_Gain_Idq);

// Load those values to the ctrl structure
CTRL_setKp(ctrlHandle,CTRL_Type_PID_Id,gMotorVars.Kp_Idq);
CTRL_setKi(ctrlHandle,CTRL_Type_PID_Id,gMotorVars.Ki_Idq);
CTRL_setKp(ctrlHandle,CTRL_Type_PID_Iq,gMotorVars.Kp_Idq);
CTRL_setKi(ctrlHandle,CTRL_Type_PID_Iq,gMotorVars.Ki_Idq);

}

I put that piece of code in the main loop and therefore every time the system is enabled it would load the parameters I want. This is not ideal though, because every time I restart the system it would reload the old values to switch on run-time to the ones I want. Is there a better way to do this?

Regards