18 #include "scroll_graph.h"
20 #include "../ekosmanager.h"
23 #include <KMessageBox>
24 #include <KLocalizedString>
25 #include <KNotifications/KNotification>
40 m_useRapidGuide =
false;
42 first_subframe =
false;
43 m_isSubFramed =
false;
47 ui.comboBox_ThresholdAlg->clear();
61 pDriftOut =
new custom_drawer(ui.frame_Graph);
62 pDriftOut->move(ui.frame_Graph->frameWidth(), ui.frame_Graph->frameWidth());
63 pDriftOut->setAttribute(Qt::WA_NoSystemBackground,
true);
64 ui.frame_Graph->setAttribute(Qt::WA_NoSystemBackground,
true);
66 pDriftOut->set_source(drift_graph->get_buffer(),
nullptr);
68 drift_graph =
new ScrollGraph(
this, DRIFT_GRAPH_WIDTH, DRIFT_GRAPH_HEIGHT);
69 drift_graph->set_visible_ranges(DRIFT_GRAPH_WIDTH, 60);
70 drift_graph->on_paint();
71 ui.frame_Graph->resize(DRIFT_GRAPH_WIDTH + 2 * ui.frame_Graph->frameWidth(),
72 DRIFT_GRAPH_HEIGHT + 2 * ui.frame_Graph->frameWidth());
77 half_refresh_rate =
false;
78 m_isDithering =
false;
80 ui.ditherCheck->setChecked(Options::useDither());
96 half_refresh_rate = is_half;
112 ui.spinBox_AOLimit->setEnabled(enable);
117 return ui.spinBox_AOLimit->value();
132 drift_graph->get_visible_ranges(&rx, &ry);
133 ui.spinBox_XScale->setValue(rx / drift_graph->get_grid_N());
134 ui.spinBox_YScale->setValue(ry / drift_graph->get_grid_N());
138 ui.l_RecommendedGain->setText(
143 ui.l_Focal->setText(str.
setNum((
int)info_params.
focal));
147 ui.l_FOV->setText(str);
149 ui.checkBox_DirRA->setChecked(Options::enableRAGuide());
150 ui.checkBox_DirDEC->setChecked(Options::enableDECGuide());
180 targetChip->
getFrame(&fx, &fy, &fw, &fh);
182 ui.subFrameCheck->setEnabled(targetChip->
canSubframe());
187 Options::setUseDither(ui.ditherCheck->isChecked());
191 Options::setEnableRAGuide(ui.checkBox_DirRA->isChecked());
192 Options::setEnableDECGuide(ui.checkBox_DirDEC->isChecked());
212 phd2->startGuiding();
215 m_useRapidGuide = ui.rapidGuideCheck->isChecked();
219 ui.pushButton_StartStop->setText(i18n(
"Stop"));
225 logFile.
open(QIODevice::WriteOnly | QIODevice::Text);
227 out <<
"Guiding rate,x15 arcsec/sec: " << ui.spinBox_GuideRate->value() << endl;
228 out <<
"Focal,mm: " << ui.l_Focal->text() << endl;
229 out <<
"Aperture,mm: " << ui.l_Aperture->text() << endl;
230 out <<
"F/D: " << ui.l_FbyD->text() << endl;
231 out <<
"FOV: " << ui.l_FOV->text() << endl;
232 out <<
"Frame #, Time Elapsed (ms), RA Error (arcsec), RA Correction (ms), RA Correction Direction, DEC Error "
233 "(arcsec), DEC Correction (ms), DEC Correction Direction"
236 drift_graph->reset_data();
237 ui.pushButton_StartStop->setText(i18n(
"Stop"));
242 m_useRapidGuide = ui.rapidGuideCheck->isChecked();
244 guideModule->startRapidGuide();
248 guideModule->setSuspended(
false);
252 if (ui.subFrameCheck->isEnabled() && ui.subFrameCheck->isChecked() && m_isSubFramed ==
false)
253 first_subframe =
true;
257 pmath->setLogFile(&logFile);
266 ui.pushButton_StartStop->setText(i18n(
"Start Autoguide"));
269 m_isDithering =
false;
272 return phd2->stopGuiding();
277 Qt::UniqueConnection);
278 ui.pushButton_StartStop->setText(i18n(
"Start Autoguide"));
288 guideModule->stopRapidGuide();
292 m_isDithering =
false;
307 m_useRapidGuide = ui.rapidGuideCheck->isChecked();
309 ui.pushButton_StartStop->setText(i18n(
"Stop"));
315 ui.pushButton_StartStop->setText(i18n(
"Start Autoguide"));
335 if (ui.subFrameCheck->isChecked() && m_isSubFramed ==
false)
337 int x,
y, w, h, binX = 1, binY = 1;
339 int square_size = guideFrame->getTrackingBox().width();
342 x = (ret_x - square_size) * binX;
343 y = (ret_y - square_size) * binY;
344 w = square_size * 2 * binX;
345 h = square_size * 2 * binY;
347 int minX, maxX, minY, maxY, minW, maxW, minH, maxH;
348 targetChip->
getFrameMinMax(&minX, &maxX, &minY, &maxY, &minW, &maxW, &minH, &maxH);
350 m_isSubFramed =
true;
372 else if (m_isSubFramed && ui.subFrameCheck->isChecked() ==
false)
374 m_isSubFramed =
false;
390 ui.swapCheck->disconnect(
this);
391 ui.swapCheck->setChecked(enable);
397 static int maxPulseCounter = 0;
401 double drift_x = 0, drift_y = 0;
407 first_subframe =
false;
410 else if (first_frame)
412 if (m_isDithering ==
false)
428 if (pmath->
isStarLost() && ++m_lostStarTries > 2)
431 i18n(
"Lost track of the guide star. Try increasing the square size and check the mount."));
447 if (maxPulseCounter > 3)
449 guideModule->
appendLogText(i18n(
"Lost track of the guide star. Aborting guiding..."));
462 drift_graph->add_point(drift_x, drift_y);
480 if (half_refresh_rate && (tick & 1))
483 drift_graph->on_paint();
486 profilePixmap = pDriftOut->grab(
QRect(
QPoint(0, 100),
QSize(pDriftOut->width(), 101)));
494 if (m_isReady && guideFrame && m_isStarted ==
false)
496 Qt::UniqueConnection);
514 if (m_isStarted ==
true)
530 static unsigned int retries = 0;
532 if (ui.ditherCheck->isChecked() ==
false)
535 double cur_x, cur_y, ret_angle;
538 Matrix ROT_Z = pmath->
getROTZ();
542 if (m_isDithering ==
false)
549 double ditherPixels = ui.ditherPixels->value();
550 int polarity = (rand() % 2 == 0) ? 1 : -1;
551 double angle = ((double)rand() / RAND_MAX) * M_PI / 2.0;
552 double diff_x = ditherPixels * cos(angle);
553 double diff_y = ditherPixels * sin(angle);
555 m_isDithering =
true;
561 target_pos =
Vector(cur_x, cur_y, 0) +
Vector(diff_x, diff_y, 0);
563 target_pos =
Vector(cur_x, cur_y, 0) -
Vector(diff_x, diff_y, 0);
566 qDebug() <<
"Guide: Dithering process started.. Reticle Target Pos X " << target_pos.
x <<
" Y "
581 star_pos.
y = -star_pos.
y;
582 star_pos = star_pos * ROT_Z;
585 qDebug() <<
"Guide: Dithering in progress. Diff star X:" << star_pos.
x <<
"Y:" << star_pos.
y;
587 if (fabs(star_pos.
x) < 1 && fabs(star_pos.
y) < 1)
591 m_isDithering =
false;
594 qDebug() <<
"Guide: Dither complete.";
601 if (++retries > MAX_DITHER_RETIRES)
603 m_isDithering =
false;
617 return ui.comboBox_ThresholdAlg->currentText();
622 return ui.subFrameCheck->isChecked();
627 return ui.rapidGuideCheck->isChecked();
632 for (
int i = 0; i < ui.comboBox_ThresholdAlg->count(); i++)
634 if (ui.comboBox_ThresholdAlg->itemText(i) == algorithm)
636 ui.comboBox_ThresholdAlg->setCurrentIndex(i);
641 ui.subFrameCheck->setChecked(useSubFrame);
642 ui.rapidGuideCheck->setChecked(useRapidGuide);
647 ui.ditherCheck->setChecked(enable);
649 if (enable && value > 0)
650 ui.ditherPixels->setValue(value);
656 if (phd2 && phd ==
nullptr)
661 bool enable = (phd2 ==
nullptr) ?
true :
false;
674 ui.connectPHD2B->setHidden(enable);
676 ui.pushButton_StartStop->setEnabled(enable);
677 ui.controlGroup->setEnabled(enable);
678 ui.infoGroup->setEnabled(enable);
679 ui.captureB->setEnabled(enable);
680 ui.subFrameCheck->setEnabled(enable);
681 ui.rapidGuideCheck->setEnabled(enable);
682 ui.comboBox_ThresholdAlg->setEnabled(enable);
683 ui.ditherCheck->setEnabled(enable);
684 ui.ditherPixels->setEnabled(enable);
685 ui.driftGraphicsGroup->setEnabled(enable);
693 phd2->disconnectPHD2();
701 ui.connectPHD2B->setText(i18n(
"Disconnect PHD2"));
703 ui.pushButton_StartStop->setEnabled(
true);
704 ui.ditherCheck->setEnabled(
true);
705 ui.ditherPixels->setEnabled(
true);
710 ui.connectPHD2B->setText(i18n(
"Connect PHD2"));
712 ui.pushButton_StartStop->setEnabled(
false);
713 ui.ditherCheck->setEnabled(
false);
714 ui.ditherPixels->setEnabled(
false);
bool sendPulse(GuideDirection ra_dir, int ra_msecs, GuideDirection dec_dir, int dec_msecs)
bool setVideoParameters(int vid_wd, int vid_ht, int binX, int binY)
Q_SCRIPTABLE bool capture()
DBUS interface function.
bool getReticleParameters(double *x, double *y, double *ang) const
void event(const QLatin1String &name, const QString &message, EventType type)
void onStartStopButtonClick()
void appendLogText(const QString &)
static void setRAMaximumPulse(uint v)
Set RAMaximumPulse.
bool setFrame(int x, int y, int w, int h, bool force=false)
static void setDECIntegralGain(double v)
Set DECIntegralGain.
int getSquareAlgorithmIndex(void) const
CCDChip class controls a particular chip in CCD device.
void onSetDECSwap(bool enable)
bool isGuiding(void) const
const square_alg_t guide_square_alg[]
static double dECProportionalGain()
Get DECProportionalGain.
void setTargetChip(ISD::CCDChip *chip)
static double rAProportionalGain()
Get RAProportionalGain.
static uint rAMaximumPulse()
Get RAMaximumPulse.
Vector findLocalStarPosition(void) const
void setImageView(FITSView *image)
void setFileName(const QString &name)
void setPHD2Disconnected()
Uses external PHD2 for guiding.
bool declinationSwapEnabled()
void setDither(bool enable, double value)
info_params_t getInfoParameters(void) const
static QString writableLocation(QStandardPaths::StandardLocation type)
bool isStarLost(void) const
void setPHD2(Ekos::PHD2 *phd)
static uint rAMinimumPulse()
Get RAMinimumPulse.
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
uint32_t getTicks(void) const
bool setReticleParameters(double x, double y, double ang)
void getStarScreenPosition(double *dx, double *dy) const
static void setRAIntegralGain(double v)
Set RAIntegralGain.
GuideDirection pulse_dir[2]
const char * name() const
void setDECSwap(bool enable)
internalGuider(cgmath *mathObject, Ekos::Guide *parent=nullptr)
static void setDitherPixels(double v)
Set How many pixels to move between subsequent exposures under auto dithering mode.
QVector3D getStarPosition()
getStarPosition Return star center as selected by the user or auto-detected by KStars ...
static double rADerivativeGain()
Get RADerivativeGain.
static void setDECMinimumPulse(uint v)
Set DECMinimumPulse.
static double dECDerivativeGain()
Get DECDerivativeGain.
static bool guideLogging()
Get GuideLogging.
Performs calibration and autoguiding using an ST4 port or directly via the INDI driver.
virtual bool open(QFlags< QIODevice::OpenModeFlag > mode)
void toggleExternalGuideStateGUI(Ekos::GuideState state)
static void setDECMaximumPulse(uint v)
Set DECMaximumPulse.
static double ditherPixels()
Get How many pixels to move between subsequent exposures under auto dithering mode.
static void setRADerivativeGain(double v)
Set RADerivativeGain.
void newStatus(Ekos::GuideState)
static void setRAProportionalGain(double v)
Set RAProportionalGain.
static uint dECMinimumPulse()
Get DECMinimumPulse.
void setMathObject(cgmath *math)
bool isConnected() override
bool getFrame(int *x, int *y, int *w, int *h)
void performProcessing(void)
void setGuideOptions(const QString &algorithm, bool useSubFrame, bool useRapidGuide)
bool getFrameMinMax(int *minX, int *maxX, int *minY, int *maxY, int *minW, int *maxW, int *minH, int *maxH)
static double rAIntegralGain()
Get RAIntegralGain.
static double guidingRate()
Get GuidingRate.
static void setRAMinimumPulse(uint v)
Set RAMinimumPulse.
QString & setNum(short n, int base)
void getStarDrift(double *dx, double *dy) const
static void setDECProportionalGain(double v)
Set DECProportionalGain.
static void setGuidingRate(double v)
Set GuidingRate.
void setDECSwap(bool enable)
setDECSwap Change ST4 declination pulse direction.
void setHalfRefreshRate(bool is_half)
void onRapidGuideChanged(bool enable)
void newStarPosition(QVector3D, bool)
static uint dECMaximumPulse()
Get DECMaximumPulse.
static double dECIntegralGain()
Get DECIntegralGain.
static double aOLimit()
Get The Adaptive Optics unit is utilized if the guiding deviation is less than this limit in arcsecon...
static void setAOLimit(double v)
Set The Adaptive Optics unit is utilized if the guiding deviation is less than this limit in arcsecon...
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
bool abort(bool silence=false)
static void setDECDerivativeGain(double v)
Set DECDerivativeGain.
const cproc_out_params * getOutputParameters() const
void newProfilePixmap(QPixmap &)
void trackingStarSelected(int x, int y)