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/dev/FrameGrabberInterfaces.h>
15 #include <yarp/os/Log.h>
16 #include <yarp/os/LogStream.h>
17 
18 using namespace yarp::os;
19 using namespace yarp::dev;
20 
21 #include "FirewireCameraDC1394-DR2_2.h"
22 
24 inline CFWCamera_DR2_2* RES(void *res) { return (CFWCamera_DR2_2*)res; }
26 
27 bool DragonflyDeviceDriver2Rgb::getImage(yarp::sig::ImageOf<yarp::sig::PixelRgb>& image)
28 {
29  return RES(system_resources)->CaptureImage(image);
30 }
31 
32 bool DragonflyDeviceDriver2Rgb::getImage(yarp::sig::ImageOf<yarp::sig::PixelMono>& image)
33 {
34  return RES(system_resources)->CaptureImage(image);
35 }
36 
37 int DragonflyDeviceDriver2Rgb::width () const
38 {
39  return RES(system_resources)->width();
40 }
41 
42 int DragonflyDeviceDriver2Rgb::height () const
43 {
44  return RES(system_resources)->height();
45 }
46 
47 bool DragonflyDeviceDriver2Raw::getImage(yarp::sig::ImageOf<yarp::sig::PixelMono>& image)
48 {
49  return RES(system_resources)->CaptureImage(image);
50 }
51 
52 int DragonflyDeviceDriver2Raw::width () const
53 {
54  return RES(system_resources)->width();
55 }
56 
57 int DragonflyDeviceDriver2Raw::height () const
58 {
59  return RES(system_resources)->height();
60 }
61 
63 
64 DragonflyDeviceDriver2::DragonflyDeviceDriver2(bool raw) :
65  raw(raw), system_resources(NULL)
66 {
67 }
68 
70 {
71  if (system_resources)
72  {
74  system_resources=NULL;
75  }
76 }
77 
78 bool DragonflyDeviceDriver2::open(yarp::os::Searchable& config)
79 {
80  if(config.check("pixelType"))
81  {
82  if(config.find(("pixelType")).asVocab32()==VOCAB_PIXEL_MONO)
83  raw=true;
84  else if((config.find(("pixelType")).asVocab32()==VOCAB_PIXEL_RGB))
85  raw=false;
86  else
87  {
88  yError()<<"DragonflyDeviceDriver2: invalid pixelType:"<<yarp::os::Vocab32::decode(config.find(("pixelType")).asVocab32());
89  return false;
90  }
91  }
92 
94  if (!RES(system_resources)->Create(config))
95  {
96  fprintf(stderr,"DragonflyDeviceDriver2: can't open camera\n");
97  return false;
98  }
99 
100  return true;
101 }
102 
104 {
105  if (system_resources)
106  {
108  return true;
109  }
110 
111  return false;
112 }
113 
114 bool DragonflyDeviceDriver2::getRawBuffer(unsigned char *buff)
115 {
116  return RES(system_resources)->CaptureRaw(buff);
117 }
118 
119 bool DragonflyDeviceDriver2::getRgbBuffer(unsigned char *buff)
120 {
121  return RES(system_resources)->CaptureRgb(buff);
122 }
123 
125 {
127 }
128 
130 {
132 }
133 
135 {
136  return RES(system_resources)->width();
137 }
138 
140 {
141  return RES(system_resources)->height();
142 }
143 
144 // SET
145 
147 {
148  return RES(system_resources)->setBrightness(value);
149 }
151 {
152  return RES(system_resources)->setExposure(value);
153 }
155 {
156  return RES(system_resources)->setSharpness(value);
157 }
158 bool DragonflyDeviceDriver2::setWhiteBalance(double blue, double red)
159 {
160  return RES(system_resources)->setWhiteBalance(blue,red);
161 }
163 {
164  return RES(system_resources)->setHue(value);
165 }
167 {
168  return RES(system_resources)->setSaturation(value);
169 }
171 {
172  return RES(system_resources)->setGamma(value);
173 }
175 {
176  return RES(system_resources)->setShutter(value);
177 }
179 {
180  return RES(system_resources)->setGain(value);
181 }
183 {
184  return RES(system_resources)->setIris(value);
185 }
186 
187 // GET
188 
190 {
192 }
194 {
195  return RES(system_resources)->getExposure();
196 }
198 {
199  return RES(system_resources)->getSharpness();
200 }
201 bool DragonflyDeviceDriver2::getWhiteBalance(double &blue, double &red)
202 {
203  return RES(system_resources)->getWhiteBalance(blue,red);
204 }
206 {
207  return RES(system_resources)->getHue();
208 }
210 {
212 }
214 {
215  return RES(system_resources)->getGamma();
216 }
218 {
219  return RES(system_resources)->getShutter();
220 }
222 {
223  return RES(system_resources)->getGain();
224 }
226 {
227  return RES(system_resources)->getIris();
228 }
229 
231 // DC1394
233 
236 {
237  return RES(system_resources)->hasFeatureDC1394(feature);
238 }
239 bool DragonflyDeviceDriver2::setFeatureDC1394(int feature,double value)
240 {
241  return RES(system_resources)->setFeatureDC1394(feature,value);
242 }
244 {
245  return RES(system_resources)->getFeatureDC1394(feature);
246 }
248 {
249  return RES(system_resources)->hasOnOffDC1394(feature);
250 }
251 bool DragonflyDeviceDriver2::setActiveDC1394(int feature, bool onoff)
252 {
253  return RES(system_resources)->setActiveDC1394(feature,onoff);
254 }
256 {
257  return RES(system_resources)->getActiveDC1394(feature);
258 }
260 {
261  return RES(system_resources)->hasAutoDC1394(feature);
262 }
264 {
265  return RES(system_resources)->hasManualDC1394(feature);
266 }
268 {
269  return RES(system_resources)->hasOnePushDC1394(feature);
270 }
271 bool DragonflyDeviceDriver2::setModeDC1394(int feature, bool auto_onoff)
272 {
273  return RES(system_resources)->setModeDC1394(feature,auto_onoff);
274 }
276 {
277  return RES(system_resources)->getModeDC1394(feature);
278 }
280 {
281  return RES(system_resources)->setOnePushDC1394(feature);
282 }
284 {
286 }
288 {
289  return RES(system_resources)->setVideoModeDC1394(video_mode);
290 }
292 {
294 }
296 {
298 }
300 {
301  return RES(system_resources)->getFPSDC1394();
302 }
304 {
305  return RES(system_resources)->setFPSDC1394(fps);
306 }
308 {
310 }
312 {
313  return RES(system_resources)->setISOSpeedDC1394(speed);
314 }
315 unsigned int DragonflyDeviceDriver2::getColorCodingMaskDC1394(unsigned int video_mode)
316 {
317  return RES(system_resources)->getColorCodingMaskDC1394(video_mode);
318 }
320 {
322 }
324 {
325  return RES(system_resources)->setColorCodingDC1394(coding);
326 }
328 {
330 }
332 {
334 }
335 bool DragonflyDeviceDriver2::getFormat7MaxWindowDC1394(unsigned int &xdim,unsigned int &ydim,unsigned int &xstep,unsigned int &ystep,unsigned int &xoffstep,unsigned int &yoffstep)
336 {
337  return RES(system_resources)->getFormat7MaxWindowDC1394(xdim,ydim,xstep,ystep,xoffstep,yoffstep);
338 }
339 bool DragonflyDeviceDriver2::setFormat7WindowDC1394(unsigned int xdim,unsigned int ydim,int x0,int y0)
340 {
341  return RES(system_resources)->setFormat7WindowDC1394(xdim,ydim,x0,y0);
342 }
343 bool DragonflyDeviceDriver2::getFormat7WindowDC1394(unsigned int &xdim,unsigned int &ydim,int &x0,int &y0)
344 {
345  return RES(system_resources)->getFormat7WindowDC1394(xdim,ydim,x0,y0);
346 }
348 {
350 }
352 {
354 }
356 {
358 }
360 {
362 }
363 /*
364 bool DragonflyDeviceDriver2::setBayerDC1394(bool bON)
365 {
366  return RES(system_resources)->setBayerDC1394(bON);
367 }
368 bool DragonflyDeviceDriver2::getBayerDC1394()
369 {
370  return RES(system_resources)->getBayerDC1394();
371 }
372 */
374 {
375  return RES(system_resources)->setBroadcastDC1394(onoff);
376 }
378 {
380 }
382 {
384 }
386 {
387  return RES(system_resources)->setPowerDC1394(onoff);
388 }
390 {
391  return RES(system_resources)->setCaptureDC1394(bON);
392 }
394 {
396 }
398 {
400 }
401 
402 //IVisualParams
403 
405  return RES(system_resources)->getRgbHeight();
406 }
407 
409  return RES(system_resources)->getRgbWidth();
410 }
411 
412 bool DragonflyDeviceDriver2::getRgbSupportedConfigurations(yarp::sig::VectorOf<CameraConfig> &configurations)
413 {
414  return RES(system_resources)->getRgbSupportedConfigurations(configurations);
415 }
416 
417 bool DragonflyDeviceDriver2::getRgbResolution(int &width, int &height)
418 {
420 }
421 
422 bool DragonflyDeviceDriver2::setRgbResolution(int width, int height){
423  if(width<=0 || height<=0){
424  yError()<<"DragonflyDeviceDriver: invalid width or height";
425  return false;
426  }
428 }
429 
430 bool DragonflyDeviceDriver2::getRgbFOV(double &horizontalFov, double &verticalFov){
431  return RES(system_resources)->getRgbFOV(horizontalFov, verticalFov);
432 }
433 
434 bool DragonflyDeviceDriver2::setRgbFOV(double horizontalFov, double verticalFov){
435  return RES(system_resources)->setRgbFOV(horizontalFov, verticalFov);
436 }
437 
438 bool DragonflyDeviceDriver2::getRgbIntrinsicParam(yarp::os::Property &intrinsic){
439  return RES(system_resources)->getRgbIntrinsicParam(intrinsic);
440 }
441 
443  return RES(system_resources)->getRgbMirroring(mirror);
444 
445 }
446 
448  return RES(system_resources)->setRgbMirroring(mirror);
449 }
450 
452 // IFrameGrabberControl2 //
454 
455 bool DragonflyDeviceDriver2::getCameraDescription(CameraDescriptor* camera)
456 {
457  camera->busType = BUS_FIREWIRE;
458  camera->deviceDescription = "DragonFly2";
459  return true;
460 }
461 
462 bool DragonflyDeviceDriver2::getActive(int feature, bool* isActive)
463 {
464  *isActive = RES(system_resources)->getActiveDC1394(feature);
465  return true;
466 }
467 
468 bool DragonflyDeviceDriver2::getFeature(int feature, double* values)
469 {
470  *values = RES(system_resources)->getFeatureDC1394(feature);
471  return true;
472 }
473 
474 bool DragonflyDeviceDriver2::getMode(int feature, FeatureMode* mode)
475 {
476  *mode = TRANSL_MODE( RES(system_resources)->getModeDC1394(feature) );
477  return true;
478 }
479 
480 bool DragonflyDeviceDriver2::hasAuto(int feature, bool* hasAuto)
481 {
483  return true;
484 }
485 
486 bool DragonflyDeviceDriver2::hasFeature(int feature, bool* hasFeature)
487 {
489  return true;
490 }
491 
492 bool DragonflyDeviceDriver2::hasManual(int feature, bool* hasManual)
493 {
495  return true;
496 }
497 
498 bool DragonflyDeviceDriver2::hasOnePush(int feature, bool* hasOnePush)
499 {
501  return true;
502 }
503 
504 bool DragonflyDeviceDriver2::hasOnOff(int feature, bool* HasOnOff)
505 {
506  *HasOnOff = RES(system_resources)->hasOnOffDC1394(feature);
507  return true;
508 }
509 
510 bool DragonflyDeviceDriver2::setActive(int feature, bool onoff)
511 {
512  return RES(system_resources)->setActiveDC1394(feature,onoff);
513 }
514 
515 bool DragonflyDeviceDriver2::setFeature(int feature, double value)
516 {
517  return RES(system_resources)->setFeatureDC1394(feature, value);
518 }
519 
520 bool DragonflyDeviceDriver2::getFeature(int feature, double* value1, double* value2)
521 {
522  if(feature == YARP_FEATURE_WHITE_BALANCE)
523  return RES(system_resources)->getWhiteBalanceDC1394(*value1, *value2);
524  else
525  return false;
526 }
527 
528 bool DragonflyDeviceDriver2::setFeature(int feature, double value1, double value2)
529 {
530  if(feature == YARP_FEATURE_WHITE_BALANCE)
531  return RES(system_resources)->setWhiteBalanceDC1394(value1, value2);
532  else
533  return false;
534 }
535 
536 bool DragonflyDeviceDriver2::setMode(int feature, FeatureMode mode)
537 {
538  return RES(system_resources)->setModeDC1394(feature, TRANSL_MODE(mode));
539 }
540 
542 {
543  return RES(system_resources)->setOnePushDC1394(feature);
544 }
545 
CFWCamera_DR2_2 * RES(void *res)
virtual bool setModeDC1394(int feature, bool auto_onoff)
virtual bool setTransmissionDC1394(bool bTxON)
virtual unsigned int getISOSpeedDC1394()
bool CaptureRaw(unsigned char *pBuffer)
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)
bool CaptureRgb(unsigned char *pBuffer)
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 getRawBuffer(unsigned char *buffer)
Implements FrameGrabber basic interface.
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 int getRawBufferSize()
Implements the Frame grabber basic interface.
virtual bool setIris(double v)
Set Iris.
virtual bool hasFeatureDC1394(int feature)
Is feature present?
virtual bool getRgbBuffer(unsigned char *buffer)
FrameGrabber bgr interface, returns the last acquired frame as a buffer of bgr triplets.
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 int height() const
Implements FrameGrabber basic interface.
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 int width() const
Implements FrameGrabber basic interface.
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')