Instrument Neutral Distributed Interface INDI 2.2.5
BuiltInMathPlugin.cpp
Go to the documentation of this file.
1
4
5#include "BuiltInMathPlugin.h"
6
7#include "DriverCommon.h"
8
9namespace INDI
10{
11namespace AlignmentSubsystem
12{
13// Private methods
14
15void 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!");
62 nullptr,
63 "Calculated Alpha conversion matrix is singular (not a true transform). Defaulting to unity matrix.");
64 }
65
66 MatrixMatrixMultiply(pBetaMatrix, pInvertedAlphaMatrix, pAlphaToBeta);
67
68 if (nullptr != pBetaToAlpha)
69 {
70 if (!MatrixInvert3x3(pAlphaToBeta, pBetaToAlpha))
71 {
72 // pAlphaToBeta is singular and therefore is not a true transform
73 // and cannot be inverted. This probably means it contains at least
74 // one row or column that contains only zeroes
75 gsl_matrix_set_identity(pBetaToAlpha);
76 ASSDEBUG("CalculateTransformMatrices - AlphaToBeta matrix is singular!");
78 nullptr,
79 "Calculated Celestial to Telescope transformation matrix is singular (not a true transform).");
80 }
81
82 Dump3x3("BetaToAlpha", pBetaToAlpha);
83 }
84
85 // Clean up
86 gsl_matrix_free(pInvertedAlphaMatrix);
87 gsl_matrix_free(pBetaMatrix);
88 gsl_matrix_free(pAlphaMatrix);
89}
90
91} // namespace AlignmentSubsystem
92} // namespace INDI
93
94#ifndef NO_PLUGIN_HOOKS
95// Standard functions required for all plugins
96extern "C" {
101
103 {
104 delete pPlugin;
105 }
106
107 const char *GetDisplayName()
108 {
109 return "Built In Math Plugin";
110 }
111}
112#endif
const char * GetDisplayName()
INDI::AlignmentSubsystem::BuiltInMathPlugin * Create()
void Destroy(INDI::AlignmentSubsystem::BuiltInMathPlugin *pPlugin)
#define ASSDEBUG(msg)
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.
This class implements the default math plugin.
void IDMessage(const char *dev, const char *fmt,...)
Definition indidriver.c:983
Namespace to encapsulate INDI client, drivers, and mediator classes.