VEXPController.cpp 17.9 KB
Newer Older
legoc's avatar
legoc committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Nomad Instrument Control Software
 *
 * Copyright 2011 Institut Laue-Langevin
 *
 * Licensed under the EUPL, Version 1.1 only (the "License");
 * You may not use this work except in compliance with the Licence.
 * You may obtain a copy of the Licence at:
 *
 * http://joinup.ec.europa.eu/software/page/eupl
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the Licence is distributed on an "AS IS" basis,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the Licence for the specific language governing permissions and
 * limitations under the Licence.
 */

#include "VEXPController.h"
#include "controllers/common/family/Families.h"
yannick legoc's avatar
yannick legoc committed
21
22
23
24
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/reader.h>
#include <rapidjson/stringbuffer.h>
yannick legoc's avatar
yannick legoc committed
25
#include <rapidjson/prettywriter.h>
yannick legoc's avatar
yannick legoc committed
26
#include <rapidjson/writer.h>
legoc's avatar
legoc committed
27

yannick legoc's avatar
yannick legoc committed
28
using namespace cameo;
ics's avatar
ics committed
29
using namespace std;
yannick legoc's avatar
yannick legoc committed
30
using namespace rapidjson;
legoc's avatar
legoc committed
31

legoc's avatar
legoc committed
32
33
34
35
36
namespace vexp {

const string VEXPController::TYPE = "vexp_controller";

VEXPController::VEXPController(const string& name) :
37
	ExperimentController(name) {
38

legoc's avatar
legoc committed
39
40
	setFamily(family::HIDDEN);

legoc's avatar
legoc committed
41
42
43
44
45
46
47
48
49
50
51
52
	as.init(this, NOSAVE, "as");
	bs.init(this, NOSAVE, "bs");
	cs.init(this, NOSAVE, "cs");
	aa.init(this, NOSAVE, "aa");
	bb.init(this, NOSAVE, "bb");
	cc.init(this, NOSAVE, "cc");
	ax.init(this, NOSAVE, "ax");
	ay.init(this, NOSAVE, "ay");
	az.init(this, NOSAVE, "az");
	bx.init(this, NOSAVE, "bx");
	by.init(this, NOSAVE, "by");
	bz.init(this, NOSAVE, "bz");
legoc's avatar
legoc committed
53
54
55
	u.init(this, NOSAVE, "Umatrix");
	b.init(this, NOSAVE, "Bmatrix");

legoc's avatar
legoc committed
56
57
58
59
60
	qh.init(this, NOSAVE, "qh");
	qk.init(this, NOSAVE, "qk");
	ql.init(this, NOSAVE, "ql");
	en.init(this, NOSAVE, "en");
	qm.init(this, NOSAVE, "qm");
61
	fx.init(this, NOSAVE, "fx");
62
	ss.init(this, NOSAVE, "ss");
legoc's avatar
legoc committed
63
64
65
66
67
68
69

	ki.init(this, NOSAVE, "ki");
	kf.init(this, NOSAVE, "kf");

	a1.init(this, NOSAVE, "a1");
	a2.init(this, NOSAVE, "a2");
	a3.init(this, NOSAVE, "a3");
yannick legoc's avatar
yannick legoc committed
70
	a3p.init(this, NOSAVE, "a3p");
legoc's avatar
legoc committed
71
72
73
74
	a4.init(this, NOSAVE, "a4");
	a5.init(this, NOSAVE, "a5");
	a6.init(this, NOSAVE, "a6");

ics's avatar
ics committed
75
76
77
78
79
	calcvalues.init(this, NOSAVE, "calcvalues");

	calca1.init(this, NOSAVE, "calca1");
	calca2.init(this, NOSAVE, "calca2");
	calca3.init(this, NOSAVE, "calca3");
yannick legoc's avatar
yannick legoc committed
80
	calca3p.init(this, NOSAVE, "calca3p");
ics's avatar
ics committed
81
82
83
84
	calca4.init(this, NOSAVE, "calca4");
	calca5.init(this, NOSAVE, "calca5");
	calca6.init(this, NOSAVE, "calca6");

85
	calculationStatus.init(this, NOSAVE, "calculation_status");
86
87
	calculationError.init(this, NOSAVE, "calculation_error");

legoc's avatar
legoc committed
88
	errorMessage.init(this, NOSAVE, "error_message");
89
	moveModel.init(this, SAVE, "move_model");
legoc's avatar
legoc committed
90

yannick legoc's avatar
yannick legoc committed
91
92
	spyPeriod.init(this, SAVE, "spy_period");

93
94
95
96
97
98
99
100
101
102
	qhScan.init(this, NOSAVE, "qh_scan");
	qkScan.init(this, NOSAVE, "qk_scan");
	qlScan.init(this, NOSAVE, "ql_scan");
	enScan.init(this, NOSAVE, "en_scan");

	dqhScan.init(this, NOSAVE, "dqh_scan");
	dqkScan.init(this, NOSAVE, "dqk_scan");
	dqlScan.init(this, NOSAVE, "dql_scan");
	denScan.init(this, NOSAVE, "den_scan");

103
104
105
106
107
	kiScan.init(this, NOSAVE, "ki_scan");
	kfScan.init(this, NOSAVE, "kf_scan");
	fxScan.init(this, NOSAVE, "fx_scan");
	ssScan.init(this, NOSAVE, "ss_scan");

108
109
110
	nbPointsScan.init(this, NOSAVE, "nb_points_scan");
	runningScan.init(this, NOSAVE, "running_scan");

legoc's avatar
legoc committed
111
112
113
114
115
	tasSettings.init(this, "tas_settings");
	sample.init(this, "sample");
	scattering.init(this, "scattering");
	incidentBeam.init(this, "incident_beam");
	scatteredBeam.init(this, "scattered_beam");
legoc's avatar
legoc committed
116
117
118
119

	a1Controller.init(this, "A1");
	a2Controller.init(this, "A2");
	a3Controller.init(this, "A3");
yannick legoc's avatar
yannick legoc committed
120
	a3pController.init(this, "A3P");
legoc's avatar
legoc committed
121
122
123
	a4Controller.init(this, "A4");
	a5Controller.init(this, "A5");
	a6Controller.init(this, "A6");
124
125

	scanController.init(this, "scan");
legoc's avatar
legoc committed
126
127
128
}

VEXPController::VEXPController(const VEXPController& controller) :
129
	ExperimentController(controller) {
legoc's avatar
legoc committed
130
131
132
}

VEXPController::~VEXPController() {
yannick legoc's avatar
yannick legoc committed
133
134
135
136
137

	m_running.store(false);
	if (m_periodicUpdateThread.get() != nullptr) {
		m_periodicUpdateThread->join();
	}
138
}
legoc's avatar
legoc committed
139
140
141
142

void VEXPController::updateUMatrix() {
	u.update(sample->uRef());
	u.setSize(sample->uRef.getSize());
143
	u.sendEvent();
legoc's avatar
legoc committed
144
145
146
147
148
}

void VEXPController::updateBMatrix() {
	b.update(tasSettings->b());
	b.setSize(tasSettings->b.getSize());
149
	b.sendEvent();
legoc's avatar
legoc committed
150
151
}

ics's avatar
ics committed
152
void VEXPController::refreshCalcParameters(const std::string& value) {
153

154
	//cout << "refreshCalcParameters " << value << endl;
155

ics's avatar
ics committed
156
157
158
	// Parse the values.
	rapidjson::Document document;
	document.Parse(value.c_str());
159

ics's avatar
ics committed
160
161
162
163
164
	rapidjson::Value& ki = document["ki"];
	rapidjson::Value& kf = document["kf"];
	rapidjson::Value& qh = document["qh"];
	rapidjson::Value& qk = document["qk"];
	rapidjson::Value& ql = document["ql"];
165
	rapidjson::Value& fx = document["fx"];
166
	rapidjson::Value& ss = document["ss"];
167

ics's avatar
ics committed
168
	// Calculate the angles and the status.
169
	calculate(ki.GetDouble(), kf.GetDouble(), qh.GetDouble(), qk.GetDouble(), ql.GetDouble(), fx.GetInt(), ss.GetInt());
170
171
}

172
double toDouble(double value) {
ics's avatar
ics committed
173

174
175
176
	if (isinf(value)) {
		return numeric_limits<double>::max();
	}
ics's avatar
ics committed
177

178
179
180
	if (isnan(value)) {
		return 0.0;
	}
legoc's avatar
legoc committed
181

182
183
	return value;
}
ics's avatar
ics committed
184

185
void VEXPController::refreshFloat64Property(SimpleProperty<float64>& property, float64 value) {
legoc's avatar
legoc committed
186
187
188

	// Update the value.
	property = value;
legoc's avatar
legoc committed
189
190
}

191
192
193
194
195
196
197
198
void VEXPController::refreshFloat64PropertyToMoveModel(SimpleProperty<float64>& property, float64 value) {

	// Update the value only in case moveModel is true.
	if (moveModel()) {
		property = value;
	}
}

199
200
201
void VEXPController::updateScanReference(int index) {

	if (index == 0) {
yannick legoc's avatar
yannick legoc committed
202
		updateFloat64PropertyValue(qhScan, scanController->reference.get(0));
203
204
	}
	else if (index == 1) {
yannick legoc's avatar
yannick legoc committed
205
		updateFloat64PropertyValue(qkScan, scanController->reference.get(1));
206
207
	}
	else if (index == 2) {
yannick legoc's avatar
yannick legoc committed
208
		updateFloat64PropertyValue(qlScan, scanController->reference.get(2));
209
210
	}
	else if (index == 3) {
yannick legoc's avatar
yannick legoc committed
211
		updateFloat64PropertyValue(enScan, scanController->reference.get(3));
212
213
214
215
216
217
	}
}

void VEXPController::updateScanDelta(int index) {

	if (index == 0) {
yannick legoc's avatar
yannick legoc committed
218
		updateFloat64PropertyValue(dqhScan, scanController->delta.get(0));
219
220
	}
	else if (index == 1) {
yannick legoc's avatar
yannick legoc committed
221
		updateFloat64PropertyValue(dqkScan, scanController->delta.get(1));
222
223
	}
	else if (index == 2) {
yannick legoc's avatar
yannick legoc committed
224
		updateFloat64PropertyValue(dqlScan, scanController->delta.get(2));
225
226
	}
	else if (index == 3) {
yannick legoc's avatar
yannick legoc committed
227
		updateFloat64PropertyValue(denScan, scanController->delta.get(3));
228
229
230
	}
}

231
void VEXPController::updateNbPoints(int index) {
yannick legoc's avatar
yannick legoc committed
232
	updateInt32PropertyValue(nbPointsScan, scanController->nSteps.get(0));
233
234
}

235
void VEXPController::updateScanStatus() {
236

237
238
239
240
241
242
243
244
245
246
247
248
249
250
	if (isHKLScan()) {
		bool running = scanController->commandStatus.isRunning();
		runningScan.update(running);

		if (running) {
			// Get ki, kf, fixed, ss when the scan is starting.
			updateFloat64PropertyValue(kiScan, ki());
			updateFloat64PropertyValue(kfScan, kf());
			updateInt32PropertyValue(fxScan, fx());
			updateInt32PropertyValue(ssScan, ss());
		}
	}
	else {
		runningScan.update(false);
251
	}
252
253
}

ics's avatar
ics committed
254
void VEXPController::updateProperties() {
legoc's avatar
legoc committed
255

legoc's avatar
legoc committed
256
	// Copy the values.
yannick legoc's avatar
yannick legoc committed
257
258
259
260
261
262
263
264
265
266
267
268
	updateFloat64PropertyValue(as, tasSettings->as());
	updateFloat64PropertyValue(bs, tasSettings->bs());
	updateFloat64PropertyValue(cs, tasSettings->cs());
	updateFloat64PropertyValue(aa, tasSettings->aa());
	updateFloat64PropertyValue(bb, tasSettings->bb());
	updateFloat64PropertyValue(cc, tasSettings->cc());
	updateFloat64PropertyValue(ax, tasSettings->ax());
	updateFloat64PropertyValue(ay, tasSettings->ay());
	updateFloat64PropertyValue(az, tasSettings->az());
	updateFloat64PropertyValue(bx, tasSettings->bx());
	updateFloat64PropertyValue(by, tasSettings->by());
	updateFloat64PropertyValue(bz, tasSettings->bz());
legoc's avatar
legoc committed
269
270
271
272

	updateUMatrix();
	updateBMatrix();

yannick legoc's avatar
yannick legoc committed
273
274
275
276
277
278
279
	updateFloat64PropertyValue(qh, scattering->qh());
	updateFloat64PropertyValue(qk, scattering->qk());
	updateFloat64PropertyValue(ql, scattering->ql());
	updateFloat64PropertyValue(en, scattering->en());
	updateFloat64PropertyValue(qm, scattering->qm());
	updateInt32PropertyValue(fx, scattering->fx());
	updateInt32PropertyValue(ss, scattering->sens());
ics's avatar
ics committed
280

yannick legoc's avatar
yannick legoc committed
281
282
	updateFloat64PropertyValue(ki, incidentBeam->ki());
	updateFloat64PropertyValue(kf, scatteredBeam->kf());
ics's avatar
ics committed
283
284
285
286

	a1.update(a1Controller->position());
	a2.update(a2Controller->position());
	a3.update(a3Controller->position());
yannick legoc's avatar
yannick legoc committed
287
	a3p.update(a3pController->position());
ics's avatar
ics committed
288
289
290
	a4.update(a4Controller->position());
	a5.update(a5Controller->position());
	a6.update(a6Controller->position());
291

yannick legoc's avatar
yannick legoc committed
292
293
294
295
	updateFloat64PropertyValue(qhScan, scanController->reference.get(0));
	updateFloat64PropertyValue(qkScan, scanController->reference.get(1));
	updateFloat64PropertyValue(qlScan, scanController->reference.get(2));
	updateFloat64PropertyValue(enScan, scanController->reference.get(3));
296

yannick legoc's avatar
yannick legoc committed
297
298
299
300
	updateFloat64PropertyValue(dqhScan, scanController->delta.get(0));
	updateFloat64PropertyValue(dqkScan, scanController->delta.get(1));
	updateFloat64PropertyValue(dqlScan, scanController->delta.get(2));
	updateFloat64PropertyValue(denScan, scanController->delta.get(3));
301

yannick legoc's avatar
yannick legoc committed
302
	updateInt32PropertyValue(nbPointsScan, scanController->nSteps.get(0));
303
304
305
306
307
308
309

	if (isHKLScan()) {
		runningScan.update(scanController->commandStatus.isRunning());
	}
	else {
		runningScan.update(false);
	}
ics's avatar
ics committed
310
311
}

yannick legoc's avatar
yannick legoc committed
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
void VEXPController::updateFloat64PropertyValue(SimpleProperty<float64>& property, float64 value) {
	property.update(value);
}

void VEXPController::updateFloat64Property(SimpleProperty<float64>& property, SimpleProperty<float64>& sourceProperty) {
	updateFloat64PropertyValue(property, sourceProperty());
}

void VEXPController::updateInt32PropertyValue(SimpleProperty<int32>& property, int32 value) {
	property.update(value);
}

void VEXPController::updateInt32Property(SimpleProperty<int32>& property, SimpleProperty<int32>& sourceProperty) {
	updateInt32PropertyValue(property, sourceProperty());
}

void VEXPController::registerFloat64PropertyUpdater(SimpleProperty<float64>& property, SimpleProperty<float64>& targetProperty) {
	registerUpdater(property, &VEXPController::updateFloat64Property, this, targetProperty, property);
}

void VEXPController::registerInt32PropertyUpdater(SimpleProperty<int32>& property, SimpleProperty<int32>& targetProperty) {
	registerUpdater(property, &VEXPController::updateInt32Property, this, targetProperty, property);
}

ics's avatar
ics committed
336
void VEXPController::postConfiguration() {
337
338

	// Register the property updaters.
yannick legoc's avatar
yannick legoc committed
339
340
341
342
343
344
345
346
347
348
349
350
	registerFloat64PropertyUpdater(tasSettings->as, as);
	registerFloat64PropertyUpdater(tasSettings->bs, bs);
	registerFloat64PropertyUpdater(tasSettings->cs, cs);
	registerFloat64PropertyUpdater(tasSettings->aa, aa);
	registerFloat64PropertyUpdater(tasSettings->bb, bb);
	registerFloat64PropertyUpdater(tasSettings->cc, cc);
	registerFloat64PropertyUpdater(tasSettings->ax, ax);
	registerFloat64PropertyUpdater(tasSettings->ay, ay);
	registerFloat64PropertyUpdater(tasSettings->az, az);
	registerFloat64PropertyUpdater(tasSettings->bx, bx);
	registerFloat64PropertyUpdater(tasSettings->by, by);
	registerFloat64PropertyUpdater(tasSettings->bz, bz);
legoc's avatar
legoc committed
351
352
353
354

	registerUpdater(sample->uRef, &VEXPController::updateUMatrix, this);
	registerUpdater(sample->b, &VEXPController::updateBMatrix, this);

yannick legoc's avatar
yannick legoc committed
355
356
357
358
359
360
361
	registerFloat64PropertyUpdater(scattering->qh, qh);
	registerFloat64PropertyUpdater(scattering->qk, qk);
	registerFloat64PropertyUpdater(scattering->ql, ql);
	registerFloat64PropertyUpdater(scattering->en, en);
	registerFloat64PropertyUpdater(scattering->qm, qm);
	registerInt32PropertyUpdater(scattering->fx, fx);
	registerInt32PropertyUpdater(scattering->sens, ss);
ics's avatar
ics committed
362

yannick legoc's avatar
yannick legoc committed
363
364
	registerFloat64PropertyUpdater(incidentBeam->ki, ki);
	registerFloat64PropertyUpdater(scatteredBeam->kf, kf);
ics's avatar
ics committed
365
366
367
368

	registerPropertyCopierByUpdate(a1Controller->position, a1);
	registerPropertyCopierByUpdate(a2Controller->position, a2);
	registerPropertyCopierByUpdate(a3Controller->position, a3);
yannick legoc's avatar
yannick legoc committed
369
	registerPropertyCopierByUpdate(a3pController->position, a3p);
ics's avatar
ics committed
370
371
372
373
374
375
376
377
378
	registerPropertyCopierByUpdate(a4Controller->position, a4);
	registerPropertyCopierByUpdate(a5Controller->position, a5);
	registerPropertyCopierByUpdate(a6Controller->position, a6);


	// To calculate the angles.
	registerRefresher(calcvalues, &VEXPController::refreshCalcParameters, this);

	// To move the model.
379
380
381
	registerRefresher(calca1, &VEXPController::refreshFloat64PropertyToMoveModel, this, a1Controller->position);
	registerRefresher(calca2, &VEXPController::refreshFloat64PropertyToMoveModel, this, a2Controller->position);
	registerRefresher(calca3, &VEXPController::refreshFloat64PropertyToMoveModel, this, a3Controller->position);
yannick legoc's avatar
yannick legoc committed
382
	registerRefresher(calca3p, &VEXPController::refreshFloat64PropertyToMoveModel, this, a3pController->position);
383
384
385
	registerRefresher(calca4, &VEXPController::refreshFloat64PropertyToMoveModel, this, a4Controller->position);
	registerRefresher(calca5, &VEXPController::refreshFloat64PropertyToMoveModel, this, a5Controller->position);
	registerRefresher(calca6, &VEXPController::refreshFloat64PropertyToMoveModel, this, a6Controller->position);
ics's avatar
ics committed
386

387
388
389
	// Scan properties.
	registerUpdater(scanController->reference, &VEXPController::updateScanReference, this);
	registerUpdater(scanController->delta, &VEXPController::updateScanDelta, this);
390
	registerUpdater(scanController->nSteps, &VEXPController::updateNbPoints, this);
391
392
	registerStatus(scanController, &VEXPController::updateScanStatus, this);

ics's avatar
ics committed
393
	updateProperties();
yannick legoc's avatar
yannick legoc committed
394
395
396
397
398

	m_spyPublisher = application::Publisher::create("vexp_spy");

	m_running.store(true);
	m_periodicUpdateThread.reset(new std::thread(std::bind(&VEXPController::periodicUpdate, this)));
ics's avatar
ics committed
399
400
}

401
void VEXPController::calculate(float64 ki, float64 kf, float64 qh, float64 qk, float64 ql, int32 fx, int32 ss) {
ics's avatar
ics committed
402
403
404

	// Reset status.
	calculationStatus.setIdle();
405
	calculationError = 0;
ics's avatar
ics committed
406

ics's avatar
ics committed
407
408
409
410
411
412
413
414
415
416
417
418
419
	try {
		// Ki.
		incidentBeam->calcki = ki;

		// calca1, calca2, calcStatus are calculated.
		incidentBeam->calculate(tas::Beam::K_MODE);

		calca1 = toDouble(incidentBeam->calca1());
		calca2 = toDouble(incidentBeam->calca2());

		// Manage the status.
		if (incidentBeam->calcStatus.isError()) {
			calculationStatus.setError();
420
			calculationError = incidentBeam->calcError();
ics's avatar
ics committed
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
		}
		else if (incidentBeam->calcStatus.isWarning()) {
			calculationStatus.setWarning();
		}

		//cout << "Ki -> status " << incidentBeam->calcStatus() << endl;

		// Kf.
		scatteredBeam->calckf = kf;

		// calca1, calca2, calcStatus are calculated.
		scatteredBeam->calculate(tas::Beam::K_MODE);

		calca5 = toDouble(scatteredBeam->calca5());
		calca6 = toDouble(scatteredBeam->calca6());

		// Manage the status.
		if (scatteredBeam->calcStatus.isError()) {
			calculationStatus.setError();
440
			calculationError = scatteredBeam->calcError();
ics's avatar
ics committed
441
442
443
444
445
446
447
448
449
450
451
452
453
454
		}
		else if (scatteredBeam->calcStatus.isWarning() && !calculationStatus.isError()) {
			calculationStatus.setWarning();
		}

		//cout << "Kf -> status " << scatteredBeam->calcStatus() << endl;

		// Q.
		scattering->calcqh = qh;
		scattering->calcqk = qk;
		scattering->calcql = ql;
		scattering->calcen = 2.072 * (ki * ki - kf * kf);
		scattering->calcki = ki;
		scattering->calckf = kf;
455
		scattering->calcsens = ss;
ics's avatar
ics committed
456
457

		// Calculate by fixing Ki.
458
		scattering->calculate(tas::Beam::K_MODE, fx);
ics's avatar
ics committed
459
460
461
462
463

		calca3 = toDouble(scattering->calca3());
		calca3p = toDouble(scattering->calca3p());
		calca4 = toDouble(scattering->calca4());

464
465
466
467
468
469
470
//		cout << "calc A1 " << calca1() << endl;
//		cout << "calc A2 " << calca2() << endl;
//		cout << "calc A3 " << calca3() << endl;
//		cout << "calc A3P " << calca3p() << endl;
//		cout << "calc A4 " << calca4() << endl;
//		cout << "calc A5 " << calca5() << endl;
//		cout << "calc A6 " << calca6() << endl << endl;
ics's avatar
ics committed
471
472
473
474
475


		// Manage the status.
		if (scattering->calcStatus.isError()) {
			calculationStatus.setError();
476
			calculationError = scattering->calcError();
ics's avatar
ics committed
477
478
479
480
481
		}
		else if (scattering->calcStatus.isWarning() && !calculationStatus.isError()) {
			calculationStatus.setWarning();
			cerr << "Warning: Calculated Kf are different" << endl;
		}
ics's avatar
ics committed
482
	}
ics's avatar
ics committed
483
	catch (...) {
ics's avatar
ics committed
484
		calculationStatus.setError();
485
		calculationError = 0;
ics's avatar
ics committed
486
487
	}

488
489
490
//	if (calculationError() != 0) {
//		cout << "VEXP error " << calculationError() << endl;
//	}
legoc's avatar
legoc committed
491
492
}

493
494
495
496
497
498
499
500
501
bool VEXPController::isHKLScan() {

	if (scanController->controller.get(0) != "Scattering") {
		return false;
	}

	return true;
}

yannick legoc's avatar
yannick legoc committed
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
std::string VEXPController::getSpyData() {

	PrettyWriter<StringBuffer> writer(s);
	s.Clear();

	writer.StartObject();

	writer.Key("as"); writer.Double(as());
	writer.Key("bs"); writer.Double(bs());
	writer.Key("cs"); writer.Double(cs());
	writer.Key("aa"); writer.Double(aa());
	writer.Key("bb"); writer.Double(bb());
	writer.Key("cc"); writer.Double(cc());
	writer.Key("ax"); writer.Double(ax());
	writer.Key("ay"); writer.Double(ay());
	writer.Key("az"); writer.Double(az());
	writer.Key("bx"); writer.Double(bx());
	writer.Key("by"); writer.Double(by());
	writer.Key("bz"); writer.Double(bz());
	writer.Key("qh"); writer.Double(qh());
	writer.Key("qk"); writer.Double(qk());
	writer.Key("ql"); writer.Double(ql());
	writer.Key("en"); writer.Double(en());
	writer.Key("qm"); writer.Double(qm());

	writer.Key("fx"); writer.Int(fx());
	writer.Key("ss"); writer.Int(ss());

	writer.Key("ki"); writer.Double(ki());
	writer.Key("kf"); writer.Double(kf());

	writer.Key("qhScan"); writer.Double(qhScan());
	writer.Key("qkScan"); writer.Double(qkScan());
	writer.Key("qlScan"); writer.Double(qlScan());
	writer.Key("enScan"); writer.Double(enScan());

	writer.Key("dqhScan"); writer.Double(dqhScan());
	writer.Key("dqkScan"); writer.Double(dqkScan());
	writer.Key("dqlScan"); writer.Double(dqlScan());
	writer.Key("denScan"); writer.Double(denScan());

	writer.Key("nbPointsScan"); writer.Int(nbPointsScan());

	writer.Key("kiScan"); writer.Double(kiScan());
	writer.Key("kfScan"); writer.Double(kfScan());

	writer.Key("fxScan"); writer.Int(fxScan());
	writer.Key("ssScan"); writer.Int(ssScan());

551
	writer.Key("dTypeScan"); writer.String(scanController->deltaType.get(0).c_str());
552
	writer.Key("runningScan"); writer.Bool(runningScan());
553
	writer.Key("nameScan"); writer.Int(scanController->numor());
554
	writer.Key("startingTime"); writer.String(scanController->startingTime().c_str());
555

yannick legoc's avatar
yannick legoc committed
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
	writer.EndObject();

	return s.GetString();
}

void VEXPController::periodicUpdate() {

	while (m_running.load()) {

		std::this_thread::yield();
		std::this_thread::sleep_for(std::chrono::seconds(spyPeriod()));

		std::lock_guard<std::mutex> lock(m_publisherMutex);

		// Send using the publisher.
		string spyData = getSpyData();
		m_spyPublisher->send(spyData);
	}
}

legoc's avatar
legoc committed
576
}