magnetps.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 magnetpsH
15 #define magnetpsH
16 //---------------------------------------------------------------------------
17 #include "primarydriverwiththread.h"
18 #include "xnodeconnector.h"
19 
20 class XScalarEntry;
21 class QMainWindow;
22 class Ui_FrmMagnetPS;
24 class Ui_FrmMagnetPSConfig;
26 
27 class DECLSPEC_SHARED XMagnetPS : public XPrimaryDriverWithThread {
28 public:
29  XMagnetPS(const char *name, bool runtime,
30  Transaction &tr_meas, const shared_ptr<XMeasure> &meas);
31  //! usually nothing to do
32  virtual ~XMagnetPS() {}
33  //! Shows all forms belonging to driver
34  virtual void showForms();
35 
36  struct Payload : public XPrimaryDriver::Payload {
37  double magnetField() const {return m_magnetField;}
38  double outputCurrent() const {return m_outputCurrent;}
39  private:
40  friend class XMagnetPS;
41  double m_magnetField;
42  double m_outputCurrent;
43  };
44 protected:
45  //! This function will be called when raw data are written.
46  //! Implement this function to convert the raw data to the record (Payload).
47  //! \sa analyze()
48  virtual void analyzeRaw(RawDataReader &reader, Transaction &tr) throw (XRecordError&);
49  //! This function is called after committing XPrimaryDriver::analyzeRaw() or XSecondaryDriver::analyze().
50  //! This might be called even if the record is invalid (time() == false).
51  virtual void visualize(const Snapshot &shot);
52 
53  //! driver specific part below
54  const shared_ptr<XScalarEntry> &field() const {return m_field;}
55  const shared_ptr<XScalarEntry> &current() const {return m_current;}
56 
57  const shared_ptr<XDoubleNode> &targetField() const {return m_targetField;}
58  const shared_ptr<XDoubleNode> &sweepRate() const {return m_sweepRate;}
59  const shared_ptr<XBoolNode> &allowPersistent() const {return m_allowPersistent;}
60  const shared_ptr<XComboNode> &approach() const {return m_approach;}
61 
62  //! averaged err between magnet field and target one
63  const shared_ptr<XDoubleNode> &stabilized() const {return m_stabilized;}
64 protected:
65  const shared_ptr<XDoubleNode> &magnetField() const {return m_magnetField;}
66  const shared_ptr<XDoubleNode> &outputField() const {return m_outputField;}
67  const shared_ptr<XDoubleNode> &outputCurrent() const {return m_outputCurrent;}
68  const shared_ptr<XDoubleNode> &outputVolt() const {return m_outputVolt;}
69  const shared_ptr<XBoolNode> &pcsHeater() const {return m_pcsHeater;}
70  const shared_ptr<XBoolNode> &persistent() const {return m_persistent;}
71 
72  virtual double fieldResolution() = 0;
73  virtual void toNonPersistent() = 0;
74  virtual void toPersistent() = 0;
75  virtual void toZero() = 0;
76  virtual void toSetPoint() = 0;
77  virtual void setPoint(double field) = 0;
78  virtual void setRate(double hpm) = 0;
79  virtual double getPersistentField() = 0;
80  virtual double getOutputField() = 0;
81  virtual double getTargetField() = 0;
82  virtual double getSweepRate() = 0;
83  virtual double getOutputVolt() = 0;
84  virtual double getOutputCurrent() = 0;
85  //! Persistent Current Switch Heater
86  virtual bool isPCSHeaterOn() = 0;
87  //! please return false if no PCS fitted
88  virtual bool isPCSFitted() = 0;
89  virtual bool canChangePolarityDuringSweep() {return true;}
90 private:
91  virtual void onRateChanged(const Snapshot &shot, XValueNodeBase *);
92  virtual void onConfigShow(const Snapshot &shot, XTouchableNode *);
93 
94  const shared_ptr<XScalarEntry> m_field, m_current;
95  const shared_ptr<XScalarEntryList> m_entries;
96 
97  const shared_ptr<XDoubleNode> m_targetField;
98  const shared_ptr<XDoubleNode> m_sweepRate;
99  const shared_ptr<XBoolNode> m_allowPersistent;
100  enum {APPROACH_LINEAR = 0, APPROACH_OSC = 1};
101  const shared_ptr<XComboNode> m_approach;
102  //! averaged err between magnet field and target one
103  const shared_ptr<XDoubleNode> m_stabilized;
104  const shared_ptr<XDoubleNode> m_magnetField, m_outputField, m_outputCurrent, m_outputVolt;
105  const shared_ptr<XBoolNode> m_pcsHeater, m_persistent, m_aborting;
106 
107  const shared_ptr<XTouchableNode> m_configShow;
108  //! Rate limiting. [T/min] and [T].
109  const shared_ptr<XDoubleNode> m_rateLimit1, m_rateLimit1UBound;
110  const shared_ptr<XDoubleNode> m_rateLimit2, m_rateLimit2UBound;
111  const shared_ptr<XDoubleNode> m_rateLimit3, m_rateLimit3UBound;
112  const shared_ptr<XDoubleNode> m_rateLimit4, m_rateLimit4UBound;
113  const shared_ptr<XDoubleNode> m_rateLimit5, m_rateLimit5UBound;
114 
115  const shared_ptr<XDoubleNode> m_secondaryPSMultiplier; //!< For Shim coil. [T/T]
116  const shared_ptr<XItemNode<XDriverList, XMagnetPS> > m_secondaryPS; //!< For Shim coil
117 
118  //! Configuration for safe conditions.
119  const shared_ptr<XItemNode<XScalarEntryList, XScalarEntry> > m_safeCond1Entry;
120  const shared_ptr<XDoubleNode> m_safeCond1Min, m_safeCond1Max;
121  const shared_ptr<XItemNode<XScalarEntryList, XScalarEntry> > m_safeCond2Entry;
122  const shared_ptr<XDoubleNode> m_safeCond2Min, m_safeCond2Max;
123  const shared_ptr<XItemNode<XScalarEntryList, XScalarEntry> > m_safeCond3Entry;
124  const shared_ptr<XDoubleNode> m_safeCond3Min, m_safeCond3Max;
125 
126  const shared_ptr<XItemNode<XScalarEntryList, XScalarEntry> > m_persistentCondEntry;
127  const shared_ptr<XDoubleNode> m_persistentCondMax;
128  const shared_ptr<XItemNode<XScalarEntryList, XScalarEntry> > m_nonPersistentCondEntry;
129  const shared_ptr<XDoubleNode> m_nonPersistentCondMin;
130 
131  const shared_ptr<XDoubleNode> m_pcshWait; //!< [sec]
132 
133  shared_ptr<XListener> m_lsnRate, m_lsnConfigShow;
134 
135  xqcon_ptr m_conAllowPersistent;
136  xqcon_ptr m_conTargetField, m_conSweepRate;
137  xqcon_ptr m_conMagnetField, m_conOutputField, m_conOutputCurrent, m_conOutputVolt;
138  xqcon_ptr m_conPCSH, m_conPersist, m_conAborting, m_conApproach;
139  xqcon_ptr m_conConfigShow;
140  xqcon_ptr m_conRateLimit1, m_conRateLimit1UBound;
141  xqcon_ptr m_conRateLimit2, m_conRateLimit2UBound;
142  xqcon_ptr m_conRateLimit3, m_conRateLimit3UBound;
143  xqcon_ptr m_conRateLimit4, m_conRateLimit4UBound;
144  xqcon_ptr m_conRateLimit5, m_conRateLimit5UBound;
145  xqcon_ptr m_conSecondaryPS, m_conSecondaryPSMultiplier;
146  xqcon_ptr m_conSafeCond1Entry, m_conSafeCond1Min, m_conSafeCond1Max;
147  xqcon_ptr m_conSafeCond2Entry, m_conSafeCond2Min, m_conSafeCond2Max;
148  xqcon_ptr m_conSafeCond3Entry, m_conSafeCond3Min, m_conSafeCond3Max;
149  xqcon_ptr m_conPersistentCondEntry, m_conPersistentCondMax;
150  xqcon_ptr m_conNonPersistentCondEntry, m_conNonPersistentCondMin;
151  xqcon_ptr m_conPCSHWait;
152 
153  const qshared_ptr<FrmMagnetPS> m_form;
154  const qshared_ptr<FrmMagnetPSConfig> m_formConfig;
155  const shared_ptr<XStatusPrinter> m_statusPrinter;
156 
157  void *execute(const atomic<bool> &);
158 
159  bool isSafeConditionSatisfied(const Snapshot &shot, const Snapshot &shot_entries);
160  bool isPersistentStabilized(const Snapshot &shot, const Snapshot &shot_entries, const XTime &pcsh_off_time);
161  bool isNonPersistentStabilized(const Snapshot &shot, const Snapshot &shot_entries, const XTime &pcsh_on_time);
162  double limitSweepRate(double field, double rate, const Snapshot &shot);
163  double limitTargetField(double field, const Snapshot &shot);
164 };
165 
166 #endif

Generated for KAME4 by  doxygen 1.8.3