%  MODIFY PID CONTROLLER TUNING CONSTANTS

%  FILENAME: PIDCONST.M
%  DATE: October 1994
%  VERSION: 02
%  COPYRIGHT 1993, 1994 M.Gretzinger & T.Marlin
%            McMaster University   

% This m-file is called from STABLE.M. It sets up menu to allow user to
%       modify the PID controller tuning constants.

while 1
  clc
  disp('*************************************************************')
  disp('*        MODIFY PID CONTROLLER TUNING CONSTANTS             *')
  disp('*                                                           *')
  disp('*************************************************************')
  disp('')
  disp('SELECT THE APPROPRIATE MENU ITEM')
  disp('')
  disp('MODIFY...')
  disp('                               PRESENT VALUES')
  fprintf('1) Controller Gain, Kc         %4.2f\n',kc)
  fprintf('2) Integral Time, TI           %4.2f\n',ti)
  fprintf('3) Derivative Time, TD         %4.2f\n',td)
  disp('4) Return to main menu')
  disp('')
        
  m3 = input('Enter the desired selection:   ');
  
  if isempty(m3), break, end       % go back to main menu if ENTER is pressed
      
  m3 = round(m3);
  if (m3<1) | (m3>4)
      disp('')
      disp('Not a valid selection')
      disp('')
      disp('Press ENTER to continue')
      pause;
  end    
  
  if m3 == 1
      junkkc = input('Enter value for controller gain:  ') ;
      if isempty(junkkc)
          junkkc = kc ;
      end
      kc = junkkc;

  elseif m3 == 2
      junkti = input('Enter value for integral time:  ') ;
      if isempty(junkti)
          junkti = ti ;
      end
      if junkti < 0
         junkti = ti;
         disp (' integral time can not be negative')
         disp (' press enter to continue')
         pause
      end
      ti = junkti;

  elseif m3 == 3
      junktd = input('Enter value for derivative time:  ') ;
      if isempty(junktd)
          junktd = td ;
      end
      if junktd < 0
         junktd = td;
         disp (' derivative time can not be negative')
         disp (' press enter to continue')
         pause
      end
      td = junktd;

  else
      break
  end        % if m3
  
end    % while 1 (line 10)
