N K
/
analoghalls6
motor spins
Fork of analoghalls5 by
meta.h@3:0a2396597e0d, 2015-03-02 (annotated)
- Committer:
- bwang
- Date:
- Mon Mar 02 01:24:37 2015 +0000
- Revision:
- 3:0a2396597e0d
- Parent:
- 2:8696a62a4077
- Child:
- 4:fdadf4a3577a
should turn moter
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bwang | 1:1f58bdcf2956 | 1 | #ifndef __META_H |
bwang | 1:1f58bdcf2956 | 2 | #define __META_H |
bwang | 1:1f58bdcf2956 | 3 | |
bwang | 1:1f58bdcf2956 | 4 | #include "includes.h" |
bwang | 1:1f58bdcf2956 | 5 | #include "core.h" |
bwang | 1:1f58bdcf2956 | 6 | #include "sensors.h" |
bwang | 1:1f58bdcf2956 | 7 | |
bwang | 1:1f58bdcf2956 | 8 | class Modulator { |
bwang | 1:1f58bdcf2956 | 9 | public: |
bwang | 1:1f58bdcf2956 | 10 | Modulator(Inverter *inverter) {_inverter = inverter;} |
bwang | 1:1f58bdcf2956 | 11 | virtual void Update(float va, float vb) = 0; |
bwang | 1:1f58bdcf2956 | 12 | protected: |
bwang | 1:1f58bdcf2956 | 13 | Inverter* _inverter; |
bwang | 1:1f58bdcf2956 | 14 | }; |
bwang | 1:1f58bdcf2956 | 15 | |
bwang | 1:1f58bdcf2956 | 16 | class SinusoidalModulator: public Modulator { |
bwang | 1:1f58bdcf2956 | 17 | public: |
bwang | 1:1f58bdcf2956 | 18 | SinusoidalModulator(Inverter *inverter):Modulator(inverter) {} |
bwang | 1:1f58bdcf2956 | 19 | virtual void Update(float va, float vb); |
bwang | 1:1f58bdcf2956 | 20 | }; |
bwang | 1:1f58bdcf2956 | 21 | |
bwang | 1:1f58bdcf2956 | 22 | class PidController { |
bwang | 1:1f58bdcf2956 | 23 | public: |
bwang | 1:1f58bdcf2956 | 24 | PidController(float ki, float kp, float kd, float out_max, float out_min); |
bwang | 1:1f58bdcf2956 | 25 | float Update(float ref, float in); |
bwang | 1:1f58bdcf2956 | 26 | private: |
bwang | 1:1f58bdcf2956 | 27 | float _ki, _kp, _kd; |
bwang | 1:1f58bdcf2956 | 28 | float _last_in, _integral; |
bwang | 1:1f58bdcf2956 | 29 | float _out_max, _out_min; |
bwang | 1:1f58bdcf2956 | 30 | }; |
bwang | 1:1f58bdcf2956 | 31 | |
bwang | 3:0a2396597e0d | 32 | class ReferenceSynthesizer { |
bwang | 3:0a2396597e0d | 33 | public: |
bwang | 3:0a2396597e0d | 34 | ReferenceSynthesizer(float max_phase_current) {_max_phase_current = max_phase_current;} |
bwang | 3:0a2396597e0d | 35 | virtual void GetReference(float angle, float *ref_d, float *ref_q) {*ref_d = 0; *ref_q = 0;} |
bwang | 3:0a2396597e0d | 36 | protected: |
bwang | 3:0a2396597e0d | 37 | static float LutSin(float theta); |
bwang | 3:0a2396597e0d | 38 | static float LutCos(float theta); |
bwang | 3:0a2396597e0d | 39 | protected: |
bwang | 3:0a2396597e0d | 40 | float _max_phase_current; |
bwang | 3:0a2396597e0d | 41 | }; |
bwang | 3:0a2396597e0d | 42 | |
bwang | 3:0a2396597e0d | 43 | class SynchronousReferenceSynthesizer : public ReferenceSynthesizer { |
bwang | 3:0a2396597e0d | 44 | public: |
bwang | 3:0a2396597e0d | 45 | SynchronousReferenceSynthesizer(float max_phase_current):ReferenceSynthesizer(max_phase_current) {} |
bwang | 3:0a2396597e0d | 46 | virtual void GetReference(float angle, float *ref_d, float *ref_q); |
bwang | 3:0a2396597e0d | 47 | }; |
bwang | 3:0a2396597e0d | 48 | |
bwang | 1:1f58bdcf2956 | 49 | class StatusUpdater { |
bwang | 1:1f58bdcf2956 | 50 | public: |
bwang | 1:1f58bdcf2956 | 51 | StatusUpdater(Inverter *inverter, Motor *motor, User *user); |
bwang | 1:1f58bdcf2956 | 52 | void Config(int fast_sample_rate, int slow_sample_rate); |
bwang | 1:1f58bdcf2956 | 53 | void Start(); |
bwang | 1:1f58bdcf2956 | 54 | private: |
bwang | 1:1f58bdcf2956 | 55 | static void time_upd_isr(); |
bwang | 1:1f58bdcf2956 | 56 | private: |
bwang | 1:1f58bdcf2956 | 57 | Inverter *_inverter; |
bwang | 1:1f58bdcf2956 | 58 | Motor *_motor; |
bwang | 1:1f58bdcf2956 | 59 | User *_user; |
bwang | 1:1f58bdcf2956 | 60 | int _fast_sample_rate; |
bwang | 1:1f58bdcf2956 | 61 | int _slow_sample_rate; |
bwang | 1:1f58bdcf2956 | 62 | |
bwang | 1:1f58bdcf2956 | 63 | static unsigned long _time; |
bwang | 1:1f58bdcf2956 | 64 | Ticker _time_ticker; |
bwang | 1:1f58bdcf2956 | 65 | }; |
bwang | 1:1f58bdcf2956 | 66 | |
bwang | 1:1f58bdcf2956 | 67 | class LoopDriver { |
bwang | 1:1f58bdcf2956 | 68 | public: |
bwang | 3:0a2396597e0d | 69 | LoopDriver(Inverter *inverter, Motor *motor, User *user, PidController *pid_d, PidController *pid_q, |
bwang | 3:0a2396597e0d | 70 | Modulator *modulator, float max_phase_current, int update_frequency); |
bwang | 1:1f58bdcf2956 | 71 | void Start(); |
bwang | 1:1f58bdcf2956 | 72 | private: |
bwang | 3:0a2396597e0d | 73 | static void Clarke(float a, float b, float *alpha, float *beta); |
bwang | 3:0a2396597e0d | 74 | static void Parke(float alpha, float beta, float theta, float *d, float *q); |
bwang | 3:0a2396597e0d | 75 | static void InverseParke(float d, float q, float theta, float *alpha, float *beta); |
bwang | 1:1f58bdcf2956 | 76 | private: |
bwang | 1:1f58bdcf2956 | 77 | static void update(); |
bwang | 1:1f58bdcf2956 | 78 | private: |
bwang | 3:0a2396597e0d | 79 | static float LutSin(float theta); |
bwang | 3:0a2396597e0d | 80 | static float LutCos(float theta); |
bwang | 3:0a2396597e0d | 81 | private: |
bwang | 3:0a2396597e0d | 82 | static Inverter *_inverter; |
bwang | 3:0a2396597e0d | 83 | static Motor *_motor; |
bwang | 3:0a2396597e0d | 84 | static User *_user; |
bwang | 3:0a2396597e0d | 85 | static PidController *_pid_d, *_pid_q; |
bwang | 3:0a2396597e0d | 86 | static ReferenceSynthesizer *_reference; |
bwang | 3:0a2396597e0d | 87 | static Modulator *_modulator; |
bwang | 1:1f58bdcf2956 | 88 | |
bwang | 3:0a2396597e0d | 89 | Ticker _upd_ticker; |
bwang | 3:0a2396597e0d | 90 | float _max_phase_current; |
bwang | 1:1f58bdcf2956 | 91 | int _update_frequency; |
bwang | 2:8696a62a4077 | 92 | }; |
bwang | 1:1f58bdcf2956 | 93 | |
bwang | 1:1f58bdcf2956 | 94 | #endif |
bwang | 1:1f58bdcf2956 | 95 |