* add the constant chi vertical mode to the K6C diffractometer.
[hkl.git] / src / hkl-pseudoaxis-common.c
blob97521b1e1e3ecb8717645abfeea1a19221b40de2
1 #include <string.h>
2 #include <gsl/gsl_sf_trig.h>
3 #include <hkl/hkl-pseudoaxis.h>
5 /********************************/
6 /* common methode use by getter */
7 /********************************/
9 int RUBh_minus_Q(double const x[], void *params, double f[])
11 HklVector Hkl;
12 HklVector ki, dQ;
13 HklPseudoAxisEngine *engine;
14 HklPseudoAxis *H, *K, *L;
15 HklHolder *holder;
16 size_t i;
18 engine = params;
19 H = &engine->pseudoAxes[0];
20 K = &engine->pseudoAxes[1];
21 L = &engine->pseudoAxes[2];
23 // update the workspace from x;
24 for(i=0; i<engine->axes_len; ++i) {
25 HklAxis *axis = engine->axes[i];
26 axis->config.value = x[i];
27 axis->config.dirty = 1;
29 hkl_geometry_update(engine->geometry);
31 hkl_vector_init(&Hkl, H->config.value, K->config.value,
32 L->config.value);
34 // R * UB * h = Q
35 // for now the 0 holder is the sample holder.
36 holder = &engine->geometry->holders[0];
37 hkl_matrix_times_vector(&engine->sample->UB, &Hkl);
38 hkl_vector_rotated_quaternion(&Hkl, &holder->q);
40 // kf - ki = Q
41 hkl_source_compute_ki(&engine->geometry->source, &ki);
42 hkl_detector_compute_kf(engine->detector, engine->geometry, &dQ);
43 hkl_vector_minus_vector(&dQ, &ki);
45 hkl_vector_minus_vector(&dQ, &Hkl);
47 f[0] = dQ.data[0];
48 f[1] = dQ.data[1];
49 f[2] = dQ.data[2];
51 return GSL_SUCCESS;
54 int hkl_pseudo_axis_engine_getter_func_hkl(HklPseudoAxisEngine *self,
55 HklGeometry *geometry, HklDetector const *detector,
56 HklSample const *sample)
58 HklHolder *holder;
59 HklMatrix RUB;
60 HklVector hkl, ki, Q;
62 // update the geometry internals
63 hkl_geometry_update(geometry);
65 // R * UB
66 // for now the 0 holder is the sample holder.
67 holder = &geometry->holders[0];
68 hkl_quaternion_to_smatrix(&holder->q, &RUB);
69 hkl_matrix_times_smatrix(&RUB, &sample->UB);
71 // kf - ki = Q
72 hkl_source_compute_ki(&geometry->source, &ki);
73 hkl_detector_compute_kf(detector, geometry, &Q);
74 hkl_vector_minus_vector(&Q, &ki);
76 hkl_matrix_solve(&RUB, &hkl, &Q);
78 // update the pseudoAxes current and consign parts
79 self->pseudoAxes[0].config.value = hkl.data[0];
80 self->pseudoAxes[1].config.value = hkl.data[1];
81 self->pseudoAxes[2].config.value = hkl.data[2];
83 return HKL_SUCCESS;