25 #define MODULE "example_waste_level"
150 bool status = app_config != NULL;
168 if (app_config != NULL)
181 bool status = app_config != NULL;
219 uint16_t sweeps_per_frame = 0U;
220 uint16_t median_filter_len = 0U;
242 uint16_t num_elem = sweeps_per_frame > median_filter_len ? sweeps_per_frame : median_filter_len;
244 status =
handle->scratch != NULL;
251 status =
handle->
state.distance_history_points != NULL;
266 if (
handle->scratch != NULL)
281 if (
handle != NULL && app_config != NULL && metadata != NULL && frame != NULL && waste_level_result != NULL)
289 uint16_t phase_vars_under_threshold = 0U;
291 bool point_of_waste_found =
false;
292 uint16_t point_of_waste = 0U;
294 for (uint16_t point_idx = 0U; point_idx < sweep_length; point_idx++)
296 float complex column_sum;
302 for (uint16_t sweep_idx = 0U; sweep_idx < sweeps_per_frame; sweep_idx++)
304 uint16_t frame_idx = sweep_idx * sweep_length + point_idx;
306 float complex float_point = (float)point.
real + (
float)point.
imag * I;
308 handle->scratch[sweep_idx] = cargf(float_point * column_sum);
313 if (point_phase_variance < threshold_squared)
315 phase_vars_under_threshold++;
319 phase_vars_under_threshold = 0U;
322 if (phase_vars_under_threshold >= distance_seq_len)
324 point_of_waste = point_idx - (phase_vars_under_threshold - 1U);
325 point_of_waste_found =
true;
356 printf(
"Waste level config:\n");
360 printf(
"distance_sequence_len: %" PRIu16
"\n",
config->distance_sequence_len);
361 printf(
"median_filter_len: %" PRIu16
"\n",
config->median_filter_len);
369 bool status = app_config != NULL;
375 status = sensor_config != NULL && processing_config != NULL;
378 if (status && processing_config->
bin_start_m < 0.08f)
380 fprintf(stderr,
"Bin start needs to be greater or equal than 0.08m\n");
386 fprintf(stderr,
"Bin end needs to be greater than bin start\n");
390 if (status && (processing_config->
threshold < 0.0f || processing_config->
threshold > 4.0f))
398 fprintf(stderr,
"Distance sequence length shoud be in the range [1, 10], was %" PRIu16
"\n", processing_config->
distance_sequence_len);
404 fprintf(stderr,
"Median filter length shoud be in the range [1, 10], was %" PRIu16
"\n", processing_config->
median_filter_len);
410 fprintf(stderr,
"Subsweeps with higher indexes should measure farther away than those with lower indexes\n");
416 uint8_t subsweep_idx;
420 fprintf(stderr,
"Disallowed range overlap between susweeps %" PRIu16
" and %" PRIu16
"\n", subsweep_idx, subsweep_idx + 1U);
427 fprintf(stderr,
"Start point must be greater or equal than 32\n");
433 fprintf(stderr,
"Bin start is outside measuring interval\n");
439 fprintf(stderr,
"Bin end is outside measuring interval\n");
445 fprintf(stderr,
"Sweeps per frame needs to be greater than 3\n");
454 bool increasing =
true;
458 for (uint8_t subsweep_idx = 1U; subsweep_idx < num_subsweeps; subsweep_idx++)
463 if (curr_start <= prev_start)
475 bool overlap_found =
false;
478 for (uint8_t subsweep_idx = 0U; subsweep_idx < num_subsweeps - 1U; subsweep_idx++)
483 if (curr_end >= next_start)
485 *offending_subsweep = subsweep_idx;
486 overlap_found =
true;
491 return overlap_found;
496 const int32_t minimum_allowed_start_point = 32;
500 return min_start_point < minimum_allowed_start_point;
505 float min_measured_point_m = 1000.0f;
506 float max_measured_point_m = -1000.0f;
510 for (uint8_t subsweep_idx = 0U; subsweep_idx < num_subsweeps; subsweep_idx++)
515 if (current_begin_m < min_measured_point_m)
517 min_measured_point_m = current_begin_m;
520 if (current_end_m > max_measured_point_m)
522 max_measured_point_m = current_end_m;
526 return distance_m < min_measured_point_m || distance_m > max_measured_point_m;
548 float distance_m = 0.0f;
550 for (uint8_t subsweep_idx = 0U; subsweep_idx < num_subsweeps; subsweep_idx++)
555 if (point_idx >= start && point_idx < end)
570 buffer[*write_idx] = elem;
572 *write_idx = (*write_idx + 1U) % capacity;
574 if (*length < capacity)
576 *length = *length + 1U;
582 uint16_t num_normal = 0U;
584 for (uint16_t i = 0U; i < length; i++)
586 if (fpclassify(in[i]) != FP_NAN)
588 out[num_normal] = in[i];
598 float bin_end_m = processing_config->
bin_end_m;
599 float bin_start_m = processing_config->
bin_start_m;
601 float fill_level_m = bin_end_m - filtered_distance;
602 float fill_level_percent_f =
acc_algorithm_clip_f32(100.0f * fill_level_m / (bin_end_m - bin_start_m), 0.0f, 100.0f);
604 fill_level_percent_f += 0.5f;
605 uint8_t fill_level_percent = (uint8_t)fill_level_percent_f;