130 lines
3.1 KiB
C++
130 lines
3.1 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_ */
|