MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/driver/HiperfacePositionData.hh

67 lines
1.8 KiB
C++
Raw Normal View History

2024-06-07 11:12:56 +03:00
/*
* HiperfacePositionData.h
*
* Created on: 20 июл. 2020 г.
* Author: user
*/
#ifndef UMLIBRARY_DRIVER_HIPERFACEPOSITIONDATA_H_
#define UMLIBRARY_DRIVER_HIPERFACEPOSITIONDATA_H_
#include "../math/math_inc.hh"
namespace driver {
//!Абсолютное положение.
struct PositionData {
float angle; //!< Угол внутри оборота, рад. Диапазон изменения зависит от реализации.
unsigned short turn; //!< Номер оборота.
PositionData operator+(float any_angle) const {
const short turns_in_angle = ( angle + any_angle ) / math::constants::pi2;
const float angle_in_turn = ( angle + any_angle ) - turns_in_angle*math::constants::pi2;
return { angle_in_turn, turn + turns_in_angle };
}
PositionData operator-(float any_angle) const { return *this + (-any_angle); }
};
//!Данные о положении, используемые модулем Hiperface.
struct PositionComponents {
/// Данные по резольверу.
float sin;
float cos;
/// Данные по инкрементальному счетчику.
unsigned long increment_position;
/// Проверка на валидность данных.
operator bool() const {
using namespace std;
return isfinite(sin) and isfinite(cos);
}
bool isLostSinCosComponents() const {
using namespace std;
return not( isfinite(sin) or isfinite(cos) );
}
PositionComponents(float sin, float cos, unsigned long inc_pos) : sin(sin), cos(cos), increment_position(inc_pos) {}
PositionComponents & operator=(const PositionComponents &) = default;
PositionComponents() : sin(NAN), cos(NAN), increment_position(0) {}
};
}
#endif /* UMLIBRARY_DRIVER_HIPERFACEPOSITIONDATA_H_ */