130 lines
3.4 KiB
C++
130 lines
3.4 KiB
C++
/*
|
||
* ThetaNullEstimate.h
|
||
*
|
||
* Created on: 23 нояб. 2016 г.
|
||
* Author: titov
|
||
*/
|
||
|
||
#ifndef SOURCE_COMMISSIONING_THETANULLESTIMATE_H_
|
||
|
||
#define SOURCE_COMMISSIONING_THETANULLESTIMATE_H_
|
||
|
||
#include "../../algorithm/LinearRegression.hh"
|
||
|
||
#include "../../math/math_inc.hh"
|
||
|
||
#include <algorithm>
|
||
|
||
#include <memory_resource>
|
||
|
||
namespace technological { namespace commissioning {
|
||
|
||
//todo: Очеень нужен рефакторинг тулзы.
|
||
class ThetaNullEstimate {
|
||
public:
|
||
struct TSetting {
|
||
|
||
float Ts;
|
||
float Np;
|
||
|
||
float valid_mismatch_theta_1;
|
||
float valid_error;
|
||
|
||
bool isValid() const {
|
||
return Ts > 0.0f
|
||
&& Np > 0
|
||
&& Np < 128
|
||
and valid_mismatch_theta_1 > 0
|
||
and valid_error > 0;
|
||
}
|
||
};
|
||
|
||
private:
|
||
enum TDirection {
|
||
forward,
|
||
backward
|
||
};
|
||
|
||
//Состояние.
|
||
bool enable;
|
||
bool data_collection;
|
||
bool data_analysis;
|
||
|
||
//Параметры движения.
|
||
int sector_setpoint; //!<Заданное количество секторов (1/6 электрических оборотов).
|
||
unsigned int Np; //!<Количество пар полюсов.
|
||
float speed; //!<Скорость для вращения вектора напряжения.
|
||
float Ts; //!<Период дискретизации.
|
||
|
||
//Организация движения.
|
||
TDirection direction;
|
||
unsigned long count_rise; //!<Количество отсчетов в движении.
|
||
unsigned long count_next; //!<Количество отсчетов в секторе.
|
||
int sector; //!<Текущий номер сектора.
|
||
unsigned long count; //!<Счетчик
|
||
|
||
//Используемые модули.
|
||
algorithm::LinearRegression * null_calculator;
|
||
//Проверка результатов.
|
||
float errorEstimate;
|
||
float totalError; //!<Общая ошибка.
|
||
//Проверка данных по ходу дела.
|
||
float previous_feedback;
|
||
float delta_previous;
|
||
|
||
|
||
|
||
std::pmr::monotonic_buffer_resource * buff_resource;
|
||
private:
|
||
void add_data(float theta_feedback);
|
||
|
||
float calc_null_result() const {
|
||
const unsigned int start_k = 0;
|
||
|
||
return (null_calculator->getTheta(0)
|
||
+ null_calculator->getTheta(1) * start_k);
|
||
}
|
||
|
||
bool check_valid_result() const {
|
||
return null_calculator->getTheta(1) < ( math::constants::pi_3 + errorEstimate )
|
||
&& null_calculator->getTheta(1) > ( math::constants::pi_3 - errorEstimate )
|
||
and std::abs( null_calculator->getError() ) < totalError;
|
||
}
|
||
|
||
public:
|
||
ThetaNullEstimate();
|
||
|
||
bool setBuffer( std::pmr::monotonic_buffer_resource * buffer );
|
||
void resetBuffer();
|
||
|
||
bool configure(const TSetting & setting);
|
||
|
||
bool start(float average_speed, unsigned int number_sector, float rise_to_hold);
|
||
void stop();
|
||
|
||
void execute(float theta_feedback, float & iota);
|
||
|
||
void process();
|
||
|
||
bool isDataCollection() const {return enable && data_collection;}
|
||
bool isDataCollected() const {return enable && not data_collection;}
|
||
bool isDataAnalysis() const {return enable && data_analysis;}
|
||
|
||
bool isDataReady() const {return enable && null_calculator && null_calculator->isFull();}
|
||
bool isDataFailure() const {return enable && !data_collection && null_calculator && !null_calculator->isFull();}
|
||
bool isCalcReady() const {return enable && null_calculator && null_calculator->isFinish();}
|
||
|
||
float get_result() const {
|
||
if(null_calculator && check_valid_result())
|
||
return calc_null_result();
|
||
else
|
||
return NAN;
|
||
}
|
||
};
|
||
|
||
}}
|
||
|
||
|
||
|
||
#endif /* SOURCE_COMMISSIONING_THETANULLESTIMATE_H_ */
|