int ar2VideoGetAbsMaxValue1394(AR2VideoParam1394T *vid, int paramName, ARdouble *value) { dc1394feature_t feature; float min, max; switch (paramName) { case AR_VIDEO_1394_GAMMA: feature = DC1394_FEATURE_GAMMA; break; default: return -1; } if (dc1394_feature_get_absolute_boundaries(vid->camera, feature, &min, &max) != DC1394_SUCCESS) { ARLOGe("unable to get max value.\n"); return -1; } *value = (float)max; return 0; }
void setSetting(dc1394camera_t *cam, dc1394feature_t setting, float value){ dc1394error_t err; float min, max; dc1394_feature_get_absolute_boundaries(cam, setting, &min, &max); if(value < min || value > max){ std::cerr << "CameraIIDC: cannot set value. Out of permissable range." << std::endl; } else { err = dc1394_feature_set_absolute_control(cam, setting, DC1394_ON); if(err != DC1394_SUCCESS) cerr << "Could not enable absolute control!" << endl; err = dc1394_feature_set_absolute_value(cam, setting, value); if(err != DC1394_SUCCESS) cerr << "Could not set absolute value!" << endl; } }
/************************************************************************************** ** Client is asking us to establish connection to the device ***************************************************************************************/ bool FFMVCCD::Connect() { dc1394camera_list_t *list; dc1394error_t err; bool supported; bool settings_valid; uint32_t val; dc1394format7mode_t fm7; dc1394feature_info_t feature; float min, max; dc1394 = dc1394_new(); if (!dc1394) { return false; } err = dc1394_camera_enumerate(dc1394, &list); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not find DC1394 cameras!"); return false; } if (!list->num) { IDMessage(getDeviceName(), "No DC1394 cameras found!"); return false; } dcam = dc1394_camera_new(dc1394, list->ids[0].guid); if (!dcam) { IDMessage(getDeviceName(), "Unable to connect to camera!"); return false; } /* Reset camera */ err = dc1394_camera_reset(dcam); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to reset camera!"); return false; } /* Set mode */ err = dc1394_video_set_mode(dcam, DC1394_VIDEO_MODE_640x480_MONO16); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to connect to set videomode!"); return false; } /* Disable Auto exposure control */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_EXPOSURE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable auto exposure control"); return false; } /* Set frame rate to the lowest possible */ err = dc1394_video_set_framerate(dcam, DC1394_FRAMERATE_7_5); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to connect to set framerate!"); return false; } /* Turn frame rate control off to enable extended exposure (subs of 512ms) */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_FRAME_RATE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable framerate!"); return false; } /* Get the longest possible exposure length */ err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_SHUTTER, DC1394_FEATURE_MODE_MANUAL); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable manual shutter control."); } err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_SHUTTER, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable absolute shutter control."); } err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_SHUTTER, &min, &max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not get max shutter length"); } else { max_exposure = max; } /* Set gain to max. By setting the register directly, we can achieve a * gain of 24 dB...compared to a gain of 12 dB which is reported as the * max */ err = dc1394_set_control_register(dcam, 0x820, 0x40); //err = dc1394_set_control_register(dcam, 0x820, 0x7f); if (err != DC1394_SUCCESS) { return err; } #if 0 /* Set absolute gain to max */ err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_GAIN, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable ansolute gain control."); } err = dc1394_feature_get_absolute_boundaries(dcam, DC1394_FEATURE_GAIN, &min, &max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not get max gain value"); } else { err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAIN, max); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set max gain value"); } } #endif /* Set brightness */ err = dc1394_feature_set_mode(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_FEATURE_MODE_MANUAL); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable manual brightness control."); } err = dc1394_feature_set_absolute_control(dcam, DC1394_FEATURE_BRIGHTNESS, DC1394_ON); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Failed to enable ansolute brightness control."); } err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_BRIGHTNESS, 1); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set max brightness value"); } /* Turn gamma control off */ err = dc1394_feature_set_absolute_value(dcam, DC1394_FEATURE_GAMMA, 1); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Could not set gamma value"); } err = dc1394_feature_set_power(dcam, DC1394_FEATURE_GAMMA, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable gamma!"); return false; } /* Turn off white balance */ err = dc1394_feature_set_power(dcam, DC1394_FEATURE_WHITE_BALANCE, DC1394_OFF); if (err != DC1394_SUCCESS) { IDMessage(getDeviceName(), "Unable to disable white balance!"); return false; } err=dc1394_capture_setup(dcam,10, DC1394_CAPTURE_FLAGS_DEFAULT); return true; }
/** Configure a feature for the currently open device. * * @pre feature_set_ initialized * * @param feature desired feature number * @param control [in,out] pointer to control parameter (may change) * @param value [in,out] pointer to requested parameter value (may * change depending on device restrictions) * @param value2 [in,out] optional pointer to second parameter value * for white balance (may change depending on device * restrictions). No second value if NULL pointer. * * The parameter values are represented as double despite the fact * that most features on most cameras only allow unsigned 12-bit * values. The exception is the rare feature that supports * "absolute" values in 32-bit IEEE float format. Double can * represent all possible option values accurately. */ void Features::configure(dc1394feature_t feature, int *control, double *value, double *value2) { // device-relevant information for this feature dc1394feature_info_t *finfo = &feature_set_.feature[feature - DC1394_FEATURE_MIN]; if (!finfo->available) // feature not available? { *control = camera1394::Camera1394_None; return; } switch (*control) { case camera1394::Camera1394_Off: setPower(finfo, DC1394_OFF); break; case camera1394::Camera1394_Query: getValues(finfo, value, value2); break; case camera1394::Camera1394_Auto: if (!setMode(finfo, DC1394_FEATURE_MODE_AUTO)) { setPower(finfo, DC1394_OFF); } break; case camera1394::Camera1394_Manual: if (!setMode(finfo, DC1394_FEATURE_MODE_MANUAL)) { setPower(finfo, DC1394_OFF); break; } // TODO: break this into some internal methods if (finfo->absolute_capable && finfo->abs_control) { // supports reading and setting float value float fmin, fmax; if (DC1394_SUCCESS == dc1394_feature_get_absolute_boundaries(camera_, feature, &fmin, &fmax)) { // clamp *value between minimum and maximum if (*value < fmin) *value = (double) fmin; else if (*value > fmax) *value = (double) fmax; } else { ROS_WARN_STREAM("failed to get feature " << featureName(feature) << " boundaries "); } // @todo handle absolute White Balance values float fval = *value; if (DC1394_SUCCESS != dc1394_feature_set_absolute_value(camera_, feature, fval)) { ROS_WARN_STREAM("failed to set feature " << featureName(feature) << " to " << fval); } } else // no float representation { // round requested value to nearest integer *value = rint(*value); // clamp *value between minimum and maximum if (*value < finfo->min) *value = (double) finfo->min; else if (*value > finfo->max) *value = (double) finfo->max; dc1394error_t rc; uint32_t ival = (uint32_t) *value; // handle White Balance, which has two components if (feature == DC1394_FEATURE_WHITE_BALANCE) { *value2 = rint(*value2); // clamp *value2 between same minimum and maximum if (*value2 < finfo->min) *value2 = (double) finfo->min; else if (*value2 > finfo->max) *value2 = (double) finfo->max; uint32_t ival2 = (uint32_t) *value2; rc = dc1394_feature_whitebalance_set_value(camera_, ival, ival2); } else { // other features only have one component rc = dc1394_feature_set_value(camera_, feature, ival); } if (rc != DC1394_SUCCESS) { ROS_WARN_STREAM("failed to set feature " << featureName(feature) << " to " << ival); } } break; case camera1394::Camera1394_OnePush: // Try to set OnePush mode setMode(finfo, DC1394_FEATURE_MODE_ONE_PUSH_AUTO); // Now turn the control off, so camera does not continue adjusting setPower(finfo, DC1394_OFF); break; case camera1394::Camera1394_None: // Invalid user input, because this feature actually does exist. ROS_INFO_STREAM("feature " << featureName(feature) << " exists, cannot set to None"); break; default: ROS_WARN_STREAM("unknown state (" << *control <<") for feature " << featureName(feature)); } // return actual state reported by the device *control = getState(finfo); ROS_DEBUG_STREAM("feature " << featureName(feature) << " now in state " << *control); }