-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathsaturateInput.m
46 lines (36 loc) · 1.12 KB
/
saturateInput.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function y = saturateInput(u, umin, umax)
% SATURATEINPUT saturates the input value.
%
% FORMAT: y = saturateInput(u, umin, umax)
%
% INPUT: - umin = [n * 1] min values;
% - umax = [n * 1] max values;
% - u = [n * 1] current values;
%
% OUTPUT: - y = [n * 1] saturated values;
%
% Author(s): Gabriele Nava
%
% all authors are with the Italian Istitute of Technology (IIT)
% email: [email protected]
%
% Genoa, Jul 2020
%
%% --- Initialization ---
assert(isequal(size(umin), size(umax)), 'umin and umax must be same size')
if length(umin) == 1
y = u;
y(y > umax) = umax;
y(y < umin) = umin;
else
assert(length(umin) == length(u), 'input and saturation must have same size');
y = u;
for i = 1:length(umin)
if y(i) > umax(i)
y(i) = umax(i);
elseif y(i) < umin(i)
y(i) = umin(i);
end
end
end
end