% function getdhpar.m
%

function [dh, dhrow] = getdhpar

dh = [];
dhrow = 0;
%whitebg('blue')

dhrow=menu('Select NUMBER OF LINKS/JOINTS','1','2','3','4','5','6');

for link = 1:dhrow
  fprintf('Enter parameters for link %1.0f\n',link);

  sigma = menu('Select TYPE OF JOINT','Revolute','Prismatic')-1;

  length = menu('Select LINK LENGTH','a = 0','a <> 0')-1;
  alpha = menu('Select LINK TWIST',...
          'alpha = -180','alpha =  -90','alpha =   0','alpha =  90','alpha = 180')-3;
  alpha = alpha*90;

  if sigma   % true means prismatic
     theta = menu('Select JOINT ANGLE',...
             'theta = -180','theta =  -90','theta =   0','theta =  90','theta = 180')-3;
     theta = theta*90;
     offset = 1;
  else       % joint is revolute
     offset = menu('Select LINK OFFSET','d = 0','d <> 0')-1;
     theta = 0;
  end

  dh(link,:) = [alpha length theta offset sigma];
end

%disp(['The number of links is ' dhrow])
disp('DH parameters are:')
disp('  alpha    a  theta    d    sigma')
disp(dh)

s = menu('Do you want to save DH parameters in a file?','Yes','No');

if s==1      % save the file
   [fname, pname] = uiputfile('*.dat','Save DH Parameters As..');
   eval(['save ' fname ' dh -ascii'])
   disp(['DH parameters saved in file ' fname])
end


