Fawkes API  Fawkes Development Version
pike.cpp
1 
2 /***************************************************************************
3  * pike.cpp - Allied Vision Technologies Pike camera
4  *
5  * Generated: Tue Mar 16 15:27:32 2010
6  * Copyright 2010 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <fvcams/cam_exceptions.h>
25 #include <fvcams/pike.h>
26 #include <fvutils/system/camargp.h>
27 
28 #include <cstdlib>
29 #include <cstring>
30 
31 using namespace std;
32 using namespace fawkes;
33 
34 namespace firevision {
35 
36 /** @class PikeCamera <fvcams/pike.h>
37  * Pike camera.
38  * Allows to access some special features of the Pike camera made by
39  * Allied Vision Technologies.
40  */
41 
42 // AVT specific registers
43 /** Register for white balance settings */
44 #define AVT_WHITE_BALANCE_REGISTER (0x0F0080C)
45 
46 /** Registers for area of interest settings */
47 #define AVT_AUTOFNC_AOI_REGISTER (0x0390)
48 #define AVT_AF_AREA_POSITION_REGISTER (0x0394)
49 #define AVT_AF_AREA_SIZE_REGISTER (0x0398)
50 
51 /** Extended version information registerst */
52 #define AVT_VERSION_INFO1_REGISTER (0x1000010)
53 #define AVT_VERSION_INFO3_REGISTER (0x1000018)
54 
55 // AVT specific data structures
56 // /** White balance settings data structure */
57 // typedef struct {
58 // uint32_t abs_control : 1;
59 // uint32_t reserved : 3;
60 // uint32_t one_push : 1;
61 // uint32_t on_off : 1;
62 // uint32_t a_m_mode : 1;
63 // uint32_t ub_value : 12;
64 // uint32_t vr_value : 12;
65 // uint32_t presence_inq : 1;
66 // } avt_white_balance_t;
67 
68 /** Datastructure for the autofunction AOI */
69 typedef struct
70 {
71  uint32_t xuints : 12; /**< X units of work area/pos. beginning with 0 (read only) */
72  uint32_t yuints : 12; /**< Y units of work area/pos. beginning with 0 (read only) */
73  uint32_t reserved3 : 1; /**< Reserved. */
74  uint32_t on_off : 1; /**< Enable/disable AOI (see note above). */
75  uint32_t reserved2 : 1; /**< Reserved. */
76  uint32_t show_work_area : 1; /**< Show work area. */
77  uint32_t reserved1 : 3; /**< Reserved. */
78  uint32_t presence_inq : 1; /**< Indicates presence of this feature (read only). */
80 
81 /** Datastructure for the position of the autofunction AOI */
82 typedef struct
83 {
84  uint32_t top : 16; /**< Work area position (top coordinate). */
85  uint32_t left : 16; /**< Work area position (left coordinate). */
87 
88 /** Datastructure for the size of the autofunction AOI */
89 typedef struct
90 {
91  uint32_t height : 16; /**< Height of work area size. */
92  uint32_t width : 16; /**< Width of work area size. */
94 
95 /** Datastructure for version information of the uC */
96 typedef struct
97 {
98  uint32_t uc_version : 16; /**< Bcd-coded version number. */
99  uint32_t uc_type_id : 16; /**< Always 0. */
101 
102 /** Datastructure for version information of the FGPA */
103 typedef struct
104 {
105  uint32_t fpga_version : 16; /**< Bcd-coded version number. */
106  uint32_t
107  camera_type_id : 16; /**< See Table 122: Camera type ID list on page 267 in the technical manual (v 4.3.0). */
109 
110 /** Constructor.
111  * @param cap Camera argument parser.
112  */
113 PikeCamera::PikeCamera(const CameraArgumentParser *cap) : FirewireCamera(cap)
114 {
115  aoi_left_ = 0;
116  aoi_top_ = 0;
117  aoi_width_ = 0;
118  aoi_height_ = 0;
119  aoi_show_work_area_ = false;
120 
121  set_autofnc_aoi_ = false;
122 
123  if (cap->has("autofnc_aoi")) {
124  set_autofnc_aoi_ = true;
125  parse_set_autofnc_aoi(cap->get("autofnc_aoi").c_str());
126  }
127 }
128 
129 /** Destructor. */
131 {
132 }
133 
134 void
136 {
137  try {
139  } catch (Exception &e) {
140  throw;
141  }
142 
143  if (!_opened) {
144  throw Exception("PikeCamera::open: FirewireCamera::open dit not succed");
145  }
146 
147  if (!set_autofunction_aoi(aoi_left_, aoi_top_, aoi_width_, aoi_height_, aoi_show_work_area_)) {
148  throw Exception("PikeCamera::PikeCamera: setting autofnc AOI failed.");
149  }
150 }
151 
152 void
154 {
156 
157  uint32_t value;
158  dc1394error_t err = dc1394_get_register(_camera, AVT_VERSION_INFO1_REGISTER, &value);
159 
160  if (err != DC1394_SUCCESS) {
161  throw Exception("Pike::print_info; dc1394_get_register(AVT_VERSION_INFO1_REGISTER) failed\n");
162  }
163 
164  avt_version_info1_t version1;
165  memcpy((void *)&version1, (void *)&value, sizeof(uint32_t));
166 
167  err = dc1394_get_register(_camera, AVT_VERSION_INFO3_REGISTER, &value);
168 
169  if (err != DC1394_SUCCESS) {
170  throw Exception("Pike::print_info; dc1394_get_register(AVT_VERSION_INFO3_REGISTER) failed\n");
171  }
172 
173  avt_version_info3_t version3;
174  memcpy((void *)&version3, (void *)&value, sizeof(uint32_t));
175 
176  printf("uC type ID: %d uC version: %x camera type id: %d FPGA version: %x\n",
177  version1.uc_type_id,
178  version1.uc_version,
179  version3.camera_type_id,
180  version3.fpga_version);
181 }
182 
183 /** Set the area of interest (AOI) for the auto functions.
184  * @param left offset form the left image border
185  * @param top offset form the top image border
186  * @param width width of the AOI
187  * @param height height of the AOI
188  * @param show_work_area highlight the work area in the image
189  * @return true on success, false otherwise
190  */
191 bool
193  unsigned int top,
194  unsigned int width,
195  unsigned int height,
196  bool show_work_area)
197 {
198  if (!_opened) {
199  return false;
200  }
201 
202  if (!set_autofnc_aoi_) {
203  return true;
204  }
205 
206  avt_autofnc_aoi_t aoi;
207  avt_af_area_position_t position;
208  avt_af_area_size_t size;
209 
210  aoi.show_work_area = show_work_area;
211  aoi.on_off = true;
212 
213  position.left = left;
214  position.top = top;
215 
216  size.width = width;
217  size.height = height;
218 
219  dc1394error_t err;
220 
221  uint32_t value = 0;
222  memcpy((void *)&value, (void *)&aoi, sizeof(value));
223 
224  err = dc1394_set_adv_control_register(_camera, AVT_AUTOFNC_AOI_REGISTER, value);
225 
226  if (err != DC1394_SUCCESS) {
227  throw Exception(
228  "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AUTOFNC_AOI_REGISTER) failed\n");
229  }
230 
231  memcpy((void *)&value, (void *)&position, sizeof(value));
232  err = dc1394_set_adv_control_register(_camera, AVT_AF_AREA_POSITION_REGISTER, value);
233 
234  if (err != DC1394_SUCCESS) {
235  throw Exception(
236  "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AF_AREA_POSITION_REGISTER) failed\n");
237  }
238 
239  memcpy((void *)&value, (void *)&size, sizeof(value));
240  err = dc1394_set_adv_control_register(_camera, AVT_AF_AREA_SIZE_REGISTER, value);
241 
242  if (err != DC1394_SUCCESS) {
243  throw Exception(
244  "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AF_AREA_SIZE_REGISTER) failed\n");
245  }
246 
247  err = dc1394_get_adv_control_register(_camera, AVT_AUTOFNC_AOI_REGISTER, &value);
248  if (err != DC1394_SUCCESS) {
249  throw Exception(
250  "Pike::set_autofunction_aoi; dc1394_get_register(AVT_AUTOFNC_AOI_REGISTER) failed\n");
251  }
252 
253  memcpy((void *)&aoi, (void *)&value, sizeof(value));
254 
255  return aoi.on_off;
256 }
257 
258 /** Parse the autofnc_aoi parameter in the camera argument string.
259  * The format ist <left>x<top>+<width>x<height>-<show>. "-<show>" is
260  * optional.
261  * @param aoi the parameter string of the autofnc_aoi parameter
262  */
263 void
265 {
266  // format: left x top + width x height - show
267 
268  string a = aoi;
269 
270  string::size_type pos;
271 
272  pos = a.find("x", 0);
273  if (pos == string::npos) {
274  throw Exception("Illegal autofnc AOI parameter");
275  }
276  string left = a.substr(0, pos);
277  a = a.substr(pos + 1);
278 
279  pos = a.find("+", 0);
280  if (pos == string::npos) {
281  throw Exception("Illegal autofnc AOI parameter");
282  }
283  string top = a.substr(0, pos);
284  a = a.substr(pos + 1);
285 
286  pos = a.find("x", 0);
287  if (pos == string::npos) {
288  throw Exception("Illegal autofnc AOI parameter");
289  }
290  string width = a.substr(0, pos);
291  a = a.substr(pos + 1);
292 
293  string height;
294  string show;
295  pos = a.find("-", 0);
296  if (pos == string::npos) {
297  height = a;
298  aoi_show_work_area_ = false;
299  } else {
300  height = a.substr(0, pos);
301  show = a.substr(pos + 1);
302 
303  aoi_show_work_area_ = (show == "show") ? true : false;
304  }
305 
306  aoi_left_ = atoi(left.c_str());
307  aoi_top_ = atoi(top.c_str());
308  aoi_width_ = atoi(width.c_str());
309  aoi_height_ = atoi(height.c_str());
310 }
311 
312 } // end namespace firevision
bool _opened
true if camera has been opened, false otherwise
Definition: firewire.h:127
uint32_t fpga_version
Bcd-coded version number.
Definition: pike.cpp:105
Datastructure for version information of the uC.
Definition: pike.cpp:96
uint32_t camera_type_id
See Table 122: Camera type ID list on page 267 in the technical manual (v 4.3.0).
Definition: pike.cpp:107
uint32_t reserved1
Reserved.
Definition: pike.cpp:77
virtual void print_info()
Print out camera information.
Definition: firewire.cpp:279
Fawkes library namespace.
uint32_t left
Work area position (left coordinate).
Definition: pike.cpp:85
uint32_t width
Width of work area size.
Definition: pike.cpp:92
uint32_t uc_type_id
Always 0.
Definition: pike.cpp:99
virtual void open()
Open the camera.
Definition: pike.cpp:135
uint32_t reserved3
Reserved.
Definition: pike.cpp:73
Camera argument parser.
Definition: camargp.h:35
uint32_t uc_version
Bcd-coded version number.
Definition: pike.cpp:98
uint32_t on_off
Enable/disable AOI (see note above).
Definition: pike.cpp:74
uint32_t show_work_area
Show work area.
Definition: pike.cpp:76
bool has(std::string s) const
Check if an parameter was given.
Definition: camargp.cpp:145
uint32_t presence_inq
Indicates presence of this feature (read only).
Definition: pike.cpp:78
Base class for exceptions in Fawkes.
Definition: exception.h:35
Datastructure for the size of the autofunction AOI.
Definition: pike.cpp:89
uint32_t top
Work area position (top coordinate).
Definition: pike.cpp:84
uint32_t reserved2
Reserved.
Definition: pike.cpp:75
uint32_t yuints
Y units of work area/pos.
Definition: pike.cpp:72
uint32_t xuints
X units of work area/pos.
Definition: pike.cpp:71
Datastructure for the position of the autofunction AOI.
Definition: pike.cpp:82
virtual void open()
Open the camera.
Definition: firewire.cpp:147
uint32_t height
Height of work area size.
Definition: pike.cpp:91
dc1394camera_t * _camera
DC1394 camera handle.
Definition: firewire.h:156
White balance settings data structure.
Definition: pike.cpp:69
virtual void print_info()
Print out camera information.
Definition: pike.cpp:153
std::string get(std::string s) const
Get the value of the given parameter.
Definition: camargp.cpp:156
virtual bool set_autofunction_aoi(unsigned int left, unsigned int top, unsigned int width, unsigned int height, bool show_work_area=false)
Set the area of interest (AOI) for the auto functions.
Definition: pike.cpp:192
virtual ~PikeCamera()
Destructor.
Definition: pike.cpp:130
Firewire camera.
Definition: firewire.h:40
virtual void parse_set_autofnc_aoi(const char *aoi)
Parse the autofnc_aoi parameter in the camera argument string.
Definition: pike.cpp:264
Datastructure for version information of the FGPA.
Definition: pike.cpp:103