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.

Lab 5f, motor vibrating when PID gains are used

Using the DRV-8312-69M-KIT and the DT4260 motor, In lab 5a, and Lab 5b, I calculated the gains of the PID control as follows: Kp_speed=0.897, Ki_speed=0.045, Kp_idq=0.312, Ki_idq=0.043, inertia = 0.01709, Friction = 0.04595.  In Lab 5e, calculated VelCTLBwScale = 6.1.  I can run the motor with no problem to maximum speed in lab 5e, even at 5K rpm.  In lab 5f, with spinTAC enabled, the motor ran pefectly.  Now, in lab 5f, when i disable the SpiTAC so motor will run using pid gains that get loaded by the CCS which are different than the above, CCS gains, Kp_speed = 8.0, Ki_speed=0.0533, Kp_idq=0.972076, and Ki_idq=0.04336, motor runs very good.  When I enter my values from lab 5a, and 5b, the motor will oscillate in lab 5f, but it ran perfectly before. 

Questions: 1.  Why are my gain values different than what CCS calculates or get loaded automatically when running lab 5f.  2.  The gains that I calculated in labs 5a, and 5b, I feel are correct, but when entered in lab 5f, motor oscillates.

Thank you

  • Michael,

    Are these the PI gains that you calculated from the lab documentation?  

    1. The gains from the lab documentation are not calculated in the same way as in the lab code.

    2. The calculated PI gains often require additional tuning.  Also PI gains often don't work across a wide operating range sometimes requiring multiple sets of gains.  

    This really illustrates the value of SpinTAC.  With one gain is becomes much easier to tune and works across the entire operating range.

  • just had a really long reply and my laptop froze up.....grrrrr.

    Michael Mina1 said:
    I calculated the gains of the PID control as follows: Kp_speed=0.897, Ki_speed=0.045,

    The write-up in 5b is very confusing. Even though the same kit + motor is used I never get a valid calculation. I've asked that this be looked at....but in general your Kp looks too low.  But that is greatly affected by your IQ_V setting. But even if you have it at say (48.0) while I'm using (24.0) you should get something closer to ~1.5-2.0

    Your Ki is a bit stiff relative to Kp.  Again, all the numbers get affected by the ADC_V / IQ_V scale factors, but with my set-up a Kp = 2 and Ki = 0.02 work across the speed range (I typically increase both at lower speeds).

    Michael Mina1 said:
    Kp_idq=0.312, Ki_idq=0.043

    This Kp seems low. Again, your scale factors must be quite a bit different than mine, but the automatic calcPIgains() function gives me 1.75

    Kp = 0.25*Ls * (fsCurrent / *fsVoltage) / ctrlPeriod_sec

    Michael Mina1 said:
    Now, in lab 5f, when i disable the SpiTAC so motor will run using pid gains that get loaded by the CCS which are different than the above, CCS gains, Kp_speed = 8.0, Ki_speed=0.0533, Kp_idq=0.972076, and Ki_idq=0.04336, motor runs very good.

    05f will load the default values unless you over-write them with your hand calculated values.  These default values look better than the ones you calculated IMO.

    Is the user.h you are using in instaspin_motion the same as in instaspin_foc besides the new variables?  You are using the exact same IQ_V, IQ_C, ADC_V, ADC_C?

    Michael Mina1 said:
    1.  Why are my gain values different than what CCS calculates or get loaded automatically when running lab 5f. 

    Because there are two methods.

    I would not hand calculate the current gains. The calculations done in software by calcPIgains() work extremely well. The only reason I would ever change them is if I did specific step input testing using the gains and decided I wanted a sligthly different response.  The write-up in 5a for calcualting the current gains is not helpufl IMO and completely unnecessary.  We are looking at removing this from the lab write-ups.

    The speed gains that are set by default in software are NOT tuned at all, and have no knowledge of your motor or load.  It uses a very simple "rule of thumb first guess" to set a starting point for these gains, primarily based on the value you set as your USER_MAX_CURRENT and MAX_HZ:

    Kp = 0.02 * MAX_HZ  *  MAX_CURRENT   /   IQ_CURRENT

    Ki = 2.0 * CTRL_HZ  *  MAX_HZ  *  MAX_CURRENT   /    IQ_CURRENT

    You do need to calculated / do some testing to get speed gains AND you will find that you will have to "gain stage" when using a PI controller. This means different sets of gains for different operating points / conditions.  Your state machine code will have to load these values in under certain conditions (specific speed_ref settings, specific acceleration movements, etc.).  That's why SpinTAC in InstaSPIN-MOTION is so helpfu.  Much easier to tune and you don't have to set different speed gains across your system use case. One setting and you're typically done.

    Michael Mina1 said:
    2.  The gains that I calculated in labs 5a, and 5b, I feel are correct, but when entered in lab 5f, motor oscillates.

    I do not think they are correct.