Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PID Controls
06-19-2015, 06:22 AM (This post was last modified: 06-19-2015 06:30 AM by KomX.)
Post: #2
RE: PID Controls
Here's a snippet of code from the sketch (This function for the two red faders, the two orange faders, and the two toggle buttons):
Code:
// Read control PID parameters from user. This is only for advanced users that want to "play" with the controllers...
void readControlParameters()
{
  // Parameter initialization (first time we enter page2)
  if ((OSC.page==2)&&(!modifing_control_parameters))
  {
    OSC.fadder1 = 0.5;
    OSC.fadder2 = 0.5;
    OSC.fadder3 = 0.5;
    OSC.fadder4 = 0.0;
    //OSC.toggle1 = 0;
    modifing_control_parameters=true;
  }
  // Parameters Mode (page2 controls)
  // User could adjust KP, KD, KP_THROTTLE and KI_THROTTLE (fadder1,2,3,4)
  // Now we need to adjust all the parameters all the times because we donĀ“t know what parameter has been moved
  if (OSC.page==2)
  {
    Kp_user = KP*2*OSC.fadder1;
    Kd_user = KD*2*OSC.fadder2;
    Kp_thr_user = KP_THROTTLE*2*OSC.fadder3;
    Ki_thr_user = (KI_THROTTLE+0.1)*2*OSC.fadder4;
    #if DEBUG>0
    Serial.print("Par: ");
    Serial.print(Kp_user);
    Serial.print(" ");
    Serial.print(Kd_user);
    Serial.print(" ");
    Serial.print(Kp_thr_user);
    Serial.print(" ");
    Serial.println(Ki_thr_user);
    #endif
    // Kill robot => Sleep
    while (OSC.toggle2)
    {
      //Reset external parameters
      mpu.resetFIFO();
      PID_errorSum = 0;
      timer_old = millis();
      setMotorSpeedM1(0);
      setMotorSpeedM2(0);
      OSC.MsgRead();
    }
    newControlParameters = true;
  }
  if ((newControlParameters)&&(!modifing_control_parameters))
  {
    // Reset parameters
    OSC.fadder1 = 0.5;
    OSC.fadder2 = 0.5;
    //OSC.toggle1 = 0;
    newControlParameters=false;
  }
}

I quote:
Quote: Parameters Mode (page2 controls).
User could adjust KP, KD, KP_THROTTLE and KI_THROTTLE (fadder1,2,3,4)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
PID Controls - wfbaron - 06-19-2015, 03:03 AM
RE: PID Controls - KomX - 06-19-2015 06:22 AM
RE: PID Controls - wfbaron - 06-19-2015, 09:30 PM
RE: PID Controls - KomX - 06-20-2015, 07:57 AM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)