• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • ekos
guide.cpp
Go to the documentation of this file.
1 /* Ekos
2  Copyright (C) 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
3 
4  This application is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8  */
9 
10 #include "guide.h"
11 
12 #include <QDateTime>
13 
14 #include "guide/gmath.h"
15 #include "guide/guider.h"
16 #include "Options.h"
17 
18 
19 #include <KMessageBox>
20 #include <KLed>
21 
22 #include "indi/driverinfo.h"
23 #include "fitsviewer/fitsviewer.h"
24 #include "fitsviewer/fitsview.h"
25 
26 #include "guide/rcalibration.h"
27 
28 #include <basedevice.h>
29 
30 namespace Ekos
31 {
32 
33 Guide::Guide() : QWidget()
34 {
35  setupUi(this);
36 
37  currentCCD = NULL;
38  currentTelescope = NULL;
39  ccd_hor_pixel = ccd_ver_pixel = focal_length = aperture = -1;
40  useGuideHead = false;
41 
42  tabWidget = new QTabWidget(this);
43 
44  tabLayout->addWidget(tabWidget);
45 
46  guiderStage = CALIBRATION_STAGE;
47 
48  pmath = new cgmath();
49 
50  calibration = new rcalibration(this);
51  calibration->set_math(pmath);
52 
53  guider = new rguider(this);
54  guider->set_math(pmath);
55 
56 
57  tabWidget->addTab(calibration, calibration->windowTitle());
58  tabWidget->addTab(guider, guider->windowTitle());
59  tabWidget->setTabEnabled(1, false);
60 
61  connect(ST4Combo, SIGNAL(currentIndexChanged(int)), this, SLOT(newST4(int)));
62 
63  foreach(QString filter, FITSViewer::filterTypes)
64  filterCombo->addItem(filter);
65 
66 }
67 
68 Guide::~Guide()
69 {
70  delete guider;
71  delete calibration;
72  delete pmath;
73 }
74 
75 void Guide::setCCD(ISD::GDInterface *newCCD)
76 {
77  currentCCD = (ISD::CCD *) newCCD;
78 
79  guiderCombo->addItem(currentCCD->getDeviceName());
80  useGuideHead = false;
81 
82  connect(currentCCD, SIGNAL(FITSViewerClosed()), this, SLOT(viewerClosed()));
83 
84  syncCCDInfo();
85 
86  //qDebug() << "SetCCD: ccd_pix_w " << ccd_hor_pixel << " - ccd_pix_h " << ccd_ver_pixel << " - focal length " << focal_length << " aperture " << aperture << endl;
87 
88 }
89 
90 void Guide::setTelescope(ISD::GDInterface *newTelescope)
91 {
92  currentTelescope = (ISD::Telescope*) newTelescope;
93 
94  syncTelescopeInfo();
95 
96 
97 }
98 
99 void Guide::addGuideHead()
100 {
101  // Let's just make sure
102  if (currentCCD && currentCCD->hasGuideHead())
103  {
104  guiderCombo->clear();
105  guiderCombo->addItem(currentCCD->getDeviceName() + QString(" Guider"));
106  useGuideHead = true;
107  syncCCDInfo();
108  }
109 
110 }
111 
112 void Guide::syncCCDInfo()
113 {
114  INumberVectorProperty * nvp = NULL;
115 
116  if (currentCCD == NULL)
117  return;
118 
119  if (useGuideHead)
120  nvp = currentCCD->getBaseDevice()->getNumber("GUIDER_INFO");
121  else
122  nvp = currentCCD->getBaseDevice()->getNumber("CCD_INFO");
123 
124  if (nvp)
125  {
126  INumber *np = IUFindNumber(nvp, "CCD_PIXEL_SIZE_X");
127  if (np)
128  ccd_hor_pixel = np->value;
129 
130  np = IUFindNumber(nvp, "CCD_PIXEL_SIZE_Y");
131  if (np)
132  ccd_ver_pixel = np->value;
133 
134  np = IUFindNumber(nvp, "CCD_PIXEL_SIZE_Y");
135  if (np)
136  ccd_ver_pixel = np->value;
137  }
138 
139  if (ccd_hor_pixel != -1 && ccd_ver_pixel != -1 && focal_length != -1 && aperture != -1)
140  {
141  pmath->set_guider_params(ccd_hor_pixel, ccd_ver_pixel, aperture, focal_length);
142  int x,y,w,h;
143 
144  ISD::CCDChip *targetChip = currentCCD->getChip(useGuideHead ? ISD::CCDChip::GUIDE_CCD : ISD::CCDChip::PRIMARY_CCD);
145 
146  if (targetChip->getFrame(&x,&y,&w,&h))
147  pmath->set_video_params(w, h);
148 
149  guider->fill_interface();
150  }
151 
152  //qDebug() << "SetCCD: ccd_pix_w " << ccd_hor_pixel << " - ccd_pix_h " << ccd_ver_pixel << " - focal length " << focal_length << " aperture " << aperture << endl;
153 }
154 
155 void Guide::syncTelescopeInfo()
156 {
157  INumberVectorProperty * nvp = currentTelescope->getBaseDevice()->getNumber("TELESCOPE_INFO");
158 
159  if (nvp)
160  {
161  INumber *np = IUFindNumber(nvp, "GUIDER_APERTURE");
162 
163  if (np && np->value != 0)
164  aperture = np->value;
165  else
166  {
167  np = IUFindNumber(nvp, "TELESCOPE_APERTURE");
168  if (np)
169  aperture = np->value;
170  }
171 
172  np = IUFindNumber(nvp, "GUIDER_FOCAL_LENGTH");
173  if (np && np->value != 0)
174  focal_length = np->value;
175  else
176  {
177  np = IUFindNumber(nvp, "TELESCOPE_FOCAL_LENGTH");
178  if (np)
179  focal_length = np->value;
180  }
181  }
182 
183  if (ccd_hor_pixel != -1 && ccd_ver_pixel != -1 && focal_length != -1 && aperture != -1)
184  {
185  pmath->set_guider_params(ccd_hor_pixel, ccd_ver_pixel, aperture, focal_length);
186  int x,y,w,h;
187 
188  ISD::CCDChip *targetChip = currentCCD->getChip(useGuideHead ? ISD::CCDChip::GUIDE_CCD : ISD::CCDChip::PRIMARY_CCD);
189 
190  if (targetChip->getFrame(&x,&y,&w,&h))
191  pmath->set_video_params(w, h);
192 
193  guider->fill_interface();
194 
195  }
196 
197  //qDebug() << "SetScope: ccd_pix_w " << ccd_hor_pixel << " - ccd_pix_h " << ccd_ver_pixel << " - focal length " << focal_length << " aperture " << aperture << endl;
198 
199 }
200 
201 void Guide::addST4(ISD::ST4 *newST4)
202 {
203  ST4Combo->addItem(newST4->getDeviceName());
204  ST4List.append(newST4);
205 
206  ST4Driver = ST4List.at(0);
207  ST4Combo->setCurrentIndex(0);
208 
209 }
210 
211 bool Guide::capture()
212 {
213  if (currentCCD == NULL)
214  return false;
215 
216  double seqExpose = exposureSpin->value();
217 
218  ISD::CCDChip *targetChip = currentCCD->getChip(useGuideHead ? ISD::CCDChip::GUIDE_CCD : ISD::CCDChip::PRIMARY_CCD);
219 
220  CCDFrameType ccdFrame = FRAME_LIGHT;
221 
222  if (currentCCD->isConnected() == false)
223  {
224  appendLogText(i18n("Error: Lost connection to CCD."));
225  return false;
226  }
227 
228  connect(currentCCD, SIGNAL(BLOBUpdated(IBLOB*)), this, SLOT(newFITS(IBLOB*)));
229 
230  targetChip->setCaptureMode(FITS_GUIDE);
231  targetChip->setCaptureFilter( (FITSScale) filterCombo->currentIndex());
232 
233  targetChip->setFrameType(ccdFrame);
234 
235  targetChip->capture(seqExpose);
236 
237  return true;
238 
239 }
240 void Guide::newFITS(IBLOB *bp)
241 {
242  INDI_UNUSED(bp);
243 
244  FITSViewer *fv = currentCCD->getViewer();
245 
246  disconnect(currentCCD, SIGNAL(BLOBUpdated(IBLOB*)), this, SLOT(newFITS(IBLOB*)));
247 
248  ISD::CCDChip *targetChip = currentCCD->getChip(useGuideHead ? ISD::CCDChip::GUIDE_CCD : ISD::CCDChip::PRIMARY_CCD);
249  FITSView *targetImage = targetChip->getImage(FITS_GUIDE);
250 
251  if (targetImage == NULL)
252  return;
253 
254  FITSImage *image_data = targetImage->getImageData();
255 
256  if (image_data == NULL)
257  return;
258 
259  image_data->findStars();
260 
261  pmath->set_image(targetImage);
262  guider->set_image(targetImage);
263  calibration->set_image(targetImage);
264 
265  fv->show();
266 
267  if (guider->is_guiding())
268  {
269  guider->guide();
270 
271  if (guider->is_guiding())
272  capture();
273  }
274  else if (calibration->is_calibrating())
275  {
276 
277  pmath->do_processing();
278  calibration->process_calibration();
279 
280  //if (calibration->is_calibrating())
281  // capture();
282 
283  if (calibration->is_finished())
284  {
285  guider->set_ready(true);
286  tabWidget->setTabEnabled(1, true);
287  }
288  }
289 
290 }
291 
292 
293 void Guide::appendLogText(const QString &text)
294 {
295 
296  logText.insert(0, i18nc("log entry; %1 is the date, %2 is the text", "%1 %2", QDateTime::currentDateTime().toString("yyyy-MM-ddThh:mm:ss"), text));
297 
298  emit newLog();
299 }
300 
301 void Guide::clearLog()
302 {
303  logText.clear();
304  emit newLog();
305 }
306 
307 bool Guide::do_pulse( GuideDirection ra_dir, int ra_msecs, GuideDirection dec_dir, int dec_msecs )
308 {
309  if (ST4Driver == NULL)
310  return false;
311 
312  if (calibration->is_calibrating())
313  QTimer::singleShot( (ra_msecs > dec_msecs ? ra_msecs : dec_msecs) + 100, this, SLOT(capture()));
314 
315  return ST4Driver->doPulse(ra_dir, ra_msecs, dec_dir, dec_msecs);
316 }
317 
318 bool Guide::do_pulse( GuideDirection dir, int msecs )
319 {
320  if (ST4Driver == NULL)
321  return false;
322 
323  if (calibration->is_calibrating())
324  QTimer::singleShot(msecs+100, this, SLOT(capture()));
325 
326  return ST4Driver->doPulse(dir, msecs);
327 
328 }
329 
330 void Guide::newST4(int index)
331 {
332  if (ST4List.empty() || index >= ST4List.count())
333  return;
334 
335  ST4Driver = ST4List.at(index);
336 
337 }
338 
339 double Guide::getReticleAngle()
340 {
341  return calibration->getReticleAngle();
342 }
343 
344 void Guide::viewerClosed()
345 {
346  guider->set_image(NULL);
347  calibration->set_image(NULL);
348 }
349 
350 }
351 
352 #include "guide.moc"
FITSView::getImageData
FITSImage * getImageData()
Definition: fitsview.h:98
Ekos::Guide::capture
bool capture()
Definition: guide.cpp:211
rguider::set_math
void set_math(cgmath *math)
Definition: guider.cpp:121
Ekos::Guide::appendLogText
void appendLogText(const QString &)
Definition: guide.cpp:293
rcalibration::is_calibrating
bool is_calibrating()
Definition: rcalibration.cpp:297
ISD::CCD::getChip
CCDChip * getChip(CCDChip::ChipType cType)
Definition: indiccd.cpp:872
rguider::guide
void guide(void)
Definition: guider.cpp:387
FITSImage
Definition: fitsimage.h:73
FITSImage::findStars
int findStars()
Definition: fitsimage.cpp:985
gmath.h
ISD::CCDChip
Definition: indiccd.h:23
guide.h
Ekos::Guide::newFITS
void newFITS(IBLOB *)
Definition: guide.cpp:240
cgmath::set_guider_params
bool set_guider_params(double ccd_pix_wd, double ccd_pix_ht, double guider_aperture, double guider_focal)
Definition: gmath.cpp:150
Ekos::Guide::newLog
void newLog()
QWidget
ISD::CCD::getViewer
FITSViewer * getViewer()
Definition: indiccd.h:97
GuideDirection
GuideDirection
Definition: indicommon.h:23
FITSView
Definition: fitsview.h:81
ISD::DeviceDecorator::getDeviceName
const char * getDeviceName()
Definition: indistd.cpp:703
ISD::CCD::hasGuideHead
bool hasGuideHead()
Definition: indiccd.cpp:867
Ekos::Guide::syncTelescopeInfo
void syncTelescopeInfo()
Definition: guide.cpp:155
rcalibration::set_math
void set_math(cgmath *math)
Definition: rcalibration.cpp:144
ISD::CCDChip::getImage
FITSView * getImage(FITSMode imageType)
Definition: indiccd.cpp:51
rcalibration::getReticleAngle
double getReticleAngle()
Definition: rcalibration.h:47
fitsview.h
ISD::CCDChip::PRIMARY_CCD
Definition: indiccd.h:26
Ekos::Guide::CALIBRATION_STAGE
Definition: guide.h:44
driverinfo.h
cgmath::do_processing
void do_processing(void)
Definition: gmath.cpp:889
ISD::CCDChip::capture
bool capture(double exposure)
Definition: indiccd.cpp:198
rcalibration::set_image
void set_image(FITSView *image)
Definition: rcalibration.cpp:684
FITSScale
FITSScale
Definition: fitscommon.h:22
Ekos::Guide::clearLog
void clearLog()
Definition: guide.cpp:301
ISD::CCDChip::GUIDE_CCD
Definition: indiccd.h:26
ISD::CCDChip::setFrameType
bool setFrameType(CCDFrameType fType)
Definition: indiccd.cpp:299
Ekos::Guide::viewerClosed
void viewerClosed()
Definition: guide.cpp:344
rguider
Definition: guider.h:24
rguider::set_image
void set_image(FITSView *image)
Definition: guider.cpp:450
ISD::Telescope
Definition: inditelescope.h:19
i18nc
i18nc("string from libindi, used in the config dialog","100x")
Ekos::Guide::setCCD
void setCCD(ISD::GDInterface *newCCD)
Definition: guide.cpp:75
Ekos::Guide::syncCCDInfo
void syncCCDInfo()
Definition: guide.cpp:112
Ekos::Guide::do_pulse
bool do_pulse(GuideDirection ra_dir, int ra_msecs, GuideDirection dec_dir, int dec_msecs)
Definition: guide.cpp:307
cgmath
Definition: gmath.h:116
ISD::ST4::getDeviceName
const char * getDeviceName()
Definition: indistd.cpp:750
Ekos::Guide::setTelescope
void setTelescope(ISD::GDInterface *newTelescope)
Definition: guide.cpp:90
ISD::CCDChip::getFrame
bool getFrame(int *x, int *y, int *w, int *h)
Definition: indiccd.cpp:106
cgmath::set_video_params
bool set_video_params(int vid_wd, int vid_ht)
Definition: gmath.cpp:107
Ekos::Guide::newST4
void newST4(int index)
Definition: guide.cpp:330
Options.h
rcalibration::is_finished
bool is_finished()
Definition: rcalibration.h:50
rguider::is_guiding
bool is_guiding(void) const
Definition: guider.cpp:115
CCDFrameType
CCDFrameType
Definition: indicommon.h:68
Ekos::Guide::~Guide
~Guide()
Definition: guide.cpp:68
ISD::ST4
Definition: indistd.h:195
ISD::CCDChip::setCaptureFilter
void setCaptureFilter(FITSScale fType)
Definition: indiccd.h:33
rguider::set_ready
void set_ready(bool enable)
Definition: guider.h:38
rcalibration
Definition: rcalibration.h:29
rcalibration.h
guider.h
ISD::CCDChip::setCaptureMode
void setCaptureMode(FITSMode mode)
Definition: indiccd.h:32
Ekos::Guide::addST4
void addST4(ISD::ST4 *newST4)
Definition: guide.cpp:201
ISD::DeviceDecorator::isConnected
virtual bool isConnected()
Definition: indistd.cpp:718
ISD::DeviceDecorator::getBaseDevice
virtual INDI::BaseDevice * getBaseDevice()
Definition: indistd.cpp:708
fitsviewer.h
Ekos::Guide::addGuideHead
void addGuideHead()
Definition: guide.cpp:99
Ekos::Guide::Guide
Guide()
Definition: guide.cpp:33
ISD::CCD
Definition: indiccd.h:73
rguider::fill_interface
void fill_interface(void)
Definition: guider.cpp:128
FITSViewer::filterTypes
static QStringList filterTypes
Definition: fitsviewer.h:71
Ekos::Guide::getReticleAngle
double getReticleAngle()
Definition: guide.cpp:339
FITSViewer
Definition: fitsviewer.h:51
cgmath::set_image
void set_image(FITSView *image)
Definition: gmath.cpp:125
ISD::GDInterface
Definition: indistd.h:48
FRAME_LIGHT
Definition: indicommon.h:68
ISD::ST4::doPulse
bool doPulse(GuideDirection ra_dir, int ra_msecs, GuideDirection dec_dir, int dec_msecs)
Definition: indistd.cpp:755
FITS_GUIDE
Definition: fitscommon.h:20
rcalibration::process_calibration
void process_calibration()
Definition: rcalibration.cpp:267
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal