motorcontroldemo_028/Vinclude/V_MotorModel.h
2019-07-29 08:18:57 +03:00

173 lines
8.0 KiB
C

/*!
Copyright 2017 ÀÎ "ÍÈÈÝÒ" è ÎÎÎ "ÍÏÔ ÂÅÊÒÎÐ"
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
\file V_MotorModel.h
\brief Ìîäóëü ìîäåëåé ýëåêòðîäâèãàòåëåé (ñì. TMotorModel)
\author ÎÎÎ "ÍÏÔ Âåêòîð". http://motorcontrol.ru
\version v 2.0 25/03/2017
\defgroup V_MotorModel.h Ìîäóëü ìîäåëåé ýëåêòðîäâèãàòåëåé (ñì. TMotorModel)
@{
*/
#ifndef V_MOTOR_MODEL_H
#define V_MOTOR_MODEL_H
#ifdef __cplusplus
extern "C" {
#endif
#include "DSP.h"
#include "V_IQmath.h"
// faults
#define MODEL_WRONG_PARAMETERS 1
#define MODEL_MAX_CURRENT_FAULT 2
#define MODEL_MAX_SPEED_FAULT 3
// motor types (for internal use)
#define MODEL_INDUCTION_MOTOR 0
#define MODEL_SYNC_MOTOR 1
#define MODEL_DC_MOTOR 2
#define MODEL_SRD_MOTOR 3
#define MOTOR_MODEL_PI 3.1415926f
#define MODEL_INV_2PI 0.15915494f
//ñòðóêòóðà ñ ïàðàìåòðàìè äâèãàòåëÿ è ïðåîáðàçîâàòåëÿ
struct Smotor
{
int cmpr0, cmpr1, cmpr2, cmpr3; //!< óñòàâêè ñðàâíåíèÿ ØÈÌ
int tpr; //!< ïåðèîä ØÈÌ
float inv_tpr; //!< 1/ïåðèîä ØÈÌ
int dt; //!< âåëè÷èíà ìåðòâîãî âðåìåíè â òàêòàõ
int dta, dtb, dtc, dtf; //!< âëèÿíèå ìåðòâîãî âðåìåíè íà ïîòåíöèàëû ôàç
float udc; //!< íàïðÿæåíèå ÇÏÒ
float fia, fib, fic, fiav; //!< ïîòåíöèàëû ôàç è ñðåäíåé òî÷êè
float ua, ub, uc; //!< ôàçíûå íàïðÿæåíèÿ
float isa, isb, isc, isd, isq; //!< ôàçíûå òîêè â îñÿõ àëüôà, áåòòà
float usa, usb, usd, usq, urd, urq; //!< íàïðÿæåíèÿ â îðòîãîíàëüíûõ îñÿõ
float ird, irq, ira, irb; //!< òîêè â îðòîãîíàëüíûõ îñÿõ
float omega,omega_rpm,torque; //!< ñêîðîñòü (÷àñòîòà âðàùåíèÿ), ìîìåíò
float torque_a, torque_b, torque_c; //!< ìîìåíò îò êàæäîé ôàçû (SRD)
float j, inv_j; //!< ìîìåíò èíåðöèè è îáðàòíàÿ âåëè÷èíà
float MechLoss; //!< ìîìåíò èíåðöèè
float pp; //!< ÷èñëî ïàð ïîëþñîâ
float inv_pp; //!< 1/pp
float tetaR; //!< óãîë ïîëîæåíèÿ ðîòîðà, ýëåêòðè÷åñêèé
float tetaRM; //!< óãîë ïîëîæåíèÿ ðîòîðà, ìåõàíè÷åñêèé
float cosTetaR, sinTetaR; //!< cos è sin óãëà ïîëîæåíèÿ ðîòîðà
float lm, lr, ls, lsd, lsq; //!< èíäóêòèâíîñòè - âçàèìíàÿ, ðîòîðà, ñòàòîðà
float lmin, lmax, dls; //!< ìèíèìàëüíàÿ èíäóêòèâíîñòü (çóá-ïàç), ìàêñèìàëüíàÿ èíäóêòèâíîñòü (çóá-çóá), àìïëèòóäà èçìåíåíèÿ èíäóêòèâíîñòè
float inv_lmin; //!< 1/lmin
float l; //!< òåêóùàÿ èíäóêòèâíàñòü
float lp; //!< èíäóêòèâíàñòü â îêðåñòíîñòè òåêóùåãî ïîëîæåíèÿ
float ip, im; //!< òîêè â îêðåñòíîñòè òåêóùåãî ïîëîæåíèÿ
float wp, wm; //!< ìàãíèòíûå ýíåðãèè ôàçíîé êàòóøêè â îêðåñòíîñòè òåêóùåãî ïîëîæåíèÿ
float isat; //!< òîê íàñûùåíèÿ
float rr, rs; //!< ñîïðîòèâëåíèå ðîòðà è ñòàòîðà
float ks, kr, km; //!< êîýôôèöèåíòû èíäóêòèâíîñòåé
float psa, psb, psc, psd, psq, prd, prq, pra, prb; //!< ïîòîêîñöåïëåíèÿ ñòàòîðà è ðîòîðà â îðòîãîíàëüíûõ îñÿõ èëè ôàçíûå
float ppsa, ppsb, ppsd, ppsq, pprd, pprq, ppra, pprb; //!< ïðåäèêòîðû ïîòîêîñöåïëåíèé â îðòîãîíàëüíûõ îñÿõ
float dpsa, dpsb, dpsd, dpsq, dprd, dprq; //!< ïðîèçâîäíûå ïîòîêîñöåïëåíèé â îðòîãîíàëüíûõ îñÿõ
int type; //!< òèï äâèãàòåëÿ
float t, t2; //!< ïåðèîä äèñêðåòèçàöèè, ïîëîâèíà ïåðèîäà äèñêðåòèçàöèè
float speedK; //!< êîýôôèöèåíò äàò÷èêà ñêîðîñòè
float iSenseK, ifSenseK, udSenseK, iSenseR, iSenseN; //!< êîýôôèöèåíò äàò÷èêà òîêà, ñîïðîòèâëåíèå èçìåðèòåëüíîãî ðåçèñòîðà ÄÒ, êîëè÷åñòâî âèòêîâ ïðîâîäà ÷åðåç ÄÒ
float RatedPower; //!< íîìèíàëüíàÿ ìîùíîñòü (ñïðàâî÷íàÿ âåëè÷èíà, íå èñïîëüçóåòñÿ â ðàñ÷åòàõ)
float RatedSpeed; //!< íîìèíàëüíàÿ ñêîðîñòü (ñïðàâî÷íàÿ âåëè÷èíà, íå èñïîëüçóåòñÿ â ðàñ÷åòàõ)
float RatedCurrent; //!< íîìèíàëüíûé òîê
float RatedFluxCurrent; //!< íîìèíàëüíûé òîê âîçáóæäåíèÿ
int iADCk, ifADCk;
float QEPResolution; //!< ÷èñëî ìåòîê ÄÏÐ
float m; //!< ïîòîêîñöåïëåíèå ðîòîðà ñèíõðîííîé ìàøèíû
float i_a, i_f, u_a, u_f, u_an;
float r_a, r_f, r_ad, l_a, l_f;
float _1_l_a, _1_l_f;
float _1_lsd, _1_lsq;
float dia, dif, dpa, dpf, pia, pif;
float l_m,kf; //!< êîýôôèöèåíò òîêà ÎÂ, ïîòîâ ÎÂ
int dcm_pm; //!< ôëàã, ÷òî ÄÏÒ ñ ÏÌ.
int syncm_pm; //!< ôëàã, ÷òî ÑÄ ñ ÏÌ.
float isPhaseA,isPhaseB,isPhaseC,isPhaseD; //!< òîê ôàçû A,B,C
float isPhaseA_prev,isPhaseB_prev,isPhaseC_prev; //!< òîê ôàçû A,B,C ïðåäûäóùèå çíà÷åíèÿ
int CurrentInvertedFlag; //!< Ôëàã î òîì, ÷òî ïîñëå âûêë÷þåíèÿ èíâåðòîðà òîêè ôàç îäèí ðàç ñìåíèëè ñâîé çíàê
float cos30; //!< cos 30 ãðàäóñîâ
float pisa,dprb,disa; //!< ïðåäèêòîð òîêà ñòàòîðà àëüôà, ïðèðàùåíèÿ ïîòîêîñöåïëåíèÿ ðîòîðà ïî îñè áåòà, òîêà ñòàòîðà ïî îñè àëüôà
float ThetaMax, PsiMax, IMax; //!< ìàêñèìàëüíûé óãîë, ïîòîê è òîê SRM (äëÿ èíòåðïîëÿöèè)
float ThetaStep, PsiStep, IStep; //!< øàã ïî óãëó, ïîòîêó è òîêó SRM (äëÿ èíòåðïîëÿöèè)
float ThetaStep_inv, PsiStep_inv, IStep_inv; //!< îáðàòíûå çíà÷åíèÿ øàãà ïî óãëó, ïîòîêó è òîêó SRM (äëÿ èíòåðïîëÿöèè)
float power; //!< Ìîùíîñòü íà âàëó
long iAtemp, iBtemp, iCtemp, iDtemp, Udc_temp, adcSpeedtemp;//!<Âðåìåííûå ïåðåìåííûå äëÿ ðàñ÷åòà ìîäåëè
Uint16 hallSensor; //!< ñèãíàë ñ äàò÷èêà ïîëîæåíèÿ Õîëëà
Uint16 hallSensorPrev; //!< ñèãíàë ñ äàò÷èêà ïîëîæåíèÿ Õîëëà ïðåäûäóùèé
float hallSensorOmegaPrev; //!< Äëÿ èìèòàöèè èçìåðåíèÿ ÷àñòîòû âðàùåíèÿ ñ äàò÷èêà Õîëëà
};
typedef volatile struct Smotor Tmotor;
//Ñòðóêòóðà ñ äàííûìè ìîäåëè. ÿâëÿåòñÿ èíòåðôåéñîì ìåæäó îñíîâíîé ïðîãðàììîé è ìîäåëüþ äâèãàòåëÿ.
//Ïðèíèìàåò óñòàâêè ñðàâíåíèÿ, ïåðèîä ØÈÌ è âåëè÷èíó ìåðòâîãî âðåìåíè, ìîìåíò íàãðóçêè. Âûäàåò ïîêàçàíèÿ äàò÷èêîâ.
struct SMotorModel
{
Uint16 MotorType; //!< Òèï äâèãàòåëÿ â ìîäåëè (äëÿ ñèìóëÿòîðà)
Uint16 MotorParametersNum; //!< Íîìåð ïàðàìåòðîâ äâèãàòåëÿ èç òàáëèöû
Uint16 MotorParametersNumMax; // Ìàêñèìàëüíûé âîçìîæíûé íîìåð ïàðàìåòðîâ èç òàáëèöû
Uint16 cmpr0; //!< óñòàâêè ñðàâíåíèÿ ØÈÌ
Uint16 cmpr1;
Uint16 cmpr2;
Uint16 cmpr3;
int16 InvertorEna; //!< Ôëàã âêëþ÷åíèÿ èíâåðòîðà (åñëè íåò, òî êëþ÷è íå óïðàâëÿþòñÿ)
Uint16 tpr; //!< ïåðèîä ØÈÌ
Uint16 dt; //!< ìåðòâîå âðåìÿ â òèêàõ òàéìåðà
Uint16 adc_code_Speed; //!< èçìåðåííàÿ ñêîðîñòü
Uint32 qepCounter; //!< ïîëîæåíèå ñ ýíêîäåðà
Uint16 hallSensor; //!< Äèñêðåòíûé ñèãíàë ñ äàò÷èêà ïîëîæåíèÿ Õîëëà (òðè ïåðâûõ áèòà)
float hallSensorInterpAdd; //!< Äëÿ èìèòàöèè èíòåðïîëÿöèè äàò÷èêà Õîëëà
float hallSensorOmega; //!< Äëÿ èìèòàöèè èçìåðåíèÿ ÷àñòîòû âðàùåíèÿ ñ äàò÷èêà Õîëëà
Uint16 adc_code_iA; //!< èçìåðåííûå òîêè
Uint16 adc_code_iB;
Uint16 adc_code_iC;
Uint16 adc_code_iD;
Uint16 adc_code_Udc; //!< èçìåðåííîå çíà÷åíèå íàïðÿæåíèÿ çâåíà ïîñòîÿííîãî òîêà (ÇÏÒ)
int16 fault; //!< îøèáêà ìîäåëè
float load; //!< ìîìåíò íàãðóçêè
float loadTmp; //!< ìîìåíò íàãðóçêè âðåìåííàÿ ïåðåìåííàÿ
void (*Init)(volatile struct SMotorModel*); //!< Pointer to the init function
void (*Execute)(volatile struct SMotorModel*); //!< Pointer to the update function
Tmotor motorInternals; //!< Âíóòðåííèå ïåðåìåííûå äëÿ ðàñ÷åòà ìîäåëè äâèãàòåëÿ
};
typedef volatile struct SMotorModel TMotorModel;
#define MOTOR_MODEL_DEFAULTS {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,MotorModel_Init, MotorModel_Execute}
void MotorModel_Init(TMotorModel*);
void MotorModel_Execute(TMotorModel*);
#ifdef __cplusplus
}
#endif
#endif
/*@}*/