Skip to content

Commit

Permalink
sf45: remove useless pointer for measured distance
Browse files Browse the repository at this point in the history
  • Loading branch information
bresch committed Jan 10, 2025
1 parent 49e7e41 commit b05267c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ int SF45LaserSerial::measure()

int SF45LaserSerial::collect()
{
float distance_m = -1.0f;

if (_sensor_state == STATE_UNINIT) {

perf_begin(_sample_perf);
Expand Down Expand Up @@ -195,8 +193,7 @@ int SF45LaserSerial::collect()
sf45_get_and_handle_request(payload_length, SF_DISTANCE_DATA_CM);

if (_crc_valid) {
sf45_process_replies(&distance_m);
PX4_DEBUG("val (float): %8.4f, valid: %s", (double)distance_m, ((_crc_valid) ? "OK" : "NO"));
sf45_process_replies();
perf_end(_sample_perf);
return PX4_OK;
}
Expand Down Expand Up @@ -591,7 +588,7 @@ void SF45LaserSerial::sf45_send(uint8_t msg_id, bool write, int32_t *data, uint8
}
}

void SF45LaserSerial::sf45_process_replies(float *distance_m)
void SF45LaserSerial::sf45_process_replies()
{
switch (rx_field.msg_id) {
case SF_DISTANCE_DATA_CM: {
Expand Down Expand Up @@ -639,14 +636,14 @@ void SF45LaserSerial::sf45_process_replies(float *distance_m)
}

// Convert to meters for the debug message
*distance_m = raw_distance * SF45_SCALE_FACTOR;
float distance_m = raw_distance * SF45_SCALE_FACTOR;
_current_bin_dist = ((uint16_t)raw_distance < _current_bin_dist) ? (uint16_t)raw_distance : _current_bin_dist;

uint8_t current_bin = sf45_convert_angle(scaled_yaw);

if (current_bin != _previous_bin) {
PX4_DEBUG("scaled_yaw: \t %d, \t current_bin: \t %d, \t distance: \t %8.4f\n", scaled_yaw, current_bin,
(double)*distance_m);
(double)distance_m);

if (_vehicle_attitude_sub.updated()) {
vehicle_attitude_s vehicle_attitude;
Expand All @@ -656,7 +653,7 @@ void SF45LaserSerial::sf45_process_replies(float *distance_m)
}
}

ObstacleMath::project_distance_on_horizontal_plane(*distance_m, scaled_yaw, _vehicle_attitude);
ObstacleMath::project_distance_on_horizontal_plane(distance_m, scaled_yaw, _vehicle_attitude);

if (_current_bin_dist > _obstacle_distance.max_distance) {
_current_bin_dist = _obstacle_distance.max_distance + 1; // As per ObstacleDistance.msg definition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class SF45LaserSerial : public px4::ScheduledWorkItem
void sf45_get_and_handle_request(const int payload_length, const SF_SERIAL_CMD msg_id);
void sf45_send(uint8_t msg_id, bool r_w, int32_t *data, uint8_t data_len);
uint16_t sf45_format_crc(uint16_t crc, uint8_t data_value);
void sf45_process_replies(float *data);
void sf45_process_replies();
uint8_t sf45_convert_angle(const int16_t yaw);
float sf45_wrap_360(float f);

Expand Down

0 comments on commit b05267c

Please sign in to comment.