INOS
cinosbasecontroller.h
Go to the documentation of this file.
1//******************************************************************************
27//******************************************************************************
28
29#ifndef INC_CINOSBASECONTROLLER_H
30#define INC_CINOSBASECONTROLLER_H
31
32//------------------------------------------------------------------------------
33// defines
34//------------------------------------------------------------------------------
35//
36// --- controller states -------------------------------------------------------
37//
38#define DF_INOS_CONTROLLER_STATE_PEACE 0 // peace
39#define DF_INOS_CONTROLLER_STATE_ACTIVATING 1 // activating
40#define DF_INOS_CONTROLLER_STATE_ACTIVE 2 // active
41#define DF_INOS_CONTROLLER_STATE_INACTIVATING 3 // inactivating
42#define DF_INOS_CONTROLLER_STATE_TUNING 4 // tuning
43#define DF_INOS_CONTROLLER_STATE_STOPPING 5 // stopping
44//
45// --- controller sub states ---------------------------------------------------
46//
47// sub states for state ACTIVE
48#define DF_INOS_CONTROLLER_SUBSTATE_ACTIVE_HALT 0 // active halt
49#define DF_INOS_CONTROLLER_SUBSTATE_ACTIVE_RUN 1 // active run
50#define DF_INOS_CONTROLLER_SUBSTATE_ACTIVE_JUMP 2 // active jump
51#define DF_INOS_CONTROLLER_SUBSTATE_ACTIVE_SETTLE 3 // active settle
52//
53// --- controller errors -------------------------------------------------------
54//
55#define ER_INOS_CONTROLLER_VALCHK 0x00000001 // controller value check error
56#define ER_INOS_CONTROLLER_SETTLE 0x00000002 // settling timeout
57#define ER_INOS_CONTROLLER_OUTCHN 0x00000800 // output channel not found
58#define ER_INOS_CONTROLLER_INPCHN 0x00001000 // input channel not found
59#define ER_INOS_CONTROLLER_ACTIVATE 0x00002000 // activation error
60#define ER_INOS_CONTROLLER_EXTERN 0x00004000 // external controller error
61#define ER_INOS_CONTROLLER_OFFLINE 0x00008000 // value channel offline
62//
63// --- controller warnings -----------------------------------------------------
64//
65#define WR_INOS_CONTROLLER_INTLIMIT 0x00000001 // integrator limit reached
66#define WR_INOS_CONTROLLER_NOTSUP 0x00000002 // not supported
67//
68// --- controller flags --------------------------------------------------------
69//
70#define DF_INOS_BASE_CONTROLLER_FLAG_CHK_VAL 0x00000001 // check value error
71#define DF_INOS_BASE_CONTROLLER_FLAG_SIM_VAL 0x00000002 // simulate actual value
72#define DF_INOS_BASE_CONTROLLER_FLAG_SIM_OUT 0x00000004 // simulate output
73#define DF_INOS_BASE_CONTROLLER_FLAG_SIM_ACT 0x00000008 // simulate activate
74#define DF_INOS_BASE_CONTROLLER_FLAG_ENB_BLZ 0x00000010 // enable boltzmann feed forward
82#define DF_INOS_BASE_CONTROLLER_FLAG_IGN_ALM_ACT 0x00000020
85#define DF_INOS_BASE_CONTROLLER_FLAG_ZERO_INT_JUMP 0x00000040
86#define DF_INOS_BASE_CONTROLLER_FLAG_KEEP_CMDS 0x20000000 // keep cmdS at activate
87#define DF_INOS_BASE_CONTROLLER_FLAG_SUP_JFW 0x40000000 // supports jump forward
88#define DF_INOS_BASE_CONTROLLER_FLAG_SUP_JBW 0x80000000 // supports jump backward
89//
90#define DF_INOS_BASE_CONTROLLER_MAX_V_FILTER 16 // max. allowed V filter length
91//
92//------------------------------------------------------------------------------
93// includes
94//------------------------------------------------------------------------------
95//
96// system
97#include <cinosprocessimage.h>
98#include <inco_com.h>
99//
100// C++
101//
102// project
103//
104//------------------------------------------------------------------------------
105// class definition
106//------------------------------------------------------------------------------
107//
108struct SINOSRampData;
109class CINOSControl;
111{
112 //--- user interface ---------------------------------------------------
113
114 // public member functions
115 public :
116
117 // constructor/destructor
118
119 CINOSBaseController(const char* apInpName, const char* apOutName);
120 //; constructor
121 virtual ~CINOSBaseController();
122 //; destructor
123 static CINOSBaseController* GetController(const char* apType,
124 const char* apInpName, const char* apOutName);
125 //; create controller of type 'apType' return pointer to it or NULL
126 //; if 'apType' not available
127
128 // activate / inactivate
129
130 virtual void Activate(bool abCheckVal = true, bool abSimulateVal = false,
131 bool abSimulateOut = false, bool abSimulateAct = false);
132 //; activate controller
133 virtual void InActivate();
134 //; inactivate controller
135
136 // Tune
137
138 virtual uint32 Tune(const char* apParam);
139 //; tune controller
140 virtual uint32 TuneAccept(const char* apParam);
141 //; accept tune results
142
143 // pull
144
145 ICACHE virtual uint32 Pull(SINOSRampData* apData);
146 //; follow apData
147 ICACHE virtual uint32 Pull(real64 arValue, real64 arVelocity,
148 real64 arAcceleration, real64 arJerk);
149 //; follow arValue with arVelocity and arAcceleration
150
151 virtual void GetCmdValue(real64& arValue);
152 //; get commanded value
153 virtual void GetCmdVelocity(real64& arVelocity);
154 //; get commanded velocity
155 virtual void GetCmdAcceleration(real64& arAcceleration);
156 //; get commanded acceleration
157 virtual void GetCmdJerk(real64& arJerk);
158 //; get commanded jerk
159 ICACHE virtual void SetActValue(real64 arValue, bool abIgnorePosError=false);
160 //; set actual value to arValue
161 ICACHE virtual void GetActValue(real64& arValue);
162 //; get value
163 virtual void GetActVelocity(real64& arVelocity);
164 //; get actual velocity
165 virtual void GetActAcceleration(real64& arAcceleration);
166 //; get actual acceleration
167 virtual void GetActJerk(real64& arJerk);
168 //; get actual jerk
169 virtual void GetActValError(real64& arValError);
170 //; get actual value error
171
172 virtual uint32 GetParam(const char* apName, real64& arResult);
173 //; universal get parameter with apName to arResult and return error code
174 virtual volatile real64* GetParamAdr(const char* apName);
175 //; universal get address of parameter with aName or NULL if not found
176 virtual uint32 SetParam(const char* apName, real64 arValue);
177 //; universal set parameter with apName to arValue and return error code
178
179 void SetFlag(uint32 auFlag)
180 { INOS_OR(m_uFlag, auFlag);};
181 //; set controller flags
182 void ClrFlag(uint32 auFlag)
183 { INOS_AND(m_uFlag, ~auFlag);};
184 //; clear controller flags
185 uint32 GetFlag()
186 { return m_uFlag;};
187 //; get controller flags
188 ICACHE virtual uint32 GetState();
189 //; get controller state
190 ICACHE virtual uint32 GetState(uint32& auSubState);
191 //; get controller state and sub state
192 virtual uint32 SetError(uint32 auError);
193 //; set controller error and return old ones
194 ICACHE virtual uint32 GetError(bool abResolveExternal = false);
195 //; get controller error
196 virtual uint32 GetWarning();
197 //; get controller warning
198 virtual void AcceptError(uint32 auError=0xffffffff);
199 //; accept controller error (auError=0xffffffff -> accept all errors)
200 virtual void AcceptWarning(uint32 auWarning=0xffffffff);
201 //; accept controller warning (auWarning=0xffffffff -> accept all warnings)
202
203 virtual void GetCycleTime(real64& arCycleTime);
204 //; get controller cycle time [sec]
205 virtual void SetCycleTime(real64 arCycleTime);
206 //; set controller cycle time [sec]
207 virtual uint16 GetCycleNumber();
208 //; get controller cycle number
209 virtual uint16 GetCycleId();
210 //; get controller cycle id
211 virtual uint8 GetBusId();
212 //; get controller bus id
213
214 virtual const char* GetUnit()
215 { return m_cUnit; };
216 //; get ramping base unit (e.g. mm, deg, ...)
217 virtual uint32 GetCharacteristics()
218 { return m_uCharacteristics; };
219 //; get ramping base unit inco characteristics
220 virtual uint8 GetTypeChar() {return m_uTypeChar;};
221 //; get type character, e.g. 'T' for temperature ramp
222 virtual void SetParent(CINOSControl* apParent)
223 { m_pParent = apParent;};
224 //; set pointer to my parent controller
225 virtual const char* GetType() {return m_pType;};
226 //; get type string
227
228 virtual CINCOObject* GetRegister();
229 //; do inco registration and return pointer to it
230
231 virtual bool OnEmergency()
232 { return (m_uError & m_uErrorDis) != 0;};
233
234 virtual CINOSProcessImageChannel* GetInput() { return m_pInpChannel;};
235 virtual CINOSProcessImageChannel* GetOutput() { return m_pOutChannel;};
236
237 //--- internals --------------------------------------------------------
238
239 friend class CINCOpidDelayToHalt;
240 friend class CINOSControl;
241 friend class CINOSRemoteControlWorker;
242
243 // protected member functions
244 protected:
245 virtual void Reset();
246 //; reset controller values (called whenever the controller is
247 //; switched on)
248 virtual void StopJump();
249 //; stop controller jump
250 virtual void StopTune();
251 //; stop controller tune
252 virtual void Jump(real64 arSrc, real64 arDst){};
253 //; jump detected
254 virtual void PreControl(){};
255 //; called before control
256 virtual void Control();
257 //; do a control cycle
258 virtual void SetOutput(real64 arOutput);
259 //; set output
260 virtual void CalcError();
261 //; calc actual Serr and Verr
262 virtual bool IsSettled(bool abAdjAllowed=false)
263 { return true;};
264 //; return true if settled
265
270
271 // public member methods but just for internal use
272 public :
273 virtual const char* GetStateText();
274 //; get pointer to actual state text
275
276 // protected members
277 protected:
278 uint32 m_uState;
279 //; actual state
280 uint32 m_uSubState;
281 //; actual sub state
282 uint32 m_uError;
283 //; actual errors
284 uint32 m_uErrorMask;
285 //; errors to be masked out
286 uint32 m_uErrorDis;
287 //; errors which disable the cotroller
288 uint32 m_uMaskFatal;
289 //; mask of fatal errors
290 uint32 m_uWarning;
291 //; actual warnings
292 uint32 m_uWarningMask;
293 //; warnings to be masked out
294 uint32 m_uFlag;
295 //; actual flags
296 uint32 m_uLiveCount;
297 //; actual flags
298 bool m_bStartup;
299 //; startup flag
300 CINOSControl* m_pParent;
301 //; pointer to parent controller
302
303 // pointers
304 CINCOObject* m_pRegister;
305 //; pointer to inco registration
306 CINCOObject* m_pError;
307 //; pointer to inco registration of errors
308 CINCOObject* m_pErrorMask;
309 //; pointer to inco registration of error mask
310 CINCOObject* m_pErrorDis;
311 //; pointer to inco registration of disabling errors
312 CINCOObject* m_pWarning;
313 //; pointer to inco registration of warnings
314 CINCOObject* m_pWarningMask;
315 //; pointer to inco registration of warning mask
316 CINCOObject* m_pFlag;
317 //; pointer to inco registration of flags
318 CINCOObject* m_pCmd;
319 //; pointer to inco registration of commanded values
320 CINCOObject* m_pAct;
321 //; pointer to inco registration of actual values
322 CINCOObject* m_pErr;
323 //; pointer to inco registration of error values
324 CINCOObject* m_pMax;
325 //; pointer to inco registration of max values (obsolete)
326 CINCOObject* m_pProp;
327 //; pointer to inco registration of controller properties
328 CINOSProcessImageChannel* m_pInpChannel;
329 //; pointer to according input channel
330 CINOSProcessImageChannel* m_pOutChannel;
331 //; pointer to according output channel
332 const char* m_pType;
333 //; controller type
334 uint8 m_uTypeChar;
335 //; type character, e.g. 'T' for temperature
336 inosName m_cUnit;
337 //; controller unit
339 inosName64 m_cInpChannel;
341 inosName64 m_cOutChannel;
342
343 // cycle time
344
345 real64 m_rCycleTime;
346 //; cycle time in s
347 real64 m_rCycleTime_1;
348 //; 1 / CYCLETIME
349 real64 m_rCycleTimeMs;
350 //; cycle time in ms
351 real64 m_rDelayToHalt;
352 //; delay [ms] before switching from run to halt parameters
353 real64 m_rActivateTimeout;
354 //; activation timeout {ms]
355 int32 m_iActivateStart;
356 //; activation starting ticks
357
358 // settling
359 real64 m_rSettleTime;
360 //; requested settling time
361 real64 m_rSettleTimeout;
362 //; max. allowed settling time
363 int32 m_iSettleStart;
364 //; settling starting ticks
365
366 // commanded values
367
368 real64 m_rScmd;
369 //; commanded position
370 real64 m_rVcmd;
371 //; commanded velocity
372 real64 m_rAcmd;
373 //; commanded acceleration
374 real64 m_rJcmd;
375 //; commanded jerk
376
377 // actual values
378
379 real64 m_rSact;
380 //; actual position
381 real64 m_rVact;
382 //; actual velocity
383 uint32 m_uVactLength;
384 //; act v filter length
385 uint32 m_uVactIndex;
386 //; act v calc index
387 real64 m_rVactSum;
388 //; actual velocity
389 real64 m_rVactRaw[DF_INOS_BASE_CONTROLLER_MAX_V_FILTER];
390 //; actual raw velocity
391 real64 m_rAact;
392 //; actual acceleration
393 real64 m_rJact;
394 //; actual jerk
395 real64 m_rOutact;
396 //; actual output
397 real64 m_rOutmin;
398 //; minimal output
399 real64 m_rOutmax;
400 //; maximal output
401 real64 m_rOutfct;
402 //; output factor
403 real64 m_rSstart;
404 //; position at start of jump/run
405
406 // error values
407
408 real64 m_rSerr;
409 //; actual position error
410 real64 m_rVerr;
411 //; actual velocity error
412 real64 m_rSmax;
413 //; max. allowed position error in state 'halt'
414 real64 m_rSmaxRun;
415 //; max. allowed position error in state 'run'
416 real64 m_rSerrMax;
417 //; max. reached position error
418 real64 m_rSerrMin;
419 //; min. reached position error
420
421 // factors
422
423 uint32 m_uCharacteristics;
424 //; inco registration characteristics
425 uint32 m_uDelayToHalt;
426 //; delay [ticks] before switching from run to halt parameters
427 int32 m_iDelayToHalt;
428 //; actual delay [ticks]
429
430 // allow dynamic object handling (new/delete)
432};
433
434
435//------------------------------------------------------------------------------
436// class registration
437//------------------------------------------------------------------------------
438
439typedef CINOSBaseController *(*TCreateController)(const char*, const char*);
440
442{
443 // after this function you can register new controllers
444 friend void _INI_0000_CINOSBaseController();
445
446 //--- internals --------------------------------------------------------
447
448 // private members
449private:
450 // pointer to the first registered controller
451 static CINOSRegisterBaseController* m_pFirst;
452 // pointer to the next controller
454 // create function for the controller
455 TCreateController m_pCreate;
456 // controller type name
457 const char* m_pType;
458
459 //--- user interface ---------------------------------------------------
460
461public:
462 // register a new controller type
463 CINOSRegisterBaseController(TCreateController apFunction,
464 const char* apType);
465
466 // create and return and new controller instance
467 static CINOSBaseController* GetController(const char* apType,
468 const char* apInpName, const char* apOutName);
469};
470
471//------------------------------------------------------------------------------
472// end of file
473//------------------------------------------------------------------------------
474
475#endif // INC_CINOSBASECONTROLLER_H
#define DECLARE_DYNAMIC(aClass)
Definition cinospartitionmemory.h:328
Short comment.
Definition cinosbasecontroller.h:111
void GetOutChannel()
get pointer to output channel
void GetInpChannel()
get pointer to input channel
inosName64 m_cOutChannel
name of output channel
Definition cinosbasecontroller.h:341
inosName64 m_cInpChannel
name of input channel
Definition cinosbasecontroller.h:339
Definition cinoscontrol.h:164
Definition cinosprocessimagechannel.h:111
Definition cinosbasecontroller.h:442
#define INOS_OR(variable, mask)
Definition inosmacro.h:201
#define INOS_AND(variable, mask)
Definition inosmacro.h:210
ramp data
Definition cinosbaseramp.h:602