#ifndef PWM_VECTOR_REGUL
#define PWM_VECTOR_REGUL

#include "pid_reg3.h"

void pwm_vector_model_titov(_iq Pzad, _iq Fzad, int direction, _iq Frot, int mode,
                            int reset, int calcPWMtimes);
void init_DQ_pid(void);
//void detect_I_M_overload(void);
void analog_dq_calc_const(void);

void set_cos_tetta_calc_params();
void limit_mzz_zad_power(_iq Frot);

extern _iq zadan_Id_min;
extern PIDREG3 pidD;
extern PIDREG3 pidQ;
extern PIDREG3 pidD2;
extern PIDREG3 pidQ2;

extern long koeff_Ud_filter;

typedef struct {
	_iq cos_fi_nom;
	_iq cos_fi_nom_squared;
} COS_FI_STRUCT;

extern COS_FI_STRUCT cos_fi;

#define ONE_IQ24 16777216

typedef struct {
    _iq iqId_zad;
    _iq iqIq_zad;
    _iq iqUdKm1;
    _iq iqUqKm1;
    _iq iqUdKm2;
    _iq iqUqKm2;
    _iq iqUdCompensation1;
    _iq iqUqCompensation1;
    _iq iqUdCompensation2;
    _iq iqUqCompensation2;
    _iq iqUdKm1Out;
    _iq iqUqKm1Out;
    _iq iqUdKm2Out;
    _iq iqUqKm2Out;

    _iq iqUzad1;
    _iq iqUzad2;

    _iq koef_Ud_comp;
    _iq koef_Uq_comp;
    _iq koeff_correct_Id;

    _iq equial_Iq_Proportional;   //Пропорциональный коэффициент регулятора поддержания Iq одинаковым на обоих обмотках
    _iq equial_Iq_Delta;    //Разница в Iq двух обмоток
    _iq equial_Iq_Out;

    _iq k_modul_max;
    _iq k_modul_max_square;
    _iq iq_Id_out_max;

    _iq iqPzad;
    _iq iqPizm;
    _iq iqFrot;

    int flag_reverse;
    
    float theta;

} VECTOR_CONTROL;

#define VECTOR_CONTROL_DEFAULTS {0,0,0,0,0,0,0,0,0,0, 0,0, 0,0,0, 0,0,0, 0,0,0,0,0, 0,0}

extern VECTOR_CONTROL vect_control;

extern PIDREG3 pidFvect;

#endif //PWM_VECTOR_REGUL


