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/pike.h>
25 #include <fvcams/cam_exceptions.h>
26 
27 #include <fvutils/system/camargp.h>
28 
29 #include <cstring>
30 #include <cstdlib>
31 
32 using namespace std;
33 using namespace fawkes;
34 
35 namespace firevision {
36 #if 0 /* just to make Emacs auto-indent happy */
37 }
38 #endif
39 
40 /** @class PikeCamera <fvcams/pike.h>
41  * Pike camera.
42  * Allows to access some special features of the Pike camera made by
43  * Allied Vision Technologies.
44  */
45 
46 // AVT specific registers
47 /** Register for white balance settings */
48 #define AVT_WHITE_BALANCE_REGISTER (0x0F0080C)
49 
50 /** Registers for area of interest settings */
51 #define AVT_AUTOFNC_AOI_REGISTER (0x0390)
52 #define AVT_AF_AREA_POSITION_REGISTER (0x0394)
53 #define AVT_AF_AREA_SIZE_REGISTER (0x0398)
54 
55 /** Extended version information registerst */
56 #define AVT_VERSION_INFO1_REGISTER (0x1000010)
57 #define AVT_VERSION_INFO3_REGISTER (0x1000018)
58 
59 // AVT specific data structures
60 // /** White balance settings data structure */
61 // typedef struct {
62 // uint32_t abs_control : 1;
63 // uint32_t reserved : 3;
64 // uint32_t one_push : 1;
65 // uint32_t on_off : 1;
66 // uint32_t a_m_mode : 1;
67 // uint32_t ub_value : 12;
68 // uint32_t vr_value : 12;
69 // uint32_t presence_inq : 1;
70 // } avt_white_balance_t;
71 
72 /** Datastructure for the autofunction AOI */
73 typedef struct {
74  uint32_t xuints : 12; /**< X units of work area/pos. beginning with 0 (read only) */
75  uint32_t yuints : 12; /**< Y units of work area/pos. beginning with 0 (read only) */
76  uint32_t reserved3 : 1; /**< Reserved. */
77  uint32_t on_off : 1; /**< Enable/disable AOI (see note above). */
78  uint32_t reserved2 : 1; /**< Reserved. */
79  uint32_t show_work_area : 1; /**< Show work area. */
80  uint32_t reserved1 : 3; /**< Reserved. */
81  uint32_t presence_inq : 1; /**< Indicates presence of this feature (read only). */
83 
84 /** Datastructure for the position of the autofunction AOI */
85 typedef struct {
86  uint32_t top : 16; /**< Work area position (top coordinate). */
87  uint32_t left : 16; /**< Work area position (left coordinate). */
89 
90 /** Datastructure for the size of the autofunction AOI */
91 typedef struct {
92  uint32_t height : 16; /**< Height of work area size. */
93  uint32_t width : 16; /**< Width of work area size. */
95 
96 /** Datastructure for version information of the uC */
97 typedef struct {
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  uint32_t fpga_version : 16; /**< Bcd-coded version number. */
105  uint32_t camera_type_id : 16; /**< See Table 122: Camera type ID list on page 267 in the technical manual (v 4.3.0). */
107 
108 
109 /** Constructor.
110  * @param cap Camera argument parser.
111  */
112 PikeCamera::PikeCamera(const CameraArgumentParser* cap)
113  : 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  {
125  __set_autofnc_aoi = true;
126  parse_set_autofnc_aoi( cap->get( "autofnc_aoi" ).c_str() );
127  }
128 }
129 
130 /** Destructor. */
132 {
133 }
134 
135 void
137 {
138  try
139  {
141  } catch ( Exception &e )
142  { throw; }
143 
144  if ( !_opened )
145  { throw Exception( "PikeCamera::open: FirewireCamera::open dit not succed" ); }
146 
147  if ( !set_autofunction_aoi( __aoi_left, __aoi_top, __aoi_width, __aoi_height,
148  __aoi_show_work_area ) )
149  {
150  throw Exception( "PikeCamera::PikeCamera: setting autofnc AOI failed." );
151  }
152 }
153 
154 void
156 {
158 
159  uint32_t value;
160  dc1394error_t err = dc1394_get_register( _camera,
161  AVT_VERSION_INFO1_REGISTER,
162  &value );
163 
164  if ( err != DC1394_SUCCESS )
165  {
166  throw Exception( "Pike::print_info; dc1394_get_register(AVT_VERSION_INFO1_REGISTER) failed\n" );
167  }
168 
169  avt_version_info1_t version1;
170  memcpy( (void*) &version1, (void*) &value, sizeof(uint32_t) );
171 
172  err = dc1394_get_register( _camera,
173  AVT_VERSION_INFO3_REGISTER,
174  &value );
175 
176  if ( err != DC1394_SUCCESS )
177  {
178  throw Exception( "Pike::print_info; dc1394_get_register(AVT_VERSION_INFO3_REGISTER) failed\n" );
179  }
180 
181  avt_version_info3_t version3;
182  memcpy( (void*) &version3, (void*) &value, sizeof(uint32_t) );
183 
184  printf( "uC type ID: %d uC version: %x camera type id: %d FPGA version: %x\n",
185  version1.uc_type_id, version1.uc_version, version3.camera_type_id, version3.fpga_version );
186 }
187 
188 /** Set the area of interest (AOI) for the auto functions.
189  * @param left offset form the left image border
190  * @param top offset form the top image border
191  * @param width width of the AOI
192  * @param height height of the AOI
193  * @param show_work_area highlight the work area in the image
194  * @return true on success, false otherwise
195  */
196 bool
198  unsigned int top,
199  unsigned int width,
200  unsigned int height,
201  bool show_work_area )
202 {
203  if ( !_opened )
204  { return false; }
205 
206  if ( !__set_autofnc_aoi )
207  { return true; }
208 
209  avt_autofnc_aoi_t aoi;
210  avt_af_area_position_t position;
211  avt_af_area_size_t size;
212 
213  aoi.show_work_area = show_work_area;
214  aoi.on_off = true;
215 
216  position.left = left;
217  position.top = top;
218 
219  size.width = width;
220  size.height = height;
221 
222  dc1394error_t err;
223 
224  uint32_t value = 0;
225  memcpy( (void*) &value, (void*) &aoi, sizeof( value ) );
226 
227  err = dc1394_set_adv_control_register( _camera,
228  AVT_AUTOFNC_AOI_REGISTER,
229  value );
230 
231  if ( err != DC1394_SUCCESS )
232  {
233  throw Exception( "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AUTOFNC_AOI_REGISTER) failed\n" );
234  }
235 
236  memcpy( (void*) &value, (void*) &position, sizeof( value ) );
237  err = dc1394_set_adv_control_register( _camera,
238  AVT_AF_AREA_POSITION_REGISTER,
239  value );
240 
241  if ( err != DC1394_SUCCESS )
242  {
243  throw Exception( "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AF_AREA_POSITION_REGISTER) failed\n" );
244  }
245 
246  memcpy( (void*) &value, (void*) &size, sizeof( value ) );
247  err = dc1394_set_adv_control_register( _camera,
248  AVT_AF_AREA_SIZE_REGISTER,
249  value );
250 
251  if ( err != DC1394_SUCCESS )
252  {
253  throw Exception( "Pike::set_autofunction_aoi; dc1394_set_register(AVT_AF_AREA_SIZE_REGISTER) failed\n" );
254  }
255 
256  err = dc1394_get_adv_control_register( _camera,
257  AVT_AUTOFNC_AOI_REGISTER,
258  &value );
259  if ( err != DC1394_SUCCESS )
260  {
261  throw Exception( "Pike::set_autofunction_aoi; dc1394_get_register(AVT_AUTOFNC_AOI_REGISTER) failed\n" );
262  }
263 
264  memcpy ( (void*) &aoi, (void*) &value, sizeof( value ) );
265 
266  return aoi.on_off;
267 }
268 
269 /** Parse the autofnc_aoi parameter in the camera argument string.
270  * The format ist <left>x<top>+<width>x<height>-<show>. "-<show>" is
271  * optional.
272  * @param aoi the parameter string of the autofnc_aoi parameter
273  */
274 void
276 {
277  // format: left x top + width x height - show
278 
279  string a = aoi;
280 
281  string::size_type pos;
282 
283  pos = a.find( "x", 0 );
284  if ( pos == string::npos )
285  { throw Exception( "Illegal autofnc AOI parameter" ); }
286  string left = a.substr( 0, pos );
287  a = a.substr( pos + 1 );
288 
289  pos = a.find( "+", 0 );
290  if ( pos == string::npos )
291  { throw Exception( "Illegal autofnc AOI parameter" ); }
292  string top = a.substr( 0, pos );
293  a = a.substr( pos + 1 );
294 
295  pos = a.find( "x", 0 );
296  if ( pos == string::npos )
297  { throw Exception( "Illegal autofnc AOI parameter" ); }
298  string width = a.substr( 0, pos );
299  a = a.substr( pos + 1 );
300 
301  string height;
302  string show;
303  pos = a.find( "-", 0 );
304  if ( pos == string::npos )
305  {
306  height = a;
307  __aoi_show_work_area = false;
308  }
309  else
310  {
311  height = a.substr( 0, pos );
312  show = a.substr( pos + 1 );
313 
314  __aoi_show_work_area = ( show == "show" ) ? true : false;
315  }
316 
317  __aoi_left = atoi( left.c_str() );
318  __aoi_top = atoi( top.c_str() );
319  __aoi_width = atoi( width.c_str() );
320  __aoi_height = atoi( height.c_str() );
321 }
322 
323 } // end namespace firevision
bool _opened
true if camera has been opened, false otherwise
Definition: firewire.h:129
uint32_t fpga_version
Bcd-coded version number.
Definition: pike.cpp:104
Datastructure for version information of the uC.
Definition: pike.cpp:97
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:105
uint32_t reserved1
Reserved.
Definition: pike.cpp:80
virtual void print_info()
Print out camera information.
Definition: firewire.cpp:282
Fawkes library namespace.
uint32_t left
Work area position (left coordinate).
Definition: pike.cpp:87
uint32_t width
Width of work area size.
Definition: pike.cpp:93
STL namespace.
uint32_t uc_type_id
Always 0.
Definition: pike.cpp:99
virtual void open()
Open the camera.
Definition: pike.cpp:136
uint32_t reserved3
Reserved.
Definition: pike.cpp:76
Camera argument parser.
Definition: camargp.h:38
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:77
uint32_t show_work_area
Show work area.
Definition: pike.cpp:79
bool has(std::string s) const
Check if an parameter was given.
Definition: camargp.cpp:152
uint32_t presence_inq
Indicates presence of this feature (read only).
Definition: pike.cpp:81
Base class for exceptions in Fawkes.
Definition: exception.h:36
Datastructure for the size of the autofunction AOI.
Definition: pike.cpp:91
uint32_t top
Work area position (top coordinate).
Definition: pike.cpp:86
uint32_t reserved2
Reserved.
Definition: pike.cpp:78
uint32_t yuints
Y units of work area/pos.
Definition: pike.cpp:75
uint32_t xuints
X units of work area/pos.
Definition: pike.cpp:74
Datastructure for the position of the autofunction AOI.
Definition: pike.cpp:85
virtual void open()
Open the camera.
Definition: firewire.cpp:153
uint32_t height
Height of work area size.
Definition: pike.cpp:92
dc1394camera_t * _camera
DC1394 camera handle.
Definition: firewire.h:158
White balance settings data structure.
Definition: pike.cpp:73
virtual void print_info()
Print out camera information.
Definition: pike.cpp:155
std::string get(std::string s) const
Get the value of the given parameter.
Definition: camargp.cpp:164
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:197
virtual ~PikeCamera()
Destructor.
Definition: pike.cpp:131
Firewire camera.
Definition: firewire.h:44
virtual void parse_set_autofnc_aoi(const char *aoi)
Parse the autofnc_aoi parameter in the camera argument string.
Definition: pike.cpp:275
Datastructure for version information of the FGPA.
Definition: pike.cpp:103