-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path40_Pid_Algorithm.cpp
36 lines (29 loc) · 1.15 KB
/
40_Pid_Algorithm.cpp
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
#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
// PID(Proportional, Integral, Derivative) ;
// PID aslında bir kontrol geri bildirim mekanizmasıdır.
// Bir PID denetleyici ölçülü bir süreç içinde değişen ve istenilen ayar noktası ile arasındaki farkı olarak bir “hata” değerini hesaplar.
// Kontrol giriş ayarı yapılarak bu hata en aza indirilmesi sağlanır.
int track = 500; // track value default 500
int integrl = 0, lasterror = 0;
float pidvalue = 0.0;
float kp = 0.5, ki = 0, kd = 0.3; // kp -> Prooprtional katsayi, ki -> inegral katsayi ..
void trackfunc(int, void*)
{
int error = 500 - track; // 500 referans deger olarak alinir ve 500 ustunde veya altinda olmasi hata degeri olusturur
integrl += error; // integral degeri, referans noktasindan olan toplam uzakliktir.
lasterror = error;
pidvalue = kp * error + ki * integrl + kd * (error - lasterror);
cout << pidvalue <<endl;
}
int main()
{
namedWindow("Trackbar", WINDOW_AUTOSIZE);
createTrackbar("Vlue", "Trackbar", &track, 1000, trackfunc);
waitKey(0);
return 0;
}