CARMA C++
OpticalTelCommon.h
Go to the documentation of this file.
1 
12 #ifndef CARMA_OPTICALTELCOMMON_H
13 #define CARMA_OPTICALTELCOMMON_H
14 
15 #include "carma/corba/corba.h"
16 
17 #include "carma/antenna/common/Image.h"
18 #include "carma/antenna/common/OpticalTelControl.h"
19 #include "carma/monitor/AntennaCommon.h"
20 #include "carma/util/PthreadRWLock.h"
21 #include "carma/util/UserException.h"
22 
23 namespace log4cpp {
24  // Forward dec
25  class Category;
26 } // End namespace log4cpp
27 
28 namespace carma
29 {
30  namespace antenna
31  {
32  namespace common
33  {
34 
35  class FrameContext;
36  class FrameGrabber;
37 
38  class OpticalTelCommon
39  {
40  public:
49  OpticalTelCommon( carma::monitor::AntennaCommon::OpticalTel &monObj,
50  FrameGrabber & fg,
51  float azFieldOfViewInArcminutes,
52  float elFieldOfViewInArcminutes,
53  float rotationInDegrees,
54  bool simulate );
55 
56  virtual ~OpticalTelCommon( );
57 
58  void setFrameDimensions( CORBA::Short x, CORBA::Short y,
59  CORBA::Short x0 = 0, CORBA::Short y0 = 0 );
60 
61  void setBrightness( CORBA::Float brightness );
62 
63  void setContrast( CORBA::Float contrast );
64 
65  void setFramegrabberResolution( Resolution res );
66 
67  void setRotationAndFieldsOfView( CORBA::Float rotationInDegrees,
68  CORBA::Float azFOVInArcminutes,
69  CORBA::Float elFOVInArcminutes );
70 
71  flattenedOpticalImage * grabFrame();
72 
73  flattenedOpticalImage * getImage( CORBA::UShort numFrames,
74  CORBA::Boolean subBackground,
75  CORBA::Boolean normalizeMedian,
76  CORBA::Boolean normalizeImage );
77 
78  void takeBackgroundImage( CORBA::UShort numFrames,
79  CORBA::ULong seqNo );
80 
81  flattenedOpticalImage * getStoredBackgroundImage( );
82 
83  virtual void turn( carma::antenna::common::SwitchState state );
84 
85  void findCentroid( CORBA::UShort numFramesPerImage,
86  CORBA::UShort minValidCentroids,
87  CORBA::UShort maxCentroidAttempts,
88  CORBA::UShort numEdgePixels,
89  CORBA::UShort apertureRadiusPixels,
90  CORBA::Float pixelThresholdSigma,
91  CORBA::Boolean subBackground,
92  CORBA::Boolean normalizeMedian,
93  CORBA::ULong seqNo );
94 
95  CentroidResults * getCentroidResults( );
96 
97  void applyTestOffset( CORBA::Double azInArcmin,
98  CORBA::Double elInArcmin );
99 
100  void zeroTestOffset( );
101 
102  static void copyFrameToFOI( Image & image,
103  flattenedOpticalImage * foi,
104  const FrameContext & frameContext,
105  const float rotationInDegrees,
106  const float azFieldOfViewInArcminutes,
107  const float elFieldOfViewInArcminutes,
108  bool normalizeImage );
109 
110  static ::std::string
111  getResolutionAsString( carma::antenna::common::Resolution res );
112 
113  void writeMonitorData( );
114 
115  protected:
116 
117  void setFakeStarHoldingWriteLock( );
118 
119  struct FindCentroidThreadArgs {
120 
121  FindCentroidThreadArgs( OpticalTelCommon & otcRef );
122 
123  CORBA::UShort numFramesPerImage;
124  CORBA::UShort minValidCentroids;
125  CORBA::UShort maxCentroidAttempts;
126  CORBA::UShort numEdgePixels;
127  CORBA::UShort apertureRadiusPixels;
128  CORBA::Float pixelThresholdSigma;
129  CORBA::Boolean subBackground;
130  CORBA::Boolean normalizeMedian;
131  CORBA::ULong seqNo;
132  OpticalTelCommon & This;
133  };
134 
135  static void
136  findCentroidThread( FindCentroidThreadArgs & args );
137 
138  struct TakeBackgroundThreadArgs {
139 
140  TakeBackgroundThreadArgs( OpticalTelCommon & otcRef );
141 
142  CORBA::UShort numFrames;
143  CORBA::ULong seqNo;
144  OpticalTelCommon & This;
145  };
146 
147  static void
148  takeBackgroundThread( TakeBackgroundThreadArgs & args );
149 
150  // A note on synchronization here: Its pretty complicated
151  // based on the fact that we don't want framegrabber parameters
152  // or image context to change while centroiding or taking a
153  // background, but at the same time we need to make sure and write
154  // monitor data in a timely manner. The latter requirement means
155  // we want to minimize the amount of time we block the monitor
156  // system out since we don't want to miss the write deadline.
157  // While not perfect, using a RWLock nicely solves this since it
158  // allows the monitor system to go on writing while centroiding or
159  // performing other time consuming tasks (i.e. touching hardware).
160  // So for example, I'll coadd 100 frames while only read locking
161  // so that the monitor system can still write without blocking for the
162  // 1-2 seconds it takes to grab and coadd 100 frames.
164 
165  CORBA::ULong seqNo_;
166 
167  FrameGrabber & fg_;
168  carma::monitor::AntennaCommon::OpticalTel &mon_;
169  log4cpp::Category &log_;
170 
171  float azFieldOfViewInArcminutes_;
172  float elFieldOfViewInArcminutes_;
173  const float grossRotationInDegrees_;
174  float fineRotationInDegrees_; // !deprecated - use context
175 
176  CentroidResults centroidResults_;
177 
178  Image backgroundImage_;
179 
180  std::auto_ptr< FrameContext > frameContext_;
181 
182  ::std::pair<float, float> fakeStarPosition_; // arcmin from center
183  ::std::pair<float, float> fakeStarOffset_; // arcmin from fake star
184  const bool simulate_;
185 
186  }; // class OpticalTelCommon
187  } // namespace common
188  } // namespace antenna
189 } // namespace carma
190 
191 #endif // CARMA_OPTICALTELCOMMON_H
A simple wrapper class that makes use of ::pthread_rwlock_t easier in a C++ world.
Definition: PthreadRWLock.h:46
Resolution
Resolutions supported by our framegrabber.
SwitchState
Generic switch state enumerator.
Definition: SwitchState.idl:18