Instrument Neutral Distributed Interface INDI  2.0.2
BuiltInMathPlugin.cpp
Go to the documentation of this file.
1 
5 #include "BuiltInMathPlugin.h"
6 
7 #include "DriverCommon.h"
8 
9 namespace INDI
10 {
11 namespace AlignmentSubsystem
12 {
13 // Private methods
14 
15 void BuiltInMathPlugin::CalculateTransformMatrices(const TelescopeDirectionVector &Alpha1,
16  const TelescopeDirectionVector &Alpha2,
17  const TelescopeDirectionVector &Alpha3,
18  const TelescopeDirectionVector &Beta1,
19  const TelescopeDirectionVector &Beta2,
20  const TelescopeDirectionVector &Beta3, gsl_matrix *pAlphaToBeta,
21  gsl_matrix *pBetaToAlpha)
22 {
23  // Derive the Actual to Apparent transformation matrix
24  gsl_matrix *pAlphaMatrix = gsl_matrix_alloc(3, 3);
25  gsl_matrix_set(pAlphaMatrix, 0, 0, Alpha1.x);
26  gsl_matrix_set(pAlphaMatrix, 1, 0, Alpha1.y);
27  gsl_matrix_set(pAlphaMatrix, 2, 0, Alpha1.z);
28  gsl_matrix_set(pAlphaMatrix, 0, 1, Alpha2.x);
29  gsl_matrix_set(pAlphaMatrix, 1, 1, Alpha2.y);
30  gsl_matrix_set(pAlphaMatrix, 2, 1, Alpha2.z);
31  gsl_matrix_set(pAlphaMatrix, 0, 2, Alpha3.x);
32  gsl_matrix_set(pAlphaMatrix, 1, 2, Alpha3.y);
33  gsl_matrix_set(pAlphaMatrix, 2, 2, Alpha3.z);
34 
35  Dump3x3("AlphaMatrix", pAlphaMatrix);
36 
37  gsl_matrix *pBetaMatrix = gsl_matrix_alloc(3, 3);
38  gsl_matrix_set(pBetaMatrix, 0, 0, Beta1.x);
39  gsl_matrix_set(pBetaMatrix, 1, 0, Beta1.y);
40  gsl_matrix_set(pBetaMatrix, 2, 0, Beta1.z);
41  gsl_matrix_set(pBetaMatrix, 0, 1, Beta2.x);
42  gsl_matrix_set(pBetaMatrix, 1, 1, Beta2.y);
43  gsl_matrix_set(pBetaMatrix, 2, 1, Beta2.z);
44  gsl_matrix_set(pBetaMatrix, 0, 2, Beta3.x);
45  gsl_matrix_set(pBetaMatrix, 1, 2, Beta3.y);
46  gsl_matrix_set(pBetaMatrix, 2, 2, Beta3.z);
47 
48  Dump3x3("BetaMatrix", pBetaMatrix);
49 
50  // Use the quick and dirty method
51  // This can result in matrices which are not true transforms
52  gsl_matrix *pInvertedAlphaMatrix = gsl_matrix_alloc(3, 3);
53 
54  if (!MatrixInvert3x3(pAlphaMatrix, pInvertedAlphaMatrix))
55  {
56  // pAlphaMatrix is singular and therefore is not a true transform
57  // and cannot be inverted. This probably means it contains at least
58  // one row or column that contains only zeroes
59  gsl_matrix_set_identity(pInvertedAlphaMatrix);
60  ASSDEBUG("CalculateTransformMatrices - Alpha matrix is singular!");
61  IDMessage(nullptr, "Alpha matrix is singular and cannot be inverted.");
62  }
63  else
64  {
65  MatrixMatrixMultiply(pBetaMatrix, pInvertedAlphaMatrix, pAlphaToBeta);
66 
67  Dump3x3("AlphaToBeta", pAlphaToBeta);
68 
69  if (nullptr != pBetaToAlpha)
70  {
71  // Invert the matrix to get the Apparent to Actual transform
72  if (!MatrixInvert3x3(pAlphaToBeta, pBetaToAlpha))
73  {
74  // pAlphaToBeta is singular and therefore is not a true transform
75  // and cannot be inverted. This probably means it contains at least
76  // one row or column that contains only zeroes
77  gsl_matrix_set_identity(pBetaToAlpha);
78  ASSDEBUG("CalculateTransformMatrices - AlphaToBeta matrix is singular!");
79  IDMessage(
80  nullptr,
81  "Calculated Celestial to Telescope transformation matrix is singular (not a true transform).");
82  }
83 
84  Dump3x3("BetaToAlpha", pBetaToAlpha);
85  }
86  }
87 
88  // Clean up
89  gsl_matrix_free(pInvertedAlphaMatrix);
90  gsl_matrix_free(pBetaMatrix);
91  gsl_matrix_free(pAlphaMatrix);
92 }
93 
94 } // namespace AlignmentSubsystem
95 } // namespace INDI
#define ASSDEBUG(msg)
Definition: DriverCommon.h:17
bool MatrixInvert3x3(gsl_matrix *pInput, gsl_matrix *pInversion)
Calculate the inverse of the supplied matrix.
void MatrixMatrixMultiply(gsl_matrix *pA, gsl_matrix *pB, gsl_matrix *pC)
Multiply matrix A by matrix B and put the result in C.
void Dump3x3(const char *Label, gsl_matrix *pMatrix)
Print out a 3x3 matrix to debug.
void IDMessage(const char *dev, const char *fmt,...)
Definition: indidriver.c:960
Namespace to encapsulate INDI client, drivers, and mediator classes.