sony_evid100p.cpp

00001 
00002 /***************************************************************************
00003  *  sony_evid100p_control.cpp - Controller for Sony EVI-D100P
00004  *
00005  *  Created: Tue Jun 07 19:27:20 2005
00006  *  Copyright  2005-2009  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023 
00024 #include <cams/control/sony_evid100p.h>
00025 #include <cams/control/visca.h>
00026 #include <fvutils/system/camargp.h>
00027 
00028 #include <utils/math/angle.h>
00029 
00030 #include <termios.h>
00031 #include <cstring>
00032 #include <cstdlib>
00033 
00034 using namespace std;
00035 using namespace fawkes;
00036 
00037 namespace firevision {
00038 #if 0 /* just to make Emacs auto-indent happy */
00039 }
00040 #endif
00041 
00042 /** Maximum pan. */
00043 const int   SonyEviD100PControl::MAX_PAN       =  1440;
00044 /** Minimum pan. */
00045 const int   SonyEviD100PControl::MIN_PAN       = -1439;
00046 /** Max Tilt. */
00047 const int   SonyEviD100PControl::MAX_TILT      =   360;
00048 /** Min tilt .*/
00049 const int   SonyEviD100PControl::MIN_TILT      = - 359;
00050 
00051 /** Max pan in degrees. */
00052 const float SonyEviD100PControl::MAX_PAN_DEG   =  100.f;
00053 /** Min pan in degrees. */
00054 const float SonyEviD100PControl::MIN_PAN_DEG   = -100.f;
00055 /** Max tilt in degrees. */
00056 const float SonyEviD100PControl::MAX_TILT_DEG  =   25.f;
00057 /** Min tilt in degrees. */
00058 const float SonyEviD100PControl::MIN_TILT_DEG  = - 25.f;
00059 
00060 /** Max pan in rad. */
00061 const float SonyEviD100PControl::MAX_PAN_RAD   = deg2rad(MAX_PAN_DEG);
00062 /** Min pan in rad. */
00063 const float SonyEviD100PControl::MIN_PAN_RAD   = deg2rad(MIN_PAN_DEG);
00064 /** Max tilt in rad. */
00065 const float SonyEviD100PControl::MAX_TILT_RAD  = deg2rad(MAX_TILT_DEG);
00066 /** Min tilt in rad. */
00067 const float SonyEviD100PControl::MIN_TILT_RAD  = deg2rad(MIN_TILT_DEG);
00068 
00069 /** Pan steps per degree */
00070 const float SonyEviD100PControl::PAN_STEPS_PER_DEG  = MAX_PAN  / MAX_PAN_DEG;
00071 /** Tilt steps per degree */
00072 const float SonyEviD100PControl::TILT_STEPS_PER_DEG = MAX_TILT / MAX_TILT_DEG;
00073 
00074 /** Pan steps per rad */
00075 const float SonyEviD100PControl::PAN_STEPS_PER_RAD  = MAX_PAN  / MAX_PAN_RAD;
00076 /** Tilt steps per rad */
00077 const float SonyEviD100PControl::TILT_STEPS_PER_RAD = MAX_TILT / MAX_TILT_RAD;
00078 
00079 /** Pastel effect. */
00080 const unsigned int SonyEviD100PControl::EFFECT_PASTEL   = 1;
00081 /** Negative effect. */
00082 const unsigned int SonyEviD100PControl::EFFECT_NEGATIVE = 2;
00083 /** Sepia effect. */
00084 const unsigned int SonyEviD100PControl::EFFECT_SEPIA    = 3;
00085 /** B/W effect. */
00086 const unsigned int SonyEviD100PControl::EFFECT_BW       = 4;
00087 /** Solarize effect. */
00088 const unsigned int SonyEviD100PControl::EFFECT_SOLARIZE = 5;
00089 /** Mosaic effect. */
00090 const unsigned int SonyEviD100PControl::EFFECT_MOSAIC   = 6;
00091 /** Slim effect. */
00092 const unsigned int SonyEviD100PControl::EFFECT_SLIM     = 7;
00093 /** Stretch effect. */
00094 const unsigned int SonyEviD100PControl::EFFECT_STRETCH  = 8;
00095 
00096 
00097 /** @class SonyEviD100PControl <cams/control/sony_evid100p.h>
00098  * Sony Evi D100P pan/tilt control.
00099  * Internally uses Visca.
00100  * @author Tim Niemueller
00101  */
00102 
00103 
00104 /** Constructor.
00105  * @param tty_port serial port (e.g. /dev/ttyS0)
00106  */
00107 SonyEviD100PControl::SonyEviD100PControl(const char *tty_port)
00108 {
00109   this->tty_port = strdup(tty_port);
00110   visca = new ViscaControl( /* non-blocking */ false );
00111   opened = false;
00112   pan_target = 0;
00113   tilt_target = 0;
00114   _effect = EFFECT_NONE;
00115 
00116   open();
00117 }
00118 
00119 
00120 /** Constructor.
00121  * Uses camera argument parser to gather arguments. The ID that the camera argument
00122  * parser returns is used as the serial port (like /dev/ttyS0).
00123  * @param cap camera argument parser
00124  */
00125 SonyEviD100PControl::SonyEviD100PControl(const CameraArgumentParser *cap)
00126 {
00127   tty_port = strdup(cap->cam_id().c_str());
00128 
00129   visca = new ViscaControl( /* non-blocking */ false );
00130   opened = false;
00131   pan_target = 0;
00132   tilt_target = 0;
00133   _effect = EFFECT_NONE;
00134 
00135   open();
00136 }
00137 
00138 
00139 /** Destructor. */
00140 SonyEviD100PControl::~SonyEviD100PControl()
00141 {
00142   close();
00143   delete visca;
00144   free(tty_port);
00145 }
00146 
00147 
00148 /** Open visca device.
00149  * @return true on success
00150  */
00151 void
00152 SonyEviD100PControl::open()
00153 {
00154   if (opened) return;
00155 
00156   try {
00157     visca->open(tty_port);
00158     visca->set_address(1);
00159     visca->clear();
00160   } catch (ViscaControlException &e) {
00161     visca->close();
00162     e.append("Sony EviD100PControl failed");
00163     throw;
00164   }
00165 
00166   opened = true;
00167 }
00168 
00169 
00170 /** Close Visca device.
00171  */
00172 void
00173 SonyEviD100PControl::close()
00174 {
00175   if ( ! opened ) return;
00176   visca->close();
00177 }
00178 
00179 
00180 void
00181 SonyEviD100PControl::process_pantilt()
00182 {
00183   visca->process();
00184 }
00185 
00186 
00187 bool
00188 SonyEviD100PControl::supports_pan()
00189 {
00190   return true;
00191 }
00192 
00193 
00194 bool
00195 SonyEviD100PControl::supports_tilt()
00196 {
00197   return true;
00198 }
00199 
00200 
00201 void
00202 SonyEviD100PControl::set_pan(int pan)
00203 {
00204   pan_target = pan;
00205   visca->setPanTilt(pan, tilt_target);
00206 }
00207 
00208 
00209 void
00210 SonyEviD100PControl::set_tilt(int tilt)
00211 {
00212   tilt_target = tilt;
00213   visca->setPanTilt(pan_target, tilt);
00214 }
00215 
00216 
00217 void
00218 SonyEviD100PControl::set_pan_tilt(int pan, int tilt)
00219 {
00220   pan_target  = pan;
00221   tilt_target = tilt;
00222   visca->setPanTilt(pan, tilt);
00223 }
00224 
00225 
00226 void
00227 SonyEviD100PControl::set_pan_tilt_rad(float pan, float tilt)
00228 {
00229   int tpan = 0, ttilt = 0;
00230 
00231   tpan = (int)rint(  pan  * PAN_STEPS_PER_RAD  );
00232   ttilt = (int)rint( tilt * TILT_STEPS_PER_RAD );
00233 
00234   set_pan_tilt(tpan, ttilt);
00235 }
00236 
00237 
00238 void
00239 SonyEviD100PControl::start_get_pan_tilt()
00240 {
00241   visca->startGetPanTilt();
00242 }
00243 
00244 
00245 void
00246 SonyEviD100PControl::pan_tilt(int &pan, int &tilt)
00247 {
00248   int tpan, ttilt;
00249   visca->getPanTilt(&tpan, &ttilt);
00250   pan  = tpan;
00251   tilt = ttilt;
00252 }
00253 
00254 
00255 void
00256 SonyEviD100PControl::pan_tilt_rad(float &pan, float &tilt)
00257 {
00258   int tpan = 0, ttilt = 0;
00259   visca->getPanTilt(&tpan, &ttilt);
00260 
00261   pan  = tpan  / PAN_STEPS_PER_RAD;
00262   tilt = ttilt / PAN_STEPS_PER_RAD;
00263 }
00264 
00265 
00266 int
00267 SonyEviD100PControl::pan()
00268 {
00269   int pan = 0, tilt = 0;
00270   visca->getPanTilt(&pan, &tilt);
00271   return pan;
00272 }
00273 
00274 
00275 int
00276 SonyEviD100PControl::tilt()
00277 {
00278   int pan = 0, tilt = 0;
00279   visca->getPanTilt(&pan, &tilt);
00280   return tilt;
00281 }
00282 
00283 
00284 int
00285 SonyEviD100PControl::max_pan()
00286 {
00287   return MAX_PAN;
00288 }
00289 
00290 
00291 int
00292 SonyEviD100PControl::min_pan()
00293 {
00294   return MIN_PAN;
00295 }
00296 
00297 
00298 int
00299 SonyEviD100PControl::max_tilt()
00300 {
00301   return MAX_TILT;
00302 }
00303 
00304 
00305 int
00306 SonyEviD100PControl::min_tilt()
00307 {
00308   return MIN_TILT;
00309 }
00310 
00311 
00312 void
00313 SonyEviD100PControl::reset_pan_tilt()
00314 {
00315   visca->resetPanTilt();
00316 }
00317 
00318 
00319 void
00320 SonyEviD100PControl::set_pan_tilt_limit(int pan_left, int pan_right,
00321                                      int tilt_up, int tilt_down)
00322 {
00323   visca->setPanTiltLimit(pan_left, pan_right, tilt_up, tilt_down);
00324 }
00325 
00326 
00327 void
00328 SonyEviD100PControl::reset_pan_tilt_limit()
00329 {
00330   visca->resetPanTiltLimit();
00331 }
00332 
00333 
00334 void
00335 SonyEviD100PControl::reset_zoom()
00336 {
00337   visca->resetZoom();
00338 }
00339 
00340 
00341 void
00342 SonyEviD100PControl::set_zoom(unsigned int zoom)
00343 {
00344   visca->setZoom(zoom);
00345 }
00346 
00347 
00348 unsigned int
00349 SonyEviD100PControl::zoom()
00350 {
00351   unsigned int zoom;
00352   visca->getZoom(&zoom);
00353   return zoom;
00354 }
00355 
00356 
00357 unsigned int
00358 SonyEviD100PControl::zoom_min()
00359 {
00360   return 0;
00361 }
00362 
00363 
00364 unsigned int
00365 SonyEviD100PControl::zoom_max()
00366 {
00367   return 0x4000;
00368 }
00369 
00370 
00371 void
00372 SonyEviD100PControl::set_zoom_speed_tele(unsigned int speed)
00373 {
00374   visca->setZoomSpeedTele(speed);
00375 }
00376 
00377 
00378 void
00379 SonyEviD100PControl::set_zoom_speed_wide(unsigned int speed)
00380 {
00381   visca->setZoomSpeedWide(speed);
00382 }
00383 
00384 
00385 void
00386 SonyEviD100PControl::set_zoom_digital_enabled(bool enabled)
00387 {
00388   visca->setZoomDigitalEnabled(enabled);
00389 }
00390 
00391 
00392 bool
00393 SonyEviD100PControl::supports_effect(unsigned int __effect)
00394 {
00395   if ( __effect == EFFECT_NONE ) {
00396     return true;
00397   }
00398 
00399   switch (__effect) {
00400   case EFFECT_PASTEL:
00401   case EFFECT_NEGATIVE:
00402   case EFFECT_SEPIA:
00403   case EFFECT_BW:
00404   case EFFECT_SOLARIZE:
00405   case EFFECT_MOSAIC:
00406   case EFFECT_SLIM:
00407   case EFFECT_STRETCH:
00408     return true;
00409     break;
00410   default:
00411     return false;
00412   }
00413 }
00414 
00415 
00416 void
00417 SonyEviD100PControl::set_effect(unsigned int __effect)
00418 {
00419   this->_effect = __effect;
00420   if ( __effect == EFFECT_NONE ) {
00421     visca->resetEffect();
00422   }
00423   switch (__effect) {
00424   case EFFECT_PASTEL:
00425     visca->applyEffectPastel();
00426     break;
00427   case EFFECT_NEGATIVE:
00428     visca->applyEffectNegArt();
00429     break;
00430   case EFFECT_SEPIA:
00431     visca->applyEffectSepia();
00432     break;
00433   case EFFECT_BW:
00434     visca->applyEffectBnW();
00435     break;
00436   case EFFECT_SOLARIZE:
00437     visca->applyEffectSolarize();
00438     break;
00439   case EFFECT_MOSAIC:
00440     visca->applyEffectMosaic();
00441     break;
00442   case EFFECT_SLIM:
00443     visca->applyEffectSlim();
00444     break;
00445   case EFFECT_STRETCH:
00446     visca->applyEffectStretch();
00447     break;
00448   default:
00449     break;
00450   }
00451 
00452 }
00453 
00454 
00455 unsigned int
00456 SonyEviD100PControl::effect()
00457 {
00458   return _effect;
00459 }
00460 
00461 
00462 void
00463 SonyEviD100PControl::reset_effect()
00464 {
00465   visca->resetEffect();
00466 }
00467 
00468 
00469 /** Get current white balance mode.
00470  * @return white balance mode
00471  */
00472 unsigned int
00473 SonyEviD100PControl::white_balance_mode()
00474 {
00475   return visca->getWhiteBalanceMode();
00476 }
00477 
00478 } // end namespace firevision

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1