17#include "rotatorutils.h"
20#include "opticaltrainmanager.h"
23#include <basedevice.h>
26RotatorUtils * RotatorUtils::m_Instance =
nullptr;
28RotatorUtils * RotatorUtils::Instance()
33 m_Instance =
new RotatorUtils();
37void RotatorUtils::release()
43RotatorUtils::RotatorUtils() {}
45RotatorUtils::~RotatorUtils() {}
47void RotatorUtils::initRotatorUtils(
const QString &train)
49 m_Offset = Options::pAOffset();
50 m_Mount = Ekos::OpticalTrainManager::Instance()->getMount(train);
54 connect(m_Mount, &ISD::Mount::pierSideChanged,
this, [
this] (ISD::Mount::PierSide Side)
56 m_flippedMount = (Side != m_CalPierside);
57 emit changedPierside(Side);
62double RotatorUtils::calcRotatorAngle(
double PositionAngle)
68 return KSUtils::range360(PositionAngle - m_Offset);
71double RotatorUtils::calcCameraAngle(
double RotatorAngle,
bool flippedImage)
73 double PositionAngle = 0;
74 if (RotatorAngle > 180)
76 PositionAngle = (RotatorAngle - 360) + m_Offset;
80 PositionAngle = RotatorAngle + m_Offset;
82 if (!m_flippedMount != !flippedImage)
84 if (PositionAngle > 0)
94 return KSUtils::rangePA(PositionAngle);
97double RotatorUtils::calcOffsetAngle(
double RotatorAngle,
double PositionAngle)
99 double OffsetAngle = 0;
100 if (RotatorAngle > 180)
102 OffsetAngle = PositionAngle - (RotatorAngle - 360);
106 OffsetAngle = PositionAngle - RotatorAngle;
112 return KSUtils::rangePA(OffsetAngle);
115void RotatorUtils::updateOffset(
double Angle)
118 Options::setPAOffset(Angle);
121ISD::Mount::PierSide RotatorUtils::getMountPierside()
123 return(m_Mount->pierSide());
126void RotatorUtils::setImagePierside(ISD::Mount::PierSide ImgPierside)
128 m_ImgPierside = ImgPierside;
131bool RotatorUtils::checkImageFlip()
133 bool flipped =
false;
135 if (m_ImgPierside != ISD::Mount::PIER_UNKNOWN)
136 if (!m_flippedMount != (m_ImgPierside == m_CalPierside))
141double RotatorUtils::DiffPA(
double diff)
149void RotatorUtils::initTimeFrame(
const double EndAngle)
151 m_EndAngle = EndAngle;
152 m_initParameter =
true;
156int RotatorUtils::calcTimeFrame(
const double CurrentAngle)
159 m_DeltaTime = m_StartTime.
secsTo(m_CurrentTime);
161 if (m_DeltaTime >= 1)
165 m_DeltaAngle = CurrentAngle + m_ShiftAngle;
167 if (m_DeltaAngle >= 360)
170 m_DiffAngle = (360 + m_DiffAngle);
175 m_DiffAngle = (360 - m_DiffAngle);
178 m_initParameter =
false;
180 m_DeltaAngle = KSUtils::range360(CurrentAngle + m_ShiftAngle);
182 m_DeltaAngle = 360 - m_DeltaAngle;
184 m_TimeFrame = fabs(m_DiffAngle) / fabs(m_DeltaAngle/m_DeltaTime);
189void RotatorUtils::startTimeFrame(
const double StartAngle)
191 m_StartAngle = StartAngle;
193 m_ShiftAngle = 360 - m_StartAngle;
194 m_DiffAngle = m_EndAngle - m_StartAngle;
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
int secsTo(QTime t) const const