40 #define VMODEDEF(width, height, fps, hblank, vblank) { #width"x"#height"x"#fps, width, height, fps, hblank, vblank }
128 ROS_WARN(
"MT9VImager::getInstance Unable to read imager version.");
141 uint16_t val = (agc ? 2 : 0) | (aec ? 1 : 0);
148 ROS_WARN(
"Error setting AGC/AEC mode. Exposure and gain may be incorrect.");
158 ROS_WARN(
"Error setting brightness.");
168 ROS_WARN(
"Error setting analog gain.");
178 ROS_ERROR(
"setExposure called before setMode in class MT9VImager. This is a bug.");
195 ROS_WARN(
"Error setting exposure.");
205 ROS_ERROR(
"setMaxExposure called before setMode in class MT9VImager. This is a bug.");
222 ROS_WARN(
"Error setting max exposure.");
230 uint16_t mask = 0x30;
231 uint16_t val = (mirrory ? 0x10 : 0) | (mirrorx ? 0x20 : 0);
237 ROS_WARN(
"Error setting mirror mode. Read mode register settings may have been corrupted.");
243 virtual bool setBlackLevel(
bool manual_override,
int calibration_value,
int step_size,
int filter_length)
249 ROS_WARN(
"Error setting black level correction mode.");
256 virtual bool setMode(
int x,
int y,
int binx,
int biny,
double rate,
int xoffset,
int yoffset)
258 if (binx < 0 || binx > 2)
260 ROS_ERROR(
"x binning should 0, 1 or 2, not %i", binx);
264 if (biny < 0 || biny > 2)
266 ROS_ERROR(
"y binning should 0, 1 or 2, not %i", biny);
273 if (x < 1 || x > 752)
275 ROS_ERROR(
"Requested x resolution (includes binning) %i is not between 1 and 752.", x);
279 if (y < 1 || y > 480)
281 ROS_ERROR(
"Requested y resolution (includes binning) %i is not between 1 and 480.", y);
290 startx = 57 + xoffset;
291 starty = 4 + yoffset;
293 if (startx < 1 || startx + x > 752 + 1)
295 ROS_ERROR(
"Image x offset exceeds imager bounds.");
299 if (starty < 4 || starty + y > 480 + 4)
301 ROS_ERROR(
"Image y offset exceeds imager bounds.");
309 int target_tics = clock / rate;
310 int besterror = INT_MAX;
311 int packet_size = 70 + (x >> binx);
312 double max_peak_data_rate = 90e6;
313 double best_peak_data_rate = 0;
315 ROS_DEBUG(
"Target tics %i", target_tics);
317 for (
int hblank = 100; hblank < 1023; hblank++)
319 int htics = x + hblank;
321 int vblank = round(((
double) target_tics - extra_tics) / htics) - y;
326 int vtics = vblank + y;
328 int tics = htics * vtics + extra_tics;
329 int err = abs(tics - target_tics);
330 double peak_data_rate = 8 * packet_size * clock / htics;
332 if (peak_data_rate <= max_peak_data_rate && err < besterror)
338 best_peak_data_rate = peak_data_rate;
342 if (besterror == INT_MAX)
344 ROS_ERROR(
"Could not find suitable vblank and hblank for %ix%i mode.\n", x, y);
350 ROS_DEBUG(
"Selected vblank=%i hblank=%i data_rate=%f err=%f period=%f", bestvblank, besthblank, best_peak_data_rate, besterror / clock, best_tics / clock);
354 ROS_ERROR(
"Failed to set vertical blanking. Stream will probably be corrupt.");
360 ROS_ERROR(
"Failed to set horizontal blanking. Stream will probably be corrupt.");
366 ROS_ERROR(
"Failed to set start column. Stream will probably be corrupt.");
372 ROS_ERROR(
"Failed to set start row. Stream will probably be corrupt.");
378 ROS_ERROR(
"Failed to set image width. Stream will probably be corrupt.");
384 ROS_ERROR(
"Failed to set image height. Stream will probably be corrupt.");
388 uint16_t mask = 0x0F;
389 uint16_t val = (binx << 2) | biny;
395 ROS_ERROR(
"Failed to set binning modes. Read mode may be corrupted.");
410 ROS_WARN(
"Error setting companding mode.");
479 ROS_WARN(
"Error setting magic sensor register.");
483 ROS_WARN(
"Error turning off row-noise correction.");
487 ROS_WARN(
"Error setting V2 Voltge level for context B.");
491 ROS_WARN(
"Error turning off high dynamic range for alternate configuration.");
495 ROS_WARN(
"Error turning on exposure knee auto-adjust for alternate configuration.");
516 ROS_WARN(
"Error setting magic sensor register.");
520 ROS_WARN(
"Error turning off row-noise correction");
531 uint16_t imager_version;
534 ROS_ERROR(
"MT9VImager::getInstance Unable to read imager version.");
538 switch (imager_version)
544 ROS_ERROR(
"MT9VImager::getInstance Unknown imager version 0x%04x. Assuming it is compatible with MT9V032.", imager_version);