mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-22 14:32:07 +08:00
camerad: optional exposure params overrides (#25616)
* add params override * speedup * put in param list * clean up names Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
@@ -88,6 +88,8 @@ std::unordered_map<std::string, uint32_t> keys = {
|
||||
{"AthenadPid", PERSISTENT},
|
||||
{"AthenadUploadQueue", PERSISTENT},
|
||||
{"CalibrationParams", PERSISTENT},
|
||||
{"CameraDebugExpGain", CLEAR_ON_MANAGER_START},
|
||||
{"CameraDebugExpTime", CLEAR_ON_MANAGER_START},
|
||||
{"CarBatteryCapacity", PERSISTENT},
|
||||
{"CarParams", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_ON},
|
||||
{"CarParamsCache", CLEAR_ON_MANAGER_START},
|
||||
|
||||
@@ -40,6 +40,7 @@ const bool env_disable_wide_road = getenv("DISABLE_WIDE_ROAD") != NULL;
|
||||
const bool env_disable_driver = getenv("DISABLE_DRIVER") != NULL;
|
||||
const bool env_debug_frames = getenv("DEBUG_FRAMES") != NULL;
|
||||
const bool env_log_raw_frames = getenv("LOG_RAW_FRAMES") != NULL;
|
||||
const bool env_ctrl_exp_from_params = getenv("CTRL_EXP_FROM_PARAMS") != NULL;
|
||||
|
||||
typedef struct CameraInfo {
|
||||
uint32_t frame_width, frame_height;
|
||||
|
||||
@@ -1101,36 +1101,48 @@ void CameraState::set_camera_exposure(float grey_frac) {
|
||||
} else if (enable_dc_gain && target_grey > 0.3) {
|
||||
enable_dc_gain = false;
|
||||
}
|
||||
|
||||
// Simple brute force optimizer to choose sensor parameters
|
||||
// to reach desired EV
|
||||
for (int g = std::max((int)ANALOG_GAIN_MIN_IDX, gain_idx - 1); g <= std::min((int)ANALOG_GAIN_MAX_IDX, gain_idx + 1); g++) {
|
||||
float gain = sensor_analog_gains[g] * (enable_dc_gain ? DC_GAIN : 1);
|
||||
|
||||
// Compute optimal time for given gain
|
||||
int t = std::clamp(int(std::round(desired_ev / gain)), EXPOSURE_TIME_MIN, EXPOSURE_TIME_MAX);
|
||||
|
||||
// Only go below recommended gain when absolutely necessary to not overexpose
|
||||
if (g < ANALOG_GAIN_REC_IDX && t > 20 && g < gain_idx) {
|
||||
continue;
|
||||
if (env_ctrl_exp_from_params) {
|
||||
// Override gain and exposure time
|
||||
if (buf.cur_frame_data.frame_id % 5 == 0) {
|
||||
std::string gain_bytes = Params().get("CameraDebugExpGain");
|
||||
std::string time_bytes = Params().get("CameraDebugExpTime");
|
||||
gain_idx = std::stoi(gain_bytes);
|
||||
exposure_time = std::stoi(time_bytes);
|
||||
}
|
||||
new_g = gain_idx;
|
||||
new_t = exposure_time;
|
||||
enable_dc_gain = false;
|
||||
} else {
|
||||
// Simple brute force optimizer to choose sensor parameters
|
||||
// to reach desired EV
|
||||
for (int g = std::max((int)ANALOG_GAIN_MIN_IDX, gain_idx - 1); g <= std::min((int)ANALOG_GAIN_MAX_IDX, gain_idx + 1); g++) {
|
||||
float gain = sensor_analog_gains[g] * (enable_dc_gain ? DC_GAIN : 1);
|
||||
|
||||
// Compute error to desired ev
|
||||
float score = std::abs(desired_ev - (t * gain)) * 10;
|
||||
// Compute optimal time for given gain
|
||||
int t = std::clamp(int(std::round(desired_ev / gain)), EXPOSURE_TIME_MIN, EXPOSURE_TIME_MAX);
|
||||
|
||||
// Going below recommended gain needs lower penalty to not overexpose
|
||||
float m = g > ANALOG_GAIN_REC_IDX ? 5.0 : 0.1;
|
||||
score += std::abs(g - (int)ANALOG_GAIN_REC_IDX) * m;
|
||||
// Only go below recommended gain when absolutely necessary to not overexpose
|
||||
if (g < ANALOG_GAIN_REC_IDX && t > 20 && g < gain_idx) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// LOGE("cam: %d - gain: %d, t: %d (%.2f), score %.2f, score + gain %.2f, %.3f, %.3f", camera_num, g, t, desired_ev / gain, score, score + std::abs(g - gain_idx) * (score + 1.0) / 10.0, desired_ev, min_ev);
|
||||
// Compute error to desired ev
|
||||
float score = std::abs(desired_ev - (t * gain)) * 10;
|
||||
|
||||
// Small penalty on changing gain
|
||||
score += std::abs(g - gain_idx) * (score + 1.0) / 10.0;
|
||||
// Going below recommended gain needs lower penalty to not overexpose
|
||||
float m = g > ANALOG_GAIN_REC_IDX ? 5.0 : 0.1;
|
||||
score += std::abs(g - (int)ANALOG_GAIN_REC_IDX) * m;
|
||||
|
||||
if (score < best_ev_score) {
|
||||
new_t = t;
|
||||
new_g = g;
|
||||
best_ev_score = score;
|
||||
// LOGE("cam: %d - gain: %d, t: %d (%.2f), score %.2f, score + gain %.2f, %.3f, %.3f", camera_num, g, t, desired_ev / gain, score, score + std::abs(g - gain_idx) * (score + 1.0) / 10.0, desired_ev, min_ev);
|
||||
|
||||
// Small penalty on changing gain
|
||||
score += std::abs(g - gain_idx) * (score + 1.0) / 10.0;
|
||||
|
||||
if (score < best_ev_score) {
|
||||
new_t = t;
|
||||
new_g = g;
|
||||
best_ev_score = score;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <media/cam_req_mgr.h>
|
||||
|
||||
#include "system/camerad/cameras/camera_common.h"
|
||||
#include "common/params.h"
|
||||
#include "common/util.h"
|
||||
|
||||
#define FRAME_BUF_COUNT 4
|
||||
|
||||
Reference in New Issue
Block a user