VEXPController.cpp 17.3 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

	bool running = scanController->commandStatus.isRunning();
	runningScan.update(running);

	if (running) {
		// Get ki, kf, fixed, ss when the scan is starting.
yannick legoc's avatar
yannick legoc committed
242
243
244
245
		updateFloat64PropertyValue(kiScan, ki());
		updateFloat64PropertyValue(kfScan, kf());
		updateInt32PropertyValue(fxScan, fx());
		updateInt32PropertyValue(ssScan, ss());
246
	}
247
248
}

ics's avatar
ics committed
249
void VEXPController::updateProperties() {
legoc's avatar
legoc committed
250

legoc's avatar
legoc committed
251
	// Copy the values.
yannick legoc's avatar
yannick legoc committed
252
253
254
255
256
257
258
259
260
261
262
263
	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
264
265
266
267

	updateUMatrix();
	updateBMatrix();

yannick legoc's avatar
yannick legoc committed
268
269
270
271
272
273
274
	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
275

yannick legoc's avatar
yannick legoc committed
276
277
	updateFloat64PropertyValue(ki, incidentBeam->ki());
	updateFloat64PropertyValue(kf, scatteredBeam->kf());
ics's avatar
ics committed
278
279
280
281

	a1.update(a1Controller->position());
	a2.update(a2Controller->position());
	a3.update(a3Controller->position());
yannick legoc's avatar
yannick legoc committed
282
	a3p.update(a3pController->position());
ics's avatar
ics committed
283
284
285
	a4.update(a4Controller->position());
	a5.update(a5Controller->position());
	a6.update(a6Controller->position());
286

yannick legoc's avatar
yannick legoc committed
287
288
289
290
	updateFloat64PropertyValue(qhScan, scanController->reference.get(0));
	updateFloat64PropertyValue(qkScan, scanController->reference.get(1));
	updateFloat64PropertyValue(qlScan, scanController->reference.get(2));
	updateFloat64PropertyValue(enScan, scanController->reference.get(3));
291

yannick legoc's avatar
yannick legoc committed
292
293
294
295
	updateFloat64PropertyValue(dqhScan, scanController->delta.get(0));
	updateFloat64PropertyValue(dqkScan, scanController->delta.get(1));
	updateFloat64PropertyValue(dqlScan, scanController->delta.get(2));
	updateFloat64PropertyValue(denScan, scanController->delta.get(3));
296

yannick legoc's avatar
yannick legoc committed
297
	updateInt32PropertyValue(nbPointsScan, scanController->nSteps.get(0));
298
	runningScan.update(scanController->commandStatus.isRunning());
ics's avatar
ics committed
299
300
}

yannick legoc's avatar
yannick legoc committed
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
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
325
void VEXPController::postConfiguration() {
326
327

	// Register the property updaters.
yannick legoc's avatar
yannick legoc committed
328
329
330
331
332
333
334
335
336
337
338
339
	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
340
341
342
343

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

yannick legoc's avatar
yannick legoc committed
344
345
346
347
348
349
350
	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
351

yannick legoc's avatar
yannick legoc committed
352
353
	registerFloat64PropertyUpdater(incidentBeam->ki, ki);
	registerFloat64PropertyUpdater(scatteredBeam->kf, kf);
ics's avatar
ics committed
354
355
356
357

	registerPropertyCopierByUpdate(a1Controller->position, a1);
	registerPropertyCopierByUpdate(a2Controller->position, a2);
	registerPropertyCopierByUpdate(a3Controller->position, a3);
yannick legoc's avatar
yannick legoc committed
358
	registerPropertyCopierByUpdate(a3pController->position, a3p);
ics's avatar
ics committed
359
360
361
362
363
364
365
366
367
	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.
368
369
370
	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
371
	registerRefresher(calca3p, &VEXPController::refreshFloat64PropertyToMoveModel, this, a3pController->position);
372
373
374
	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
375

376
377
378
	// Scan properties.
	registerUpdater(scanController->reference, &VEXPController::updateScanReference, this);
	registerUpdater(scanController->delta, &VEXPController::updateScanDelta, this);
379
	registerUpdater(scanController->nSteps, &VEXPController::updateNbPoints, this);
380
381
	registerStatus(scanController, &VEXPController::updateScanStatus, this);

ics's avatar
ics committed
382
	updateProperties();
yannick legoc's avatar
yannick legoc committed
383
384
385
386
387

	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
388
389
}

390
void VEXPController::calculate(float64 ki, float64 kf, float64 qh, float64 qk, float64 ql, int32 fx, int32 ss) {
ics's avatar
ics committed
391
392
393

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

ics's avatar
ics committed
396
397
398
399
400
401
402
403
404
405
406
407
408
	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();
409
			calculationError = incidentBeam->calcError();
ics's avatar
ics committed
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
		}
		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();
429
			calculationError = scatteredBeam->calcError();
ics's avatar
ics committed
430
431
432
433
434
435
436
437
438
439
440
441
442
443
		}
		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;
444
		scattering->calcsens = ss;
ics's avatar
ics committed
445
446

		// Calculate by fixing Ki.
447
		scattering->calculate(tas::Beam::K_MODE, fx);
ics's avatar
ics committed
448
449
450
451
452

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

453
454
455
456
457
458
459
//		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
460
461
462
463
464


		// Manage the status.
		if (scattering->calcStatus.isError()) {
			calculationStatus.setError();
465
			calculationError = scattering->calcError();
ics's avatar
ics committed
466
467
468
469
470
		}
		else if (scattering->calcStatus.isWarning() && !calculationStatus.isError()) {
			calculationStatus.setWarning();
			cerr << "Warning: Calculated Kf are different" << endl;
		}
ics's avatar
ics committed
471
	}
ics's avatar
ics committed
472
	catch (...) {
ics's avatar
ics committed
473
		calculationStatus.setError();
474
		calculationError = 0;
ics's avatar
ics committed
475
476
	}

477
478
479
//	if (calculationError() != 0) {
//		cout << "VEXP error " << calculationError() << endl;
//	}
legoc's avatar
legoc committed
480
481
}

yannick legoc's avatar
yannick legoc committed
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
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());

	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
551
}