Skip to content

Commit a46125b

Browse files
SF45 revert missing bin logic (#25173)
* revert missing bin logic Signed-off-by: dirksavage88 <dirksavage88@gmail.com> * removed else and initialized at variable declaration Signed-off-by: dirksavage88 <dirksavage88@gmail.com> --------- Signed-off-by: dirksavage88 <dirksavage88@gmail.com> Co-authored-by: Claudio Chies <61051109+Claudio-Chies@users.noreply.github.com>
1 parent c320a92 commit a46125b

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

src/drivers/distance_sensor/lightware_sf45_serial/lightware_sf45_serial.cpp

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -686,22 +686,37 @@ void SF45LaserSerial::_handle_missed_bins(uint8_t current_bin, uint8_t previous_
686686
{
687687
// if the sensor has its cycle delay configured for a low value like 5, it can happen that not every bin gets a measurement.
688688
// 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;
689691

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+
}
705720
}
706721
}
707722

0 commit comments

Comments
 (0)