-
Notifications
You must be signed in to change notification settings - Fork 1
/
pidthread.h
41 lines (33 loc) · 958 Bytes
/
pidthread.h
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
#ifndef PIDTHREAD_H
#define PIDTHREAD_H
#include <QThread>
#define RND(x) ((int)(x>0?x+0.5:x-0.5))
class PIDThread : public QThread
{
Q_OBJECT
public:
PIDThread();
protected:
void run();
public slots:
void setTargetPosition(int target) { targetPosition = target; }
void setCurrentPosition(int pos) // act as a feedback
{
currentPosition = pos / 10.0;
}
void setPIDParameters(double p, double i, double d);
void clearData();
signals:
void updatePosition(int pos); // tell the gui to move the slider
private:
long targetPosition;
double currentPosition;
double proportion, integral, derivative; // pid coefficients
double error_this_time, error_last_time; // the most recent 2 errors (between target and current value)
double error_integral; // accumulated error
int finalStateCount;
private:
double calculateSpeed();
bool checkEnd(double speed);
};
#endif // PIDTHREAD_H