The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/wmr: Add auto exposure

authored by

Mateo de Mayo and committed by
Jakob Bornecrantz
df5b5f40 77139b02

+25 -4
+25 -4
src/xrt/drivers/wmr/wmr_camera.c
··· 17 17 #include <inttypes.h> 18 18 19 19 #include "os/os_threading.h" 20 + #include "util/u_autoexpgain.h" 21 + #include "util/u_debug.h" 20 22 #include "util/u_var.h" 21 23 #include "util/u_sink.h" 22 24 #include "util/u_frame.h" ··· 25 27 #include "wmr_protocol.h" 26 28 #include "wmr_camera.h" 27 29 30 + //! Specifies whether the user wants to enable autoexposure from the start. 31 + DEBUG_GET_ONCE_BOOL_OPTION(wmr_autoexposure, "WMR_AUTOEXPOSURE", true) 32 + 28 33 static int 29 - update_expgain(struct wmr_camera *cam); 34 + update_expgain(struct wmr_camera *cam, struct xrt_frame *xf); 30 35 31 36 /* 32 37 * ··· 92 97 93 98 struct libusb_transfer *xfers[NUM_XFERS]; 94 99 100 + bool manual_control; //!< Whether to control exp/gain manually or with aeg 95 101 uint16_t last_exposure, exposure; 96 102 uint8_t last_gain, gain; 97 103 struct u_var_draggable_u16 exposure_ui; //! Widget to control `exposure` value 104 + struct u_autoexpgain *aeg; 98 105 99 106 struct u_sink_debug debug_sinks[2]; 100 107 ··· 361 368 u_frame_create_roi(xf, cam->configs[0].roi, &xf_left); 362 369 u_frame_create_roi(xf, cam->configs[1].roi, &xf_right); 363 370 364 - update_expgain(cam); 371 + update_expgain(cam, xf_left); 365 372 366 373 if (cam->left_sink != NULL) { 367 374 xrt_sink_push_frame(cam->left_sink, xf_left); ··· 438 445 goto fail; 439 446 } 440 447 } 448 + 449 + bool enable_aeg = debug_get_bool_option_wmr_autoexposure(); 450 + int aeg_update_every = 3; // WMR takes about three frames until the cmd changes the image 451 + cam->aeg = u_autoexpgain_create(U_AEG_STRATEGY_TRACKING, enable_aeg, aeg_update_every); 441 452 442 453 cam->exposure_ui.val = &cam->exposure; 443 454 cam->exposure_ui.max = WMR_MAX_EXPOSURE; ··· 448 459 u_sink_debug_init(&cam->debug_sinks[1]); 449 460 u_var_add_root(cam, "WMR Camera", true); 450 461 u_var_add_log_level(cam, &cam->log_level, "Log level"); 462 + u_var_add_bool(cam, &cam->manual_control, "Manual exposure and gain control"); 451 463 u_var_add_draggable_u16(cam, &cam->exposure_ui, "Exposure (usec)"); 452 464 u_var_add_u8(cam, &cam->gain, "Gain"); 465 + u_var_add_gui_header(cam, NULL, "Auto exposure and gain control"); 466 + u_autoexpgain_add_vars(cam->aeg, cam); 467 + u_var_add_gui_header(cam, NULL, "Camera Streams"); 453 468 u_var_add_sink_debug(cam, &cam->debug_sinks[0], "Tracking Streams"); 454 469 u_var_add_sink_debug(cam, &cam->debug_sinks[1], "Controller Streams"); 455 470 ··· 527 542 goto fail; 528 543 } 529 544 530 - res = update_expgain(cam); 545 + res = update_expgain(cam, NULL); 531 546 if (res < 0) { 532 547 goto fail; 533 548 } ··· 597 612 } 598 613 599 614 static int 600 - update_expgain(struct wmr_camera *cam) 615 + update_expgain(struct wmr_camera *cam, struct xrt_frame *xf) 601 616 { 617 + if (!cam->manual_control && xf != NULL) { 618 + u_autoexpgain_update(cam->aeg, xf); 619 + cam->exposure = u_autoexpgain_get_exposure(cam->aeg); 620 + cam->gain = u_autoexpgain_get_gain(cam->aeg); 621 + } 622 + 602 623 if (cam->last_exposure == cam->exposure && cam->last_gain == cam->gain) { 603 624 return 0; 604 625 }