mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-07-15 22:10:36 +08:00
improve end to end control latency measurement (#9388)
This commit is contained in:
@@ -52,6 +52,7 @@
|
||||
#include <lib/mixer/mixer_load.h>
|
||||
#include <parameters/param.h>
|
||||
#include <systemlib/pwm_limit/pwm_limit.h>
|
||||
#include <perf/perf_counter.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "navio_sysfs.h"
|
||||
@@ -77,6 +78,8 @@ int _armed_sub = -1;
|
||||
orb_advert_t _outputs_pub = nullptr;
|
||||
orb_advert_t _rc_pub = nullptr;
|
||||
|
||||
perf_counter_t _perf_control_latency = nullptr;
|
||||
|
||||
// topic structures
|
||||
actuator_controls_s _controls[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS];
|
||||
orb_id_t _controls_topics[actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS];
|
||||
@@ -212,6 +215,8 @@ void task_main(int argc, char *argv[])
|
||||
{
|
||||
_is_running = true;
|
||||
|
||||
_perf_control_latency = perf_alloc(PC_ELAPSED, "linux_pwm_out control latency");
|
||||
|
||||
// Set up mixer
|
||||
if (initialize_mixer(_mixer_filename) < 0) {
|
||||
PX4_ERR("Mixer initialization failed.");
|
||||
@@ -240,6 +245,7 @@ void task_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
_mixer_group->groups_required(_groups_required);
|
||||
|
||||
// subscribe and set up polling
|
||||
subscribe();
|
||||
|
||||
@@ -321,7 +327,6 @@ void task_main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (_mixer_group != nullptr) {
|
||||
_outputs.timestamp = hrt_absolute_time();
|
||||
/* do mixing */
|
||||
_outputs.noutputs = _mixer_group->mix(_outputs.output, actuator_outputs_s::NUM_ACTUATOR_OUTPUTS);
|
||||
|
||||
@@ -379,6 +384,8 @@ void task_main(int argc, char *argv[])
|
||||
pwm_out->send_output_pwm(pwm, _outputs.noutputs);
|
||||
}
|
||||
|
||||
_outputs.timestamp = hrt_absolute_time();
|
||||
|
||||
if (_outputs_pub != nullptr) {
|
||||
orb_publish(ORB_ID(actuator_outputs), _outputs_pub, &_outputs);
|
||||
|
||||
@@ -386,6 +393,17 @@ void task_main(int argc, char *argv[])
|
||||
_outputs_pub = orb_advertise(ORB_ID(actuator_outputs), &_outputs);
|
||||
}
|
||||
|
||||
// use first valid timestamp_sample for latency tracking
|
||||
for (int i = 0; i < actuator_controls_s::NUM_ACTUATOR_CONTROL_GROUPS; i++) {
|
||||
const bool required = _groups_required & (1 << i);
|
||||
const hrt_abstime ×tamp_sample = _controls[i].timestamp_sample;
|
||||
|
||||
if (required && (timestamp_sample > 0)) {
|
||||
perf_set_elapsed(_perf_control_latency, _outputs.timestamp - timestamp_sample);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
PX4_ERR("Could not mix output! Exiting...");
|
||||
_task_should_exit = true;
|
||||
@@ -424,6 +442,8 @@ void task_main(int argc, char *argv[])
|
||||
orb_unsubscribe(params_sub);
|
||||
}
|
||||
|
||||
perf_free(_perf_control_latency);
|
||||
|
||||
_is_running = false;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user