camerad: define the constants directly in ctor (#30651)

old-commit-hash: 8fdcddec8a
chrysler-long2
Dean Lee 1 year ago committed by GitHub
parent f483812d07
commit db18ad7467
  1. 48
      system/camerad/sensors/ar0231.cc
  2. 47
      system/camerad/sensors/ox03c10.cc

@ -10,32 +10,12 @@ const size_t AR0231_REGISTERS_HEIGHT = 2;
// TODO: this extra height is universal and doesn't apply per camera // TODO: this extra height is universal and doesn't apply per camera
const size_t AR0231_STATS_HEIGHT = 2 + 8; const size_t AR0231_STATS_HEIGHT = 2 + 8;
const float DC_GAIN_AR0231 = 2.5;
const float DC_GAIN_ON_GREY_AR0231 = 0.2;
const float DC_GAIN_OFF_GREY_AR0231 = 0.3;
const int DC_GAIN_MIN_WEIGHT_AR0231 = 0;
const int DC_GAIN_MAX_WEIGHT_AR0231 = 1;
const float TARGET_GREY_FACTOR_AR0231 = 1.0;
const float sensor_analog_gains_AR0231[] = { const float sensor_analog_gains_AR0231[] = {
1.0 / 8.0, 2.0 / 8.0, 2.0 / 7.0, 3.0 / 7.0, // 0, 1, 2, 3 1.0 / 8.0, 2.0 / 8.0, 2.0 / 7.0, 3.0 / 7.0, // 0, 1, 2, 3
3.0 / 6.0, 4.0 / 6.0, 4.0 / 5.0, 5.0 / 5.0, // 4, 5, 6, 7 3.0 / 6.0, 4.0 / 6.0, 4.0 / 5.0, 5.0 / 5.0, // 4, 5, 6, 7
5.0 / 4.0, 6.0 / 4.0, 6.0 / 3.0, 7.0 / 3.0, // 8, 9, 10, 11 5.0 / 4.0, 6.0 / 4.0, 6.0 / 3.0, 7.0 / 3.0, // 8, 9, 10, 11
7.0 / 2.0, 8.0 / 2.0, 8.0 / 1.0}; // 12, 13, 14, 15 = bypass 7.0 / 2.0, 8.0 / 2.0, 8.0 / 1.0}; // 12, 13, 14, 15 = bypass
const int ANALOG_GAIN_MIN_IDX_AR0231 = 0x1; // 0.25x
const int ANALOG_GAIN_REC_IDX_AR0231 = 0x6; // 0.8x
const int ANALOG_GAIN_MAX_IDX_AR0231 = 0xD; // 4.0x
const int ANALOG_GAIN_COST_DELTA_AR0231 = 0;
const float ANALOG_GAIN_COST_LOW_AR0231 = 0.1;
const float ANALOG_GAIN_COST_HIGH_AR0231 = 5.0;
const int EXPOSURE_TIME_MIN_AR0231 = 2; // with HDR, fastest ss
const int EXPOSURE_TIME_MAX_AR0231 = 0x0855; // with HDR, slowest ss, 40ms
std::map<uint16_t, std::pair<int, int>> ar0231_build_register_lut(CameraState *c, uint8_t *data) { std::map<uint16_t, std::pair<int, int>> ar0231_build_register_lut(CameraState *c, uint8_t *data) {
// This function builds a lookup table from register address, to a pair of indices in the // This function builds a lookup table from register address, to a pair of indices in the
// buffer where to read this address. The buffer contains padding bytes, // buffer where to read this address. The buffer contains padding bytes,
@ -119,25 +99,25 @@ AR0231::AR0231() {
frame_offset = AR0231_REGISTERS_HEIGHT; frame_offset = AR0231_REGISTERS_HEIGHT;
stats_offset = AR0231_REGISTERS_HEIGHT + FRAME_HEIGHT; stats_offset = AR0231_REGISTERS_HEIGHT + FRAME_HEIGHT;
dc_gain_factor = DC_GAIN_AR0231; dc_gain_factor = 2.5;
dc_gain_min_weight = DC_GAIN_MIN_WEIGHT_AR0231; dc_gain_min_weight = 0;
dc_gain_max_weight = DC_GAIN_MAX_WEIGHT_AR0231; dc_gain_max_weight = 1;
dc_gain_on_grey = DC_GAIN_ON_GREY_AR0231; dc_gain_on_grey = 0.2;
dc_gain_off_grey = DC_GAIN_OFF_GREY_AR0231; dc_gain_off_grey = 0.3;
exposure_time_min = EXPOSURE_TIME_MIN_AR0231; exposure_time_min = 2; // with HDR, fastest ss
exposure_time_max = EXPOSURE_TIME_MAX_AR0231; exposure_time_max = 0x0855; // with HDR, slowest ss, 40ms
analog_gain_min_idx = ANALOG_GAIN_MIN_IDX_AR0231; analog_gain_min_idx = 0x1; // 0.25x
analog_gain_rec_idx = ANALOG_GAIN_REC_IDX_AR0231; analog_gain_rec_idx = 0x6; // 0.8x
analog_gain_max_idx = ANALOG_GAIN_MAX_IDX_AR0231; analog_gain_max_idx = 0xD; // 4.0x
analog_gain_cost_delta = ANALOG_GAIN_COST_DELTA_AR0231; analog_gain_cost_delta = 0;
analog_gain_cost_low = ANALOG_GAIN_COST_LOW_AR0231; analog_gain_cost_low = 0.1;
analog_gain_cost_high = ANALOG_GAIN_COST_HIGH_AR0231; analog_gain_cost_high = 5.0;
for (int i = 0; i <= analog_gain_max_idx; i++) { for (int i = 0; i <= analog_gain_max_idx; i++) {
sensor_analog_gains[i] = sensor_analog_gains_AR0231[i]; sensor_analog_gains[i] = sensor_analog_gains_AR0231[i];
} }
min_ev = exposure_time_min * sensor_analog_gains[analog_gain_min_idx]; min_ev = exposure_time_min * sensor_analog_gains[analog_gain_min_idx];
max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx]; max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx];
target_grey_factor = TARGET_GREY_FACTOR_AR0231; target_grey_factor = 1.0;
} }
void ar0231_process_registers(MultiCameraState *s, CameraState *c, cereal::FrameData::Builder &framed) { void ar0231_process_registers(MultiCameraState *s, CameraState *c, cereal::FrameData::Builder &framed) {

@ -2,16 +2,6 @@
namespace { namespace {
const float DC_GAIN_OX03C10 = 7.32;
const float DC_GAIN_ON_GREY_OX03C10 = 0.9;
const float DC_GAIN_OFF_GREY_OX03C10 = 1.0;
const int DC_GAIN_MIN_WEIGHT_OX03C10 = 1; // always on is fine
const int DC_GAIN_MAX_WEIGHT_OX03C10 = 1;
const float TARGET_GREY_FACTOR_OX03C10 = 0.01;
const float sensor_analog_gains_OX03C10[] = { const float sensor_analog_gains_OX03C10[] = {
1.0, 1.0625, 1.125, 1.1875, 1.25, 1.3125, 1.375, 1.4375, 1.5, 1.5625, 1.6875, 1.0, 1.0625, 1.125, 1.1875, 1.25, 1.3125, 1.375, 1.4375, 1.5, 1.5625, 1.6875,
1.8125, 1.9375, 2.0, 2.125, 2.25, 2.375, 2.5, 2.625, 2.75, 2.875, 3.0, 1.8125, 1.9375, 2.0, 2.125, 2.25, 2.375, 2.5, 2.625, 2.75, 2.875, 3.0,
@ -26,15 +16,6 @@ const uint32_t ox03c10_analog_gains_reg[] = {
0x5C0, 0x600, 0x640, 0x680, 0x700, 0x780, 0x800, 0x880, 0x900, 0x980, 0xA00, 0x5C0, 0x600, 0x640, 0x680, 0x700, 0x780, 0x800, 0x880, 0x900, 0x980, 0xA00,
0xA80, 0xB00, 0xB80, 0xC00, 0xC80, 0xD00, 0xD80, 0xE00, 0xE80, 0xF00, 0xF80}; 0xA80, 0xB00, 0xB80, 0xC00, 0xC80, 0xD00, 0xD80, 0xE00, 0xE80, 0xF00, 0xF80};
const int ANALOG_GAIN_MIN_IDX_OX03C10 = 0x0;
const int ANALOG_GAIN_REC_IDX_OX03C10 = 0x0; // 1x
const int ANALOG_GAIN_MAX_IDX_OX03C10 = 0x36;
const int ANALOG_GAIN_COST_DELTA_OX03C10 = -1;
const float ANALOG_GAIN_COST_LOW_OX03C10 = 0.4;
const float ANALOG_GAIN_COST_HIGH_OX03C10 = 6.4;
const int EXPOSURE_TIME_MIN_OX03C10 = 2; // 1x
const int EXPOSURE_TIME_MAX_OX03C10 = 2016;
const uint32_t VS_TIME_MIN_OX03C10 = 1; const uint32_t VS_TIME_MIN_OX03C10 = 1;
const uint32_t VS_TIME_MAX_OX03C10 = 34; // vs < 35 const uint32_t VS_TIME_MAX_OX03C10 = 34; // vs < 35
@ -47,25 +28,25 @@ OX03C10::OX03C10() {
extra_height = 16; // top 2 + bot 14 extra_height = 16; // top 2 + bot 14
frame_offset = 2; frame_offset = 2;
dc_gain_factor = DC_GAIN_OX03C10; dc_gain_factor = 7.32;
dc_gain_min_weight = DC_GAIN_MIN_WEIGHT_OX03C10; dc_gain_min_weight = 1; // always on is fine
dc_gain_max_weight = DC_GAIN_MAX_WEIGHT_OX03C10; dc_gain_max_weight = 1;
dc_gain_on_grey = DC_GAIN_ON_GREY_OX03C10; dc_gain_on_grey = 0.9;
dc_gain_off_grey = DC_GAIN_OFF_GREY_OX03C10; dc_gain_off_grey = 1.0;
exposure_time_min = EXPOSURE_TIME_MIN_OX03C10; exposure_time_min = 2; // 1x
exposure_time_max = EXPOSURE_TIME_MAX_OX03C10; exposure_time_max = 2016;
analog_gain_min_idx = ANALOG_GAIN_MIN_IDX_OX03C10; analog_gain_min_idx = 0x0;
analog_gain_rec_idx = ANALOG_GAIN_REC_IDX_OX03C10; analog_gain_rec_idx = 0x0; // 1x
analog_gain_max_idx = ANALOG_GAIN_MAX_IDX_OX03C10; analog_gain_max_idx = 0x36;
analog_gain_cost_delta = ANALOG_GAIN_COST_DELTA_OX03C10; analog_gain_cost_delta = -1;
analog_gain_cost_low = ANALOG_GAIN_COST_LOW_OX03C10; analog_gain_cost_low = 0.4;
analog_gain_cost_high = ANALOG_GAIN_COST_HIGH_OX03C10; analog_gain_cost_high = 6.4;
for (int i = 0; i <= analog_gain_max_idx; i++) { for (int i = 0; i <= analog_gain_max_idx; i++) {
sensor_analog_gains[i] = sensor_analog_gains_OX03C10[i]; sensor_analog_gains[i] = sensor_analog_gains_OX03C10[i];
} }
min_ev = (exposure_time_min + VS_TIME_MIN_OX03C10) * sensor_analog_gains[analog_gain_min_idx]; min_ev = (exposure_time_min + VS_TIME_MIN_OX03C10) * sensor_analog_gains[analog_gain_min_idx];
max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx]; max_ev = exposure_time_max * dc_gain_factor * sensor_analog_gains[analog_gain_max_idx];
target_grey_factor = TARGET_GREY_FACTOR_OX03C10; target_grey_factor = 0.01;
} }
std::vector<struct i2c_random_wr_payload> ox03c10_get_exp_registers(const SensorInfo *ci, int exposure_time, int new_exp_g, bool dc_gain_enabled) { std::vector<struct i2c_random_wr_payload> ox03c10_get_exp_registers(const SensorInfo *ci, int exposure_time, int new_exp_g, bool dc_gain_enabled) {

Loading…
Cancel
Save