67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
/*
|
|
* 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_ */
|