mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-03 13:58:53 +08:00
delete lib/mixer and mixer_module static mixing
This commit is contained in:
@@ -41,22 +41,14 @@
|
||||
using namespace pwm_out;
|
||||
|
||||
LinuxPWMOut::LinuxPWMOut() :
|
||||
CDev("/dev/pwm_out"),
|
||||
OutputModuleInterface(MODULE_NAME, px4::wq_configurations::hp_default),
|
||||
_cycle_perf(perf_alloc(PC_ELAPSED, MODULE_NAME": cycle")),
|
||||
_interval_perf(perf_alloc(PC_INTERVAL, MODULE_NAME": interval"))
|
||||
{
|
||||
if (!_mixing_output.useDynamicMixing()) {
|
||||
_mixing_output.setAllMinValues(PWM_DEFAULT_MIN);
|
||||
_mixing_output.setAllMaxValues(PWM_DEFAULT_MAX);
|
||||
}
|
||||
}
|
||||
|
||||
LinuxPWMOut::~LinuxPWMOut()
|
||||
{
|
||||
/* clean up the alternate device node */
|
||||
unregister_class_devname(PWM_OUTPUT_BASE_DEVICE_PATH, _class_instance);
|
||||
|
||||
perf_free(_cycle_perf);
|
||||
perf_free(_interval_perf);
|
||||
delete _pwm_out;
|
||||
@@ -64,21 +56,9 @@ LinuxPWMOut::~LinuxPWMOut()
|
||||
|
||||
int LinuxPWMOut::init()
|
||||
{
|
||||
/* do regular cdev init */
|
||||
int ret = CDev::init();
|
||||
|
||||
if (ret != OK) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* try to claim the generic PWM output device node as well - it's OK if we fail at this */
|
||||
_class_instance = register_class_devname(PWM_OUTPUT_BASE_DEVICE_PATH);
|
||||
|
||||
_mixing_output.setDriverInstance(_class_instance);
|
||||
|
||||
_pwm_out = new BOARD_PWM_OUT_IMPL(MAX_ACTUATORS);
|
||||
|
||||
ret = _pwm_out->init();
|
||||
int ret = _pwm_out->init();
|
||||
|
||||
if (ret != 0) {
|
||||
PX4_ERR("PWM output init failed");
|
||||
@@ -87,8 +67,6 @@ int LinuxPWMOut::init()
|
||||
return ret;
|
||||
}
|
||||
|
||||
update_params();
|
||||
|
||||
ScheduleNow();
|
||||
|
||||
return ret;
|
||||
@@ -134,8 +112,6 @@ void LinuxPWMOut::Run()
|
||||
return;
|
||||
}
|
||||
|
||||
SmartLock lock_guard(_lock);
|
||||
|
||||
perf_begin(_cycle_perf);
|
||||
perf_count(_interval_perf);
|
||||
|
||||
@@ -148,7 +124,7 @@ void LinuxPWMOut::Run()
|
||||
_parameter_update_sub.copy(&pupdate);
|
||||
|
||||
// update parameters from storage
|
||||
update_params();
|
||||
updateParams();
|
||||
}
|
||||
|
||||
_mixing_output.updateSubscriptions(false);
|
||||
@@ -156,168 +132,6 @@ void LinuxPWMOut::Run()
|
||||
perf_end(_cycle_perf);
|
||||
}
|
||||
|
||||
void LinuxPWMOut::update_params()
|
||||
{
|
||||
updateParams();
|
||||
|
||||
// skip update when armed or dynamic mixing enabled
|
||||
if (_mixing_output.armed().armed || _mixing_output.useDynamicMixing()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t pwm_min_default = PWM_DEFAULT_MIN;
|
||||
int32_t pwm_max_default = PWM_DEFAULT_MAX;
|
||||
int32_t pwm_disarmed_default = 0;
|
||||
int32_t pwm_default_channels = 0;
|
||||
|
||||
const char *prefix;
|
||||
|
||||
if (_class_instance == CLASS_DEVICE_PRIMARY) {
|
||||
prefix = "PWM_MAIN";
|
||||
|
||||
param_get(param_find("PWM_MAIN_MIN"), &pwm_min_default);
|
||||
param_get(param_find("PWM_MAIN_MAX"), &pwm_max_default);
|
||||
param_get(param_find("PWM_MAIN_DISARM"), &pwm_disarmed_default);
|
||||
param_get(param_find("PWM_MAIN_OUT"), &pwm_default_channels);
|
||||
|
||||
} else if (_class_instance == CLASS_DEVICE_SECONDARY) {
|
||||
prefix = "PWM_AUX";
|
||||
|
||||
param_get(param_find("PWM_AUX_MIN"), &pwm_min_default);
|
||||
param_get(param_find("PWM_AUX_MAX"), &pwm_max_default);
|
||||
param_get(param_find("PWM_AUX_DISARM"), &pwm_disarmed_default);
|
||||
param_get(param_find("PWM_AUX_OUT"), &pwm_default_channels);
|
||||
|
||||
} else if (_class_instance == CLASS_DEVICE_TERTIARY) {
|
||||
prefix = "PWM_EXTRA";
|
||||
|
||||
param_get(param_find("PWM_EXTRA_MIN"), &pwm_min_default);
|
||||
param_get(param_find("PWM_EXTRA_MAX"), &pwm_max_default);
|
||||
param_get(param_find("PWM_EXTRA_DISARM"), &pwm_disarmed_default);
|
||||
|
||||
} else {
|
||||
PX4_ERR("invalid class instance %d", _class_instance);
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t single_ch = 0;
|
||||
uint32_t pwm_default_channel_mask = 0;
|
||||
|
||||
while ((single_ch = pwm_default_channels % 10)) {
|
||||
pwm_default_channel_mask |= 1 << (single_ch - 1);
|
||||
pwm_default_channels /= 10;
|
||||
}
|
||||
|
||||
char str[17];
|
||||
|
||||
for (unsigned i = 0; i < MAX_ACTUATORS; i++) {
|
||||
// PWM_MAIN_MINx
|
||||
{
|
||||
sprintf(str, "%s_MIN%u", prefix, i + 1);
|
||||
int32_t pwm_min = -1;
|
||||
|
||||
if (param_get(param_find(str), &pwm_min) == PX4_OK && pwm_min >= 0) {
|
||||
_mixing_output.minValue(i) = math::constrain(pwm_min, PWM_LOWEST_MIN, PWM_HIGHEST_MIN);
|
||||
|
||||
if (pwm_min != _mixing_output.minValue(i)) {
|
||||
int32_t pwm_min_new = _mixing_output.minValue(i);
|
||||
param_set(param_find(str), &pwm_min_new);
|
||||
}
|
||||
|
||||
} else if (pwm_default_channel_mask & 1 << i) {
|
||||
_mixing_output.minValue(i) = pwm_min_default;
|
||||
}
|
||||
}
|
||||
|
||||
// PWM_MAIN_MAXx
|
||||
{
|
||||
sprintf(str, "%s_MAX%u", prefix, i + 1);
|
||||
int32_t pwm_max = -1;
|
||||
|
||||
if (param_get(param_find(str), &pwm_max) == PX4_OK && pwm_max >= 0) {
|
||||
_mixing_output.maxValue(i) = math::constrain(pwm_max, PWM_LOWEST_MAX, PWM_HIGHEST_MAX);
|
||||
|
||||
if (pwm_max != _mixing_output.maxValue(i)) {
|
||||
int32_t pwm_max_new = _mixing_output.maxValue(i);
|
||||
param_set(param_find(str), &pwm_max_new);
|
||||
}
|
||||
|
||||
} else if (pwm_default_channel_mask & 1 << i) {
|
||||
_mixing_output.maxValue(i) = pwm_max_default;
|
||||
}
|
||||
}
|
||||
|
||||
// PWM_MAIN_DISx
|
||||
{
|
||||
sprintf(str, "%s_DIS%u", prefix, i + 1);
|
||||
int32_t pwm_dis = -1;
|
||||
|
||||
if (param_get(param_find(str), &pwm_dis) == PX4_OK && pwm_dis >= 0) {
|
||||
_mixing_output.disarmedValue(i) = math::constrain(pwm_dis, 0, PWM_HIGHEST_MAX);
|
||||
|
||||
if (pwm_dis != _mixing_output.disarmedValue(i)) {
|
||||
int32_t pwm_dis_new = _mixing_output.disarmedValue(i);
|
||||
param_set(param_find(str), &pwm_dis_new);
|
||||
}
|
||||
|
||||
} else if (pwm_default_channel_mask & 1 << i) {
|
||||
_mixing_output.disarmedValue(i) = pwm_disarmed_default;
|
||||
}
|
||||
}
|
||||
|
||||
// PWM_MAIN_FAILx
|
||||
{
|
||||
sprintf(str, "%s_FAIL%u", prefix, i + 1);
|
||||
int32_t pwm_failsafe = -1;
|
||||
|
||||
if (param_get(param_find(str), &pwm_failsafe) == PX4_OK && pwm_failsafe >= 0) {
|
||||
_mixing_output.failsafeValue(i) = math::constrain(pwm_failsafe, 0, PWM_HIGHEST_MAX);
|
||||
|
||||
if (pwm_failsafe != _mixing_output.failsafeValue(i)) {
|
||||
int32_t pwm_fail_new = _mixing_output.failsafeValue(i);
|
||||
param_set(param_find(str), &pwm_fail_new);
|
||||
}
|
||||
|
||||
} else {
|
||||
// if no channel specific failsafe value is configured, use the disarmed value
|
||||
_mixing_output.failsafeValue(i) = _mixing_output.disarmedValue(i);
|
||||
}
|
||||
}
|
||||
|
||||
// PWM_MAIN_REVx
|
||||
{
|
||||
sprintf(str, "%s_REV%u", prefix, i + 1);
|
||||
int32_t pwm_rev = 0;
|
||||
|
||||
if (param_get(param_find(str), &pwm_rev) == PX4_OK) {
|
||||
uint16_t &reverse_pwm_mask = _mixing_output.reverseOutputMask();
|
||||
|
||||
if (pwm_rev >= 1) {
|
||||
reverse_pwm_mask = reverse_pwm_mask | (2 << i);
|
||||
|
||||
} else {
|
||||
reverse_pwm_mask = reverse_pwm_mask & ~(2 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_mixing_output.mixers()) {
|
||||
int16_t values[MAX_ACTUATORS] {};
|
||||
|
||||
for (unsigned i = 0; i < MAX_ACTUATORS; i++) {
|
||||
sprintf(str, "%s_TRIM%u", prefix, i + 1);
|
||||
|
||||
float pval = 0.0f;
|
||||
param_get(param_find(str), &pval);
|
||||
values[i] = roundf(10000 * pval);
|
||||
}
|
||||
|
||||
// copy the trim values to the mixer offsets
|
||||
_mixing_output.mixers()->set_trims(values, MAX_ACTUATORS);
|
||||
}
|
||||
}
|
||||
|
||||
int LinuxPWMOut::custom_command(int argc, char *argv[])
|
||||
{
|
||||
return print_usage("unknown command");
|
||||
|
||||
@@ -33,9 +33,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <drivers/device/device.h>
|
||||
#include <lib/cdev/CDev.hpp>
|
||||
#include <lib/mathlib/mathlib.h>
|
||||
#include <lib/mixer_module/mixer_module.hpp>
|
||||
#include <lib/parameters/param.h>
|
||||
@@ -51,8 +49,7 @@
|
||||
|
||||
using namespace time_literals;
|
||||
|
||||
|
||||
class LinuxPWMOut : public cdev::CDev, public ModuleBase<LinuxPWMOut>, public OutputModuleInterface
|
||||
class LinuxPWMOut : public ModuleBase<LinuxPWMOut>, public OutputModuleInterface
|
||||
{
|
||||
public:
|
||||
LinuxPWMOut();
|
||||
@@ -72,9 +69,7 @@ public:
|
||||
/** @see ModuleBase::print_status() */
|
||||
int print_status() override;
|
||||
|
||||
int ioctl(device::file_t *filp, int cmd, unsigned long arg) override;
|
||||
|
||||
int init() override;
|
||||
int init();
|
||||
|
||||
bool updateOutputs(bool stop_motors, uint16_t outputs[MAX_ACTUATORS],
|
||||
unsigned num_outputs, unsigned num_control_groups_updated) override;
|
||||
@@ -82,14 +77,10 @@ public:
|
||||
private:
|
||||
static constexpr int MAX_ACTUATORS = 8;
|
||||
|
||||
void update_params();
|
||||
|
||||
MixingOutput _mixing_output{"PWM_MAIN", MAX_ACTUATORS, *this, MixingOutput::SchedulingPolicy::Auto, false};
|
||||
|
||||
uORB::SubscriptionInterval _parameter_update_sub{ORB_ID(parameter_update), 1_s};
|
||||
|
||||
int _class_instance{-1};
|
||||
|
||||
pwm_out::PWMOutBase *_pwm_out{nullptr};
|
||||
|
||||
perf_counter_t _cycle_perf;
|
||||
|
||||
Reference in New Issue
Block a user