add getExposureTimeLimits

This commit is contained in:
2021-06-15 14:39:46 +02:00
parent 1aaa137d88
commit 02e906764c
2 changed files with 97 additions and 19 deletions

View File

@ -138,7 +138,7 @@ void Camera::aCallback(void* instance, int type, ArvBuffer *buffer)
Camera* instance_ = reinterpret_cast<Camera*>(instance); Camera* instance_ = reinterpret_cast<Camera*>(instance);
if(type == ARV_STREAM_CALLBACK_TYPE_BUFFER_DONE) if(type == ARV_STREAM_CALLBACK_TYPE_BUFFER_DONE)
{ {
if(instance_->run) if(instance_->run && instance_->aqmode != MODE_DISCARD)
{ {
gint inBuffers; gint inBuffers;
gint outBuffers; gint outBuffers;
@ -147,8 +147,6 @@ void Camera::aCallback(void* instance, int type, ArvBuffer *buffer)
std::unique_lock<std::mutex> decodeBufferMutexLock(instance_->decodeBufferMutex); std::unique_lock<std::mutex> decodeBufferMutexLock(instance_->decodeBufferMutex);
instance_->decodeBuffer = arv_stream_pop_buffer(instance_->aStream_); instance_->decodeBuffer = arv_stream_pop_buffer(instance_->aStream_);
instance_->bufferCondition.notify_all(); instance_->bufferCondition.notify_all();
if(instance_->aqmode == MODE_SINGLE)
instance_->run = false;
} }
else else
{ {
@ -194,13 +192,25 @@ bool Camera::chooseFormat()
bool Camera::setupCamera() bool Camera::setupCamera()
{ {
GError* error = nullptr;
bool doubleRate = arv_camera_is_feature_available(aCamera_, "DoubleRate_Enable", &error);
if(!error && doubleRate)
{
Log(Log::INFO)<<"Disable broken PhotonFocus DoubleRate implementation";
arv_device_set_boolean_feature_value(arv_camera_get_device(aCamera_), "DoubleRate_Enable", false, &error);
if(error)
{
Log(Log::ERROR)<<"Failed to disable DoubleRate\n";
return false;
}
}
if(!chooseFormat()) if(!chooseFormat())
{ {
Log(Log::ERROR)<<"Camera provides no supported pixel format"; Log(Log::ERROR)<<"Camera provides no supported pixel format";
return false; return false;
} }
GError* error = nullptr;
gint ymin, ymax; gint ymin, ymax;
arv_camera_get_height_bounds(aCamera_, &ymin, &ymax, &error); arv_camera_get_height_bounds(aCamera_, &ymin, &ymax, &error);
if(error) if(error)
@ -253,18 +263,6 @@ bool Camera::setupCamera()
} }
Log(Log::DEBUG)<<"Binning: "<<(binning ? "yes" : "no"); Log(Log::DEBUG)<<"Binning: "<<(binning ? "yes" : "no");
bool doubleRate = arv_camera_is_feature_available(aCamera_, "DoubleRate_Enable", &error);
if(!error && doubleRate)
{
Log(Log::INFO)<<"Disable broken PhotonFocus DoubleRate implementation";
arv_device_set_boolean_feature_value(arv_camera_get_device(aCamera_), "DoubleRate_Enable", false, &error);
if(error)
{
Log(Log::ERROR)<<"Failed to disable DoubleRate\n";
return false;
}
}
decoderThread = new std::thread([this](){decoderThreadFunc();}); decoderThread = new std::thread([this](){decoderThreadFunc();});
Log(Log::DEBUG)<<"Using "<<arv_camera_get_pixel_format_as_string(aCamera_, nullptr)<<" as pixel format"; Log(Log::DEBUG)<<"Using "<<arv_camera_get_pixel_format_as_string(aCamera_, nullptr)<<" as pixel format";
@ -282,12 +280,15 @@ bool Camera::setupCamera()
imageBuffers[i] = arv_buffer_new(frameSize, nullptr); imageBuffers[i] = arv_buffer_new(frameSize, nullptr);
arv_stream_push_buffer(aStream_, imageBuffers[i]); arv_stream_push_buffer(aStream_, imageBuffers[i]);
} }
setExposureAuto(false);
arv_camera_stop_acquisition(aCamera_, nullptr);
setExposureAuto(true);
setTriggerMode(TRIGGER_FREE); setTriggerMode(TRIGGER_FREE);
setAcquisitionMode(ARV_ACQUISITION_MODE_CONTINUOUS); setAcquisitionMode(ARV_ACQUISITION_MODE_CONTINUOUS);
setFrameRate(10); setFrameRate(10);
setExposureTime(100000); setExposureTime(100000);
arv_camera_stop_acquisition(aCamera_, nullptr); setGain(1);
return true; return true;
} }
@ -395,6 +396,9 @@ bool Camera::setExposureTime(uint64_t us)
{ {
GError* error = nullptr; GError* error = nullptr;
arv_camera_set_exposure_time(aCamera_, static_cast<double>(us), &error); arv_camera_set_exposure_time(aCamera_, static_cast<double>(us), &error);
if(error)
Log(Log::WARN)<<error->message;
return !error; return !error;
} }
@ -402,6 +406,8 @@ uint64_t Camera::getExposureTime()
{ {
GError* error = nullptr; GError* error = nullptr;
double ret = arv_camera_get_exposure_time(aCamera_, &error); double ret = arv_camera_get_exposure_time(aCamera_, &error);
if(error)
Log(Log::WARN)<<error->message;
return !error ? static_cast<uint64_t>(ret) : 0; return !error ? static_cast<uint64_t>(ret) : 0;
} }
@ -409,6 +415,8 @@ double Camera::getFrameRate()
{ {
GError* error = nullptr; GError* error = nullptr;
double ret = arv_camera_get_frame_rate(aCamera_, &error); double ret = arv_camera_get_frame_rate(aCamera_, &error);
if(error)
Log(Log::WARN)<<error->message;
return !error ? ret : -1; return !error ? ret : -1;
} }
@ -416,6 +424,8 @@ bool Camera::setFrameRate(double rate)
{ {
GError* error = nullptr; GError* error = nullptr;
arv_camera_set_frame_rate(aCamera_, rate, &error); arv_camera_set_frame_rate(aCamera_, rate, &error);
if(error)
Log(Log::WARN)<<error->message;
return !error; return !error;
} }
@ -424,13 +434,61 @@ int64_t Camera::getPixelFormat()
return static_cast<ArvPixelFormat>(format); return static_cast<ArvPixelFormat>(format);
} }
double Camera::getGain()
{
GError* error = nullptr;
double gain = arv_camera_get_gain(aCamera_, &error);
if(error)
{
Log(Log::WARN)<<error->message;
return -1;
}
return gain;
}
bool Camera::setGain(double gain)
{
GError* error = nullptr;
arv_camera_set_gain(aCamera_, gain, &error);
if(error)
Log(Log::WARN)<<error->message;
return !error;
}
bool Camera::getExposureTimeLimits(uint64_t& min, uint64_t& max)
{
double minD = 0;
double maxD = 0;
GError* error;
arv_camera_get_exposure_time_bounds(aCamera_, &minD, &maxD, &error);
if(error)
Log(Log::WARN)<<error->message;
min = static_cast<uint64_t>(minD);
max = static_cast<uint64_t>(maxD);
return !error;
}
bool Camera::hasExposureAuto()
{
GError* error = nullptr;
bool ret = arv_camera_is_exposure_auto_available(aCamera_, &error);
if(error)
{
Log(Log::WARN)<<error->message;
return false;
}
return ret;
}
bool Camera::setExposureAuto(bool enable) bool Camera::setExposureAuto(bool enable)
{ {
if(!arv_camera_is_exposure_auto_available(aCamera_, nullptr)) if(!hasExposureAuto())
return false; return false;
GError* error = nullptr; GError* error = nullptr;
arv_camera_set_exposure_time(aCamera_, enable ? ARV_AUTO_CONTINUOUS : ARV_AUTO_OFF, &error); arv_camera_set_exposure_time(aCamera_, enable ? ARV_AUTO_CONTINUOUS : ARV_AUTO_OFF, &error);
if(error)
Log(Log::WARN)<<error->message;
return !error; return !error;
} }
@ -439,7 +497,14 @@ bool Camera::startAcquisition()
GError* error = nullptr; GError* error = nullptr;
arv_camera_start_acquisition(aCamera_, &error); arv_camera_start_acquisition(aCamera_, &error);
if(!error) if(!error)
{
aqRunning = true;
run = true; run = true;
}
else
{
Log(Log::WARN)<<error->message;
}
return !error; return !error;
} }
@ -448,7 +513,12 @@ bool Camera::stopAcquisition()
GError* error = nullptr; GError* error = nullptr;
arv_camera_stop_acquisition(aCamera_, &error); arv_camera_stop_acquisition(aCamera_, &error);
if(!error) if(!error)
{
aqRunning = false;
run = false; run = false;
}
else
Log(Log::WARN)<<error->message;
return !error; return !error;
} }
@ -501,6 +571,7 @@ Camera::Description Camera::getDescription()
description->model = arv_camera_get_model_name(aCamera_, &error); description->model = arv_camera_get_model_name(aCamera_, &error);
if(error) if(error)
{ {
Log(Log::WARN)<<error->message;
delete description; delete description;
description = nullptr; description = nullptr;
} }

View File

@ -82,6 +82,7 @@ public:
typedef int AquisitionMode; typedef int AquisitionMode;
static constexpr AquisitionMode MODE_FREE = 0; static constexpr AquisitionMode MODE_FREE = 0;
static constexpr AquisitionMode MODE_SINGLE = 1; static constexpr AquisitionMode MODE_SINGLE = 1;
static constexpr AquisitionMode MODE_DISCARD = 2;
private: private:
ArvStream* aStream_ = nullptr; ArvStream* aStream_ = nullptr;
@ -108,6 +109,8 @@ private:
std::atomic_bool run; std::atomic_bool run;
AquisitionMode aqmode = MODE_FREE; AquisitionMode aqmode = MODE_FREE;
int discardCount = 0;
bool aqRunning = false;
void decoderThreadFunc(); void decoderThreadFunc();
@ -132,12 +135,16 @@ public:
~Camera(); ~Camera();
bool isOpen(); bool isOpen();
bool setAcquisitionMode(AquisitionMode mode); bool setAcquisitionMode(AquisitionMode mode);
bool setGain(double gain);
double getGain();
bool setExposureTime(uint64_t us); bool setExposureTime(uint64_t us);
bool getExposureTimeLimits(uint64_t& min, uint64_t& max);
uint64_t getExposureTime(); uint64_t getExposureTime();
double getFrameRate(); double getFrameRate();
bool setFrameRate(double rate); bool setFrameRate(double rate);
int64_t getPixelFormat(); int64_t getPixelFormat();
bool setExposureAuto(bool enable); bool setExposureAuto(bool enable);
bool hasExposureAuto();
bool startAcquisition(); bool startAcquisition();
bool stopAcquisition(); bool stopAcquisition();
void getSize(unsigned int* x, unsigned int* y); void getSize(unsigned int* x, unsigned int* y);