CameraControl.C

Go to the documentation of this file.
00001 /*!@file Devices/CameraControl.C Controls a pan/tilt camera head */
00002 
00003 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Devices/CameraControl.C $
00004 // $Id: CameraControl.C 6003 2005-11-29 17:22:45Z rjpeters $
00005 
00006 #include "Devices/CameraControl.H"
00007 
00008 #include "Devices/ssc.H"
00009 #include "Util/Assert.H"
00010 #include <math.h>
00011 #include <signal.h>
00012 #include <unistd.h>
00013 
00014 CameraControl::CameraControl(OptionManager& mgr,
00015                              const std::string& descrName,
00016                              const std::string& tagName,
00017                              int setPort, bool setCam,
00018                              int pPort, int tPort, int Port) :
00019   ModelComponent(mgr, descrName, tagName),
00020   ssc(new SSC(mgr))
00021 {
00022   addSubComponent(ssc);
00023 
00024   panPort = pPort; tiltPort = tPort; serialPort = Port;
00025   if(setCam)
00026   {
00027     centerCamera();
00028   }
00029   currentPan = camera.Xcenter;
00030   currentTilt = camera.Ycenter;
00031   calibrate = false;
00032 }
00033 
00034 /*============================================================*/
00035 
00036 CameraControl::~CameraControl()
00037 { }
00038 
00039 /*============================================================*/
00040 
00041 float CameraControl::moveCamXYFrame(int X, int Y, int camNumber, bool simulate)
00042 {
00043   ASSERT((X >= 0) && ((unsigned)X < camera.Xpixel));
00044   ASSERT((Y >= 0) && ((unsigned)Y < camera.Ypixel));
00045 
00046   //LINFO("ATTEMPTING TO MOVE");
00047   int gotoCY = abs(Y - (int)camera.Ypixel);
00048 
00049   float panConv = ((float)camera.Xfield/(float)camera.Xpixel);
00050   float tiltConv = ((float)camera.Yfield/(float)camera.Ypixel);
00051 
00052   float panOff = ((float)camera.Xpixel*.5)-X;
00053   float tiltOff = ((float)camera.Ypixel*.5)-gotoCY;
00054 
00055   float travelPan = ((panOff*panConv)*camera.fieldAdjustmentX);
00056   float travelTilt = ((tiltOff*tiltConv)*camera.fieldAdjustmentY);
00057   if((fabs(travelPan) > camera.minMove) || (fabs(travelTilt) > camera.minMove))
00058   {
00059     panConv = currentPan+travelPan;
00060     tiltConv = currentTilt+travelTilt;
00061 
00062     float travelPanEst = (camera.travelTime/90)*fabs(travelPan)
00063       + camera.minTravelTime;
00064     float travelTiltEst = (camera.travelTime/90)*fabs(travelTilt)
00065       + camera.minTravelTime;
00066 
00067     if(panConv < camera.XlimitStart)
00068     {
00069       panConv = camera.XlimitStart;
00070       return -1;
00071     }
00072     if(panConv > camera.XlimitEnd)
00073     {
00074       panConv = camera.XlimitEnd;
00075       return -2;
00076     }
00077     if(tiltConv < camera.YlimitStart)
00078     {
00079       tiltConv = camera.YlimitStart;
00080       return -3;
00081     }
00082     if(tiltConv > camera.YlimitEnd)
00083     {
00084       tiltConv = camera.YlimitEnd;
00085       return -4;
00086     }
00087 
00088     if(simulate == false)
00089     {
00090       //LINFO("MOVING XY TO %f %f",panConv,tiltConv);
00091       if(calibrate == true)
00092       {
00093         ssc->moveRawHack(panPort,
00094                          (int)((panConv
00095                                 +camera.cameraCalibrationPan[camNumber])
00096                                *camera.servoPixels),serialPort);
00097         ssc->moveRawHack(tiltPort,
00098                          (int)((tiltConv
00099                                 +camera.cameraCalibrationTilt[camNumber])
00100                                *camera.servoPixels),serialPort);
00101       }
00102       else
00103       {
00104         ssc->moveRawHack(panPort,
00105                          (int)(panConv*camera.servoPixels),serialPort);
00106         ssc->moveRawHack(tiltPort,
00107                          (int)(tiltConv*camera.servoPixels),serialPort);
00108       }
00109       currentPan = panConv;
00110       currentTilt = tiltConv;
00111     }
00112     simPan = panConv;
00113     simTilt = tiltConv;
00114 
00115 
00116     if(travelPanEst > travelTiltEst)
00117       return travelPanEst;
00118     else
00119       return travelTiltEst;
00120   }
00121   else
00122   {
00123     return -5;
00124   }
00125 }
00126 
00127 /*============================================================*/
00128 
00129 float CameraControl::moveCamTPFrame(float theta, float phi, int camNumber)
00130 {
00131   //LINFO("ATTEMPTING TO LOT MOVE");
00132   float panConv;
00133   float tiltConv;
00134 
00135   panConv = currentPan-theta;
00136   tiltConv = currentTilt-phi;
00137 
00138   float travelPanEst = (camera.travelTime/90)*fabs(panConv);
00139    // + camera.minTravelTime;
00140   float travelTiltEst = (camera.travelTime/90)*fabs(tiltConv);
00141     //+ camera.minTravelTime;
00142 
00143   //LINFO("MOVING AMOUNT %f, %f",  panConv,  tiltConv);
00144   if(theta < camera.XlimitStart)
00145   {
00146     return -1;
00147   }
00148   if(theta > camera.XlimitEnd)
00149   {
00150     return -2;
00151   }
00152   if(phi < camera.YlimitStart)
00153   {
00154     return -3;
00155   }
00156   if(phi > camera.YlimitEnd)
00157   {
00158     return -4;
00159   }
00160 
00161   //LINFO("MOVING TP TO %f %f",theta,phi);
00162   if(calibrate == true)
00163   {
00164     ssc->moveRawHack(panPort,
00165                      (int)((theta+camera.cameraCalibrationPan[camNumber])
00166                            *camera.servoPixels),serialPort);
00167     ssc->moveRawHack(tiltPort,
00168                      (int)((phi+camera.cameraCalibrationTilt[camNumber])
00169                            *camera.servoPixels),serialPort);
00170   }
00171   else
00172   {
00173     ssc->moveRawHack(panPort,
00174                      (int)(theta*camera.servoPixels),serialPort);
00175     ssc->moveRawHack(tiltPort,
00176                      (int)(phi*camera.servoPixels),serialPort);
00177   }
00178   currentPan = theta;
00179   currentTilt = phi;
00180 
00181   if(travelPanEst > travelTiltEst)
00182     return travelPanEst;
00183   else
00184     return travelTiltEst;
00185 
00186 }
00187 
00188 /*============================================================*/
00189 void CameraControl::centerCamera(int camNumber)
00190 {
00191   if(calibrate == true)
00192   {
00193     ssc->moveRawHack(panPort,
00194                      (int)((camera.Xcenter
00195                             +camera.cameraCalibrationPan[camNumber])
00196                            *camera.servoPixels),serialPort);
00197     ssc->moveRawHack(tiltPort,
00198                      (int)((camera.Ycenter
00199                             +camera.cameraCalibrationTilt[camNumber])
00200                            *camera.servoPixels),serialPort);
00201   }
00202   else
00203   {
00204     ssc->moveRawHack(panPort,
00205                      (int)(camera.Xcenter*camera.servoPixels),serialPort);
00206     ssc->moveRawHack(tiltPort,
00207                      (int)(camera.Ycenter*camera.servoPixels),serialPort);
00208   }
00209 }
00210 
00211 /*============================================================*/
00212 
00213 void CameraControl::panRelative(float doPan)
00214 {
00215   float calcDoPan = getCurrentPan() + doPan;
00216   ASSERT((calcDoPan > camera.XlimitStart) && (calcDoPan > camera.XlimitEnd));
00217   ssc->move(camera.SSCXconnector,calcDoPan);
00218 }
00219 
00220 /*============================================================*/
00221 
00222 void CameraControl::tiltRelative(float doTilt)
00223 {
00224   float calcDoTilt = getCurrentTilt() + doTilt;
00225   ASSERT((calcDoTilt > camera.YlimitStart) && (calcDoTilt > camera.YlimitEnd));
00226   ssc->move(camera.SSCYconnector,calcDoTilt);
00227 }
00228 /*============================================================*/
00229 
00230 void CameraControl::panAbsolute(float doPan)
00231 {
00232   ASSERT((doPan > camera.XlimitStart) && (doPan > camera.XlimitEnd));
00233   doPan = doPan - 10;
00234   ssc->move(camera.SSCXconnector,doPan);
00235 }
00236 
00237 /*============================================================*/
00238 
00239 void CameraControl::tiltAbsolute(float doTilt)
00240 {
00241   ASSERT((doTilt > camera.YlimitStart) && (doTilt > camera.YlimitEnd));
00242   doTilt = doTilt - 10;
00243   ssc->move(camera.SSCYconnector,doTilt);
00244 }
00245 
00246 /*============================================================*/
00247 
00248 void CameraControl::setImageSize(int X, int Y)
00249 {
00250   camera.Xpixel = X;
00251   camera.Ypixel = Y;
00252 }
00253 
00254 /*============================================================*/
00255 
00256 void CameraControl::useCalibration(bool useIt)
00257 {
00258   calibrate = useIt;
00259 }
00260 
00261 /*============================================================*/
00262 
00263 float CameraControl::getCurrentPan()
00264 {
00265   //return ((90-camera.Xcenter)+(ssc->getPosition(camera.SSCXconnector)/248.0F)*180.0F);
00266   return currentPan;
00267 }
00268 
00269 /*============================================================*/
00270 
00271 float CameraControl::getCurrentTilt()
00272 {
00273   //return ((90-camera.Ycenter)+(ssc->getPosition(camera.SSCYconnector)/248.0F)*180.0F);
00274   return currentTilt;
00275 }
00276 
00277 /*============================================================*/
00278 
00279 float CameraControl::getSimPan()
00280 {
00281   return simPan;
00282 }
00283 
00284 /*============================================================*/
00285 
00286 float CameraControl::getSimTilt()
00287 {
00288   return simTilt;
00289 }
00290 // ######################################################################
00291 /* So things look consistent in everyone's emacs... */
00292 /* Local Variables: */
00293 /* indent-tabs-mode: nil */
00294 /* End: */
Generated on Sun May 8 08:40:37 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3