Go to the documentation of this file.00001 #ifndef EF232LENS_H
00002 #define EF232LENS_H
00003
00009 #include "../Lens.h"
00010 #include "../TSQueue.h"
00011 #include "../CircularBuffer.h"
00012
00013 #include <string>
00014
00015 #include "EF232LensDatabase.h"
00016
00017 namespace FCam {
00018 namespace F2 {
00019
00038 class Lens: public FCam::Lens {
00039
00040 public:
00041 Lens(const std::string &tty_ = "/dev/ttyS2");
00042 ~Lens();
00043
00044 void setFocus(float diopters, float speed = -1);
00045 float getFocus();
00046 float farFocus();
00047 float nearFocus();
00048 bool focusChanging();
00049 int focusLatency();
00050
00051 float minFocusSpeed();
00052 float maxFocusSpeed();
00053
00054 void setZoom(float focal_length_mm, float speed = -1);
00055 float getZoom();
00056 float minZoom();
00057 float maxZoom();
00058 bool zoomChanging();
00059 int zoomLatency();
00060 float minZoomSpeed();
00061 float maxZoomSpeed();
00062
00063 void setAperture(float f_number, float speed = -1);
00064 float getAperture();
00065 float wideAperture(float focal_length_mm = -1);
00066 float narrowAperture(float focal_length_mm = -1);
00067 bool apertureChanging();
00068 int apertureLatency();
00069 float minApertureSpeed();
00070 float maxApertureSpeed();
00071
00073 void tagFrame(FCam::Frame);
00074
00076 enum LensState {
00077 NotInitialized,
00078 NoLens,
00079 Ready,
00080 MovingFocus,
00081 MovingAperture,
00082 Busy
00083 };
00084
00086 LensState getState();
00088 void reset();
00089
00090
00091 struct LensError {
00092 enum e {
00093 None=0,
00094 UnrecognizedCommand=1,
00095 LensIsManualFocus=2,
00096 NoLensConnected=3,
00097 LensDistanceStopError=4,
00098 ApertureNotInitialized=5,
00099 InvalidBaudRate=6,
00100 Reserved1=7,
00101 Reserved2=8,
00102 BadParameter=9,
00103 XModemTimeout=10,
00104 XModemError=11,
00105 XModemUnlockCodeIncorrect=12,
00106 NotUsed1=13,
00107 InvalidPort=14,
00108 LicenseUnlockFailure=15,
00109 InvalidLicenseFile=16,
00110 InvalidLibraryFile=17,
00111 Reserved3=18,
00112 Reserved4=19,
00113 NotUsed2=20,
00114 LibraryNotReadyForLens=21,
00115 LibraryNotReadyForCmds=22,
00116 CommandNotLicensed=23,
00117 InvalidFocusRange=24,
00118 DistanceStopsNotSupported=25,
00119 UnknownError=99
00120 };
00121 };
00122
00123 private:
00124 const std::string tty;
00125 int serial_fd;
00126
00127 EF232LensDatabase lensDB;
00128
00129 const EF232LensInfo *currentLens;
00130
00131
00132 pthread_mutex_t stateMutex;
00133 LensState state;
00134 void setState(LensState newState);
00135
00136 struct LensParams {
00137 Time time;
00138 unsigned int focalLength;
00139 unsigned int aperture;
00140 unsigned int focusDist;
00141 };
00142 CircularBuffer<LensParams> lensHistory;
00143
00144 int calcFocusDistance(const Time &t) const;
00145 int calcAperture(const Time &t) const;
00146 int calcFocalLength(const Time &t) const;
00147
00148
00149 unsigned int focusEncoderMax;
00150 float diopScaleFactor;
00151
00152 float encToDiopter(unsigned int encoder);
00153 unsigned int diopToEncoder(float diopters);
00154
00155 enum LensCmd {
00156 Initialize,
00157 Calibrate,
00158 SetAperture,
00159 SetFocus,
00160 Shutdown
00161 };
00162
00163 struct LensOrder {
00164 LensCmd cmd;
00165 unsigned int val;
00166 };
00167
00168 TSQueue<LensOrder> cmdQueue;
00169
00170
00171 pthread_t controlThread;
00172 bool controlRunning;
00173 void launchControlThread();
00174 void runLensControlThread();
00175
00176 static void *lensControlThread(void *arg);
00177
00178
00179
00180 void init();
00181 void calibrateLens();
00182
00183 void idleProcessing();
00184
00185
00186
00187
00188 std::string buf;
00189
00190 std::string cmd_GetID();
00191 unsigned int cmd_GetFocalLength(std::string idStr="");
00192 unsigned int cmd_GetMinAperture(std::string idStr="");
00193
00194 void cmd_GetZoomRange(unsigned int &min,
00195 unsigned int &max);
00196 void cmd_GetFocusBracket(unsigned int &min,
00197 unsigned int &max);
00198 unsigned int cmd_GetFocusEncoder();
00199
00200 void cmd_SetFocusEncoder(unsigned int val);
00201
00202 LensError::e cmd_DoInitialize();
00203
00204 unsigned int cmd_DoApertureOpen();
00205 unsigned int cmd_DoAperture(unsigned int val);
00206 unsigned int cmd_DoApertureClose();
00207
00208 void cmd_DoFocusAtZero();
00209 unsigned int cmd_DoFocus(unsigned int val);
00210 void cmd_DoFocusAtInf();
00211
00212
00213
00214 void send(const std::string &);
00215 template<typename T>
00216 void read(T &val);
00217 void expect(const std::string &desired);
00218 void expect(const std::string &desired, std::string &remainder);
00219 LensError::e errorCheck(std::string &remainder);
00220 };
00221
00222 }
00223 }
00224
00225 #endif