mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
wooferTweeterDM.hpp
Go to the documentation of this file.
1/** \file
2 * \author Jared R. Males (jaredmales@gmail.com)
3 * \brief
4 * \ingroup mxAO_sim_files
5 *
6 */
7
8#ifndef _wooferTweeterDM_hpp__
9#define _wooferTweeterDM_hpp__
10
11#include "deformableMirror.hpp"
12
13namespace mx
14{
15
16namespace AO
17{
18
19namespace sim
20{
21
22struct wooferTweeterDMSpec
23{
24 std::string name;
25 std::string basisName;
26
27 deformableMirrorSpec woofer;
28 deformableMirrorSpec tweeter;
29
30 int wooferModes;
31
32 wooferTweeterDMSpec()
33 {
34 wooferModes = 0;
35 }
36};
37
38/// A paired command for woofer and tweeter deformable mirrors.
39template <typename floatT>
41{
42 bool woofer{ false }; ///< Whether the woofer command is active.
43
44 Eigen::Array<floatT, Eigen::Dynamic, Eigen::Dynamic> wooferVect; ///< Woofer modal command vector.
45
46 bool tweeter{ false }; ///< Whether the tweeter command is active.
47
48 Eigen::Array<floatT, Eigen::Dynamic, Eigen::Dynamic> tweeterVect; ///< Tweeter modal command vector.
49};
50
51template <typename _floatT>
52class wooferTweeterDM
53{
54 public:
55 typedef _floatT floatT;
56
57 typedef std::complex<floatT> complexT;
58
59 /// The wavefront data type
60 typedef wavefront<floatT> wavefrontT;
61
62 /// The pupil image type
63 typedef Eigen::Array<floatT, Eigen::Dynamic, Eigen::Dynamic> imageT;
64
65 typedef wooferTweeterDMSpec specT;
66
67 // typedef wooferTweeterCommand<floatT> commandT;
68 // typedef Eigen::Array< floatT, -1, -1> commandT;
69
70 deformableMirror<floatT> woofer;
71 deformableMirror<floatT> tweeter;
72
73 int _wooferModes;
74
75 std::string _name;
76 std::string _basisName;
77
78 public:
79 /// Default c'tor.
80 wooferTweeterDM();
81
82 int initialize( specT &spec, const std::string &pupil );
83
84 /// Get the calibration amplitude.
85 // void calAmp(const std::vector<floatT> & ca);
86 void calAmp( floatT ca );
87
88 void applyMode( wavefrontT &wf, int modeNo, floatT amp, floatT lambda );
89
90 template <typename commandT>
91 void setShape( commandT &commandV );
92
93 void applyShape( wavefrontT &wf, floatT lambda );
94
95 int nModes()
96 {
97 return woofer.nModes() + tweeter.nModes();
98 }
99
100 double t0, t1, t_mm, t_sum;
101
102 std::string name()
103 {
104 return _name;
105 }
106 std::string basisName()
107 {
108 return _basisName;
109 }
110};
111
112template <typename _floatT>
113wooferTweeterDM<_floatT>::wooferTweeterDM()
114{
115 ds9_interface_set_title( &woofer.ds9i_shape, "Woofer_Shape" );
116 ds9_interface_set_title( &woofer.ds9i_phase, "Woofer_Phase" );
117 ds9_interface_set_title( &woofer.ds9i_acts, "Woofer_Acts" );
118 ds9_interface_set_title( &tweeter.ds9i_shape, "Tweeter_Shape" );
119 ds9_interface_set_title( &tweeter.ds9i_phase, "Tweeter_Phase" );
120 ds9_interface_set_title( &tweeter.ds9i_acts, "Tweeter_Acts" );
121
122 t_mm = 0;
123 t_sum = 0;
124}
125
126template <typename _floatT>
127int wooferTweeterDM<_floatT>::initialize( specT &spec, const std::string &pupil )
128{
129
130 _name = spec.name;
131 _basisName = spec.basisName;
132
133 woofer.initialize( spec.woofer, pupil );
134
135 tweeter.initialize( spec.tweeter, pupil );
136
137 _wooferModes = spec.wooferModes;
138}
139
140// template<typename _floatT>
141// void wooferTweeterDM<_floatT>::calAmp(const std::vector<_floatT> & ca)
142// {
143// woofer.calAmp(ca[0]);
144// tweeter.calAmp(ca[1]);
145// }
146
147template <typename _floatT>
148void wooferTweeterDM<_floatT>::calAmp( _floatT ca )
149{
150 woofer.calAmp( ca );
151 tweeter.calAmp( ca );
152}
153
154template <typename _floatT>
155void wooferTweeterDM<_floatT>::applyMode( wavefrontT &wf, int modeNo, floatT amp, floatT lambda )
156{
157
158 if( modeNo < _wooferModes )
159 {
160 woofer.applyMode( wf, modeNo, amp, lambda );
161 }
162 else
163 {
164 tweeter.applyMode( wf, modeNo - _wooferModes, amp, lambda );
165 }
166}
167
168template <typename _floatT>
169template <typename commandT>
170void wooferTweeterDM<_floatT>::setShape( commandT &commandV )
171{
172 // static int called = 0;
173 static commandT avgWoofV;
174
175 commandT woofV, tweetV;
176
177 BREAD_CRUMB;
178 woofV.measurement = commandV.measurement.block( 0, 0, 1, _wooferModes );
179 woofV.iterNo = commandV.iterNo;
180
181 BREAD_CRUMB;
182 // std::cerr << _wooferModes << "\n";
183 // std::cerr << commandV.cols() << "\n";
184
185 tweetV.measurement = commandV.measurement.block( 0, _wooferModes, 1, commandV.measurement.cols() - _wooferModes );
186 tweetV.iterNo = commandV.iterNo;
187
188 BREAD_CRUMB;
189
190 woofer.setShape( woofV );
191
192 // if(called == 0)
193 // {
194 // avgWoofV.measurement = woofV.measurement;
195 // ++called;
196 // }
197 // else if(called == 1)
198 // {
199 // avgWoofV.measurement += woofV.measurement;
200 // avgWoofV.measurement /= (called + 1);
201 //
202 // woofer.setShape(avgWoofV.measurement);
203 // called = 0;
204 // }
205
206 BREAD_CRUMB;
207 tweeter.setShape( tweetV );
208 BREAD_CRUMB;
209}
210
211// static int called = 0;
212//
213// if(commandV.woofer)
214// {
215// woofer.setShape(commandV.wooferVect);
216// }
217//
218// //if(commandV.tweeter)
219// if(called > 50)
220// {
221// tweeter.setShape(commandV.tweeterVect);
222// }
223//
224// ++called;
225//}
226
227template <typename _floatT>
228void wooferTweeterDM<_floatT>::applyShape( wavefrontT &wf, floatT lambda )
229{
230
231 woofer.applyShape( wf, lambda );
232 tweeter.applyShape( wf, lambda );
233}
234
235} // namespace sim
236} // namespace AO
237} // namespace mx
238
239#endif //__deformableMirror_hpp__
The mxlib c++ namespace.
Definition mxlib.hpp:37
Structure containing the phase and amplitude of a wavefront.
Definition wavefront.hpp:24
A paired command for woofer and tweeter deformable mirrors.
bool tweeter
Whether the tweeter command is active.
bool woofer
Whether the woofer command is active.
Eigen::Array< floatT, Eigen::Dynamic, Eigen::Dynamic > tweeterVect
Tweeter modal command vector.
Eigen::Array< floatT, Eigen::Dynamic, Eigen::Dynamic > wooferVect
Woofer modal command vector.