Robotics Library  0.7.0
Dc1394Camera.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009, Markus Rickert
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 // POSSIBILITY OF SUCH DAMAGE.
25 //
26 
27 #ifndef RL_HAL_DC1394CAMERA_H
28 #define RL_HAL_DC1394CAMERA_H
29 
30 #if (LIBDC1394_VERSION_MAJOR > 10)
31 #include <dc1394/dc1394.h>
32 #else
33 #include <libdc1394/dc1394_control.h>
34 #include <libraw1394/raw1394.h>
35 #endif
36 
37 #include <string>
38 
39 #include "Camera.h"
40 #include "CyclicDevice.h"
41 #include "DeviceException.h"
42 
43 namespace rl
44 {
45  namespace hal
46  {
50  class Dc1394Camera : public Camera, public CyclicDevice
51  {
52  public:
54  {
55 #if (LIBDC1394_VERSION_MAJOR > 10)
56  COLOR_CODING_MONO8 = ::DC1394_COLOR_CODING_MONO8,
57 #else
58  COLOR_CODING_MONO8 = ::COLOR_FORMAT7_MONO8,
59 #endif
70  };
71 
72  enum Feature
73  {
74 #if (LIBDC1394_VERSION_MAJOR > 10)
75  FEATURE_BRIGHTNESS = ::DC1394_FEATURE_BRIGHTNESS,
76 #else
78 #endif
100  };
101 
103  {
104 #if (LIBDC1394_VERSION_MAJOR > 10)
105  FEATURE_MODE_MANUAL = ::DC1394_FEATURE_MODE_MANUAL,
106 #else
108 #endif
111  };
112 
114  {
115 #if (LIBDC1394_VERSION_MAJOR > 10)
116  FRAMERATE_1_875 = ::DC1394_FRAMERATE_1_875,
117 #else
119 #endif
127  };
128 
129  enum IsoSpeed
130  {
131 #if (LIBDC1394_VERSION_MAJOR > 10)
132  ISO_SPEED_100 = ::DC1394_ISO_SPEED_100,
133 #else
134  ISO_SPEED_100 = ::SPEED_100,
135 #endif
141  };
142 
144  {
145 #if (LIBDC1394_VERSION_MAJOR > 10)
146  OPERATION_MODE_LEGACY = ::DC1394_OPERATION_MODE_LEGACY,
147 #else
149 #endif
151  };
152 
154  {
155 #if (LIBDC1394_VERSION_MAJOR > 10)
156  VIDEO_MODE_160x120_YUV444 = ::DC1394_VIDEO_MODE_160x120_YUV444,
157 #else
158  VIDEO_MODE_160x120_YUV444 = ::MODE_160x120_YUV444,
159 #endif
166 #if (LIBDC1394_VERSION_MAJOR > 10)
168 #else
169  VIDEO_MODE_800x600_YUV422 = ::MODE_800x600_YUV422,
170 #endif
178 #if (LIBDC1394_VERSION_MAJOR > 10)
180 #else
181  VIDEO_MODE_1280x960_YUV422 = ::MODE_1280x960_YUV422,
182 #endif
190 #if (LIBDC1394_VERSION_MAJOR > 10)
192 #else
193  VIDEO_MODE_EXIF = ::MODE_EXIF,
194 #endif
195 #if (LIBDC1394_VERSION_MAJOR > 10)
197 #else
198  VIDEO_MODE_FORMAT7_0 = ::MODE_FORMAT7_0,
199 #endif
207  };
208 
209  class Exception : public DeviceException
210  {
211  public:
212 #if (LIBDC1394_VERSION_MAJOR > 10)
213  Exception(const ::dc1394error_t& error);
214 #else
215  Exception(const int& error);
216 #endif
217 
218  virtual ~Exception() throw();
219 
220 #if (LIBDC1394_VERSION_MAJOR > 10)
221  ::dc1394error_t getError() const;
222 #else
223  int getError() const;
224 #endif
225 
226  virtual const char* what() const throw();
227 
228  protected:
229 
230  private:
231 #if (LIBDC1394_VERSION_MAJOR > 10)
232  ::dc1394error_t error;
233 #else
234  int error;
235 #endif
236  };
237 
238  Dc1394Camera(const ::std::string& filename = "", const unsigned int& node = 0);
239 
240  virtual ~Dc1394Camera();
241 
242  void close();
243 
244  unsigned int getBitsPerPixel() const;
245 
246  unsigned int getColorCodingDepth() const;
247 
248  unsigned int getHeight() const;
249 
250  bool getFeatureAbsoluteControl(const Feature& feature) const;
251 
252  void getFeatureBoundaries(const Feature& feature, unsigned int& min, unsigned int& max) const;
253 
254  void getFeatureBoundariesAbsolute(const Feature& feature, float& min, float& max) const;
255 
256  FeatureMode getFeatureMode(const Feature& feature) const;
257 
258  void getFeatureModes(const Feature& feature, bool& hasManual, bool& hasAuto, bool& hasOnePushAuto) const;
259 
260  unsigned int getFeatureValue(const Feature& feature) const;
261 
262  float getFeatureValueAbsolute(const Feature& feature) const;
263 
264  ::std::string getFilename() const;
265 
266  void getFormat7(VideoMode& videoMode, ColorCoding& colorCoding, unsigned int& left, unsigned int& top, unsigned int& width, unsigned int& height) const;
267 
268  void getFormat7MaximumImageSize(const unsigned int& mode, unsigned int& width, unsigned& height) const;
269 
270  Framerate getFramerate() const;
271 
272  unsigned int getNode() const;
273 
274  int getNumCameras() const;
275 
277 
278  unsigned int getPort() const;
279 
280  unsigned int getSize() const;
281 
282  IsoSpeed getSpeed() const;
283 
284  ::std::chrono::nanoseconds getUpdateRate() const;
285 
286  VideoMode getVideoMode() const;
287 
288  unsigned int getWidth() const;
289 
290  void grab(unsigned char* image);
291 
292  bool hasFeatureAbsoluteControl(const Feature& feature) const;
293 
294  bool isFeatureEnabled(const Feature& feature) const;
295 
296  bool isFeaturePresent(const Feature& feature) const;
297 
298  bool isFeatureReadable(const Feature& feature) const;
299 
300  bool isFeatureSwitchable(const Feature& feature) const;
301 
302  void open();
303 
304  void reset();
305 
306  void setFeatureAbsoluteControl(const Feature& feature, const bool& doOn);
307 
308  void setFeatureEnabled(const Feature& feature, const bool& doOn);
309 
310  void setFeatureMode(const Feature& feature, const FeatureMode& mode);
311 
312  void setFeatureValue(const Feature& feature, const unsigned int& value);
313 
314  void setFeatureValueAbsolute(const Feature& feature, const float& value);
315 
316  void setFilename(const ::std::string& filename);
317 
318  void setFormat7(const VideoMode& videoMode, const ColorCoding& colorCoding, const unsigned int& left, const unsigned int& top, const unsigned int& width, const unsigned int& height);
319 
320  void setFramerate(const Framerate& framerate);
321 
322  void setNode(const unsigned int& node);
323 
324  void setOperationMode(const OperationMode& mode);
325 
326  void setPort(const unsigned int& port);
327 
328  void setSpeed(const IsoSpeed& speed);
329 
330  void setVideoMode(const VideoMode& mode);
331 
332  void start();
333 
334  void step();
335 
336  void stop();
337 
338  protected:
339 
340  private:
341 #if (LIBDC1394_VERSION_MAJOR > 10)
342  unsigned int buffer;
343 
344  ::dc1394camera_t* camera;
345 
346  int cameras;
347 
349 
350  ::dc1394_t* dc1394;
351 
352  ::std::string filename;
353 
354  ::dc1394video_frame_t* frame;
355 
357 
358  unsigned int height;
359 
360  unsigned int left;
361 
362  unsigned int node;
363 
364  unsigned int speed;
365 
366  unsigned int top;
367 
369 
370  unsigned int width;
371 #else
372  unsigned int buffer;
373 
374  ::dc1394_cameracapture camera;
375 
376  int cameras;
377 
378  unsigned int channel;
379 
381 
382  unsigned int drop;
383 
384  ::std::string filename;
385 
387 
388  ::raw1394handle_t handle;
389 
390  unsigned int height;
391 
392  ::dc1394_camerainfo info;
393 
394  unsigned int left;
395 
396  unsigned int node;
397 
398  nodeid_t* nodes;
399 
400  unsigned int port;
401 
402  unsigned int speed;
403 
404  unsigned int top;
405 
407 
408  unsigned int width;
409 #endif
410  };
411  }
412 }
413 
414 #endif // RL_HAL_DC1394CAMERA_H
Framerate framerate
Definition: Dc1394Camera.h:386
Definition: Dc1394Camera.h:67
void start()
Definition: Dc1394Camera.cpp:1130
Definition: Dc1394Camera.h:95
Definition: Dc1394Camera.h:98
void open()
Definition: Dc1394Camera.cpp:830
Definition: Dc1394Camera.h:206
unsigned int getSize() const
Definition: Dc1394Camera.cpp:575
void getFeatureBoundariesAbsolute(const Feature &feature, float &min, float &max) const
Definition: Dc1394Camera.cpp:337
unsigned int channel
Definition: Dc1394Camera.h:378
IEEE 1394 based cameras.
Definition: Dc1394Camera.h:50
Definition: Camera.h:36
Definition: Dc1394Camera.h:126
Definition: Dc1394Camera.h:90
VideoMode videoMode
Definition: Dc1394Camera.h:406
bool isFeatureReadable(const Feature &feature) const
Definition: Dc1394Camera.cpp:792
unsigned int port
Definition: Dc1394Camera.h:400
void setPort(const unsigned int &port)
Definition: Dc1394Camera.h:89
unsigned int drop
Definition: Dc1394Camera.h:382
Definition: Dc1394Camera.h:86
::std::string getFilename() const
Definition: Dc1394Camera.cpp:493
bool isFeatureSwitchable(const Feature &feature) const
Definition: Dc1394Camera.cpp:811
unsigned int height
Definition: Dc1394Camera.h:390
Definition: Dc1394Camera.h:193
Framerate getFramerate() const
Definition: Dc1394Camera.cpp:525
Definition: Dc1394Camera.h:134
Definition: Dc1394Camera.h:85
void setNode(const unsigned int &node)
Definition: Dc1394Camera.cpp:1049
ColorCoding colorCoding
Definition: Dc1394Camera.h:380
unsigned int buffer
Definition: Dc1394Camera.h:372
bool hasFeatureAbsoluteControl(const Feature &feature) const
Definition: Dc1394Camera.cpp:733
virtual const char * what() const
Definition: Dc1394Camera.cpp:1331
Definition: DeviceException.h:36
float getFeatureValueAbsolute(const Feature &feature) const
Definition: Dc1394Camera.cpp:474
Definition: Dc1394Camera.h:80
Definition: Dc1394Camera.h:200
Definition: Dc1394Camera.h:94
Definition: Dc1394Camera.h:202
Definition: Dc1394Camera.h:63
OperationMode
Definition: Dc1394Camera.h:143
IsoSpeed getSpeed() const
Definition: Dc1394Camera.cpp:595
::std::string filename
Definition: Dc1394Camera.h:384
int getError() const
Definition: Dc1394Camera.cpp:1325
Definition: Dc1394Camera.h:205
Definition: Dc1394Camera.h:82
unsigned int getPort() const
Definition: Dc1394Camera.h:69
unsigned int getColorCodingDepth() const
Definition: Dc1394Camera.cpp:203
Feature
Definition: Dc1394Camera.h:72
Definition: Dc1394Camera.h:96
unsigned int top
Definition: Dc1394Camera.h:404
unsigned int getFeatureValue(const Feature &feature) const
Definition: Dc1394Camera.cpp:455
Definition: Dc1394Camera.h:77
void setOperationMode(const OperationMode &mode)
Definition: Dc1394Camera.cpp:1055
Definition: Dc1394Camera.h:58
VideoMode
Definition: Dc1394Camera.h:153
void close()
Definition: Dc1394Camera.cpp:102
Definition: Dc1394Camera.h:137
::std::chrono::nanoseconds getUpdateRate() const
Definition: Dc1394Camera.cpp:615
Definition: CyclicDevice.h:38
Definition: Dc1394Camera.h:123
Dc1394Camera(const ::std::string &filename="", const unsigned int &node=0)
Definition: Dc1394Camera.cpp:36
Definition: Dc1394Camera.h:148
Definition: Dc1394Camera.h:60
unsigned int speed
Definition: Dc1394Camera.h:402
bool getFeatureAbsoluteControl(const Feature &feature) const
Definition: Dc1394Camera.cpp:291
Definition: Dc1394Camera.h:150
unsigned int getWidth() const
Definition: Dc1394Camera.cpp:675
Definition: Dc1394Camera.h:139
::raw1394handle_t handle
Definition: Dc1394Camera.h:388
bool isFeaturePresent(const Feature &feature) const
Definition: Dc1394Camera.cpp:773
void setFeatureMode(const Feature &feature, const FeatureMode &mode)
Definition: Dc1394Camera.cpp:937
void getFeatureBoundaries(const Feature &feature, unsigned int &min, unsigned int &max) const
Definition: Dc1394Camera.cpp:310
virtual ~Dc1394Camera()
Definition: Dc1394Camera.cpp:79
Definition: Dc1394Camera.h:203
unsigned int getNode() const
Definition: Dc1394Camera.cpp:544
void setFormat7(const VideoMode &videoMode, const ColorCoding &colorCoding, const unsigned int &left, const unsigned int &top, const unsigned int &width, const unsigned int &height)
Definition: Dc1394Camera.cpp:1003
unsigned int getHeight() const
Definition: Dc1394Camera.cpp:271
Definition: Dc1394Camera.h:88
Robotics Library.
Definition: AnalogInput.cpp:29
void setFilename(const ::std::string &filename)
Definition: Dc1394Camera.cpp:997
Definition: Dc1394Camera.h:79
void setFeatureValueAbsolute(const Feature &feature, const float &value)
Definition: Dc1394Camera.cpp:982
unsigned int node
Definition: Dc1394Camera.h:396
Definition: Dc1394Camera.h:118
Definition: Dc1394Camera.h:204
Definition: Dc1394Camera.h:64
Definition: Dc1394Camera.h:68
Definition: Dc1394Camera.h:84
unsigned int width
Definition: Dc1394Camera.h:408
FeatureMode getFeatureMode(const Feature &feature) const
Definition: Dc1394Camera.cpp:352
Definition: Dc1394Camera.h:87
Definition: Dc1394Camera.h:201
Definition: Dc1394Camera.h:124
::dc1394_cameracapture camera
Definition: Dc1394Camera.h:374
Definition: Dc1394Camera.h:120
IsoSpeed
Definition: Dc1394Camera.h:129
void stop()
Definition: Dc1394Camera.cpp:1252
Definition: Dc1394Camera.h:140
Definition: Dc1394Camera.h:198
Definition: Dc1394Camera.h:83
Definition: Dc1394Camera.h:93
void setFramerate(const Framerate &framerate)
Definition: Dc1394Camera.cpp:1032
void setVideoMode(const VideoMode &mode)
Definition: Dc1394Camera.cpp:1087
void getFeatureModes(const Feature &feature, bool &hasManual, bool &hasAuto, bool &hasOnePushAuto) const
Definition: Dc1394Camera.cpp:399
int error
Definition: Dc1394Camera.h:234
Definition: Dc1394Camera.h:138
nodeid_t * nodes
Definition: Dc1394Camera.h:398
bool isFeatureEnabled(const Feature &feature) const
Definition: Dc1394Camera.cpp:752
void reset()
Definition: Dc1394Camera.cpp:893
Definition: Dc1394Camera.h:122
virtual ~Exception()
Definition: Dc1394Camera.cpp:1316
Definition: Dc1394Camera.h:121
Definition: Dc1394Camera.h:125
Definition: Dc1394Camera.h:209
void setFeatureValue(const Feature &feature, const unsigned int &value)
Definition: Dc1394Camera.cpp:967
unsigned int getBitsPerPixel() const
Definition: Dc1394Camera.cpp:125
void getFormat7(VideoMode &videoMode, ColorCoding &colorCoding, unsigned int &left, unsigned int &top, unsigned int &width, unsigned int &height) const
Definition: Dc1394Camera.cpp:499
Definition: Dc1394Camera.h:62
Framerate
Definition: Dc1394Camera.h:113
Definition: Dc1394Camera.h:66
OperationMode getOperationMode() const
Definition: Dc1394Camera.cpp:556
void setFeatureEnabled(const Feature &feature, const bool &doOn)
Definition: Dc1394Camera.cpp:922
Definition: Dc1394Camera.h:109
unsigned int left
Definition: Dc1394Camera.h:394
Definition: Dc1394Camera.h:61
FeatureMode
Definition: Dc1394Camera.h:102
void setSpeed(const IsoSpeed &speed)
Definition: Dc1394Camera.cpp:1070
::dc1394_camerainfo info
Definition: Dc1394Camera.h:392
Exception(const int &error)
Definition: Dc1394Camera.cpp:1309
void setFeatureAbsoluteControl(const Feature &feature, const bool &doOn)
Definition: Dc1394Camera.cpp:908
Definition: Dc1394Camera.h:107
ColorCoding
Definition: Dc1394Camera.h:53
Definition: Dc1394Camera.h:136
VideoMode getVideoMode() const
Definition: Dc1394Camera.cpp:656
Definition: Dc1394Camera.h:65
void step()
Definition: Dc1394Camera.cpp:1247
void grab(unsigned char *image)
Definition: Dc1394Camera.cpp:695
int getNumCameras() const
Definition: Dc1394Camera.cpp:550
int cameras
Definition: Dc1394Camera.h:376
void getFormat7MaximumImageSize(const unsigned int &mode, unsigned int &width, unsigned &height) const
Definition: Dc1394Camera.cpp:510