Skip to content

Commit

Permalink
distance_sensor add timestamp_sample. AFBR set timestamp_sample from …
Browse files Browse the repository at this point in the history
…callback time
  • Loading branch information
AlexKlimaj committed May 1, 2024
1 parent b6da0b1 commit 4222d06
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions msg/DistanceSensor.msg
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# DISTANCE_SENSOR message data

uint64 timestamp # time since system start (microseconds)
uint64 timestamp_sample

uint32 device_id # unique device ID for the sensor that does not change between power cycles

Expand Down
6 changes: 3 additions & 3 deletions src/drivers/distance_sensor/broadcom/afbrs50/AFBRS50.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ status_t AFBRS50::measurement_ready_callback(status_t status, argus_hnd_t *hnd)
if (!up_interrupt_context()) {
if (status == STATUS_OK) {
if (g_dev) {
g_dev->ProcessMeasurement(hnd);
g_dev->ProcessMeasurement(hnd, hrt_absolute_time());
}

} else {
Expand All @@ -86,7 +86,7 @@ status_t AFBRS50::measurement_ready_callback(status_t status, argus_hnd_t *hnd)
return status;
}

void AFBRS50::ProcessMeasurement(argus_hnd_t *hnd)
void AFBRS50::ProcessMeasurement(argus_hnd_t *hnd, hrt_abstime timestamp_sample)
{
perf_count(_sample_perf);

Expand All @@ -112,7 +112,7 @@ void AFBRS50::ProcessMeasurement(argus_hnd_t *hnd)

_current_distance = result_m;
_current_quality = quality;
_px4_rangefinder.update(((res.TimeStamp.sec * 1000000ULL) + res.TimeStamp.usec), result_m, quality);
_px4_rangefinder.update(timestamp_sample, result_m, quality);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/distance_sensor/broadcom/afbrs50/AFBRS50.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class AFBRS50 : public ModuleParams, public px4::ScheduledWorkItem

void Evaluate_rate();

void ProcessMeasurement(argus_hnd_t *hnd);
void ProcessMeasurement(argus_hnd_t *hnd, hrt_abstime timestamp_sample);

static status_t measurement_ready_callback(status_t status, argus_hnd_t *hnd);

Expand Down
4 changes: 3 additions & 1 deletion src/lib/drivers/rangefinder/PX4Rangefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void PX4Rangefinder::update(const hrt_abstime &timestamp_sample, const float dis
{
distance_sensor_s &report = _distance_sensor_pub.get();

report.timestamp = timestamp_sample;
report.timestamp_sample = timestamp_sample;
report.current_distance = distance;
report.signal_quality = quality;

Expand All @@ -80,5 +80,7 @@ void PX4Rangefinder::update(const hrt_abstime &timestamp_sample, const float dis
}
}

report.timestamp = hrt_absolute_time();

_distance_sensor_pub.update();
}

0 comments on commit 4222d06

Please sign in to comment.