101 lines
3.3 KiB
C++
101 lines
3.3 KiB
C++
/*
|
|
* PositionMixerv2.h
|
|
*
|
|
* Created on: 20 èþë. 2020 ã.
|
|
* Author: user
|
|
*/
|
|
|
|
#ifndef UMLIBRARY_DRIVER_POSITIONMIXERV2_H_
|
|
#define UMLIBRARY_DRIVER_POSITIONMIXERV2_H_
|
|
|
|
#include "IncrementCounter.hh"
|
|
#include "IResolver.hh"
|
|
#include "HiperfacePositionData.hh"
|
|
|
|
#include <cmath>
|
|
|
|
namespace driver {
|
|
|
|
class PositionMixer_v2 {
|
|
private:
|
|
//Èñòî÷íèêè äàííûõ î ïîëîæåíèè:
|
|
IncrementCounter increment_counter;
|
|
driver::IResolver & resolver;
|
|
|
|
const unsigned short step_per_turn; //!< Áèòîâ àáñîëþòíîé (öèôðîâîé) ïîçèöèè â ìåõàíè÷åñêîì îáîðîòå.
|
|
|
|
const float resolver_to_rad; //!< Êîýôôèöèåíò ïðåîáðàçîâàíèÿ êîîðäèíàòû ïî ðåçîëüâåðó â àáñîëþòíóþ.
|
|
|
|
const unsigned long line_in_turn;
|
|
const unsigned long max_turn_value;
|
|
|
|
const unsigned long long max_angle_code;
|
|
|
|
mutable bool phase_error_flag = false; //!< Íåñîîòâåòñòâèå óãëà ïî ðåçîëüâåðó è ïî ñ÷åò÷èêó.
|
|
bool scrt_valid = false;
|
|
|
|
PositionComponents last_position;
|
|
bool new_code_after_resolver_fault = false;
|
|
|
|
bool is_sector_synchronized = false;
|
|
unsigned long counter_before_synchronized = 0;
|
|
|
|
short sector_offset:2;
|
|
|
|
const float sector_deviation;
|
|
|
|
const unsigned short resolver_hyst; //! Êîëè÷åñòâî ïîäðÿä âàëèäíûõ ñèãíàëîâ ñèíóñà è êîñèíóñà.
|
|
const unsigned short counter_hyst; //! Êîëè÷åñòâî ïîäðÿä íåâàëèäíûõ ñèãíàëîâ ñèíóñà è êîñèíóñà.
|
|
unsigned short resolver_valid_value_count = 0;
|
|
unsigned short resolver_invalid_value_count = 0;
|
|
|
|
const float half_increment; //!<Ïîëîâèíà äèñòàíöèè ìåæäó îòñ÷åòàìè, ðàä.
|
|
|
|
PositionCode incSinCosPeriod(PositionCode code);
|
|
PositionCode decSinCosPeriod(PositionCode code);
|
|
|
|
public:
|
|
/// Áèòîâ àáñîëþòíîé (öèôðîâîé) ïîçèöèè â ïåðèîäå ñèíóñà/êîñèíóñà. Âñåãäà.
|
|
static const unsigned short periods_in_turn_power = 5;
|
|
|
|
/// Êîëè÷åñòâî îòñ÷åòîâ èíêðåìåíòàëüíîãî ýíêîäåðà â îäíîì ïåðèîäå ñèíóñà/êîñèíóñà, ñòåïåíü äâîéêè. Âñåãäà.
|
|
static const unsigned short line_in_period_power = 2;
|
|
|
|
/// Ïðîâåðêà èñòî÷íèêîâ ïîçèöèè - ïîòåðÿ êâàäðàòóðíîãî ñèãíàëà - îòêàç.
|
|
bool isValid() const { return increment_counter.isValid(); }
|
|
|
|
bool isPhaseError() const {
|
|
bool error = phase_error_flag;
|
|
if(phase_error_flag) phase_error_flag = false;
|
|
return error;
|
|
}
|
|
|
|
/// Ïðèçíàê èñïîëüçîâàíèÿ äàííûõ îò ÑÊÂÒ.
|
|
bool isScrtValid() const { return scrt_valid and is_sector_synchronized; }
|
|
|
|
/// Ñáðîñ ñ÷åò÷èêîâ.
|
|
void reset();
|
|
|
|
//!Ïðåäîñòàâëÿåò ñìèêøèðîâàííûå äàííûå â êîíå÷íîì âèäå.
|
|
PositionData calculatePosition();
|
|
|
|
/// Ïðåäîñòàâëÿåò îòäåëüíûå äàííûå î ïîëîæåíèè ñî âñåõ èñòî÷íèêîâ.
|
|
PositionComponents getPositionComponents() const;
|
|
|
|
/// Óñòàíîâêà àáñîëþòíîãî ïîëîæåíèÿ â îòñ÷åòàõ àáñîëþòíîãî ýíêîäåðà.
|
|
void setAbsolutePosition(unsigned long absolute_position);
|
|
|
|
PositionMixer_v2( peripheral::ICounter & counter, unsigned long sin_period_resolution, unsigned long max_turn_value,
|
|
driver::IResolver & resolver, unsigned short resolver_hyst, unsigned short counter_hyst, float sector_deviation );
|
|
|
|
private:
|
|
PositionCode cross_correction(const PositionCode & position, const float period_angle);
|
|
void sector_synchronization(const PositionCode & position, const float period_angle);
|
|
|
|
void sector_resynchronizarion();
|
|
};
|
|
|
|
} /* namespace driver */
|
|
|
|
#endif /* UMLIBRARY_DRIVER_POSITIONMIXERV2_H_ */
|