summaryrefslogtreecommitdiffhomepage
path: root/digital/asserv/models/limit_current.m
blob: e3d3d790d962f52ccd98a334a953358aedc27d88 (plain)
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
% Limit current.
motor;

%global to_file = 1;

function u = onoff (t)
    global sys;
    if (t < 1)
	u = sys.control.u;
    else
	u = 0;
    end
end

function u = limit_current (t, x)
    global sys;
    u = onoff (t);
    % Limit current by knowing the current speed and the motor terminal
    % resistance.
    umax = sys.control.current * sys.motor.R + x(2) / sys.motor.Kw;
    umin = - sys.control.current * sys.motor.R + x(2) / sys.motor.Kw;
    % Uncomment this if the maximum current can be overshooted when braking:
    %umax = max ([umax, 0]);
    %umin = min ([umin, 0]);
    u = min ([u, umax]);
    u = max ([u, umin]);
end

global sys;
sys.motor = re40g;
sys.gear = gear4x;
sys.load = robot10w80;
sys.load.J /= 2; % Two motors.
sys.control.func = "limit_current";
sys.control.current = 20;
sys.control.u = sys.motor.u;

plotterm ("limit");
sys_plot (2);

sys.control.func = "onoff";

plotterm ("nolimit");
sys_plot (2);