Author Topic: Data types of Kp and Ki parameters for PI Control  (Read 916 times)

TY

  • Active Member
  • *
  • Posts: 6
Data types of Kp and Ki parameters for PI Control
« on: July 14, 2020, 03:30:43 AM »
Hello,

I'd like to ask a few questons about data types of Kp and Ki parameters for PI Control.

1.
I think the Kp and Ki have been specified to have fixed point format of Q16.16 and those registers are 32-bit.
I saw FocDevice.cpp file (from line 157) describes TORQUE_KP_REG, TORQUE_KP_REG, etc., as below.
add_parameter_value(config->init, parameterRegisters, TORQUE_KP_REG, 5000);      // Torque Kp = 1.0
add_parameter_value(config->init, parameterRegisters, TORQUE_KI_REG, 0);      // Torque Ki = 0
add_parameter_value(config->init, parameterRegisters, RPM_KP_REG, -200);      // Speed Kp = 2.88
add_parameter_value(config->init, parameterRegisters, RPM_KI_REG, -5);         // Speed Ki


Could you tell me why "TORQUE_KP_REG, 5000" is "Torque Kp = 1.0" and "RPM_KP_REG, -200" is "Speed Kp = 2.88"?

For RPM_KI_REG, TORQUE_KP_REG and TORQUE_KI_REG, what do the -5, -20000 and -5000 represent?
add_parameter_value(config->torque, parameterRegisters, TORQUE_KP_REG, -20000);
add_parameter_value(config->torque, parameterRegisters, TORQUE_KI_REG, -5000);

2.
PI_Control function specifies int16_t Kp and int16_t Ki, but above registers are 32-bit.
How does the PI_Control function in foc.cpp calculate above the fixed point format of Q16.16?

Thanks

Andrei Errapart

  • Active Member
  • *
  • Posts: 35
Re: Data types of Kp and Ki parameters for PI Control
« Reply #1 on: July 23, 2020, 01:16:02 PM »
I am sorry for the delay in answer.

You are right in your observations. The documentation should read Q8.8 for the proportional setpoint and Q0.16 for the integral setpoint.

The comments require updates as follows:
// Torque Kp (Q8.8 ): register contents 5000 for the value of 19.53.
// Speed Kp (Q8.8 ): register contents -200 for the value of -0.78
// Speed Ki (Q0.16): registers contents -5 for the value of -0.000076


If there are any further questions, don't hesitate to ask.

TY

  • Active Member
  • *
  • Posts: 6
Re: Data types of Kp and Ki parameters for PI Control
« Reply #2 on: September 01, 2020, 05:40:51 PM »
Hi Andrei,

Thanks for your help. I would like to ask you some more questions.

1.
Is fixed point format of TORQUE_KI_REG also Q0.16?

2.
Unit of TORQUE_SP_REG and FLUX_SP_REG is describes in foc.h (line 91 and 108) and the unit is Resolution of the current ADC-s.
I confirmed that "focserver.conf" file defines "adc2A" as 0.00039.
How did you calculate the value of "0.00039" ?

Thanks
« Last Edit: September 01, 2020, 06:17:47 PM by TY »

Andrei Errapart

  • Active Member
  • *
  • Posts: 35
Re: Data types of Kp and Ki parameters for PI Control
« Reply #3 on: September 02, 2020, 10:10:39 AM »
1. Yes, TORQUE_KI_REG  is also Q0.16

2. This can be calculated from the component datasheets. I think I must have had a prototype board with different components, because now I arrive at another value. Please find attached the spreadsheet with the new calculations; the number you are searching for is highlighted in the block "ADC", on the last line, "Sensitivity".

TY

  • Active Member
  • *
  • Posts: 6
Re: Data types of Kp and Ki parameters for PI Control
« Reply #4 on: September 03, 2020, 04:20:20 PM »
Hi Andrei,

Thank you for your prompt reply and kind explanation!  It's clear now.

Thanks
« Last Edit: September 03, 2020, 04:22:25 PM by TY »