jcchurch13 / Mechaduino-Firmware

Hardware available here:
http://tropical-labs.com
Other
389 stars 232 forks source link

Question about magic values #12

Closed Eriobis closed 7 years ago

Eriobis commented 7 years ago

In the Interrupt routine, I would like to know the number 150 ( in mode x ) and number 200 ( in mode v ) What do they represent ??? ( Ill do a define for those numbers )

switch (mode) {
  case 'x':
    e = (r - yw);
    SerialUSB.print(y);
    SerialUSB.print(";");
    SerialUSB.print(e);
    SerialUSB.println(";");
    ITerm += (pKi * e);
    if (ITerm > 150) ITerm = 150;
    else if (ITerm < -150) ITerm = -150;
    u = ((pKp * e) + ITerm - (pKd * (yw - yw_1))); //ARDUINO library style
    //u = u+lookup_force(a)-20;
    //   u = u_1 + cA*e + cB*e_1 + cC*e_2;     //ppt linked in octave script
    //  u = 20*e;//
    break;

  case 'v':
    e = (r - ((yw - yw_1) * Fs*0.16666667));//error in degrees per rpm (sample frequency in Hz * (60 seconds/min) / (360 degrees/rev) )
    ITerm += (vKi * e);
    if (ITerm > 200) ITerm = 200;
    else if (ITerm < -200) ITerm = -200;
    u = ((vKp * e) + ITerm - (vKd * (yw - yw_1)));//+ lookup_force(a)-20; //ARDUINO library style
    break;
jcchurch13 commented 7 years ago

Those are integral windup limits: https://en.wikipedia.org/wiki/Integral_windup