Refactor camerad exposure logging (#21506)

* simplify gain logging

* clean up metadata

* log grey fractions

* those are not used

* set grey fracs in message

* fix qcom
old-commit-hash: 47be6c751e
commatwo_master
Willem Melching 4 years ago committed by GitHub
parent c042bbf09c
commit e0378d41cb
  1. 2
      cereal
  2. 6
      selfdrive/camerad/cameras/camera_common.cc
  3. 14
      selfdrive/camerad/cameras/camera_common.h
  4. 4
      selfdrive/camerad/cameras/camera_frame_stream.cc
  5. 12
      selfdrive/camerad/cameras/camera_qcom.cc
  6. 4
      selfdrive/camerad/cameras/camera_qcom.h
  7. 9
      selfdrive/camerad/cameras/camera_qcom2.cc
  8. 3
      selfdrive/camerad/cameras/camera_qcom2.h
  9. 6
      selfdrive/ui/ui.cc

@ -1 +1 @@
Subproject commit 1979127659dc7c47c6ad7b8234ff1f6ca93526fc
Subproject commit 353d8a9249e05c1bb4d1fec7ba7ba93293166131

@ -180,12 +180,14 @@ void fill_frame_data(cereal::FrameData::Builder &framed, const FrameMetadata &fr
framed.setTimestampSof(frame_data.timestamp_sof);
framed.setFrameLength(frame_data.frame_length);
framed.setIntegLines(frame_data.integ_lines);
framed.setGlobalGain(frame_data.global_gain);
framed.setGain(frame_data.gain);
framed.setHighConversionGain(frame_data.high_conversion_gain);
framed.setMeasuredGreyFraction(frame_data.measured_grey_fraction);
framed.setTargetGreyFraction(frame_data.target_grey_fraction);
framed.setLensPos(frame_data.lens_pos);
framed.setLensSag(frame_data.lens_sag);
framed.setLensErr(frame_data.lens_err);
framed.setLensTruePos(frame_data.lens_true_pos);
framed.setGainFrac(frame_data.gain_frac);
}
kj::Array<uint8_t> get_frame_image(const CameraBuf *b) {

@ -67,16 +67,24 @@ typedef struct LogCameraInfo {
typedef struct FrameMetadata {
uint32_t frame_id;
unsigned int frame_length;
// Timestamps
uint64_t timestamp_sof; // only set on tici
uint64_t timestamp_eof;
unsigned int frame_length;
// Exposure
unsigned int integ_lines;
unsigned int global_gain;
bool high_conversion_gain;
float gain;
float measured_grey_fraction;
float target_grey_fraction;
// Focus
unsigned int lens_pos;
float lens_sag;
float lens_err;
float lens_true_pos;
float gain_frac;
} FrameMetadata;
typedef struct CameraExpInfo {

@ -56,9 +56,7 @@ void run_frame_stream(CameraState &camera, const char* frame_pkt) {
camera.buf.camera_bufs_metadata[buf_idx] = {
.frame_id = frame.get("frameId").as<uint32_t>(),
.timestamp_eof = frame.get("timestampEof").as<uint64_t>(),
.frame_length = frame.get("frameLength").as<unsigned>(),
.integ_lines = frame.get("integLines").as<unsigned>(),
.global_gain = frame.get("globalGain").as<unsigned>(),
.timestamp_sof = frame.get("timestampSof").as<uint64_t>(),
};
cl_command_queue q = camera.buf.camera_bufs[buf_idx].copy_q;

@ -282,6 +282,12 @@ static void set_exposure(CameraState *s, float exposure_frac, float gain_frac) {
static void do_autoexposure(CameraState *s, float grey_frac) {
const float target_grey = 0.3;
s->frame_info_lock.lock();
s->measured_grey_fraction = grey_frac;
s->target_grey_fraction = target_grey;
s->frame_info_lock.unlock();
if (s->apply_exposure == ov8865_apply_exposure) {
// gain limits downstream
const float gain_frac_min = 0.015625;
@ -1162,12 +1168,14 @@ void cameras_run(MultiCameraState *s) {
.timestamp_eof = timestamp,
.frame_length = (uint32_t)c->frame_length,
.integ_lines = (uint32_t)c->cur_integ_lines,
.global_gain = (uint32_t)c->cur_gain,
.lens_pos = c->cur_lens_pos,
.lens_sag = c->last_sag_acc_z,
.lens_err = c->focus_err,
.lens_true_pos = c->lens_true_pos,
.gain_frac = c->cur_gain_frac,
.gain = c->cur_gain_frac,
.measured_grey_fraction = c->measured_grey_fraction,
.target_grey_fraction = c->target_grey_fraction,
.high_conversion_gain = false,
};
c->frame_metadata_idx = (c->frame_metadata_idx + 1) % METADATA_BUF_COUNT;

@ -66,6 +66,10 @@ typedef struct CameraState {
unsigned int max_gain;
float cur_exposure_frac, cur_gain_frac;
int cur_gain, cur_integ_lines;
float measured_grey_fraction;
float target_grey_fraction;
std::atomic<float> digital_gain;
camera_apply_exposure_func apply_exposure;

@ -905,9 +905,11 @@ void handle_camera_event(CameraState *s, void *evdat) {
meta_data.frame_id = main_id - s->idx_offset;
meta_data.timestamp_sof = timestamp;
s->exp_lock.lock();
meta_data.global_gain = s->analog_gain + (100*s->dc_gain_enabled);
meta_data.gain_frac = s->analog_gain_frac;
meta_data.gain = s->dc_gain_enabled ? s->analog_gain_frac * 2.5 : s->analog_gain_frac;
meta_data.high_conversion_gain = s->dc_gain_enabled;
meta_data.integ_lines = s->exposure_time;
meta_data.measured_grey_fraction = s->measured_grey_fraction;
meta_data.target_grey_fraction = s->target_grey_fraction;
s->exp_lock.unlock();
// dispatch
@ -969,6 +971,9 @@ static void set_camera_exposure(CameraState *s, float grey_frac) {
}
s->exp_lock.lock();
s->measured_grey_fraction = grey_frac;
s->target_grey_fraction = target_grey;
// always prioritize exposure time adjust
s->exposure_time *= exposure_factor;

@ -32,6 +32,9 @@ typedef struct CameraState {
int exposure_time_max;
float ef_filtered;
float measured_grey_fraction;
float target_grey_fraction;
unique_fd sensor_fd;
unique_fd csiphy_fd;

@ -199,11 +199,11 @@ static void update_state(UIState *s) {
auto camera_state = sm["roadCameraState"].getRoadCameraState();
float max_lines = Hardware::EON() ? 5408 : 1757;
float gain = camera_state.getGainFrac();
float gain = camera_state.getGain();
if (Hardware::TICI()) {
// gainFrac can go up to 4, with another 2.5x multiplier based on globalGain. Scale back to 0 - 1
gain *= (camera_state.getGlobalGain() > 100 ? 2.5 : 1.0) / 10.0;
// Max gain is 4 * 2.5 (High Conversion Gain)
gain /= 10.0;
}
scene.light_sensor = std::clamp<float>((1023.0 / max_lines) * (max_lines - camera_state.getIntegLines() * gain), 0.0, 1023.0);

Loading…
Cancel
Save