mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-06-04 21:23:57 +08:00
pwm_out: update pwm outputs up to twice as fast as actual pwm frequency
- this is done to minimize real end-to-end latency - actual pulse width only updated for next period regardless of output module - add cycle interval perf counter
This commit is contained in:
@@ -36,7 +36,8 @@
|
|||||||
PWMOut::PWMOut() :
|
PWMOut::PWMOut() :
|
||||||
CDev(PX4FMU_DEVICE_PATH),
|
CDev(PX4FMU_DEVICE_PATH),
|
||||||
OutputModuleInterface(MODULE_NAME, px4::wq_configurations::hp_default),
|
OutputModuleInterface(MODULE_NAME, px4::wq_configurations::hp_default),
|
||||||
_cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle"))
|
_cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")),
|
||||||
|
_interval_perf(perf_alloc(PC_INTERVAL, MODULE_NAME": interval"))
|
||||||
{
|
{
|
||||||
_mixing_output.setAllMinValues(PWM_DEFAULT_MIN);
|
_mixing_output.setAllMinValues(PWM_DEFAULT_MIN);
|
||||||
_mixing_output.setAllMaxValues(PWM_DEFAULT_MAX);
|
_mixing_output.setAllMaxValues(PWM_DEFAULT_MAX);
|
||||||
@@ -52,6 +53,7 @@ PWMOut::~PWMOut()
|
|||||||
unregister_class_devname(PWM_OUTPUT_BASE_DEVICE_PATH, _class_instance);
|
unregister_class_devname(PWM_OUTPUT_BASE_DEVICE_PATH, _class_instance);
|
||||||
|
|
||||||
perf_free(_cycle_perf);
|
perf_free(_cycle_perf);
|
||||||
|
perf_free(_interval_perf);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PWMOut::init()
|
int PWMOut::init()
|
||||||
@@ -397,6 +399,11 @@ void PWMOut::update_current_rate()
|
|||||||
// oneshot
|
// oneshot
|
||||||
if ((_pwm_default_rate == 0) || (_pwm_alt_rate == 0)) {
|
if ((_pwm_default_rate == 0) || (_pwm_alt_rate == 0)) {
|
||||||
max_rate = 2000;
|
max_rate = 2000;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// run up to twice PWM rate to reduce end-to-end latency
|
||||||
|
// actual pulse width only updated for next period regardless of output module
|
||||||
|
max_rate *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// max interval 0.5 - 100 ms (10 - 2000Hz)
|
// max interval 0.5 - 100 ms (10 - 2000Hz)
|
||||||
@@ -564,6 +571,7 @@ void PWMOut::Run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
perf_begin(_cycle_perf);
|
perf_begin(_cycle_perf);
|
||||||
|
perf_count(_interval_perf);
|
||||||
|
|
||||||
_mixing_output.update();
|
_mixing_output.update();
|
||||||
|
|
||||||
@@ -1992,6 +2000,7 @@ int PWMOut::print_status()
|
|||||||
}
|
}
|
||||||
|
|
||||||
perf_print_counter(_cycle_perf);
|
perf_print_counter(_cycle_perf);
|
||||||
|
perf_print_counter(_interval_perf);
|
||||||
_mixing_output.printStatus();
|
_mixing_output.printStatus();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -181,6 +181,7 @@ private:
|
|||||||
unsigned _num_disarmed_set{0};
|
unsigned _num_disarmed_set{0};
|
||||||
|
|
||||||
perf_counter_t _cycle_perf;
|
perf_counter_t _cycle_perf;
|
||||||
|
perf_counter_t _interval_perf;
|
||||||
|
|
||||||
void capture_callback(uint32_t chan_index,
|
void capture_callback(uint32_t chan_index,
|
||||||
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);
|
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);
|
||||||
|
|||||||
Reference in New Issue
Block a user