% function uOpt = optCtrl(obj, ~, ~, deriv, uMode)
function uOpt = optCtrl(obj, ~, xs, deriv, uMode)
% uOpt = optCtrl(obj, t, y, deriv, uMode)
global u_optimal

%% Input processing
if nargin < 5
  uMode = 'min';
end

if ~iscell(deriv)
  deriv = num2cell(deriv);
end

% uOpt = cell(obj.nu, 1);

%% Optimal control
%if strcmp(uMode, 'max')
  %uOpt = (deriv{obj.dims==3}>=0)*obj.wRange(2) + (deriv{obj.dims==3}<0)*(obj.wRange(1));
%  for i = 1:2
%     if any(obj.dims == i)
%       uOpt{i} = (deriv{obj.dims==i}>=0)*obj.uRange{2}(i) + ...
%         (deriv{obj.dims==i}<0)*(obj.uRange{1}(i));
%     end
%  end
%elseif strcmp(uMode, 'min')
  %uOpt = (deriv{obj.dims==3}>=0)*(obj.wRange(1)) + (deriv{obj.dims==3}<0)*obj.wRange(2);
%else
%  error('Unknown uMode!')
%end
uOpt = u_optimal;

end