autolctuner.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #ifndef AUTOLCTUNER_H_
15 #define AUTOLCTUNER_H_
16 //---------------------------------------------------------------------------
17 #include "secondarydriver.h"
18 #include "motor.h"
19 #include "networkanalyzer.h"
20 //---------------------------------------------------------------------------
21 class Ui_FrmAutoLCTuner;
23 
24 /*
25 * Tunes the reflection at the target frequency to zero.
26 */
28 public:
29  XAutoLCTuner(const char *name, bool runtime,
30  Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
31  virtual ~XAutoLCTuner();
32 
33  //! Shows all forms belonging to driver
34  virtual void showForms();
35 protected:
36 
37  //! This function is called when a connected driver emit a signal
38  virtual void analyze(Transaction &tr, const Snapshot &shot_emitter,
39  const Snapshot &shot_others,
40  XDriver *emitter) throw (XRecordError&);
41  //! This function is called after committing XPrimaryDriver::analyzeRaw() or XSecondaryDriver::analyze().
42  //! This might be called even if the record is invalid (time() == false).
43  virtual void visualize(const Snapshot &shot);
44  //! Checks if the connected drivers have valid time stamps.
45  //! \return true if dependency is resolved.
46  //! This function must be reentrant unlike analyze().
47  virtual bool checkDependency(const Snapshot &shot_this,
48  const Snapshot &shot_emitter, const Snapshot &shot_others,
49  XDriver *emitter) const;
50 public:
51  const shared_ptr<XItemNode<XDriverList, XMotorDriver> > &stm1() const {return m_stm1;}
52  const shared_ptr<XItemNode<XDriverList, XMotorDriver> > &stm2() const {return m_stm2;}
53  const shared_ptr<XItemNode<XDriverList, XNetworkAnalyzer> > &netana() const {return m_netana;}
54 
55  /// Target frequency [MHz]
56  const shared_ptr<XBoolNode> &tuning() const {return m_tuning;}
57  const shared_ptr<XBoolNode> &succeeded() const {return m_succeeded;}
58  const shared_ptr<XDoubleNode> &target() const {return m_target;}
59  const shared_ptr<XDoubleNode> &reflectionTargeted() const {return m_reflectionTargeted;}
60  const shared_ptr<XDoubleNode> &reflectionRequired() const {return m_reflectionRequired;}
61  const shared_ptr<XBoolNode> &useSTM1() const {return m_useSTM1;}
62  const shared_ptr<XBoolNode> &useSTM2() const {return m_useSTM2;}
63  const shared_ptr<XTouchableNode> &abortTuning() const {return m_abortTuning;}
64 
66  public:
67  enum STAGE {STAGE_FIRST, STAGE_DCA, STAGE_DCB};
68  STAGE stage;
69 
70  std::complex<double> ref_first, ref_plus_dCa;
71  double fmin_first, fmin_plus_dCa;
72  double dCa, dCb;
73 
74  std::complex<double> dref_dCa, dref_dCb;
75  double dfmin_dCa, dfmin_dCb;
76 
77  std::vector<std::complex<double> > trace;
78  double stm1, stm2;
79  double sor_factor;
80  int iteration_count;
81  double stm1_best, stm2_best;
82  std::complex<double> ref_f0_best;
83  double fmin_best;
84  enum MODE {TUNE_APPROACHING, TUNE_FINETUNE};
85  MODE mode;
86  bool isSTMChanged;
87  XTime started;
88  bool isTargetAbondoned;
89  };
90 private:
91  const shared_ptr<XItemNode<XDriverList, XMotorDriver> > m_stm1, m_stm2;
92  const shared_ptr<XItemNode<XDriverList, XNetworkAnalyzer> > m_netana;
93 
94  const shared_ptr<XBoolNode> m_tuning;
95  const shared_ptr<XBoolNode> m_succeeded;
96  const shared_ptr<XDoubleNode> m_target;
97  const shared_ptr<XDoubleNode> m_reflectionTargeted;
98  const shared_ptr<XDoubleNode> m_reflectionRequired;
99  const shared_ptr<XBoolNode> m_useSTM1, m_useSTM2;
100  const shared_ptr<XTouchableNode> m_abortTuning;
101 
102  std::deque<xqcon_ptr> m_conUIs;
103 
104  shared_ptr<XListener> m_lsnOnTargetChanged, m_lsnOnAbortTouched;
105 
106  const qshared_ptr<FrmAutoLCTuner> m_form;
107 
108  void onTargetChanged(const Snapshot &shot, XValueNodeBase *);
109  void onAbortTuningTouched(const Snapshot &shot, XTouchableNode *);
110 
111  void determineNextC(double &deltaC1, double &deltaC2,
112  double x, double x_err,
113  double y, double y_err,
114  double dxdC1, double dxdC2,
115  double dydC1, double dydC2);
116  void abortTuningFromAnalyze(Transaction &tr, std::complex<double> reff0);
117  void rollBack(Transaction &tr);
118 };
119 
120 
121 
122 #endif /* AUTOLCTUNER_H_ */

Generated for KAME4 by  doxygen 1.8.3