![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
dsf
Dependencies: BLE_API mbed nRF51822
ControllerFactory.cpp@0:b5906c81772b, 2017-02-05 (annotated)
- Committer:
- stoicancristi
- Date:
- Sun Feb 05 16:31:58 2017 +0000
- Revision:
- 0:b5906c81772b
BLE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stoicancristi | 0:b5906c81772b | 1 | |
stoicancristi | 0:b5906c81772b | 2 | #include "ControllerFactory.hpp" |
stoicancristi | 0:b5906c81772b | 3 | |
stoicancristi | 0:b5906c81772b | 4 | |
stoicancristi | 0:b5906c81772b | 5 | void ControllerFactory::createController (Controller *c, SysObjTypes &ctrlType) { |
stoicancristi | 0:b5906c81772b | 6 | |
stoicancristi | 0:b5906c81772b | 7 | switch (ctrlType) { |
stoicancristi | 0:b5906c81772b | 8 | case P: //fall-through |
stoicancristi | 0:b5906c81772b | 9 | case PI: |
stoicancristi | 0:b5906c81772b | 10 | case PID: { |
stoicancristi | 0:b5906c81772b | 11 | c = new PIDController(); |
stoicancristi | 0:b5906c81772b | 12 | break; |
stoicancristi | 0:b5906c81772b | 13 | } |
stoicancristi | 0:b5906c81772b | 14 | case RST: { |
stoicancristi | 0:b5906c81772b | 15 | //c = new RST::RST(); |
stoicancristi | 0:b5906c81772b | 16 | break; |
stoicancristi | 0:b5906c81772b | 17 | } |
stoicancristi | 0:b5906c81772b | 18 | default: c = 0; |
stoicancristi | 0:b5906c81772b | 19 | } |
stoicancristi | 0:b5906c81772b | 20 | } |
stoicancristi | 0:b5906c81772b | 21 | |
stoicancristi | 0:b5906c81772b | 22 | void ControllerFactory::createControllerParams (ControllerParams &cp, SysObjTypes &ctrlType, float *paramsList, int paramsListLen) { |
stoicancristi | 0:b5906c81772b | 23 | /* |
stoicancristi | 0:b5906c81772b | 24 | paramsList form: { |
stoicancristi | 0:b5906c81772b | 25 | P: [kp] |
stoicancristi | 0:b5906c81772b | 26 | PI: [kp, ti] |
stoicancristi | 0:b5906c81772b | 27 | PID: [kp, ti, td] |
stoicancristi | 0:b5906c81772b | 28 | RST: [nR,r0,r1,...,r_nR,nS,s0,s1,...,s_nS,nT,t0,t1,...,t_nT] |
stoicancristi | 0:b5906c81772b | 29 | } |
stoicancristi | 0:b5906c81772b | 30 | cond: paramsListLen = nR + nS + nT + 6 |
stoicancristi | 0:b5906c81772b | 31 | */ |
stoicancristi | 0:b5906c81772b | 32 | switch (ctrlType) { |
stoicancristi | 0:b5906c81772b | 33 | case P: { |
stoicancristi | 0:b5906c81772b | 34 | cp.kp = *paramsList; |
stoicancristi | 0:b5906c81772b | 35 | cp.ti = 0; |
stoicancristi | 0:b5906c81772b | 36 | cp.td = 0; |
stoicancristi | 0:b5906c81772b | 37 | break; |
stoicancristi | 0:b5906c81772b | 38 | } |
stoicancristi | 0:b5906c81772b | 39 | case PI: { |
stoicancristi | 0:b5906c81772b | 40 | cp.kp = *paramsList; |
stoicancristi | 0:b5906c81772b | 41 | cp.ti = paramsList[1]; |
stoicancristi | 0:b5906c81772b | 42 | cp.td = 0; |
stoicancristi | 0:b5906c81772b | 43 | break; |
stoicancristi | 0:b5906c81772b | 44 | } |
stoicancristi | 0:b5906c81772b | 45 | case PID: { |
stoicancristi | 0:b5906c81772b | 46 | cp.kp = *paramsList; |
stoicancristi | 0:b5906c81772b | 47 | cp.ti = paramsList[1]; |
stoicancristi | 0:b5906c81772b | 48 | cp.td = paramsList[2]; |
stoicancristi | 0:b5906c81772b | 49 | break; |
stoicancristi | 0:b5906c81772b | 50 | } |
stoicancristi | 0:b5906c81772b | 51 | case RST: { |
stoicancristi | 0:b5906c81772b | 52 | int i; |
stoicancristi | 0:b5906c81772b | 53 | cp.ordR = *paramsList; |
stoicancristi | 0:b5906c81772b | 54 | cp.R = new float[cp.ordR+1]; |
stoicancristi | 0:b5906c81772b | 55 | for (i=1; i<cp.ordR+2;i++) { |
stoicancristi | 0:b5906c81772b | 56 | cp.R[i] = paramsList[i]; |
stoicancristi | 0:b5906c81772b | 57 | } |
stoicancristi | 0:b5906c81772b | 58 | cp.ordS = paramsList[i]; |
stoicancristi | 0:b5906c81772b | 59 | cp.S = new float[cp.ordS+1]; |
stoicancristi | 0:b5906c81772b | 60 | for (i=cp.ordR+2; i<cp.ordR+cp.ordS+3; i++) { |
stoicancristi | 0:b5906c81772b | 61 | cp.S[i] = paramsList[i]; |
stoicancristi | 0:b5906c81772b | 62 | } |
stoicancristi | 0:b5906c81772b | 63 | cp.ordT = paramsList[i]; |
stoicancristi | 0:b5906c81772b | 64 | cp.T = new float[cp.ordT+1]; |
stoicancristi | 0:b5906c81772b | 65 | for(i=cp.ordR+cp.ordS+3; i<paramsListLen; i++) { |
stoicancristi | 0:b5906c81772b | 66 | cp.T[i] = paramsList[i]; |
stoicancristi | 0:b5906c81772b | 67 | } |
stoicancristi | 0:b5906c81772b | 68 | break; |
stoicancristi | 0:b5906c81772b | 69 | } |
stoicancristi | 0:b5906c81772b | 70 | } |
stoicancristi | 0:b5906c81772b | 71 | } |
stoicancristi | 0:b5906c81772b | 72 |