INOS
cinostempcontroller.h
Go to the documentation of this file.
1//******************************************************************************
25//******************************************************************************
26
27#ifndef INC_CINOSTEMPCONTROL_H
28#define INC_CINOSTEMPCONTROL_H
29
30//------------------------------------------------------------------------------
31// defines
32//------------------------------------------------------------------------------
33//
34#define DF_INOS_TEMP_CONTROLLER_NAME "CINOSTempController" // controller name
35//
36#define DF_INOS_TEMP_PID_FLAG_ACTIVE 0x00000001 // pid set is active
37
38// anti-windup methods
39#define DF_INOS_TEMP_AWM_BACKCALCULATION 0 // back-calculation (currently not implemented)
40#define DF_INOS_TEMP_AWM_CLAMPING 1 // clamping
41#define DF_INOS_TEMP_AWM_SATURATION 2 // saturation
42#define DF_INOS_TEMP_AWM_NONE 3 // none
43
44//
45// --- controller errors -------------------------------------------------------
46//
48#define ER_INOS_TEMP_CONTROLLER_BREAK 0x00010000 // sensor break
50#define ER_INOS_TEMP_CONTROLLER_SHORT_CIRCUIT 0x00020000 // sensor short circuit
52#define ER_INOS_TEMP_CONTROLLER_ALARM 0x00040000 // alarm temp reached
54#define ER_INOS_TEMP_CONTROLLER_OUT_FAILURE 0x00080000 // output failure
56#define ER_INOS_TEMP_CONTROLLER_DELTA 0x00100000 // max. temp delta
58#define ER_INOS_TEMP_CONTROLLER_OUTPWM_SYNC 0x00200000 // outpwm sync does not toggle
60#define ER_INOS_TEMP_CONTROLLER_LIMIT 0x00400000 // temperature limit reported
61//
62// --- controller warnings -----------------------------------------------------
63//
64#define WR_INOS_TEMP_CONTROLLER_LOW_TEMP 0x00010000 // temperature too low
65#define WR_INOS_TEMP_CONTROLLER_HIGH_TEMP 0x00020000 // temperature too high
66//
67// --- tuning ------------------------------------------------------------------
68
69// flags
70//
71#define DF_INOS_TEMP_TUNE_FLAG_ACCEPT "Accept" // tuning flag autoaccept
72//
73// types
74//
75#define DF_INOS_TEMP_TUNE_TYPE_HCP "Type=Hcp" // tuning type 'hcp'
76#define DF_INOS_TEMP_TUNE_TYPE_PID "Type=Pid" // tuning type 'pid'
77#define DF_INOS_TEMP_TUNE_TYPE_FFS "Type=ffS" // tuning type 'ffS'
78#define DF_INOS_TEMP_TUNE_TYPE_BLZ "Type=Blz" // tuning type 'Blz'
79//
80// tune type hcp
81//
82#define DF_INOS_TEMP_TUNE_STATE_HCP_POWER_SET 0 // set output
83#define DF_INOS_TEMP_TUNE_STATE_HCP_POWER_WAIT 1 // wait time
84#define DF_INOS_TEMP_TUNE_STATE_HCP_SYSTEM_WAIT 2 // wait for system
85#define DF_INOS_TEMP_TUNE_STATE_HCP_WAIT_MAX 3 // wait for max
86//
87// tune type pid
88//
89#define DF_INOS_TEMP_TUNE_STATE_PID_STEP_POWER_SET 10 // set output
90#define DF_INOS_TEMP_TUNE_STATE_PID_STEP_POWER_WAIT 11 // wait time
91#define DF_INOS_TEMP_TUNE_STATE_PID_STEP_SYSTEM_WAIT 12 // wait pulse time
92#define DF_INOS_TEMP_TUNE_STATE_PID_STEP_WAIT_MAX 13 // wait for max
93//
94#define DF_INOS_TEMP_TUNE_STATE_PID_SWING_PULSE_SET 20 // set output
95#define DF_INOS_TEMP_TUNE_STATE_PID_SWING_PULSE_WAIT 21 // wait pulse time
96#define DF_INOS_TEMP_TUNE_STATE_PID_SWING_WAIT_MAX 22 // wait for max
97#define DF_INOS_TEMP_TUNE_STATE_PID_SWING_WAIT_MIN 23 // wait for min
98#define DF_INOS_TEMP_TUNE_STATE_PID_SWING_RELAX 24 // relax
99#define DF_INOS_TEMP_TUNE_STATE_PID_SWING_SETTLE 25 // settle
100//
101// tune type ffs
102//
103#define DF_INOS_TEMP_TUNE_STATE_FFS_WAIT 30 // wait 2 min
104//
105// tune type blz
106//
107#define DF_INOS_TEMP_TUNE_STATE_BLZ_WAIT 40 // wait 2 min
108//
109// pid range indices
110//
111#define DF_INOS_TEMP_PID_RANGE_LOW 0
112#define DF_INOS_TEMP_PID_RANGE_MEDIUM 1
113#define DF_INOS_TEMP_PID_RANGE_HIGH 2
114//
115//------------------------------------------------------------------------------
116// includes
117//------------------------------------------------------------------------------
118//
119// system
120#include <cinosbasecontroller.h>
121//
122// C++
123//
124// project
125//
126//------------------------------------------------------------------------------
127//--- structures ---------------------------------------------------------------
128//------------------------------------------------------------------------------
129//
131 //; structure of PID parameters
132{
133 real64 m_rKp;
134 real64 m_rKi;
135 real64 m_rKd;
136 real64 m_rTi;
137 real64 m_rTd;
138 real64 m_rAff;
139 real64 m_rVff;
140 real64 m_rBff;
141 real64 m_rSff;
142 real64 m_rSffoffset;
143 real64 m_rSignalFF;
144 uint32 m_uFlags;
145};
146//
148{
149 real64 m_rTime;
150 real64 m_rTemp;
151 real64 m_rOut;
152};
153//------------------------------------------------------------------------------
154// class definition
155//------------------------------------------------------------------------------
156//
158{
159 //--- user interface ---------------------------------------------------
160
161 // public member functions
162 public :
163
164 // constructor/destructor
165
166 CINOSTempController(const char* apInpName, const char* apOutName);
167 //; constructor
168 virtual ~CINOSTempController();
169 //; destructor
170 virtual void SetCycleTime(real64 arCycleTime) override;
171 //; set controller cycle time [sec]
172
173 virtual void Activate(bool abCheckVal = true, bool abSimulateVal = false,
174 bool abSimulateOut = false, bool abSimulateAct = false) override;
175 //; overwritten to handle m_bIgnoreAlarmTemp
176
177 // Tune
178
179 virtual uint32 Tune(const char* apParam) override;
180 //; tune controller
181 virtual uint32 TuneAccept(const char* apParam) override;
182 //; accept tune results
183
184 virtual CINCOObject* GetRegister() override;
185 //; do inco registration and return pointer to it
186
187 bool SetPidRunParamKp(uint32 auRangeIndex, real64 arKp);
188 bool SetPidRunParamKi(uint32 auRangeIndex, real64 arKi);
189 bool SetPidRunParamKd(uint32 auRangeIndex, real64 arKd);
190 //; set specific run PID parameter of given temperature range
191 virtual bool SetPidRunParam(uint32 auRangeIndex, uint32 auParamIndex, real64 arParamValue);
192 //; set generic run PID parameter of given temperature range
193
194 bool SetPidHaltParamKp(uint32 auRangeIndex, real64 arKp);
195 bool SetPidHaltParamKi(uint32 auRangeIndex, real64 arKi);
196 bool SetPidHaltParamKd(uint32 auRangeIndex, real64 arKd);
197 //; set specific run PID parameter of given temperature range
198 virtual bool SetPidHaltParam(uint32 auRangeIndex, uint32 auParamIndex, real64 arParamValue);
199 //; set generic run PID parameter of given temperature range
200
201 //--- internals --------------------------------------------------------
202
203 friend class CINCOTempCtrPar;
204 friend class CINCOTempBlzPar;
205
206 // protected member functions
207 protected:
208 virtual void Reset() override;
209 //; reset controller values (called whenever the controller is
210 //; switched on)
211 virtual void Jump(real64 arSrc, real64 arDst) override;
212 //; jump detected
213 virtual void StopJump() override;
214 //; stop controller jump
215 virtual void StopTune() override;
216 //; stop controller tune
217 virtual void PreControl() override;
218 //; called before control
219 virtual bool IsSettled(bool abAdjAllowed=false) override;
220 //; return true if settled
221 ICACHE virtual void Control() override;
222 //; do a control cycle
223 ICACHE void SetActPidSet();
224 //; set pointer to actual pid set
225 void CalcBoltzmann();
226 //; calc boltzmann internals
227 real64 GetBoltzmann(real64 arT);
228 //; calc boltzmann radiant power of temperature arT
229 real64 GetffS(real64 arT);
230 //; calc feed forward
231 void iFeedForward();
232 //; internal standard feed forward
233 void iControl();
234 //; internal standard control
235 void iJumpCalcPolynom();
236 //; calc polynom of 3rd degree
237 void iJumpPrepareForHalt();
238 //; prepare jump for halt
239 void iJumpFeedForward();
240 //; internal jump feed forward
241 void iJumpControl();
242 //; internal jump control
243 bool iTuning();
244 //; internal tuning method
245 bool iTuningWaitTime(real64 arTime);
246 //; internal tuning method
247 bool iTuningWaitTmax();
248 //; internal tuning method
249 bool iTuningWaitTmin();
250 //; internal tuning method
251 bool iTuningSupervision();
252 //; tuning supervision
253 bool iTuningCheckResult();
254 //; check tuning result
255 uint32 iTuningGetPidIndex();
256 //; internal tuning method
257 void SetPid(SPidTemp* apSet, uint32 auIndex, real64 arValue);
258 //; set pid value
259 virtual const char* GetStateText() override;
260 //; get pointer to actual state text
261
262 void iTuneAcceptHcp();
263 //; accept hcp tuning results
264 void iTuneAcceptPid(uint8 auSet);
265 //; accept pid tuning results
266 void iTuneAcceptffS();
267 //; accept ffS tuning results
268 void iTuneAcceptBlz();
269 //; accept Blz tuning results
270
271 // protected members
272 protected:
273 // controller flag mask
274 uint32 m_uFlagMask;
275
276 // pid parameter ranges
277 real64 m_rMedium;
278 //; begin of medium range (ends at begin of high range)
279 real64 m_rHigh;
280 //; begin of high range
281
282 // controller parameters (0-low, 1-medium, 2-high)
283 SPidTemp m_PidHalt[3];
284 //; pid parameters during halt and jump
285 SPidTemp m_PidRun[3];
286 //; pid parameters during ramping
287 SPidTemp m_PidTune;
288 //; pid parameters during tuning
289 SPidTemp* m_pActSet;
290 //; pointer to actual set
291 real64 m_rSint;
292 //; actual value integrator
293 real64 m_rSintMin;
294 //; min. allowed value integrator
295 real64 m_rSintMax;
296 //; max. allowed value integrator
297 uint16 m_uAwMethod;
298 //; anti-windup method
299 real64 m_rOutact_1;
300 //; actual output of the previous cycle, i.e. after actuator saturation is considered
301 real64 m_rOutlin;
302 //; output in the linear range (i.e. before actuator saturation is considered)
303 real64 m_rSerr_1;
304 //; error of the previous control cycle
305
306 // temperatures
307 real64 m_rTmin;
308 // min temperature
309 real64 m_rTmax;
310 // max temperature
311 real64 m_rTalarm;
312 // alarm temperature
313 real64 m_rTalarmHyst;
314 // alarm temperature hysteresis
315 bool m_bIgnoreAlarmTemp;
316 // whether the alarm temperature must be ignored undershoot since last
317 // activation. See also comments on
318 // DF_INOS_BASE_CONTROLLER_FLAG_IGN_ALM_ACT. Note that the
319 // hysteresis is also taken into account. Means that the
320 // temperature must be below (m_rTalarm-m_rTalarmHyst) until the
321 // alarm temperature will be checked.
322 real64 m_rTbreak;
323 // break temperature
324 real64 m_rThalt;
325 // halt temperature (if fabs(Scmd-Sact)<=thalt -> settle)
326
327 // output
328 real64 m_rOutSff;
329 // feed forward S
330 real64 m_rOutAff;
331 // feed forward A
332 real64 m_rOutVff;
333 // feed forward V
334 real64 m_rOutBlz;
335 // feed forward Boltzmann
336 real64 m_rOutTune;
337 // feed forward tuning
338
339 // Boltzmann compensation
340 real64 m_rBlzTmin;
341 //; min. temp
342 real64 m_rBlzTmax;
343 //; max. temp
344 real64 m_rBlzPmax;
345 //; power at Tmax
346 double m_dBlzTmin4;
347 //; min. temp ^ 4
348 double m_dBlzFactor;
349 //; d*e*A
350
351 real64 m_rHeatFactor;
352 //; measured 'm*c' [J/K]
353
354 real64 m_rOutDelta;
355 //; [°C] min. delta to be reached within outtimeout time
356 //; otherwise -> output failure
357 real64 m_rOutTimeout;
358 //; [ms] max. allowed time
359
360 // jump handling
361 uint16 m_uJmpType;
362 //; jumping type (0-forward, 1-backward)
363 uint16 m_uJmpStatePff;
364 //; jumping subsstate feed forward P
365 uint16 m_uJmpStateCtr;
366 //; jumping subsstate control
367 real64 m_rJmpTimer;
368 //; time since start of jump
369 real64 m_rJmpVmax;
370 //; max. V ever reached
371 real64 m_rJmpTp;
372 //; time base of polynom
373 real64 m_rJmpTpe;
374 //; Te part of polynom
375 real64 m_rJmpOut;
376 //; jump output
377 real64 m_rJmpTc;
378 //; time base of polynom
379 real64 m_rJmpTce;
380 //; Te part of polynom
381 real64 m_rJmpSe;
382 //; jump end
383 real64 m_rJmpA;
384 //; a part of polynom
385 real64 m_rJmpB;
386 //; b part of polynom
387 real64 m_rJmpC;
388 //; c part of polynom
389 real64 m_rJmpD;
390 //; d part of polynom
391
392 // tuning handling
393
394 bool m_bTuneAccept;
395 //; true if autoaccept requested
396 uint16 m_uTuneState;
397 //; actual tune state
398 uint16 m_uTunePid;
399 //; actual pid index to be tuned
400 real64 m_rTuneTimer;
401 //; tuning timer
402 real64 m_rTuneMin;
403 //; tuning min
404 real64 m_rTuneMax;
405 //; tuning max
406 real64 m_rTuneTemp;
407 //; tuning temp
408 real64 m_rTuneTime;
409 //; tuning time
410 real64 m_rTuneTimePoint;
411 //; tuning time of last point
412 real64 m_rTuneOut;
413 //; tuning out
414 real64 m_rTunePulseOut;
415 //; tuning pulse out
416 real64 m_rTunePulseTime;
417 //; tuning pulse time
418 real64 m_rTunePulseTimeout;
419 //; tuning pulse timeout
420 int32 m_iTunePulseStart;
421 //; pulse starting ticks
422 real64 m_rTuneWaveActTime;
423 //; tuning wave act time
424 real64 m_rTuneWaveMinTime;
425 //; tuning wave min time
426 real64 m_rTuneWaveMaxTime;
427 //; tuning wave max time
428 real64 m_rTuneWaveMinAmpl;
429 //; tuning wave min ampl
430 real64 m_rTuneWaveMaxAmpl;
431 //; tuning wave max ampl
432 real64 m_rTuneWaveMinPower;
433 //; tuning wave min power
434 real64 m_rTuneWaveMaxPower;
435 //; tuning wave max power
436 uint16 m_uTuneWaveMinCnt;
437 //; requested number of tuning waves
438 uint16 m_uTuneWaveReqCnt;
439 //; requested additional number of tuning waves
440 uint16 m_uTuneWaveCnt;
441 //; actual number of tuning waves
442 STunePoint m_TuneHigh[2];
443 //; tuning peak points
444 STunePoint m_TuneLow[2];
445 //; tuning low points
446 char m_cTuneState[16];
447 //; tuning state
448 char m_cTuneResultState[16];
449 //; tune result state
450 char m_cTuneParam[64];
451 //; tune params
452 uint16 m_uTuneCavg;
453 //; internal counter
454 real64 m_rTunePavg;
455 //; tuning P average
456 real64 m_rTuneTavg;
457 //; tuning T average
458 real64 m_rTuneHcpFactor;
459 //; calculated hcp factor
460 real64 m_rTuneffSoffset;
461 //; ffS offset
462 real64 m_rTuneffS;
463 //; ffS
464 real64 m_rTuneBlzTmin;
465 //; blz tmin
466 real64 m_rTuneBlzTmax;
467 //; blz tmax
468 real64 m_rTuneBlzPmax;
469 //; blz pmax
470 real64 m_rTuneVmax;
471 //; vmax
472 real64 m_rTuneVmaxTime;
473 //; time at vmax
474 real64 m_rTuneVmaxSact;
475 //; Sact at vmax
476
477 CINOSProcessImageChannel* m_pCmpChannel;
478 //; pointer to compensation element channel or nullptr
479 CINOSBit* m_pOutChannelBit;
481 class CINOSOutPwm* m_pOutPwm;
482 //; pointer to outpwm handler or nullptr
483 uint32 m_uOutPwmSyncCount{};
484 //; last sync count
485 int32 m_iOutPwmTicks{};
486 //; got pwm sync count at this 1ms ticks
487
488 // signal feed forward
489
490 inosName64 m_cSignalName;
491 //; signal name (analog input or analog output)
492 CINOSAdcChannel* m_pAdcSignal;
493 //; analog input
494 CINOSDacChannel* m_pDacSignal;
495 //; analog output
496
497 // external temperatur limit supervision
498
499 inosName64 m_cLimInput{};
500 //; name of external temperature limit supervision digital input
501 CINOSBit* m_pLimInput{};
502 //; digital input
503
504 // allow dynamic object handling (new/delete)
505 DECLARE_DYNAMIC_CACHE(CINOSTempController);
506};
507
508
509//------------------------------------------------------------------------------
510// end of file
511//------------------------------------------------------------------------------
512
513#endif // INC_CINOSTEMPCONTROLLER_H
Short comment.
Definition cinosadcchannel.h:53
Definition cinosbasecontroller.h:111
Definition cinosbit.h:54
Definition cinosdacchannel.h:52
Definition cinosprocessimagechannel.h:111
Definition cinostempcontroller.h:158
class CINOSOutPwm * m_pOutPwm
pointer to output channel if bit
Definition cinostempcontroller.h:481
Definition cinostempcontroller.h:132
Definition cinostempcontroller.h:148