-
Notifications
You must be signed in to change notification settings - Fork 1
/
PID_Controllor.m
38 lines (36 loc) · 906 Bytes
/
PID_Controllor.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
function [Control_Output,integral] = PID_Controllor(K_P,K_I,K_D,D_t,error,integral,previous_error,P_l,I_l,D_l)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
%Input:
% K_P,K_I,K_D, PID parameters
% D_t time
% error
% integral
% previous_error
% P_l,I_l,D_l PID output limit, set 0 to disable.
propostional = error * K_P;
integral = integral + K_I * error * D_t;
derivative = K_D * (error - previous_error) /D_t;
if P_l ~= 0
if propostional > P_l
propostional = P_l;
elseif propostional < -P_l
propostional = -P_l;
end
end
if I_l ~= 0
if integral > I_l
integral = I_l;
elseif integral < -I_l
integral = -I_l;
end
end
if D_l ~= 0
if derivative > D_l
derivative = D_l;
elseif derivative < -D_l
derivative = -D_l;
end
end
Control_Output = propostional+integral+derivative;
end