forked from murmlgrmpf/Arduheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cMixer.h
80 lines (65 loc) · 1.3 KB
/
cMixer.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef cMixer_h
#define cMixer_h
#include "Arduino.h"
#include "cLFPWM.h"
#include <PID_v1.h>
class cMixer : public PID
{
public:
/// Creates the mixer
cMixer(int pinOpen_, int pinClose_,double p, double i, double d, int mode):
PWM(20000),
PID(&Is, &Power, &Setpoint, p, i, d, mode)
{
pinOpen = pinOpen_;
pinMode(pinOpen, OUTPUT);
pinClose = pinClose_;
pinMode(pinClose, OUTPUT);
Is = 0;
Power = 0;
Setpoint = 0;
}
/// Set the power in percent
/** Drives the mixer with a certain power (abs) into a direction (sign: open or close)
\param Power the desired power in percent */
void run(double Power_)
{
Power = Power_;
SetMode(MANUAL);
Compute();
run();
}
double run(double Setpoint_, double Is_)
{
Is = Is_;
Setpoint = Setpoint_;
SetMode(AUTOMATIC);
Compute();
run();
return Power;
}
double get(void){return Power;}
private:
cLFPWM PWM;
int pinOpen;
int pinClose;
double Is;
double Setpoint;
double Power;
void run()
{
boolean direction = (Power>=0);
// Check PWM and hysteresis
if(PWM.get(abs(Power))&&(abs(Power)> 0.05)) {
// Drive in direction
digitalWrite(pinClose, direction);
digitalWrite(pinOpen, !direction);
}
else {
// Stop
digitalWrite(pinClose, HIGH);
digitalWrite(pinOpen, HIGH);
}
}
};
#endif