@@ -686,22 +686,37 @@ void SF45LaserSerial::_handle_missed_bins(uint8_t current_bin, uint8_t previous_
686
686
{
687
687
// if the sensor has its cycle delay configured for a low value like 5, it can happen that not every bin gets a measurement.
688
688
// in this case we assume the measurement to be valid for all bins between the previous and the current bin.
689
+ uint8_t start = current_bin;
690
+ uint8_t end = previous_bin - 1 ;
689
691
690
- // Shift bin indices such that we can never have the wrap-around case.
691
- const float fov_offset_angle = 360 .0f - SF45_FIELDOF_VIEW / 2 .f ;
692
- const uint16_t current_bin_offset = ObstacleMath::get_offset_bin_index (current_bin, _obstacle_distance.increment ,
693
- fov_offset_angle);
694
- const uint16_t previous_bin_offset = ObstacleMath::get_offset_bin_index (previous_bin, _obstacle_distance.increment ,
695
- fov_offset_angle);
696
-
697
- const uint16_t start = math::min (current_bin_offset, previous_bin_offset) + 1 ;
698
- const uint16_t end = math::max (current_bin_offset, previous_bin_offset);
699
-
700
- // populate the missed bins with the measurement
701
- for (uint16_t i = start; i < end; i++) {
702
- uint16_t bin_index = ObstacleMath::get_offset_bin_index (i, _obstacle_distance.increment , -fov_offset_angle);
703
- _obstacle_distance.distances [bin_index] = measurement;
704
- _data_timestamps[bin_index] = now;
692
+ if (abs (current_bin - previous_bin) > BIN_COUNT / 4 ) {
693
+ // wrap-around case is assumed to have happend when the distance between the bins is larger than 1/4 of all Bins
694
+ // This is simplyfied as we are not considering the scaning direction
695
+ start = math::max (previous_bin, current_bin);
696
+ end = math::min (previous_bin, current_bin);
697
+
698
+ } else if (previous_bin < current_bin) { // Scanning clockwise
699
+ start = previous_bin + 1 ;
700
+ end = current_bin;
701
+
702
+ }
703
+
704
+ if (start <= end) {
705
+ for (uint8_t i = start; i <= end; i++) {
706
+ _obstacle_distance.distances [i] = measurement;
707
+ _data_timestamps[i] = now;
708
+ }
709
+
710
+ } else { // wrap-around case
711
+ for (uint8_t i = start; i < BIN_COUNT; i++) {
712
+ _obstacle_distance.distances [i] = measurement;
713
+ _data_timestamps[i] = now;
714
+ }
715
+
716
+ for (uint8_t i = 0 ; i <= end; i++) {
717
+ _obstacle_distance.distances [i] = measurement;
718
+ _data_timestamps[i] = now;
719
+ }
705
720
}
706
721
}
707
722
0 commit comments