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