d/wmr: Add auto exposure

This commit is contained in:
Mateo de Mayo 2022-05-14 17:06:46 -03:00 committed by Jakob Bornecrantz
parent 77139b02a1
commit df5b5f40a9

View file

@ -17,6 +17,8 @@
#include <inttypes.h>
#include "os/os_threading.h"
#include "util/u_autoexpgain.h"
#include "util/u_debug.h"
#include "util/u_var.h"
#include "util/u_sink.h"
#include "util/u_frame.h"
@ -25,8 +27,11 @@
#include "wmr_protocol.h"
#include "wmr_camera.h"
//! Specifies whether the user wants to enable autoexposure from the start.
DEBUG_GET_ONCE_BOOL_OPTION(wmr_autoexposure, "WMR_AUTOEXPOSURE", true)
static int
update_expgain(struct wmr_camera *cam);
update_expgain(struct wmr_camera *cam, struct xrt_frame *xf);
/*
*
@ -92,9 +97,11 @@ struct wmr_camera
struct libusb_transfer *xfers[NUM_XFERS];
bool manual_control; //!< Whether to control exp/gain manually or with aeg
uint16_t last_exposure, exposure;
uint8_t last_gain, gain;
struct u_var_draggable_u16 exposure_ui; //! Widget to control `exposure` value
struct u_autoexpgain *aeg;
struct u_sink_debug debug_sinks[2];
@ -361,7 +368,7 @@ img_xfer_cb(struct libusb_transfer *xfer)
u_frame_create_roi(xf, cam->configs[0].roi, &xf_left);
u_frame_create_roi(xf, cam->configs[1].roi, &xf_right);
update_expgain(cam);
update_expgain(cam, xf_left);
if (cam->left_sink != NULL) {
xrt_sink_push_frame(cam->left_sink, xf_left);
@ -439,6 +446,10 @@ wmr_camera_open(struct xrt_prober_device *dev_holo,
}
}
bool enable_aeg = debug_get_bool_option_wmr_autoexposure();
int aeg_update_every = 3; // WMR takes about three frames until the cmd changes the image
cam->aeg = u_autoexpgain_create(U_AEG_STRATEGY_TRACKING, enable_aeg, aeg_update_every);
cam->exposure_ui.val = &cam->exposure;
cam->exposure_ui.max = WMR_MAX_EXPOSURE;
cam->exposure_ui.min = WMR_MIN_EXPOSURE;
@ -448,8 +459,12 @@ wmr_camera_open(struct xrt_prober_device *dev_holo,
u_sink_debug_init(&cam->debug_sinks[1]);
u_var_add_root(cam, "WMR Camera", true);
u_var_add_log_level(cam, &cam->log_level, "Log level");
u_var_add_bool(cam, &cam->manual_control, "Manual exposure and gain control");
u_var_add_draggable_u16(cam, &cam->exposure_ui, "Exposure (usec)");
u_var_add_u8(cam, &cam->gain, "Gain");
u_var_add_gui_header(cam, NULL, "Auto exposure and gain control");
u_autoexpgain_add_vars(cam->aeg, cam);
u_var_add_gui_header(cam, NULL, "Camera Streams");
u_var_add_sink_debug(cam, &cam->debug_sinks[0], "Tracking Streams");
u_var_add_sink_debug(cam, &cam->debug_sinks[1], "Controller Streams");
@ -527,7 +542,7 @@ wmr_camera_start(struct wmr_camera *cam, const struct wmr_camera_config *cam_con
goto fail;
}
res = update_expgain(cam);
res = update_expgain(cam, NULL);
if (res < 0) {
goto fail;
}
@ -597,8 +612,14 @@ fail:
}
static int
update_expgain(struct wmr_camera *cam)
update_expgain(struct wmr_camera *cam, struct xrt_frame *xf)
{
if (!cam->manual_control && xf != NULL) {
u_autoexpgain_update(cam->aeg, xf);
cam->exposure = u_autoexpgain_get_exposure(cam->aeg);
cam->gain = u_autoexpgain_get_gain(cam->aeg);
}
if (cam->last_exposure == cam->exposure && cam->last_gain == cam->gain) {
return 0;
}