JJRobots COMMUNITY

Full Version: PID Controls
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
On the PID Adjust page of the TouchOSC app, what is the function of the two red faders, the two orange faders, and the two toggle buttons? I realize that we should not adjust the PID controls unless we know what we are doing.
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)
Thank you. That's very helpful. It looks like toggle2 resets the external parameters, but toggle1 does nothing.
The new version of the sketch has become less functional. In the first embodiment, it was as follows:
Code:
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 and KP_THROTTLE (fadder1,2,3)
  // 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)
  //if ((OSC.page==2)&&(OSC.toggle1==1))
    {
    Serial.print("Par: ");
    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 (OSC.toggle1 == 0)
      {
      max_throttle = MAX_THROTTLE;
      max_steering = MAX_STEERING;
      max_target_angle = MAX_TARGET_ANGLE;
      }
    else
      {
      max_throttle = MAX_THROTTLE_PRO;
      max_steering = MAX_STEERING_PRO;
      max_target_angle = MAX_TARGET_ANGLE_PRO;
      }
    Serial.print(Kp_user);
    Serial.print(" ");
    Serial.print(Kd_user);
    Serial.print(" ");
    Serial.print(Kp_thr_user);
    Serial.print(" ");
    Serial.println(Ki_thr_user);
    
    // Kill robot => Sleep
    while (OSC.toggle2)
      {
      //Reset external parameters
      mpu.resetFIFO();
      PID_errorSum = 0;
      timer_old = millis();
      distance_sensor = 150;
      setMotorSpeed(0,0);
      setMotorSpeed(1,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;
    }
}

So, toggle1 selects the mode of reaction of the robot to the team: normal bit slow, cautious mode or a more aggressive reaction.
Code:
#define MAX_THROTTLE 530
#define MAX_STEERING 136
#define MAX_TARGET_ANGLE 12

// PRO MODE = MORE AGGRESSIVE
#define MAX_THROTTLE_PRO 650
#define MAX_STEERING_PRO 240
#define MAX_TARGET_ANGLE_PRO 18
Reference URL's