Critical Link MityCam SoC Firmware  1.0
Critical Link MityCam SoC Firmware
PIDControl.h
Go to the documentation of this file.
1 #ifndef PIDCONTROL_H_
2 #define PIDCONTROL_H_
3 
4 #include <time.h>
5 #include <signal.h>
6 
7 #include "libdaq/mcp4725.h"
8 #include "libdaq/gpio.h"
9 
10 
11 #include "Sensors/SensorBoard.h"
12 
13 //#define DEFAULT_P (0.89f)
14 //#define DEFAULT_I (0.005f)
15 //#define DEFAULT_D (0.31f)
16 
17 #define DEFAULT_P (0.78f)
18 #define DEFAULT_I (0.025f)
19 #define DEFAULT_D (0.0006f)
20 
21 #define MAX_TEC_CURRENT (1500)
22 
23 namespace SocCamera {
27 class tcPIDControl {
28 public:
34  tcPIDControl(int anBus, int anAddr, SocCamera::tcSensorBoard *apSensorBoard, int cool_heat_gpio, int break_gpio=-1);
35  virtual ~tcPIDControl();
36 
43  bool initialize(int anMaxTECCurrentMA = 1500);
44 
48  void setPID(float anP = DEFAULT_P, float anI = DEFAULT_I, float anD = DEFAULT_D);
49 
53  void getPID(float &arP, float &arI, float &arD);
54 
59  void setEnable(bool abEnable, int anIntervalMilliseconds = 1000);
60 
65  void setTarget(float anTempC);
66 
71  float getTarget();
72 
77  bool getEnabled();
78 
84  float getDutyCycle();
85 
90  float getDacVolts();
94  void step();
95 
96 private:
97  static void timerExpired(union sigval auSig);
98 
102  void readTECState();
103 
107  void writeTECState();
108 
109  enum teHeatCoolMode { eeCooling, eeHeating } ;
110 
111  void setHeatCoolMode(teHeatCoolMode aeControlMode);
112  // internal constants
113  static const int gnTempChangePerMin = 5;
114 
115  float mnLastDelta;
116  float mnPrevDelta;
117  float mnP;
118  float mnI;
119  float mnD;
120  float mnSetpoint;
121  int mnMaxTECCurrentMA;
122  bool mbTargetSet;
123  float mnTargetTemp;
124  int mnHeatCheckCount;
125 
126  float mnCurrTemp;
127  float mnDuty;
128  float mnUpdateIntervalMilliseconds;
129 
130  int mnCnt;
131 
132  SocCamera::tcSensorBoard *mpSensorBoard;
133 
134  MityDSP::tcMCP4725 mcDac;
135 
136  struct sigevent msSigevent;
137  timer_t mhTimerId;
138  struct itimerspec msTimerInterval;
139 
140  bool mbEnabled;
141  int mnCoolGpio;
142  int mnBreakGpio;
143  teHeatCoolMode meControlMode;
144  MityDSP::tcGpio* mpHeatCoolGPIO;
145 };
146 } // namespace SocCamera
147 #endif /* PIDCONTROL_H_ */
SocCamera::tcPIDControl::getPID
void getPID(float &arP, float &arI, float &arD)
Definition: PIDControl.cpp:292
SocCamera::tcPIDControl::getDutyCycle
float getDutyCycle()
Definition: PIDControl.cpp:299
DEFAULT_P
#define DEFAULT_P
Definition: PIDControl.h:17
SensorBoard.h
SocCamera::tcPIDControl
Definition: PIDControl.h:27
SocCamera::tcPIDControl::tcPIDControl
tcPIDControl(int anBus, int anAddr, SocCamera::tcSensorBoard *apSensorBoard, int cool_heat_gpio, int break_gpio=-1)
Definition: PIDControl.cpp:27
SocCamera::tcPIDControl::getEnabled
bool getEnabled()
Definition: PIDControl.cpp:309
SocCamera::tcPIDControl::setTarget
void setTarget(float anTempC)
Definition: PIDControl.cpp:155
SocCamera::tcPIDControl::~tcPIDControl
virtual ~tcPIDControl()
Definition: PIDControl.cpp:73
SocCamera::tcPIDControl::initialize
bool initialize(int anMaxTECCurrentMA=1500)
Definition: PIDControl.cpp:77
SocCamera::tcPIDControl::setEnable
void setEnable(bool abEnable, int anIntervalMilliseconds=1000)
Definition: PIDControl.cpp:127
SocCamera
Definition: CameraTypes.h:7
SocCamera::tcPIDControl::setPID
void setPID(float anP=DEFAULT_P, float anI=DEFAULT_I, float anD=DEFAULT_D)
Definition: PIDControl.cpp:113
SocCamera::tcPIDControl::getTarget
float getTarget()
Definition: PIDControl.cpp:304
DEFAULT_I
#define DEFAULT_I
Definition: PIDControl.h:18
SocCamera::tcSensorBoard
Definition: SensorBoard.h:40
DEFAULT_D
#define DEFAULT_D
Definition: PIDControl.h:19
SocCamera::tcPIDControl::getDacVolts
float getDacVolts()
returns the current DAC voltage
Definition: PIDControl.cpp:356
SocCamera::tcPIDControl::step
void step()
Definition: PIDControl.cpp:161