iCub-main
DragonflyDeviceDriver2.cpp
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2007 RobotCub Consortium
5  * Author: Alessandro Scalzo alessandro.scalzo@iit.it
6  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
7  *
8  */
9 
11 
12 #include <yarp/os/Stamp.h>
13 #include <yarp/dev/DeviceDriver.h>
14 #include <yarp/os/Log.h>
15 #include <yarp/os/LogStream.h>
16 
17 using namespace yarp::os;
18 using namespace yarp::dev;
19 
20 #include "FirewireCameraDC1394-DR2_2.h"
21 
23 inline CFWCamera_DR2_2* RES(void *res) { return (CFWCamera_DR2_2*)res; }
25 
26 bool DragonflyDeviceDriver2Rgb::getImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image)
27 {
28  return RES(system_resources)->CaptureImage(image);
29 }
30 
31 bool DragonflyDeviceDriver2Rgb::getImage(yarp::sig::ImageOf<yarp::sig::PixelMono>& image)
32 {
33  return RES(system_resources)->CaptureImage(image);
34 }
35 
36 int DragonflyDeviceDriver2Rgb::width () const
37 {
38  return RES(system_resources)->width();
39 }
40 
41 int DragonflyDeviceDriver2Rgb::height () const
42 {
43  return RES(system_resources)->height();
44 }
45 
46 bool DragonflyDeviceDriver2Raw::getImage(yarp::sig::ImageOf<yarp::sig::PixelMono>& image)
47 {
48  return RES(system_resources)->CaptureImage(image);
49 }
50 
51 int DragonflyDeviceDriver2Raw::width () const
52 {
53  return RES(system_resources)->width();
54 }
55 
56 int DragonflyDeviceDriver2Raw::height () const
57 {
58  return RES(system_resources)->height();
59 }
60 
62 
63 DragonflyDeviceDriver2::DragonflyDeviceDriver2(bool raw) :
64  raw(raw), system_resources(NULL)
65 {
66 }
67 
69 {
70  if (system_resources)
71  {
73  system_resources=NULL;
74  }
75 }
76 
77 bool DragonflyDeviceDriver2::open(yarp::os::Searchable& config)
78 {
79  if(config.check("pixelType"))
80  {
81  if(config.find(("pixelType")).asVocab32()==VOCAB_PIXEL_MONO)
82  raw=true;
83  else if((config.find(("pixelType")).asVocab32()==VOCAB_PIXEL_RGB))
84  raw=false;
85  else
86  {
87  yError()<<"DragonflyDeviceDriver2: invalid pixelType:"<<yarp::os::Vocab32::decode(config.find(("pixelType")).asVocab32());
88  return false;
89  }
90  }
91 
93  if (!RES(system_resources)->Create(config))
94  {
95  fprintf(stderr,"DragonflyDeviceDriver2: can't open camera\n");
96  return false;
97  }
98 
99  return true;
100 }
101 
103 {
104  if (system_resources)
105  {
107  return true;
108  }
109 
110  return false;
111 }
112 
114 {
116 }
117 
118 // SET
119 
121 {
122  return RES(system_resources)->setBrightness(value);
123 }
125 {
126  return RES(system_resources)->setExposure(value);
127 }
129 {
130  return RES(system_resources)->setSharpness(value);
131 }
132 bool DragonflyDeviceDriver2::setWhiteBalance(double blue, double red)
133 {
134  return RES(system_resources)->setWhiteBalance(blue,red);
135 }
137 {
138  return RES(system_resources)->setHue(value);
139 }
141 {
142  return RES(system_resources)->setSaturation(value);
143 }
145 {
146  return RES(system_resources)->setGamma(value);
147 }
149 {
150  return RES(system_resources)->setShutter(value);
151 }
153 {
154  return RES(system_resources)->setGain(value);
155 }
157 {
158  return RES(system_resources)->setIris(value);
159 }
160 
161 // GET
162 
164 {
166 }
168 {
169  return RES(system_resources)->getExposure();
170 }
172 {
173  return RES(system_resources)->getSharpness();
174 }
175 bool DragonflyDeviceDriver2::getWhiteBalance(double &blue, double &red)
176 {
177  return RES(system_resources)->getWhiteBalance(blue,red);
178 }
180 {
181  return RES(system_resources)->getHue();
182 }
184 {
186 }
188 {
189  return RES(system_resources)->getGamma();
190 }
192 {
193  return RES(system_resources)->getShutter();
194 }
196 {
197  return RES(system_resources)->getGain();
198 }
200 {
201  return RES(system_resources)->getIris();
202 }
203 
205 // DC1394
207 
210 {
211  return RES(system_resources)->hasFeatureDC1394(feature);
212 }
213 bool DragonflyDeviceDriver2::setFeatureDC1394(int feature,double value)
214 {
215  return RES(system_resources)->setFeatureDC1394(feature,value);
216 }
218 {
219  return RES(system_resources)->getFeatureDC1394(feature);
220 }
222 {
223  return RES(system_resources)->hasOnOffDC1394(feature);
224 }
225 bool DragonflyDeviceDriver2::setActiveDC1394(int feature, bool onoff)
226 {
227  return RES(system_resources)->setActiveDC1394(feature,onoff);
228 }
230 {
231  return RES(system_resources)->getActiveDC1394(feature);
232 }
234 {
235  return RES(system_resources)->hasAutoDC1394(feature);
236 }
238 {
239  return RES(system_resources)->hasManualDC1394(feature);
240 }
242 {
243  return RES(system_resources)->hasOnePushDC1394(feature);
244 }
245 bool DragonflyDeviceDriver2::setModeDC1394(int feature, bool auto_onoff)
246 {
247  return RES(system_resources)->setModeDC1394(feature,auto_onoff);
248 }
250 {
251  return RES(system_resources)->getModeDC1394(feature);
252 }
254 {
255  return RES(system_resources)->setOnePushDC1394(feature);
256 }
258 {
260 }
262 {
263  return RES(system_resources)->setVideoModeDC1394(video_mode);
264 }
266 {
268 }
270 {
272 }
274 {
275  return RES(system_resources)->getFPSDC1394();
276 }
278 {
279  return RES(system_resources)->setFPSDC1394(fps);
280 }
282 {
284 }
286 {
287  return RES(system_resources)->setISOSpeedDC1394(speed);
288 }
289 unsigned int DragonflyDeviceDriver2::getColorCodingMaskDC1394(unsigned int video_mode)
290 {
291  return RES(system_resources)->getColorCodingMaskDC1394(video_mode);
292 }
294 {
296 }
298 {
299  return RES(system_resources)->setColorCodingDC1394(coding);
300 }
302 {
304 }
306 {
308 }
309 bool DragonflyDeviceDriver2::getFormat7MaxWindowDC1394(unsigned int &xdim,unsigned int &ydim,unsigned int &xstep,unsigned int &ystep,unsigned int &xoffstep,unsigned int &yoffstep)
310 {
311  return RES(system_resources)->getFormat7MaxWindowDC1394(xdim,ydim,xstep,ystep,xoffstep,yoffstep);
312 }
313 bool DragonflyDeviceDriver2::setFormat7WindowDC1394(unsigned int xdim,unsigned int ydim,int x0,int y0)
314 {
315  return RES(system_resources)->setFormat7WindowDC1394(xdim,ydim,x0,y0);
316 }
317 bool DragonflyDeviceDriver2::getFormat7WindowDC1394(unsigned int &xdim,unsigned int &ydim,int &x0,int &y0)
318 {
319  return RES(system_resources)->getFormat7WindowDC1394(xdim,ydim,x0,y0);
320 }
322 {
324 }
326 {
328 }
330 {
332 }
334 {
336 }
337 /*
338 bool DragonflyDeviceDriver2::setBayerDC1394(bool bON)
339 {
340  return RES(system_resources)->setBayerDC1394(bON);
341 }
342 bool DragonflyDeviceDriver2::getBayerDC1394()
343 {
344  return RES(system_resources)->getBayerDC1394();
345 }
346 */
348 {
349  return RES(system_resources)->setBroadcastDC1394(onoff);
350 }
352 {
354 }
356 {
358 }
360 {
361  return RES(system_resources)->setPowerDC1394(onoff);
362 }
364 {
365  return RES(system_resources)->setCaptureDC1394(bON);
366 }
368 {
370 }
372 {
374 }
375 
376 //IVisualParams
377 
379  return RES(system_resources)->getRgbHeight();
380 }
381 
383  return RES(system_resources)->getRgbWidth();
384 }
385 
386 bool DragonflyDeviceDriver2::getRgbSupportedConfigurations(yarp::sig::VectorOf<CameraConfig> &configurations)
387 {
388  return RES(system_resources)->getRgbSupportedConfigurations(configurations);
389 }
390 
391 bool DragonflyDeviceDriver2::getRgbResolution(int &width, int &height)
392 {
393  return RES(system_resources)->getRgbResolution(width,height);
394 }
395 
396 bool DragonflyDeviceDriver2::setRgbResolution(int width, int height){
397  if(width<=0 || height<=0){
398  yError()<<"DragonflyDeviceDriver: invalid width or height";
399  return false;
400  }
401  return RES(system_resources)->setRgbResolution(width,height);
402 }
403 
404 bool DragonflyDeviceDriver2::getRgbFOV(double &horizontalFov, double &verticalFov){
405  return RES(system_resources)->getRgbFOV(horizontalFov, verticalFov);
406 }
407 
408 bool DragonflyDeviceDriver2::setRgbFOV(double horizontalFov, double verticalFov){
409  return RES(system_resources)->setRgbFOV(horizontalFov, verticalFov);
410 }
411 
412 bool DragonflyDeviceDriver2::getRgbIntrinsicParam(yarp::os::Property &intrinsic){
413  return RES(system_resources)->getRgbIntrinsicParam(intrinsic);
414 }
415 
417  return RES(system_resources)->getRgbMirroring(mirror);
418 
419 }
420 
422  return RES(system_resources)->setRgbMirroring(mirror);
423 }
424 
426 // IFrameGrabberControl2 //
428 
429 bool DragonflyDeviceDriver2::getCameraDescription(CameraDescriptor* camera)
430 {
431  camera->busType = BUS_FIREWIRE;
432  camera->deviceDescription = "DragonFly2";
433  return true;
434 }
435 
436 bool DragonflyDeviceDriver2::getActive(int feature, bool* isActive)
437 {
438  *isActive = RES(system_resources)->getActiveDC1394(feature);
439  return true;
440 }
441 
442 bool DragonflyDeviceDriver2::getFeature(int feature, double* values)
443 {
444  *values = RES(system_resources)->getFeatureDC1394(feature);
445  return true;
446 }
447 
448 bool DragonflyDeviceDriver2::getMode(int feature, FeatureMode* mode)
449 {
450  *mode = TRANSL_MODE( RES(system_resources)->getModeDC1394(feature) );
451  return true;
452 }
453 
454 bool DragonflyDeviceDriver2::hasAuto(int feature, bool* hasAuto)
455 {
457  return true;
458 }
459 
460 bool DragonflyDeviceDriver2::hasFeature(int feature, bool* hasFeature)
461 {
463  return true;
464 }
465 
466 bool DragonflyDeviceDriver2::hasManual(int feature, bool* hasManual)
467 {
469  return true;
470 }
471 
472 bool DragonflyDeviceDriver2::hasOnePush(int feature, bool* hasOnePush)
473 {
475  return true;
476 }
477 
478 bool DragonflyDeviceDriver2::hasOnOff(int feature, bool* HasOnOff)
479 {
480  *HasOnOff = RES(system_resources)->hasOnOffDC1394(feature);
481  return true;
482 }
483 
484 bool DragonflyDeviceDriver2::setActive(int feature, bool onoff)
485 {
486  return RES(system_resources)->setActiveDC1394(feature,onoff);
487 }
488 
489 bool DragonflyDeviceDriver2::setFeature(int feature, double value)
490 {
491  return RES(system_resources)->setFeatureDC1394(feature, value);
492 }
493 
494 bool DragonflyDeviceDriver2::getFeature(int feature, double* value1, double* value2)
495 {
496  if(feature == YARP_FEATURE_WHITE_BALANCE)
497  return RES(system_resources)->getWhiteBalanceDC1394(*value1, *value2);
498  else
499  return false;
500 }
501 
502 bool DragonflyDeviceDriver2::setFeature(int feature, double value1, double value2)
503 {
504  if(feature == YARP_FEATURE_WHITE_BALANCE)
505  return RES(system_resources)->setWhiteBalanceDC1394(value1, value2);
506  else
507  return false;
508 }
509 
510 bool DragonflyDeviceDriver2::setMode(int feature, FeatureMode mode)
511 {
512  return RES(system_resources)->setModeDC1394(feature, TRANSL_MODE(mode));
513 }
514 
516 {
517  return RES(system_resources)->setOnePushDC1394(feature);
518 }
519 
CFWCamera_DR2_2 * RES(void *res)
virtual bool setModeDC1394(int feature, bool auto_onoff)
virtual bool setTransmissionDC1394(bool bTxON)
virtual unsigned int getISOSpeedDC1394()
virtual unsigned int getFPSDC1394()
virtual unsigned int getColorCodingDC1394()
const yarp::os::Stamp & getLastInputStamp()
virtual bool hasFeatureDC1394(int feature)
virtual bool getWhiteBalanceDC1394(double &b, double &r)
virtual unsigned int getVideoModeMaskDC1394()
virtual bool setPowerDC1394(bool onoff)
virtual bool setHue(double v)
virtual bool setShutter(double v)
virtual unsigned int getBytesPerPacketDC1394()
virtual bool setWhiteBalanceDC1394(double b, double r)
virtual unsigned int getVideoModeDC1394()
virtual bool setCaptureDC1394(bool bON)
virtual bool setBrightness(double v)
bool CaptureImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image)
virtual bool setFeatureDC1394(int feature, double value)
virtual bool getWhiteBalance(double &blue, double &red)
virtual bool hasOnePushDC1394(int feature)
virtual bool setRgbFOV(double horizontalFov, double verticalFov)
virtual bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0)
virtual bool setOperationModeDC1394(bool b1394b)
virtual bool setBytesPerPacketDC1394(unsigned int bpp)
virtual unsigned int getFPSMaskDC1394()
virtual bool setRgbMirroring(bool mirror)
virtual bool hasAutoDC1394(int feature)
virtual bool getRgbFOV(double &horizontalFov, double &verticalFov)
virtual bool setBroadcastDC1394(bool onoff)
virtual bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations)
virtual bool getRgbResolution(int &width, int &height)
virtual bool setExposure(double v)
virtual bool setRgbResolution(int width, int height)
virtual bool setSharpness(double v)
virtual bool hasManualDC1394(int feature)
virtual double getFeatureDC1394(int feature)
virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep)
virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic)
virtual bool setGamma(double v)
virtual bool setActiveDC1394(int feature, bool onoff)
virtual bool setIris(double v)
virtual bool setFPSDC1394(int fps)
virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode)
virtual bool hasOnOffDC1394(int feature)
virtual bool getActiveDC1394(int feature)
virtual bool setISOSpeedDC1394(int speed)
virtual bool setColorCodingDC1394(int coding)
virtual bool getModeDC1394(int feature)
virtual bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0)
virtual bool setWhiteBalance(double blue, double red)
virtual bool getRgbMirroring(bool &mirror)
virtual bool setVideoModeDC1394(int video_mode)
virtual bool setOnePushDC1394(int feature)
virtual bool setSaturation(double v)
bool Create(yarp::os::Searchable &config)
virtual bool setGain(double v)
virtual bool setColorCodingDC1394(int coding)
Set image color coding.
virtual bool setActiveDC1394(int feature, bool onoff)
Switch feature on/off.
virtual bool setPowerDC1394(bool onoff)
Switch camera power ON/OFF.
virtual bool getActiveDC1394(int feature)
Is feature ON or OFF?
virtual bool setMode(int feature, FeatureMode mode)
virtual unsigned int getColorCodingDC1394()
Get image color coding.
virtual bool setWhiteBalance(double blue, double red)
Set White Balance.
virtual unsigned int getVideoModeDC1394()
Get camera acquisition mode.
virtual unsigned int getFPSMaskDC1394()
Get supported framerates mask.
virtual bool getTransmissionDC1394()
Is image transmission ON or OFF?
virtual bool hasOnOff(int feature, bool *HasOnOff)
virtual bool close(void)
Closes the device driver.
virtual bool hasManualDC1394(int feature)
Has feature Manual mode?
virtual bool getRgbFOV(double &horizontalFov, double &verticalFov)
Get the field of view (FOV) of the rgb camera.
virtual double getBrightness()
Get Brightness.
virtual bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0)
Get image dimensions in Format 7 mode.
virtual bool setDefaultsDC1394()
Set camera features to default.
virtual double getExposure()
Get Exposure.
virtual bool setCaptureDC1394(bool bON)
Switch image capture ON/OFF.
virtual double getSharpness()
Get Sharpness.
virtual bool setVideoModeDC1394(int video_mode)
Set camera acquisition mode.
virtual bool setBroadcastDC1394(bool onoff)
Set feature commands propagation ON/OFF.
virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep)
Get maximum image dimensions in Format 7 mode.
virtual double getFeatureDC1394(int feature)
Get feature value.
virtual unsigned int getBytesPerPacketDC1394()
Get Firewire communication packet size.
virtual bool setOnePushDC1394(int feature)
Trigger feature One Push adjust.
virtual bool getModeDC1394(int feature)
Is feature mode Auto or Manual?
virtual bool hasAutoDC1394(int feature)
Has feature Auto mode?
virtual bool setTransmissionDC1394(bool bTxON)
Set image transmission ON/OFF.
virtual bool setIris(double v)
Set Iris.
virtual bool hasFeatureDC1394(int feature)
Is feature present?
virtual bool setRgbResolution(int width, int height)
Set the resolution of the rgb image from the camera.
virtual bool setModeDC1394(int feature, bool auto_onoff)
Switch feature Auto/Manual.
virtual bool setFPSDC1394(int fps)
Set camera framerate.
virtual int getRgbWidth()
Return the width of each frame.
virtual double getSaturation()
Get Saturation.
virtual bool setWhiteBalanceDC1394(double b, double r)
Set White Balance.
virtual bool setActive(int feature, bool onoff)
virtual bool getOperationModeDC1394()
Get Operation Mode.
virtual bool getFeature(int feature, double *values)
virtual bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations)
Get the possible configurations of the camera.
virtual yarp::os::Stamp getLastInputStamp()
Implements the IPreciselyTimed interface.
virtual unsigned int getFPSDC1394()
Get camera framerate.
virtual bool setOperationModeDC1394(bool b1394b)
Set Operation Mode.
virtual bool hasManual(int feature, bool *hasManual)
virtual bool getWhiteBalanceDC1394(double &b, double &r)
Get White Balance.
virtual bool hasOnePush(int feature, bool *hasOnePush)
virtual bool hasAuto(int feature, bool *hasAuto)
virtual bool setGain(double v)
Set Gain.
virtual bool hasOnOffDC1394(int feature)
Can be feature turned on/off?
virtual bool setBytesPerPacketDC1394(unsigned int bpp)
Set Firewire communication packet size.
virtual unsigned int getISOSpeedDC1394()
Get camera Firewire ISO speed.
virtual bool setGamma(double v)
Set Gamma.
virtual bool setRgbFOV(double horizontalFov, double verticalFov)
Set the field of view (FOV) of the rgb camera.
virtual bool setShutter(double v)
Set Shutter.
virtual bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0)
Set image dimensions in Format 7 mode.
virtual bool getActive(int feature, bool *isActive)
virtual unsigned int getVideoModeMaskDC1394()
Get supported video mode mask.
virtual bool hasOnePushDC1394(int feature)
Has feature Manual mode?
virtual bool setHue(double v)
Set Hue.
virtual bool setExposure(double v)
Set Exposure.
virtual bool setFeature(int feature, double values)
virtual bool setISOSpeedDC1394(int speed)
Set camera Firewire ISO speed.
virtual bool setSharpness(double v)
Set Sharpness.
virtual bool setSaturation(double v)
Set Saturation.
virtual bool getCameraDescription(CameraDescriptor *camera)
virtual int getRgbHeight()
Return the height of each frame.
virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic)
Get the intrinsic parameters of the rgb camera.
virtual bool getWhiteBalance(double &blue, double &red)
Get White Balance.
virtual bool open(yarp::os::Searchable &config)
Open the device driver.
virtual bool hasFeature(int feature, bool *hasFeature)
virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode)
Get supported color coding mask.
virtual bool getRgbMirroring(bool &mirror)
Get the mirroring setting of the sensor.
virtual double getShutter()
Get Shutter.
virtual bool getMode(int feature, FeatureMode *mode)
virtual bool getRgbResolution(int &width, int &height)
Get the resolution of the rgb image from the camera.
virtual bool setBrightness(double v)
Set Brightness.
virtual bool setFeatureDC1394(int feature, double value)
Set feature value.
virtual bool setRgbMirroring(bool mirror)
Set the mirroring setting of the sensor.
fprintf(fid,'\n')