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