qdppms.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2016 Shota Suetsugu and 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 #include "qdppms.h"
15 #include "analyzer.h"
16 #include "ui_qdppmsform.h"
17 
18 XQDPPMS::XQDPPMS(const char *name, bool runtime,
19  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
20  XPrimaryDriverWithThread(name, runtime, ref(tr_meas), meas),
21  m_temp(create<XScalarEntry>("Temp", false,
22  dynamic_pointer_cast<XDriver>(shared_from_this()), "%.3f")),
23  m_user_temp(create<XScalarEntry>("UserTemp", false,
24  dynamic_pointer_cast<XDriver>(shared_from_this()), "%.3f")),
25  m_field(create<XScalarEntry>("Field", false,
26  dynamic_pointer_cast<XDriver>(shared_from_this()), "%.3f")),
27  m_position(create<XScalarEntry>("Position", false,
28  dynamic_pointer_cast<XDriver>(shared_from_this()), "%.3f")),
29  m_heliumLevel(create<XDoubleNode>("HeliumLevel", false)),
30  m_targetField(create<XDoubleNode>("TargetField",true)),
31  m_fieldSweepRate(create<XDoubleNode>("FieldSweepRate",true)),
32  m_fieldApproachMode(create<XComboNode>("FieldApproachMode",true,true)),
33  m_fieldMagnetMode(create<XComboNode>("FieldMagnetMode",true,true)),
34  m_fieldStatus(create<XStringNode>("FieldStatus",false)),
35  m_targetPosition(create<XDoubleNode>("TargetPosition",true)),
36  m_positionApproachMode(create<XComboNode>("PositionApproachMode",true,true)),
37  m_positionSlowDownCode(create<XIntNode>("PositionSlowDownCode",true)),
38  m_positionStatus(create<XStringNode>("PositionStatus",false)),
39  m_targetTemp(create<XDoubleNode>("TargetTemp",true)),
40  m_tempSweepRate(create<XDoubleNode>("TempSweepRate",true)),
41  m_tempApproachMode(create<XComboNode>("TempApproachMode",true,true)),
42  m_tempStatus(create<XStringNode>("TempStatus",false)),
43  m_form(new FrmQDPPMS(g_pFrmMain)) {
44  meas->scalarEntries()->insert(tr_meas, m_temp);
45  meas->scalarEntries()->insert(tr_meas, m_user_temp);
46  meas->scalarEntries()->insert(tr_meas, m_field);
47  meas->scalarEntries()->insert(tr_meas, m_position);
48 
49  m_form->setWindowTitle(XString("QDPPMS - " + getLabel() ));
50 
51  m_conUIs = {
52  xqcon_create<XQLCDNumberConnector>(temp()->value(), m_form->m_lcdTemp),
53  xqcon_create<XQLCDNumberConnector>(user_temp()->value(), m_form->m_lcdUserTemp),
54  xqcon_create<XQLCDNumberConnector>(field()->value(), m_form->m_lcdField),
55  xqcon_create<XQLCDNumberConnector>(position()->value(), m_form->m_lcdPosition),
56  xqcon_create<XQLCDNumberConnector>(heliumLevel(), m_form->m_lcdHeliumLevel),
57  xqcon_create<XQLineEditConnector>(targetField(), m_form->m_edTargetField),
58  xqcon_create<XQLineEditConnector>(fieldSweepRate(), m_form->m_edFieldSweepRate),
59  xqcon_create<XQComboBoxConnector>(fieldApproachMode(), m_form->m_cmbFieldApproachMode, Snapshot( *m_fieldApproachMode)),
60  xqcon_create<XQComboBoxConnector>(fieldMagnetMode(), m_form->m_cmbMagnetMode, Snapshot( *m_fieldMagnetMode)),
61  xqcon_create<XQLabelConnector>(fieldStatus(), m_form->m_labelFieldStatus),
62  xqcon_create<XQLineEditConnector>(targetTemp(), m_form->m_edTargetTemp),
63  xqcon_create<XQLineEditConnector>(tempSweepRate(), m_form->m_edTempSweepRate),
64  xqcon_create<XQComboBoxConnector>(tempApproachMode(), m_form->m_cmbTempApproachMode, Snapshot( *m_tempApproachMode)),
65  xqcon_create<XQLabelConnector>(tempStatus(), m_form->m_labelTempStatus),
66  xqcon_create<XQLineEditConnector>(targetPosition(), m_form->m_edTargetPosition),
67  xqcon_create<XQComboBoxConnector>(positionApproachMode(), m_form->m_cmbPositionApproachMode, Snapshot( *m_positionApproachMode)),
68  xqcon_create<XQLineEditConnector>(positionSlowDownCode(), m_form->m_edPositionSlowDownCode),
69  xqcon_create<XQLabelConnector>(positionStatus(), m_form->m_labelPositionStatus)
70  };
71 
72  iterate_commit([=](Transaction &tr){
73  tr[ *fieldApproachMode()].add({"Linear", "No Overshoot", "Oscillate"});
74  tr[ *fieldMagnetMode()].add({"Persistent", "Driven"});
75  tr[ *positionApproachMode()].add("default");
76  tr[ *positionSlowDownCode()] = 0;
77  tr[ *tempApproachMode()].add({"FastSettle", "No Overshoot"});
78  std::vector<shared_ptr<XNode>> runtime_ui{
79  targetField(), fieldSweepRate(), fieldApproachMode(),
80  fieldMagnetMode(), targetTemp(), tempSweepRate(), tempApproachMode(),
81  targetPosition(), positionApproachMode(), positionSlowDownCode()
82  };
83  for(auto &&x: runtime_ui)
84  tr[ *x].setUIEnabled(false);
85  });
86 
87 }
88 void
90  m_form->showNormal();
91  m_form->raise();
92 }
93 void
95  tr[ *this].m_sampleTemp = reader.pop<float>();
96  tr[ *this].m_sampleUserTemp = reader.pop<float>();
97  tr[ *this].m_magnetField = reader.pop<float>();
98  tr[ *this].m_samplePosition = reader.pop<float>();
99  m_temp->value(tr, tr[ *this].m_sampleTemp);
100  m_user_temp->value(tr, tr[ *this].m_sampleUserTemp);
101  m_field->value(tr, tr[ *this].m_magnetField);
102  m_position->value(tr, tr[*this].m_samplePosition);
103 }
104 void
106 }
107 
108 
109 void
110 XQDPPMS::onFieldChanged(const Snapshot &shot, XValueNodeBase *){
111  double sweepRate = ***fieldSweepRate();
112  int approachMode = ***fieldApproachMode();
113  int magnetMode = ***fieldMagnetMode();
114  try {
115  setField(shot[ *targetField()], sweepRate,
116  approachMode, magnetMode);
117  }
118  catch (XKameError &e) {
119  e.print(getLabel() + "; ");
120  }
121 }
122 
123 void
124 XQDPPMS::onPositionChanged(const Snapshot &shot, XValueNodeBase *){
125  int approachMode = ***positionApproachMode();
126  int slowDownCode = ***positionSlowDownCode();
127  try {
128  setPosition(shot[ *targetPosition()], approachMode, slowDownCode);
129  }
130  catch (XKameError &e) {
131  e.print(getLabel() + "; ");
132  }
133 }
134 
135 void
136 XQDPPMS::onTempChanged(const Snapshot &shot, XValueNodeBase *){
137  double sweepRate = ***tempSweepRate();
138  int approachMode = ***tempApproachMode();
139  try {
140  setTemp(shot[ *targetTemp()], sweepRate, approachMode);
141  }
142  catch (XKameError &e) {
143  e.print(getLabel() + "; ");
144  }
145 }
146 
147 void *
148 XQDPPMS::execute(const atomic<bool> &terminated) {
149  std::vector<shared_ptr<XNode>> runtime_ui{
150  targetField(), fieldSweepRate(), fieldApproachMode(),
151  fieldMagnetMode(), targetTemp(), tempSweepRate(), tempApproachMode(),
152  targetPosition(), positionApproachMode(), positionSlowDownCode()
153  };
154  iterate_commit([=](Transaction &tr){
155  for(auto &&x: runtime_ui)
156  tr[ *x].setUIEnabled(true);
157 
158  m_lsnFieldSet = tr[ *targetField()].onValueChanged().connectWeakly(
159  shared_from_this(), &XQDPPMS::onFieldChanged);
160  m_lsnTempSet = tr[ *targetTemp()].onValueChanged().connectWeakly(
161  shared_from_this(), &XQDPPMS::onTempChanged);
162  m_lsnPositionSet = tr[ *targetPosition()].onValueChanged().connectWeakly(
163  shared_from_this(), &XQDPPMS::onPositionChanged);
164  });
165 
166  while( !terminated) {
167  msecsleep(100);
168  double magnet_field;
169  double sample_temp;
170  double sample_user_temp;
171  double sample_position;
172  double helium_level;
173  int status;
174 
175  try {
176  // Reading....
177  magnet_field = getField();
178  sample_temp = getTemp();
179  sample_user_temp = getUserTemp();
180  sample_position = getPosition();
181  helium_level = getHeliumLevel();
182  status = getStatus();
183  }
184  catch (XKameError &e) {
185  e.print(getLabel() + "; ");
186  continue;
187  }
188  auto writer = std::make_shared<RawData>();
189  writer->push((float)sample_temp);
190  writer->push((float)sample_user_temp);
191  writer->push((float)magnet_field);
192  writer->push((float)sample_position);
193 
194  finishWritingRaw(writer, XTime::now(), XTime::now());
195 
196  try{
197  iterate_commit([=](Transaction &tr){
198  tr[ *heliumLevel()] = helium_level;
199  tr[ *tempStatus()] = std::map<int,std::string>{
200  {0x0,"Unknown"},
201  {0x1,"Stable"},
202  {0x2,"Tracking"},
203  {0x5,"Near"},
204  {0x6,"Chasing"},
205  {0x7,"Pot Ops"},
206  {0xa,"Standby"},
207  {0xd,"Control Disabled"},
208  {0xe,"Cannot Complete"},
209  {0xf,"Failure"}
210  }.at(status & 0xf);
211  tr[ *fieldStatus()] = std::map<int,std::string>{
212  {0x0,"Unknown"},
213  {0x1,"Persistent"},
214  {0x2,"SW-Warm"},
215  {0x3,"SW-Cool"},
216  {0x4,"Holding"},
217  {0x5,"Itelate"},
218  {0x6,"Charging"},
219  {0x7,"Discharging"},
220  {0x8,"CurrentError"},
221  {0xf,"Failure"}
222  }.at((status >> 4) & 0xf);
223  tr[ *positionStatus()] = std::map<int,std::string>{
224  {0x0,"Unknown"},
225  {0x1,"Stopped"},
226  {0x5,"Moving"},
227  {0x8,"Limit"},
228  {0x9,"Index"},
229  {0xf,"Failure"}
230  }.at((status >> 12) & 0xf);
231  });
232  }
233  catch (std::out_of_range &) {
234  gErrPrint(i18n("PPMS: unknown status has been returned."));
235  }
236  }
237 
238  iterate_commit([=](Transaction &tr){
239  for(auto &&x: runtime_ui)
240  tr[ *x].setUIEnabled(false);
241  });
242 
243  m_lsnFieldSet.reset();
244  m_lsnTempSet.reset();
245  m_lsnPositionSet.reset();
246 
247  return NULL;
248 }

Generated for KAME4 by  doxygen 1.8.3