/*
 * vector_control.h
 *
 *  Created on: 16 нояб. 2020 г.
 *      Author: star
 */

#ifndef SRC_VECTORCONTROL_NIO12_VECTOR_CONTROL_H_
#define SRC_VECTORCONTROL_NIO12_VECTOR_CONTROL_H_

#include "pid_reg3.h"
#include "regul_power.h"
#include "regul_turns.h"

typedef struct {
    PIDREG3 pidD1;
    PIDREG3 pidQ1;
    PIDREG3 pidD2;
    PIDREG3 pidQ2;

    _iq iqId1;
    _iq iqIq1;
    _iq iqId2;
    _iq iqIq2;
    _iq iqUd1;
    _iq iqUq1;
    _iq iqUd2;
    _iq iqUq2;
    _iq iqUdKm;
    _iq iqUqKm;
    _iq iqUdCompensation;
    _iq iqUqCompensation;

    _iq iqId1_filt;
    _iq iqIq1_filt;
    _iq iqId2_filt;
    _iq iqIq2_filt;

    _iq iqPvsi1;
    _iq iqPvsi2;
    _iq iqTheta;
    _iq iqFsl;
    _iq iqFstator;
    _iq iqId_nominal;
    _iq iqId_min;
    _iq iqId_start;
    _iq koef_rmp_Id;
    _iq koef_filt_I;
    _iq koef_Ud_comp;
    _iq koef_Uq_comp;
    _iq koef_zero_Uzad;
    _iq add_tetta;

    _iq sqrtIdq1;
    _iq sqrtIdq2;

    _iq Iq_zad1;
    _iq Id_zad1;

    _iq add_bpsi;

} VECTOR_CONTROL;

#define VECTOR_CONTROL_DEFAULTS  {PIDREG3_DEFAULTS, PIDREG3_DEFAULTS, \
                                PIDREG3_DEFAULTS, PIDREG3_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,0,0,0,0,0,0,0,0,0,0}

void vectorControlConstId (_iq Pzad, _iq Fzad, int direction, _iq Frot,
						   int n_alg, unsigned int master, _iq mzz_zad,
						   _iq winding_displacement,
						   _iq theta_from_master, _iq Iq_from_master, _iq P_from_slave,
						   _iq *theta_to_slave, _iq *Iq_to_slave, _iq *P_to_master,
						   int reset, int prepare_stop_PWM);

void analog_dq_calc_external(_iq winding_displacement, _iq theta);
void initVectorControl();

extern VECTOR_CONTROL vect_control;


#endif /* SRC_VECTORCONTROL_NIO12_VECTOR_CONTROL_H_ */
