mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
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 
13 namespace mx
14 {
15 
16 namespace AO
17 {
18 
19 namespace sim
20 {
21 
22 struct 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 // template<typename floatT>
39 // struct wooferTweeterCommand
40 // {
41 // bool woofer;
42 // Eigen::Array< floatT, Eigen::Dynamic, Eigen::Dynamic> wooferVect;
43 //
44 // bool tweeter;
45 // Eigen::Array< floatT, Eigen::Dynamic, Eigen::Dynamic> tweeterVect;
46 // };
47 
48 template<typename _floatT>
49 class wooferTweeterDM
50 {
51 public:
52 
53  typedef _floatT floatT;
54 
55  typedef std::complex<floatT> complexT;
56 
57  ///The wavefront data type
58  typedef wavefront<floatT> wavefrontT;
59 
60  ///The pupil image type
61  typedef Eigen::Array< floatT, Eigen::Dynamic, Eigen::Dynamic> imageT;
62 
63  typedef wooferTweeterDMSpec specT;
64 
65  //typedef wooferTweeterCommand<floatT> commandT;
66  //typedef Eigen::Array< floatT, -1, -1> commandT;
67 
68  deformableMirror<floatT> woofer;
69  deformableMirror<floatT> tweeter;
70 
71  int _wooferModes;
72 
73  std::string _name;
74  std::string _basisName;
75 
76 public:
77 
78  ///Default c'tor.
79  wooferTweeterDM();
80 
81  int initialize( specT & spec,
82  const std::string & pupil);
83 
84 
85 
86  ///Get the calibration amplitude.
87 // void calAmp(const std::vector<floatT> & ca);
88  void calAmp(floatT ca);
89 
90  void applyMode( wavefrontT & wf,
91  int modeNo,
92  floatT amp,
93  floatT lambda );
94 
95  template<typename commandT>
96  void setShape( commandT & commandV );
97 
98  void applyShape(wavefrontT & wf, floatT lambda);
99 
100  int nModes()
101  {
102  return woofer.nModes() + tweeter.nModes();
103  }
104 
105  double t0, t1, t_mm, t_sum;
106 
107  std::string name() {return _name;}
108  std::string basisName() {return _basisName;}
109 
110 };
111 
112 
113 template<typename _floatT>
114 wooferTweeterDM<_floatT>::wooferTweeterDM()
115 {
116  ds9_interface_set_title(&woofer.ds9i_shape, "Woofer_Shape");
117  ds9_interface_set_title(&woofer.ds9i_phase, "Woofer_Phase");
118  ds9_interface_set_title(&woofer.ds9i_acts, "Woofer_Acts");
119  ds9_interface_set_title(&tweeter.ds9i_shape, "Tweeter_Shape");
120  ds9_interface_set_title(&tweeter.ds9i_phase, "Tweeter_Phase");
121  ds9_interface_set_title(&tweeter.ds9i_acts, "Tweeter_Acts");
122 
123  t_mm = 0;
124  t_sum = 0;
125 }
126 
127 template<typename _floatT>
128 int wooferTweeterDM<_floatT>::initialize( specT & spec,
129  const std::string & pupil )
130 {
131 
132  _name = spec.name;
133  _basisName = spec.basisName;
134 
135  woofer.initialize(spec.woofer, pupil);
136 
137  tweeter.initialize(spec.tweeter, pupil);
138 
139  _wooferModes = spec.wooferModes;
140 }
141 
142 
143 
144 
145 
146 // template<typename _floatT>
147 // void wooferTweeterDM<_floatT>::calAmp(const std::vector<_floatT> & ca)
148 // {
149 // woofer.calAmp(ca[0]);
150 // tweeter.calAmp(ca[1]);
151 // }
152 
153 template<typename _floatT>
154 void wooferTweeterDM<_floatT>::calAmp(_floatT ca)
155 {
156  woofer.calAmp(ca);
157  tweeter.calAmp(ca);
158 }
159 
160 
161 template<typename _floatT>
162 void wooferTweeterDM<_floatT>::applyMode( wavefrontT & wf,
163  int modeNo,
164  floatT amp,
165  floatT lambda )
166 {
167 
168  if(modeNo < _wooferModes)
169  {
170  woofer.applyMode(wf, modeNo, amp, lambda);
171  }
172  else
173  {
174  tweeter.applyMode(wf, modeNo - _wooferModes, amp, lambda);
175  }
176 }
177 
178 
179 template<typename _floatT>
180 template<typename commandT>
181 void wooferTweeterDM<_floatT>::setShape( commandT & commandV )
182 {
183  //static int called = 0;
184  static commandT avgWoofV;
185 
186  commandT woofV, tweetV;
187 
188  BREAD_CRUMB;
189  woofV.measurement = commandV.measurement.block(0, 0, 1, _wooferModes);
190  woofV.iterNo = commandV.iterNo;
191 
192  BREAD_CRUMB;
193 // std::cerr << _wooferModes << "\n";
194 // std::cerr << commandV.cols() << "\n";
195 
196  tweetV.measurement = commandV.measurement.block(0, _wooferModes, 1,commandV.measurement.cols()-_wooferModes);
197  tweetV.iterNo = commandV.iterNo;
198 
199  BREAD_CRUMB;
200 
201  woofer.setShape(woofV);
202 
203 // if(called == 0)
204 // {
205 // avgWoofV.measurement = woofV.measurement;
206 // ++called;
207 // }
208 // else if(called == 1)
209 // {
210 // avgWoofV.measurement += woofV.measurement;
211 // avgWoofV.measurement /= (called + 1);
212 //
213 // woofer.setShape(avgWoofV.measurement);
214 // called = 0;
215 // }
216 
217 
218  BREAD_CRUMB;
219  tweeter.setShape(tweetV);
220  BREAD_CRUMB;
221 }
222 
223 
224 
225 
226 // static int called = 0;
227 //
228 // if(commandV.woofer)
229 // {
230 // woofer.setShape(commandV.wooferVect);
231 // }
232 //
233 // //if(commandV.tweeter)
234 // if(called > 50)
235 // {
236 // tweeter.setShape(commandV.tweeterVect);
237 // }
238 //
239 // ++called;
240 //}
241 
242 template<typename _floatT>
243 void wooferTweeterDM<_floatT>::applyShape(wavefrontT & wf, floatT lambda)
244 {
245 
246  woofer.applyShape(wf, lambda);
247  tweeter.applyShape(wf, lambda);
248 
249 }
250 
251 } //sim
252 } //AO
253 } //namespace mx
254 
255 #endif //__deformableMirror_hpp__
256 
The mxlib c++ namespace.
Definition: mxError.hpp:107