VEXPController.cpp 8.54 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
21
/*
 * 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"

legoc's avatar
legoc committed
22
23
using namespace boost;

legoc's avatar
legoc committed
24
25
26
27
28
namespace vexp {

const string VEXPController::TYPE = "vexp_controller";

VEXPController::VEXPController(const string& name) :
29
	ExperimentController(name) {
30

legoc's avatar
legoc committed
31
32
	setFamily(family::HIDDEN);

legoc's avatar
legoc committed
33
34
35
36
37
38
39
40
41
42
43
44
	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
45
46
47
	u.init(this, NOSAVE, "Umatrix");
	b.init(this, NOSAVE, "Bmatrix");

legoc's avatar
legoc committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
	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");

	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");
	a4.init(this, NOSAVE, "a4");
	a5.init(this, NOSAVE, "a5");
	a6.init(this, NOSAVE, "a6");

64
	calculationStatus.init(this, NOSAVE, "calculation_status");
legoc's avatar
legoc committed
65
	errorMessage.init(this, NOSAVE, "error_message");
66
	moveModel.init(this, SAVE, "move_model");
legoc's avatar
legoc committed
67
68
69
70
71
72

	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
73
74
75
76
77
78
79
80
81
82

	a1Controller.init(this, "A1");
	a2Controller.init(this, "A2");
	a3Controller.init(this, "A3");
	a4Controller.init(this, "A4");
	a5Controller.init(this, "A5");
	a6Controller.init(this, "A6");
}

VEXPController::VEXPController(const VEXPController& controller) :
83
	ExperimentController(controller) {
legoc's avatar
legoc committed
84
85
86
}

VEXPController::~VEXPController() {
87
}
legoc's avatar
legoc committed
88
89
90
91

void VEXPController::updateUMatrix() {
	u.update(sample->uRef());
	u.setSize(sample->uRef.getSize());
92
	u.sendEvent();
legoc's avatar
legoc committed
93
94
95
96
97
}

void VEXPController::updateBMatrix() {
	b.update(tasSettings->b());
	b.setSize(tasSettings->b.getSize());
98
	b.sendEvent();
legoc's avatar
legoc committed
99
100
}

101
102
void VEXPController::refreshKi(float64 value) {

legoc's avatar
legoc committed
103
	// Set the value.
104
105
	incidentBeam->calcki = value;

legoc's avatar
legoc committed
106
107
108
	// calca1, calca2, calcStatus are calculated.
	incidentBeam->calculate(tas::Beam::K_MODE);

109
110
111
112
113
	a1 = incidentBeam->calca1();
	a2 = incidentBeam->calca2();

	// Copy the status.
	calculationStatus.set(incidentBeam->calcStatus);
114
115

	//cout << "Ki -> status " << incidentBeam->calcStatus() << " " << scatteredBeam->calcStatus() << endl;
116
117
118
119
}

void VEXPController::refreshKf(float64 value) {

legoc's avatar
legoc committed
120
	// Set the value.
121
122
	scatteredBeam->calckf = value;

legoc's avatar
legoc committed
123
124
125
	// calca1, calca2, calcStatus are calculated.
	scatteredBeam->calculate(tas::Beam::K_MODE);

126
127
128
129
130
	a5 = scatteredBeam->calca5();
	a6 = scatteredBeam->calca6();

	// Copy the status.
	calculationStatus.set(scatteredBeam->calcStatus);
legoc's avatar
legoc committed
131

132
	//cout << "Kf -> status " << incidentBeam->calcStatus() << " " << scatteredBeam->calcStatus() << endl;
legoc's avatar
legoc committed
133
134
}

135
void VEXPController::refreshFloat64Property(SimpleProperty<float64>& property, float64 value) {
legoc's avatar
legoc committed
136
137
138

	// Update the value.
	property = value;
legoc's avatar
legoc committed
139
140
}

141
142
143
144
145
146
147
148
void VEXPController::refreshFloat64PropertyToMoveModel(SimpleProperty<float64>& property, float64 value) {

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

legoc's avatar
legoc committed
149
150
void VEXPController::postConfiguration() {

legoc's avatar
legoc committed
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
	// Copy the values.
	as.update(tasSettings->as());
	bs.update(tasSettings->bs());
	cs.update(tasSettings->cs());
	aa.update(tasSettings->aa());
	bb.update(tasSettings->bb());
	cc.update(tasSettings->cc());
	ax.update(tasSettings->ax());
	ay.update(tasSettings->ay());
	az.update(tasSettings->az());
	bx.update(tasSettings->bx());
	by.update(tasSettings->by());
	bz.update(tasSettings->bz());

	updateUMatrix();
	updateBMatrix();

168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Not used anymore

//	qh.update(scattering->qh.setpoint());
//	qk.update(scattering->qk.setpoint());
//	ql.update(scattering->ql.setpoint());
//	en.update(scattering->en.setpoint());
//	qm.update(scattering->qm.setpoint());
//
//	ki.update(incidentBeam->ki.setpoint());
//	kf.update(scatteredBeam->kf.setpoint());
//
//	a1.update(a1Controller->position.setpoint());
//	a2.update(a2Controller->position.setpoint());
//	a3.update(a3Controller->position.setpoint());
//	a4.update(a4Controller->position.setpoint());
//	a5.update(a5Controller->position.setpoint());
//	a6.update(a6Controller->position.setpoint());
185
186
187
188
189
190
191
192
193
194
195
196
197
198

	// Register the property updaters.
	registerPropertyCopierByUpdate(tasSettings->as, as);
	registerPropertyCopierByUpdate(tasSettings->bs, bs);
	registerPropertyCopierByUpdate(tasSettings->cs, cs);
	registerPropertyCopierByUpdate(tasSettings->aa, aa);
	registerPropertyCopierByUpdate(tasSettings->bb, bb);
	registerPropertyCopierByUpdate(tasSettings->cc, cc);
	registerPropertyCopierByUpdate(tasSettings->ax, ax);
	registerPropertyCopierByUpdate(tasSettings->ay, ay);
	registerPropertyCopierByUpdate(tasSettings->az, az);
	registerPropertyCopierByUpdate(tasSettings->bx, bx);
	registerPropertyCopierByUpdate(tasSettings->by, by);
	registerPropertyCopierByUpdate(tasSettings->bz, bz);
legoc's avatar
legoc committed
199
200
201
202

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

203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// Not used anymore

//	registerPropertyCopierByUpdate(scattering->qh.setpoint, qh);
//	registerPropertyCopierByUpdate(scattering->qk.setpoint, qk);
//	registerPropertyCopierByUpdate(scattering->ql.setpoint, ql);
//	registerPropertyCopierByUpdate(scattering->en.setpoint, en);
//	registerPropertyCopierByUpdate(scattering->qm.setpoint, qm);
//
//	registerPropertyCopierByUpdate(incidentBeam->ki.setpoint, ki);
//	registerPropertyCopierByUpdate(scatteredBeam->kf.setpoint, kf);
//
//	registerPropertyCopierByUpdate(a1Controller->position.setpoint, a1);
//	registerPropertyCopierByUpdate(a2Controller->position.setpoint, a2);
//	registerPropertyCopierByUpdate(a3Controller->position.setpoint, a3);
//	registerPropertyCopierByUpdate(a4Controller->position.setpoint, a4);
//	registerPropertyCopierByUpdate(a5Controller->position.setpoint, a5);
//	registerPropertyCopierByUpdate(a6Controller->position.setpoint, a6);
//
//	// Register the refreshers.
//	registerRefresher(qh, &VEXPController::refreshFloat64Property, this, scattering->qh.setpoint);
//	registerRefresher(qk, &VEXPController::refreshFloat64Property, this, scattering->qk.setpoint);
//	registerRefresher(ql, &VEXPController::refreshFloat64Property, this, scattering->ql.setpoint);
//	registerRefresher(en, &VEXPController::refreshFloat64Property, this, scattering->en.setpoint);
//	registerRefresher(qm, &VEXPController::refreshFloat64Property, this, scattering->qm.setpoint);
//
//	registerRefresher(ki, &VEXPController::refreshFloat64Property, this, incidentBeam->ki.setpoint);
//	registerRefresher(kf, &VEXPController::refreshFloat64Property, this, scatteredBeam->kf.setpoint);

legoc's avatar
legoc committed
231
232
233
234
235
236
	registerRefresher(ax, &VEXPController::refreshFloat64Property, this, tasSettings->ax);
	registerRefresher(ay, &VEXPController::refreshFloat64Property, this, tasSettings->ay);
	registerRefresher(az, &VEXPController::refreshFloat64Property, this, tasSettings->az);
	registerRefresher(bx, &VEXPController::refreshFloat64Property, this, tasSettings->bx);
	registerRefresher(by, &VEXPController::refreshFloat64Property, this, tasSettings->by);
	registerRefresher(bz, &VEXPController::refreshFloat64Property, this, tasSettings->bz);
237
238
	registerRefresher(ki, &VEXPController::refreshKi, this);
	registerRefresher(kf, &VEXPController::refreshKf, this);
239
240
241
242
243
244
	registerRefresher(a1, &VEXPController::refreshFloat64PropertyToMoveModel, this, a1Controller->position);
	registerRefresher(a2, &VEXPController::refreshFloat64PropertyToMoveModel, this, a2Controller->position);
	registerRefresher(a3, &VEXPController::refreshFloat64PropertyToMoveModel, this, a3Controller->position);
	registerRefresher(a4, &VEXPController::refreshFloat64PropertyToMoveModel, this, a4Controller->position);
	registerRefresher(a5, &VEXPController::refreshFloat64PropertyToMoveModel, this, a5Controller->position);
	registerRefresher(a6, &VEXPController::refreshFloat64PropertyToMoveModel, this, a6Controller->position);
legoc's avatar
legoc committed
245
246
247
}

}