Skip to content
Snippets Groups Projects
Commit 900b4daf authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'feature/gainshare' into 'master'

Pylon properties from master machine

See merge request nicolas.pope/ftl!348
parents 1709c219 ae0b7aa2
No related branches found
No related tags found
1 merge request!348Pylon properties from master machine
Pipeline #32047 passed
...@@ -88,6 +88,7 @@ static void run(ftl::Configurable *root) { ...@@ -88,6 +88,7 @@ static void run(ftl::Configurable *root) {
if (opt_time_master) { if (opt_time_master) {
time_peer = *opt_time_master; time_peer = *opt_time_master;
LOG(INFO) << "Found a time master: " << time_peer.to_string(); LOG(INFO) << "Found a time master: " << time_peer.to_string();
ftl::timer::setTimeMaster(time_peer);
} }
int sync_counter = 0; int sync_counter = 0;
......
...@@ -3,9 +3,12 @@ ...@@ -3,9 +3,12 @@
#include <ftl/handle.hpp> #include <ftl/handle.hpp>
#include <functional> #include <functional>
#include <optional>
namespace ftl { namespace ftl {
class UUID;
/** /**
* A single global timer mechanism to call functions with either high or low * A single global timer mechanism to call functions with either high or low
* precision timing accuracy. This is used to provide accurate frame timing for * precision timing accuracy. This is used to provide accurate frame timing for
...@@ -114,6 +117,10 @@ size_t count(timerlevel_t); ...@@ -114,6 +117,10 @@ size_t count(timerlevel_t);
*/ */
void reset(); void reset();
void setTimeMaster(const ftl::UUID &m);
std::optional<ftl::UUID> getTimeMaster();
} }
} }
......
#include <ftl/timer.hpp> #include <ftl/timer.hpp>
#include <ftl/threads.hpp> #include <ftl/threads.hpp>
#include <ftl/uuid.hpp>
#include <loguru.hpp> #include <loguru.hpp>
#include <vector> #include <vector>
...@@ -28,6 +29,8 @@ static MUTEX mtx; ...@@ -28,6 +29,8 @@ static MUTEX mtx;
static int last_id = 0; static int last_id = 0;
static bool clock_slave = true; static bool clock_slave = true;
static std::future<void> timer_future; static std::future<void> timer_future;
static ftl::UUID time_master(0);
static bool has_time_master = false;
struct TimerJob { struct TimerJob {
int id=0; int id=0;
...@@ -42,6 +45,15 @@ struct TimerJob { ...@@ -42,6 +45,15 @@ struct TimerJob {
static list<TimerJob> jobs[kTimerMAXLEVEL]; static list<TimerJob> jobs[kTimerMAXLEVEL];
void ftl::timer::setTimeMaster(const ftl::UUID &m) {
has_time_master = true;
time_master = m;
}
std::optional<ftl::UUID> ftl::timer::getTimeMaster() {
return (has_time_master) ? time_master : std::optional<ftl::UUID>{};
}
int64_t ftl::timer::get_time() { int64_t ftl::timer::get_time() {
return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count()+clock_adjust; return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count()+clock_adjust;
} }
......
...@@ -214,6 +214,8 @@ class Universe : public ftl::Configurable { ...@@ -214,6 +214,8 @@ class Universe : public ftl::Configurable {
size_t getSendBufferSize(ftl::URI::scheme_t s); size_t getSendBufferSize(ftl::URI::scheme_t s);
size_t getRecvBufferSize(ftl::URI::scheme_t s); size_t getRecvBufferSize(ftl::URI::scheme_t s);
static inline Universe *getInstance() { return instance_; }
private: private:
void _run(); void _run();
...@@ -274,6 +276,7 @@ class Universe : public ftl::Configurable { ...@@ -274,6 +276,7 @@ class Universe : public ftl::Configurable {
std::list<ErrHandler> on_error_; std::list<ErrHandler> on_error_;
static callback_t cbid__; static callback_t cbid__;
static Universe *instance_;
// std::map<std::string, std::vector<ftl::net::Peer*>> subscriptions_; // std::map<std::string, std::vector<ftl::net::Peer*>> subscriptions_;
}; };
......
...@@ -47,6 +47,7 @@ struct NetImplDetail { ...@@ -47,6 +47,7 @@ struct NetImplDetail {
#define WS_RECEIVE_BUFFER_SIZE (62*1024) #define WS_RECEIVE_BUFFER_SIZE (62*1024)
callback_t ftl::net::Universe::cbid__ = 0; callback_t ftl::net::Universe::cbid__ = 0;
Universe *Universe::instance_ = nullptr;
Universe::Universe() : Universe::Universe() :
Configurable(), Configurable(),
...@@ -94,6 +95,9 @@ Universe::Universe(nlohmann::json &config) : ...@@ -94,6 +95,9 @@ Universe::Universe(nlohmann::json &config) :
} }
return true; return true;
}); });
if (instance_ != nullptr) LOG(FATAL) << "Multiple net instances";
instance_ = this;
} }
Universe::~Universe() { Universe::~Universe() {
......
...@@ -81,6 +81,8 @@ PylonDevice::PylonDevice(nlohmann::json &config) ...@@ -81,6 +81,8 @@ PylonDevice::PylonDevice(nlohmann::json &config)
_configureCamera(lcam_); _configureCamera(lcam_);
if (rcam_) _configureCamera(rcam_); if (rcam_) _configureCamera(rcam_);
value("gain", lcam_->Gain.GetValue());
lcam_->StartGrabbing( Pylon::GrabStrategy_OneByOne); lcam_->StartGrabbing( Pylon::GrabStrategy_OneByOne);
if (rcam_) rcam_->StartGrabbing( Pylon::GrabStrategy_OneByOne); if (rcam_) rcam_->StartGrabbing( Pylon::GrabStrategy_OneByOne);
...@@ -106,6 +108,11 @@ PylonDevice::PylonDevice(nlohmann::json &config) ...@@ -106,6 +108,11 @@ PylonDevice::PylonDevice(nlohmann::json &config)
//hres_hm_ = cv::cuda::HostMem(fullheight_, fullwidth_, CV_8UC4); //hres_hm_ = cv::cuda::HostMem(fullheight_, fullwidth_, CV_8UC4);
//rtmp_.create(fullheight_, fullwidth_, CV_8UC4); //rtmp_.create(fullheight_, fullwidth_, CV_8UC4);
//on("gain", [this]() {
// lcam_->Gain.SetValue(value("gain",1.0));
// rcam_->Gain.SetValue(value("gain",1.0));
//});
on("exposure", [this]() { on("exposure", [this]() {
if (lcam_->GetDeviceInfo().GetModelName() != "Emulation") { if (lcam_->GetDeviceInfo().GetModelName() != "Emulation") {
lcam_->ExposureTime.SetValue(value("exposure", 24000.0f)); // Exposure time in microseconds lcam_->ExposureTime.SetValue(value("exposure", 24000.0f)); // Exposure time in microseconds
...@@ -138,6 +145,26 @@ PylonDevice::PylonDevice(nlohmann::json &config) ...@@ -138,6 +145,26 @@ PylonDevice::PylonDevice(nlohmann::json &config)
return true; return true;
}); });
auto *net = ftl::net::Universe::getInstance();
if (!net->isBound("pylon_gain")) {
net->bind("pylon_gain", [this]() {
return (lcam_) ? lcam_->Gain.GetValue() : 0.0;
});
net->bind("pylon_exposure", [this]() {
return (lcam_) ? lcam_->ExposureTime.GetValue() : 0.0;
});
net->bind("pylon_white", [this]() {
cv::Vec3d wb;
lcam_->BalanceRatioSelector.SetValue(Basler_UniversalCameraParams::BalanceRatioSelector_Blue);
wb[0] = lcam_->BalanceRatio.GetValue();
lcam_->BalanceRatioSelector.SetValue(Basler_UniversalCameraParams::BalanceRatioSelector_Green);
wb[1] = lcam_->BalanceRatio.GetValue();
lcam_->BalanceRatioSelector.SetValue(Basler_UniversalCameraParams::BalanceRatioSelector_Red);
wb[2] = lcam_->BalanceRatio.GetValue();
return wb;
});
}
} }
PylonDevice::~PylonDevice() { PylonDevice::~PylonDevice() {
...@@ -200,13 +227,42 @@ void PylonDevice::_configureCamera(CBaslerUniversalInstantCamera *cam) { ...@@ -200,13 +227,42 @@ void PylonDevice::_configureCamera(CBaslerUniversalInstantCamera *cam) {
LOG(WARNING) << "Could not change pixel format"; LOG(WARNING) << "Could not change pixel format";
} }
auto *net = ftl::net::Universe::getInstance();
auto tm = ftl::timer::getTimeMaster();
if (cam->GetDeviceInfo().GetModelName() != "Emulation") { if (cam->GetDeviceInfo().GetModelName() != "Emulation") {
// Emulated device throws exception with these // Emulated device throws exception with these
cam->ExposureTime.SetValue(value("exposure", 24000.0f)); // Exposure time in microseconds if (tm) {
double expo = net->call<double>(*tm, "pylon_exposure");
cam->ExposureTime.SetValue(expo);
LOG(INFO) << "Pylon exposure from master = " << expo;
} else {
cam->ExposureTime.SetValue(value("exposure", 24000.0f)); // Exposure time in microseconds
}
cam->AutoTargetBrightness.SetValue(0.3); cam->AutoTargetBrightness.SetValue(0.3);
cam->LightSourcePreset.SetValue(Basler_UniversalCameraParams::LightSourcePreset_Tungsten2800K); // White balance option cam->LightSourcePreset.SetValue(Basler_UniversalCameraParams::LightSourcePreset_Tungsten2800K); // White balance option
cam->BalanceWhiteAuto.SetValue(Basler_UniversalCameraParams::BalanceWhiteAuto_Once);
cam->GainAuto.SetValue(Basler_UniversalCameraParams::GainAuto_Once); if (tm) {
cv::Vec3d white = net->call<cv::Vec3d>(*tm, "pylon_white");
cam->BalanceRatioSelector.SetValue(Basler_UniversalCameraParams::BalanceRatioSelector_Blue);
cam->BalanceRatio.SetValue(white[0]);
cam->BalanceRatioSelector.SetValue(Basler_UniversalCameraParams::BalanceRatioSelector_Green);
cam->BalanceRatio.SetValue(white[1]);
cam->BalanceRatioSelector.SetValue(Basler_UniversalCameraParams::BalanceRatioSelector_Red);
cam->BalanceRatio.SetValue(white[2]);
LOG(INFO) << "Pylon WB from master = " << white;
} else {
cam->BalanceWhiteAuto.SetValue(Basler_UniversalCameraParams::BalanceWhiteAuto_Once);
}
if (tm) {
double gain = net->call<double>(*tm, "pylon_gain");
cam->Gain.SetValue(gain);
LOG(INFO) << "Pylon Gain from master = " << gain;
} else {
cam->GainAuto.SetValue(Basler_UniversalCameraParams::GainAuto_Once);
}
cam->DeviceTemperatureSelector.SetValue(Basler_UniversalCameraParams::DeviceTemperatureSelector_Coreboard); cam->DeviceTemperatureSelector.SetValue(Basler_UniversalCameraParams::DeviceTemperatureSelector_Coreboard);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment