summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasem Mutlaq <mutlaqja@ikarustech.com>2016-09-13 10:42:58 (GMT)
committerJasem Mutlaq <mutlaqja@ikarustech.com>2016-09-13 10:42:58 (GMT)
commit91b5bfea488668c2f8bbe6f3c50d8101a67ef37f (patch)
tree0c6594fb875c7f7eb4aee071b753562fae25e122
parent83a192a736bbb46c4806623ecb6c7b5b39a764c1 (diff)
Get rid of obsolete signals. Move selectAutoStar to guide module instead of calibration
-rw-r--r--kstars/ekos/guide.cpp111
-rw-r--r--kstars/ekos/guide.h8
-rw-r--r--kstars/ekos/guide/gmath.cpp2
-rw-r--r--kstars/ekos/guide/rcalibration.cpp123
-rw-r--r--kstars/ekos/guide/rcalibration.h3
-rw-r--r--kstars/ekos/phd2.cpp4
-rw-r--r--kstars/ekos/phd2.h1
-rw-r--r--kstars/org.kde.kstars.Ekos.Guide.xml3
8 files changed, 124 insertions, 131 deletions
diff --git a/kstars/ekos/guide.cpp b/kstars/ekos/guide.cpp
index c8a26b1..8a4a17e 100644
--- a/kstars/ekos/guide.cpp
+++ b/kstars/ekos/guide.cpp
@@ -34,6 +34,8 @@
#include "guideadaptor.h"
#include "kspaths.h"
+#define MAX_GUIDE_STARS 10
+
namespace Ekos
{
@@ -984,21 +986,26 @@ QList<double> Guide::getGuidingDeviation()
void Guide::startAutoCalibrateGuiding()
{
if (Options::useEkosGuider())
- connect(calibration, SIGNAL(calibrationCompleted(bool)), this, SLOT(checkAutoCalibrateGuiding(bool)));
+ //connect(calibration, SIGNAL(calibrationCompleted(bool)), this, SLOT(checkAutoCalibrateGuiding(bool)));
+ connect(calibration, SIGNAL(newStatus(GuideState)), this, SLOT(checkAutoCalibrateGuiding(GuideState)));
else
- connect(phd2, SIGNAL(calibrationCompleted(bool)), this, SLOT(checkAutoCalibrateGuiding(bool)));
+ //connect(phd2, SIGNAL(calibrationCompleted(bool)), this, SLOT(checkAutoCalibrateGuiding(bool)));
+ connect(phd2, SIGNAL(newStatus(GuideState)), this, SLOT(checkAutoCalibrateGuiding(GuideState)));
startCalibration();
}
-void Guide::checkAutoCalibrateGuiding(bool successful)
+void Guide::checkAutoCalibrateGuiding(GuideState state)
{
+ if (state < GUIDE_CALIBRATION_SUCESS || state > GUIDE_CALIBRATION_ERROR)
+ return;
+
if (Options::useEkosGuider())
- disconnect(calibration, SIGNAL(calibrationCompleted(bool)), this, SLOT(checkAutoCalibrateGuiding(bool)));
+ disconnect(calibration, SIGNAL(newStatus(GuideState)), this, SLOT(checkAutoCalibrateGuiding(GuideState)));
else
- disconnect(phd2, SIGNAL(calibrationCompleted(bool)), this, SLOT(checkAutoCalibrateGuiding(bool)));
+ disconnect(phd2, SIGNAL(newStatus(GuideState)), this, SLOT(checkAutoCalibrateGuiding(GuideState)));
- if (successful)
+ if (state == GUIDE_CALIBRATION_SUCESS)
{
appendLogText(i18n("Auto calibration successful. Starting guiding..."));
startGuiding();
@@ -1178,6 +1185,98 @@ void Guide::updateTrackingBoxSize(int currentIndex)
syncTrackingBoxPosition();
}
+bool Guide::selectAutoStar()
+{
+ if (currentCCD == NULL)
+ return false;
+
+ ISD::CCDChip *targetChip = currentCCD->getChip(useGuideHead ? ISD::CCDChip::GUIDE_CCD : ISD::CCDChip::PRIMARY_CCD);
+ if (targetChip == NULL)
+ return false;
+
+ FITSView *targetImage = targetChip->getImage(FITS_GUIDE);
+ if (targetImage == NULL)
+ return false;
+
+ FITSData *imageData = targetImage->getImageData();
+ if (imageData == NULL)
+ return false;
+
+ imageData->findStars();
+
+ QList<Edge*> starCenters = imageData->getStarCenters();
+
+ if (starCenters.empty())
+ return false;
+
+ qSort(starCenters.begin(), starCenters.end(), [](const Edge *a, const Edge *b){return a->width > b->width;});
+
+ int maxX = imageData->getWidth();
+ int maxY = imageData->getHeight();
+
+ int scores[MAX_GUIDE_STARS];
+
+ int maxIndex = MAX_GUIDE_STARS < starCenters.count() ? MAX_GUIDE_STARS : starCenters.count();
+
+ for (int i=0; i < maxIndex; i++)
+ {
+ int score=100;
+
+ Edge *center = starCenters.at(i);
+
+ //qDebug() << "#" << i << " X: " << center->x << " Y: " << center->y << " HFR: " << center->HFR << " Width" << center->width;
+
+ // Severely reject stars close to edges
+ if (center->x < (center->width*5) || center->y < (center->width*5) || center->x > (maxX-center->width*5) || center->y > (maxY-center->width*5))
+ score-=50;
+
+ // Moderately favor brighter stars
+ score += center->width*center->width;
+
+ // Moderately reject stars close to other stars
+ foreach(Edge *edge, starCenters)
+ {
+ if (edge == center)
+ continue;
+
+ if (abs(center->x - edge->x) < center->width*2 && abs(center->y - edge->y) < center->width*2)
+ {
+ score -= 15;
+ break;
+ }
+ }
+
+ scores[i] = score;
+ }
+
+ int maxScore=0;
+ int maxScoreIndex=0;
+ for (int i=0; i < maxIndex; i++)
+ {
+ if (scores[i] > maxScore)
+ {
+ maxScore = scores[i];
+ maxScoreIndex = i;
+ }
+ }
+
+ /*if (ui.autoSquareSizeCheck->isEnabled() && ui.autoSquareSizeCheck->isChecked())
+ {
+ // Select appropriate square size
+ int idealSize = ceil(starCenters[maxScoreIndex]->width * 1.5);
+
+ if (Options::guideLogging())
+ qDebug() << "Guide: Ideal calibration box size for star width: " << starCenters[maxScoreIndex]->width << " is " << idealSize << " pixels";
+
+ // TODO Set square size in GuideModule
+ }*/
+
+ QVector3D newStarCenter(starCenters[maxScoreIndex]->x, starCenters[maxScoreIndex]->y, 0);
+ setStarPosition(newStarCenter, false);
+
+ return true;
+}
+
}
diff --git a/kstars/ekos/guide.h b/kstars/ekos/guide.h
index 5e304dc..236b610 100644
--- a/kstars/ekos/guide.h
+++ b/kstars/ekos/guide.h
@@ -249,6 +249,12 @@ public slots:
*/
Q_SCRIPTABLE bool capture();
+ /** DBUS interface function.
+ * Attempts to automatically select a star from the current guide frame
+ * @return Returns true if a star is selected successfully, false otherwise
+ */
+ Q_SCRIPTABLE bool selectAutoStar();
+
void checkCCD(int ccdNum=-1);
void checkExposureValue(ISD::CCDChip *targetChip, double exposure, IPState state);
void newFITS(IBLOB*);
@@ -258,7 +264,7 @@ public slots:
// Auto Calibration Guiding (Cablirate first then start guiding immediately)
void startAutoCalibrateGuiding();
- void checkAutoCalibrateGuiding(bool successful);
+ void checkAutoCalibrateGuiding(GuideState state);
void dither();
void setSuspended(bool enable);
diff --git a/kstars/ekos/guide/gmath.cpp b/kstars/ekos/guide/gmath.cpp
index 1afae0b..a08e981 100644
--- a/kstars/ekos/guide/gmath.cpp
+++ b/kstars/ekos/guide/gmath.cpp
@@ -682,6 +682,8 @@ Vector cgmath::findLocalStarPosition( void ) const
return ret;
}
}
+
+ return Vector(-1,-1,-1);
}
break;
// Alexander's Stepanenko smart threshold algorithm
diff --git a/kstars/ekos/guide/rcalibration.cpp b/kstars/ekos/guide/rcalibration.cpp
index 0c091cb..6a66914 100644
--- a/kstars/ekos/guide/rcalibration.cpp
+++ b/kstars/ekos/guide/rcalibration.cpp
@@ -37,8 +37,6 @@
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#define MAX_GUIDE_STARS 10
-
internalCalibration::internalCalibration(cgmath *mathObject, Ekos::Guide *parent)
: QWidget(parent)
{
@@ -434,8 +432,6 @@ void internalCalibration::calibrateManualReticle( void )
KNotification::event( QLatin1String( "CalibrationSuccessful" ) , i18n("Guiding calibration completed successfully"));
calibrationStage = CAL_FINISH;
- emit calibrationCompleted(true);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_SUCESS);
guideModule->setDECSwap(dec_swap);
@@ -445,8 +441,6 @@ void internalCalibration::calibrateManualReticle( void )
QMessageBox::warning( this, i18n("Error"), i18n("Calibration rejected. Start drift is too short."), QMessageBox::Ok );
is_started = false;
calibrationStage = CAL_ERROR;
- emit calibrationCompleted(false);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_ERROR);
}
}
@@ -461,8 +455,6 @@ void internalCalibration::calibrateManualReticle( void )
fillInterface();
guideModule->appendLogText(i18n("Calibration completed."));
- emit calibrationCompleted(true);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_SUCESS);
KNotification::event( QLatin1String( "CalibrationSuccessful" ) , i18n("Guiding calibration completed successfully"));
@@ -471,8 +463,6 @@ void internalCalibration::calibrateManualReticle( void )
{
calibrationStage = CAL_ERROR;
- emit calibrationCompleted(false);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_ERROR);
QMessageBox::warning( this, i18n("Error"), i18n("Calibration rejected. Start drift is too short."), QMessageBox::Ok );
@@ -626,8 +616,6 @@ void internalCalibration::calibrateRADECRecticle( bool ra_only )
calibrationStage = CAL_ERROR;
- emit calibrationCompleted(false);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_ERROR);
if (ui.autoStarCheck->isChecked())
@@ -674,14 +662,12 @@ void internalCalibration::calibrateRADECRecticle( bool ra_only )
fillInterface();
guideModule->appendLogText(i18n("Calibration completed."));
- emit calibrationCompleted(true);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_SUCESS);
ui.startCalibrationLED->setColor(okColor);
- KNotification::event( QLatin1String( "CalibrationFailed" ) , i18n("Guiding calibration failed with errors"));
+ KNotification::event( QLatin1String( "CalibrationSuccessful" ) , i18n("Guiding calibration completed successfully"));
if (ui.autoStarCheck->isChecked())
- selectAutoStar(pmath->getImageView());
+ guideModule->selectAutoStar();
}
else
{
@@ -692,8 +678,6 @@ void internalCalibration::calibrateRADECRecticle( bool ra_only )
ui.startCalibrationLED->setColor(alertColor);
calibrationStage = CAL_ERROR;
- emit calibrationCompleted(false);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_ERROR);
KNotification::event( QLatin1String( "CalibrationFailed" ) , i18n("Guiding calibration failed with errors"));
@@ -789,8 +773,6 @@ void internalCalibration::calibrateRADECRecticle( bool ra_only )
calibrationStage = CAL_ERROR;
- emit calibrationCompleted(false);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_ERROR);
if (ui.autoStarCheck->isChecked())
@@ -815,8 +797,6 @@ void internalCalibration::calibrateRADECRecticle( bool ra_only )
guideModule->appendLogText(i18n("DEC swap disabled."));
guideModule->appendLogText(i18n("Calibration completed."));
- emit calibrationCompleted(true);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_SUCESS);
ui.startCalibrationLED->setColor(okColor);
@@ -825,7 +805,7 @@ void internalCalibration::calibrateRADECRecticle( bool ra_only )
KNotification::event( QLatin1String( "CalibrationSuccessful" ) , i18n("Guiding calibration completed successfully"));
if (ui.autoStarCheck->isChecked())
- selectAutoStar(pmath->getImageView());
+ guideModule->selectAutoStar();
}
else
@@ -835,8 +815,6 @@ void internalCalibration::calibrateRADECRecticle( bool ra_only )
else
QMessageBox::warning( this, i18n("Error"), i18n("Calibration rejected. Star drift is too short."), QMessageBox::Ok );
- emit calibrationCompleted(false);
- // FIXME Just one signal is enough. Remove previous signal
emit newStatus(Ekos::GUIDE_CALIBRATION_ERROR);
ui.startCalibrationLED->setColor(alertColor);
@@ -925,17 +903,16 @@ bool internalCalibration::setImageView(FITSView *image)
if (ui.autoStarCheck->isChecked())
{
- QPair<double,double> star = selectAutoStar(guideFrame);
+ bool rc = guideModule->selectAutoStar();
- if (star.first == 0 && star.second == 0)
+ if (rc == false)
{
guideModule->appendLogText(i18n("Failed to automatically select a guide star. Please select a guide star..."));
connect(guideFrame, SIGNAL(trackingStarSelected(int,int)), this, SLOT(trackingStarSelected(int, int)), Qt::UniqueConnection);
- //pmath->moveSquare(image_data->getWidth()/2-pmath->getSquareSize()/2, image_data->getHeight()/2 - pmath->getSquareSize()/2);
return true;
}
else
- trackingStarSelected(star.first, star.second);
+ trackingStarSelected(guideModule->getStarPosition().x(), guideModule->getStarPosition().y());
return false;
}
else
@@ -952,94 +929,6 @@ bool internalCalibration::setImageView(FITSView *image)
return true;
}
-bool brighterThan(Edge *s1, Edge *s2)
-{
- return s1->width > s2->width;
-}
-
-QPair<double,double> internalCalibration::selectAutoStar(FITSView *image)
-{
- Q_ASSERT(image);
-
- //int maxVal=-1;
- //Edge *guideStar = NULL;
- QPair<double,double> star;
-
- FITSData *image_data = image->getImageData();
- image_data->findStars();
-
- QList<Edge*> starCenters = image_data->getStarCenters();
-
- if (starCenters.empty())
- return star;
-
- qSort(starCenters.begin(), starCenters.end(), brighterThan);
-
- int maxX = image_data->getWidth();
- int maxY = image_data->getHeight();
-
- int scores[MAX_GUIDE_STARS];
-
- int maxIndex = MAX_GUIDE_STARS < starCenters.count() ? MAX_GUIDE_STARS : starCenters.count();
-
- for (int i=0; i < maxIndex; i++)
- {
- int score=100;
-
- Edge *center = starCenters.at(i);
-
- //qDebug() << "#" << i << " X: " << center->x << " Y: " << center->y << " HFR: " << center->HFR << " Width" << center->width;
-
- // Severely reject stars close to edges
- if (center->x < (center->width*5) || center->y < (center->width*5) || center->x > (maxX-center->width*5) || center->y > (maxY-center->width*5))
- score-=50;
-
- // Moderately favor brighter stars
- score += center->width*center->width;
-
- // Moderately reject stars close to other stars
- foreach(Edge *edge, starCenters)
- {
- if (edge == center)
- continue;
-
- if (abs(center->x - edge->x) < center->width*2 && abs(center->y - edge->y) < center->width*2)
- {
- score -= 15;
- break;
- }
- }
-
- scores[i] = score;
- }
-
- int maxScore=0;
- int maxScoreIndex=0;
- for (int i=0; i < maxIndex; i++)
- {
- if (scores[i] > maxScore)
- {
- maxScore = scores[i];
- maxScoreIndex = i;
- }
- }
-
- star = qMakePair(starCenters[maxScoreIndex]->x, starCenters[maxScoreIndex]->y);
-
- if (ui.autoSquareSizeCheck->isEnabled() && ui.autoSquareSizeCheck->isChecked())
- {
- // Select appropriate square size
- int idealSize = ceil(starCenters[maxScoreIndex]->width * 1.5);
-
- if (Options::guideLogging())
- qDebug() << "Guide: Ideal calibration box size for star width: " << starCenters[maxScoreIndex]->width << " is " << idealSize << " pixels";
-
- // TODO Set square size in GuideModule
- }
-
- return star;
-}
-
void internalCalibration::setCalibrationTwoAxis(bool enable)
{
ui.twoAxisCheck->setChecked(enable);
diff --git a/kstars/ekos/guide/rcalibration.h b/kstars/ekos/guide/rcalibration.h
index 946408b..01d2c15 100644
--- a/kstars/ekos/guide/rcalibration.h
+++ b/kstars/ekos/guide/rcalibration.h
@@ -86,12 +86,9 @@ public slots:
void trackingStarSelected(int x, int y);
signals:
- void calibrationCompleted(bool);
void newStatus(Ekos::GuideState state);
private:
-
- QPair<double,double> selectAutoStar(FITSView *image);
void fillInterface( void );
void calibrateManualReticle( void );
void calibrateRADECRecticle( bool ra_only ); // 1 or 2-axis calibration
diff --git a/kstars/ekos/phd2.cpp b/kstars/ekos/phd2.cpp
index a071e8f..3fc8f92 100644
--- a/kstars/ekos/phd2.cpp
+++ b/kstars/ekos/phd2.cpp
@@ -72,7 +72,7 @@ PHD2::~PHD2()
}
void PHD2::connectPHD2()
-{
+{
if (connection == DISCONNECTED)
{
connection = CONNECTING;
@@ -252,7 +252,6 @@ void PHD2::processPHD2Event(const QJsonObject &jsonEvent)
// It goes immediately to guiding until PHD implements a calibration-only method
state = GUIDING;
emit newLog(i18n("PHD2: Calibration Complete."));
- emit calibrationCompleted(true);
emit guideReady();
emit newStatus(Ekos::GUIDE_CALIBRATION_SUCESS);
break;
@@ -288,7 +287,6 @@ void PHD2::processPHD2Event(const QJsonObject &jsonEvent)
case CalibrationFailed:
state = CALIBRATION_FAILED;
emit newLog(i18n("PHD2: Calibration Failed (%1).", jsonEvent["Reason"].toString()));
- emit calibrationCompleted(false);
emit newStatus(Ekos::GUIDE_CALIBRATION_ERROR);
break;
diff --git a/kstars/ekos/phd2.h b/kstars/ekos/phd2.h
index efb6b76..c01d3b5 100644
--- a/kstars/ekos/phd2.h
+++ b/kstars/ekos/phd2.h
@@ -71,7 +71,6 @@ signals:
void newLog(const QString &);
void connected();
void disconnected();
- void calibrationCompleted(bool);
void ditherComplete();
void ditherFailed();
void newAxisDelta(double delta_ra, double delta_dec);
diff --git a/kstars/org.kde.kstars.Ekos.Guide.xml b/kstars/org.kde.kstars.Ekos.Guide.xml
index 809ff00..75d9916 100644
--- a/kstars/org.kde.kstars.Ekos.Guide.xml
+++ b/kstars/org.kde.kstars.Ekos.Guide.xml
@@ -16,6 +16,9 @@
<method name="capture">
<arg type="b" direction="out"/>
</method>
+ <method name="selectAutoStar">
+ <arg type="b" direction="out"/>
+ </method>
<method name="setCCD">
<arg type="b" direction="out"/>
<arg name="device" type="s" direction="in"/>