Example #1
0
void NaoCamera::getCameraParams() {

    read_camera_params_.kCameraAutoWhiteBalance = getControlSetting(V4L2_CID_AUTO_WHITE_BALANCE);
    read_camera_params_.kCameraExposureAuto = getControlSetting(V4L2_CID_EXPOSURE_AUTO);
    read_camera_params_.kCameraBacklightCompensation = getControlSetting(V4L2_CID_BACKLIGHT_COMPENSATION);

    read_camera_params_.kCameraBrightness = getControlSetting(V4L2_CID_BRIGHTNESS);
    read_camera_params_.kCameraContrast = getControlSetting(V4L2_CID_CONTRAST);
    read_camera_params_.kCameraSaturation = getControlSetting(V4L2_CID_SATURATION);
    read_camera_params_.kCameraHue = getControlSetting(V4L2_CID_HUE);
    read_camera_params_.kCameraExposure = getControlSetting(V4L2_CID_EXPOSURE);
    read_camera_params_.kCameraGain = getControlSetting(V4L2_CID_GAIN);
    read_camera_params_.kCameraSharpness = getControlSetting(V4L2_CID_SHARPNESS);
}
Example #2
0
bool ImageTranscriber::setControlSetting(unsigned int id, int value) {
    struct v4l2_control control_s;
    control_s.id = id;
    control_s.value = value;

    int counter = 0;

    // Have to make sure the setting "sticks"
    while(getControlSetting(id) != value)
    {
        if (ioctl(fd, VIDIOC_S_CTRL, &control_s) < 0)
        {
            std::cerr << "CAMERA::Warning::Control setting failed." <<
                std::endl;
            return false;
        }
	counter++;
	if(counter > 10)
	  {
          std::cerr << "CAMERA::Warning::Timeout while setting a parameter."
                    << std::endl;
	    return false;
	  }
    }
    return true;
}
Example #3
0
bool NaoCamera::setControlSetting(unsigned int id, int value) {
    struct v4l2_queryctrl queryctrl;
    queryctrl.id = id;
    if(ioctl(videoDeviceFd, VIDIOC_QUERYCTRL, &queryctrl) < 0) {
        std::cerr << "NaoCamera: Query failed on " << queryctrl.name << "(" << id << ")\n";
        return false;
    }
    if(queryctrl.flags & V4L2_CTRL_FLAG_DISABLED) {
        std::cerr << "NaoCamera: Query disabled on " << queryctrl.name << "(" << id << ")\n";
        return false; // not available
    }
    if(queryctrl.type != V4L2_CTRL_TYPE_BOOLEAN && queryctrl.type != V4L2_CTRL_TYPE_INTEGER && queryctrl.type != V4L2_CTRL_TYPE_MENU) {
        std::cerr << "NaoCamera: Query not supported on " << queryctrl.name << "(" << id << ")\n";
        return false; // not supported
    }

    // clip value
    int oldval = value;
    if(value < queryctrl.minimum)
        value = queryctrl.minimum;
    if(value > queryctrl.maximum)
        value = queryctrl.maximum;

    if (value != oldval) {
        std::cout << "NaoCamera: Value outside range," << oldval << " on " << queryctrl.name << "(" << id << ") got cropped to " << value << std::endl;
    }

    struct v4l2_control control_s;
    control_s.id = id;
    control_s.value = value;
    if(ioctl(videoDeviceFd, VIDIOC_S_CTRL, &control_s) < 0) {
        std::cerr << "NaoCamera: Error setting " << queryctrl.name << "(" << id << ") to " << value << "\n";
        return false;
    }
    int newvalue = getControlSetting(id);
    if(newvalue != value) {
        std::cerr << "NaoCamera: " << queryctrl.name << "(" << id << ") requested as " << value << ", but was set to " << newvalue << "\n";
        return false;
    }
    std::cout << "NaoCamera: " << queryctrl.name << "(" << id << ") requested as " << value << " successfully\n";
    return true;
}
Example #4
0
void NaoCamera::assertCameraSettings()
{
  bool allFine = true;
  // check frame rate
  struct v4l2_streamparm fps;
  memset(&fps, 0, sizeof(fps));
  fps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  VERIFY(!ioctl(fd, VIDIOC_G_PARM, &fps));
  if(fps.parm.capture.timeperframe.numerator != 1)
  {
    OUTPUT(idText, text, "fps.parm.capture.timeperframe.numerator is wrong.");
    allFine = false;
  }
  if(fps.parm.capture.timeperframe.denominator != 30)
  {
    OUTPUT(idText, text, "fps.parm.capture.timeperframe.denominator is wrong.");
    allFine = false;
  }

  // check camera settings
  std::list<CameraSettingsBH::V4L2Setting> v4l2settings = settings.getSettings();
  std::list<CameraSettingsBH::V4L2Setting>::const_iterator it = v4l2settings.begin();
  std::list<CameraSettingsBH::V4L2Setting>::const_iterator end = v4l2settings.end();
  for(; it != end; it++)
  {
    int value = getControlSetting((*it).command);
    if(value != (*it).value)
    {
      OUTPUT(idText, text, "Value for command " << (*it).command << " is " << value << " but should be " << (*it).value << ".");
      allFine = false;
    }
  }

  if(allFine)
  {
    OUTPUT(idText, text, "Camera settings match settings stored in hardware/driver.");
  }
}
Example #5
0
void ImageTranscriber::assertCameraSettings() {
    bool allFine = true;
    // check frame rate
    struct v4l2_streamparm fps;
    memset(&fps, 0, sizeof(fps));
    fps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
    verify(ioctl(fd, VIDIOC_G_PARM, &fps),
           "Getting settings failed");

    if (fps.parm.capture.timeperframe.numerator != 1) {
        std::cerr << "CAMERA::fps.parm.capture.timeperframe.numerator is"
                  << " wrong." << std::endl;
        allFine = false;
    }
    if (fps.parm.capture.timeperframe.denominator != 30) {
        std::cerr << "CAMERA::fps.parm.capture.timeperframe.denominator" <<
            " is wrong." << std::endl;
        allFine = false;
    }

    // check camera settings against what the driver has
    int hflip = getControlSetting(V4L2_CID_HFLIP);
    int vflip = getControlSetting(V4L2_CID_VFLIP);
    int brightness = getControlSetting(V4L2_CID_BRIGHTNESS);
    int contrast = getControlSetting(V4L2_CID_CONTRAST);
    int saturation = getControlSetting(V4L2_CID_SATURATION);
    int hue = getControlSetting(V4L2_CID_HUE);
    int sharpness = getControlSetting(V4L2_CID_SHARPNESS);
    int gain = getControlSetting(V4L2_CID_GAIN);
    int exposure = getControlSetting(V4L2_CID_EXPOSURE);
    int whitebalance = getControlSetting(V4L2_CID_DO_WHITE_BALANCE);
    //std::cerr << "Done checking driver settings" << std::endl;

    if (hflip != settings.hflip)
    {
        std::cerr << "CAMERA::WARNING::Horizontal flip setting is wrong:"
                  << std::endl;
        std::cerr << " is " << hflip << " not " << settings.hflip <<
            std::endl;
        allFine = false;
    }
    if (vflip != settings.vflip)
    {
        std::cerr << "CAMERA::WARNING::Vertical flip setting is wrong:"
                  << std::endl;
        std::cerr << " is " << vflip  << " not " << settings.vflip <<
            std::endl;
        allFine = false;
    }
    if (brightness != settings.brightness)
    {
        std::cerr << "CAMERA::WARNING::Brightness setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  brightness << " not " << settings.brightness
                  << std::endl;
        allFine = false;
    }
    if (contrast != settings.contrast)
    {
        std::cerr << "CAMERA::WARNING::Contrast setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  contrast << " not " << settings.contrast
                  << std::endl;
        allFine = false;
    }
    if (saturation != settings.saturation)
    {
        std::cerr << "CAMERA::WARNING::Saturation setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  saturation << " not " << settings.saturation
                  << std::endl;
        allFine = false;
    }
    if (hue != settings.hue)
    {
        std::cerr << "CAMERA::WARNING::Hue setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  hue << " not " << settings.hue
                  << std::endl;
        allFine = false;
    }
   if (sharpness != settings.sharpness)
    {
        std::cerr << "CAMERA::WARNING::Sharpness setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  sharpness << " not " << settings.sharpness
                  << std::endl;
        allFine = false;
    }
   if (gain != settings.gain)
    {
        std::cerr << "CAMERA::WARNING::Gain setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  gain << " not " << settings.gain
                  << std::endl;
        allFine = false;
    }
   if (exposure != settings.exposure)
    {
        std::cerr << "CAMERA::WARNING::Exposure setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  exposure << " not " << settings.exposure
                  << std::endl;
        allFine = false;
    }
   if (whitebalance != settings.white_balance)
    {
        std::cerr << "CAMERA::WARNING::Whitebalance setting is wrong:"
                  << std::endl;
        std::cerr << " is " <<  whitebalance << " not " << settings.white_balance
                  << std::endl;
        allFine = false;
    }

    if (allFine) {
        std::cerr << "CAMERA::";
        if(cameraType == Camera::BOTTOM)
            std::cerr << "Bottom camera settings were set correctly." <<
                std::endl;
        else std::cerr << "Top camera settings were set correctly." <<
                 std::endl;
    }
}