mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-18 11:03:33 +08:00
refactor pwm_out_sim: use mixer_module and run on work queue
Tested with SITL + HITL
This commit is contained in:
@@ -39,7 +39,8 @@
|
||||
using namespace time_literals;
|
||||
|
||||
|
||||
MixingOutput::MixingOutput(OutputModuleInterface &interface, SchedulingPolicy scheduling_policy,
|
||||
MixingOutput::MixingOutput(uint8_t max_num_outputs, OutputModuleInterface &interface,
|
||||
SchedulingPolicy scheduling_policy,
|
||||
bool support_esc_calibration, bool ramp_up)
|
||||
: ModuleParams(&interface),
|
||||
_control_subs{
|
||||
@@ -50,6 +51,7 @@ MixingOutput::MixingOutput(OutputModuleInterface &interface, SchedulingPolicy sc
|
||||
},
|
||||
_scheduling_policy(scheduling_policy),
|
||||
_support_esc_calibration(support_esc_calibration),
|
||||
_max_num_outputs(max_num_outputs < MAX_ACTUATORS ? max_num_outputs : MAX_ACTUATORS),
|
||||
_interface(interface),
|
||||
_control_latency_perf(perf_alloc(PC_ELAPSED, "control latency"))
|
||||
{
|
||||
@@ -240,6 +242,11 @@ bool MixingOutput::update()
|
||||
// check arming state
|
||||
if (_armed_sub.update(&_armed)) {
|
||||
_armed.in_esc_calibration_mode &= _support_esc_calibration;
|
||||
|
||||
if (_ignore_lockdown) {
|
||||
_armed.lockdown = false;
|
||||
}
|
||||
|
||||
/* Update the armed status and check that we're not locked down.
|
||||
* We also need to arm throttle for the ESC calibration. */
|
||||
_throttle_armed = (_safety_off && _armed.armed && !_armed.lockdown) || (_safety_off && _armed.in_esc_calibration_mode);
|
||||
@@ -275,7 +282,7 @@ bool MixingOutput::update()
|
||||
|
||||
/* do mixing */
|
||||
float outputs[MAX_ACTUATORS] {};
|
||||
const unsigned mixed_num_outputs = _mixers->mix(outputs, MAX_ACTUATORS);
|
||||
const unsigned mixed_num_outputs = _mixers->mix(outputs, _max_num_outputs);
|
||||
|
||||
/* the output limit call takes care of out of band errors, NaN and constrains */
|
||||
uint16_t output_limited[MAX_ACTUATORS] {};
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <board_config.h>
|
||||
#include <drivers/drv_pwm_output.h>
|
||||
#include <lib/mixer/mixer.h>
|
||||
#include <lib/perf/perf_counter.h>
|
||||
#include <lib/output_limit/output_limit.h>
|
||||
@@ -59,7 +60,7 @@
|
||||
class OutputModuleInterface : public px4::ScheduledWorkItem, public ModuleParams
|
||||
{
|
||||
public:
|
||||
static constexpr int MAX_ACTUATORS = DIRECT_PWM_OUTPUT_CHANNELS;
|
||||
static constexpr int MAX_ACTUATORS = PWM_OUTPUT_MAX_CHANNELS;
|
||||
|
||||
OutputModuleInterface(const char *name, const px4::wq_config_t &config)
|
||||
: px4::ScheduledWorkItem(name, config), ModuleParams(nullptr) {}
|
||||
@@ -90,12 +91,13 @@ public:
|
||||
|
||||
/**
|
||||
* Contructor
|
||||
* @param max_num_outputs maximum number of supported outputs
|
||||
* @param interface Parent module for scheduling, parameter updates and callbacks
|
||||
* @param scheduling_policy
|
||||
* @param support_esc_calibration true if the output module supports ESC calibration via max, then min setting
|
||||
* @param ramp_up true if motor ramp up from disarmed to min upon arming is wanted
|
||||
*/
|
||||
MixingOutput(OutputModuleInterface &interface, SchedulingPolicy scheduling_policy,
|
||||
MixingOutput(uint8_t max_num_outputs, OutputModuleInterface &interface, SchedulingPolicy scheduling_policy,
|
||||
bool support_esc_calibration, bool ramp_up = true);
|
||||
|
||||
~MixingOutput();
|
||||
@@ -163,6 +165,8 @@ public:
|
||||
*/
|
||||
int reorderedMotorIndex(int index);
|
||||
|
||||
void setIgnoreLockdown(bool ignore_lockdown) { _ignore_lockdown = ignore_lockdown; }
|
||||
|
||||
protected:
|
||||
void updateParams() override;
|
||||
|
||||
@@ -232,6 +236,7 @@ private:
|
||||
|
||||
bool _safety_off{false}; ///< State of the safety button from the subscribed _safety_sub topic
|
||||
bool _throttle_armed{false};
|
||||
bool _ignore_lockdown{false}; ///< if true, ignore the _armed.lockdown flag (for HIL outputs)
|
||||
|
||||
MixerGroup *_mixers{nullptr};
|
||||
uint32_t _groups_required{0};
|
||||
@@ -241,6 +246,7 @@ private:
|
||||
const bool _support_esc_calibration;
|
||||
|
||||
bool _wq_switched{false};
|
||||
const uint8_t _max_num_outputs;
|
||||
|
||||
OutputModuleInterface &_interface;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user