10 QStringList usedParams;
11 usedParams << QStringLiteral(
"COM_FLTMODE1") << QStringLiteral(
"COM_FLTMODE2") << QStringLiteral(
"COM_FLTMODE3")
12 << QStringLiteral(
"COM_FLTMODE4") << QStringLiteral(
"COM_FLTMODE5") << QStringLiteral(
"COM_FLTMODE6")
13 << QStringLiteral(
"RC_MAP_FLTMODE");
22void PX4SimpleFlightModesController::channelValuesChanged(QVector<int> pwmValues)
24 int channelCount = pwmValues.size();
26 _rcChannelValues.clear();
27 for (
int i=0; i<channelCount; i++) {
28 _rcChannelValues.append(pwmValues[i]);
32 if (channelCount != _channelCount) {
33 _channelCount = channelCount;
40 qCritical() <<
"RC_MAP_FLTMODE Fact is NULL in" << __FILE__ << __LINE__;
42 qCritical() <<
"RC_MAP_FLTMODE Fact is NULL in" << __func__ << __FILE__ << __LINE__;
47 int flightModeChannel = pFact->
rawValue().toInt() - 1;
48 if (flightModeChannel == -1) {
50 _activeFlightMode = 0;
55 pFact =
getParameterFact(-1, QString(
"RC%1_REV").arg(flightModeChannel + 1));
58 qCritical() << QString(
"RC%1_REV").arg(flightModeChannel + 1) <<
"Fact is NULL in" << __FILE__ << __LINE__;
60 qCritical() << QString(
"RC%1_REV").arg(flightModeChannel + 1) <<
" Fact is NULL in" << __func__ << __FILE__ << __LINE__;
65 int pwmRev = pFact->
rawValue().toInt();
67 pFact =
getParameterFact(-1, QString(
"RC%1_MIN").arg(flightModeChannel + 1));
70 qCritical() << QString(
"RC%1_MIN").arg(flightModeChannel + 1) <<
"Fact is NULL in" << __FILE__ << __LINE__;
72 qCritical() << QString(
"RC%1_MIN").arg(flightModeChannel + 1) <<
" Fact is NULL in" << __func__ << __FILE__ << __LINE__;
77 int pwmMin = pFact->
rawValue().toInt();
79 pFact =
getParameterFact(-1, QString(
"RC%1_MAX").arg(flightModeChannel + 1));
82 qCritical() << QString(
"RC%1_MAX").arg(flightModeChannel + 1) <<
"Fact is NULL in" << __FILE__ << __LINE__;
84 qCritical() << QString(
"RC%1_MAX").arg(flightModeChannel + 1) <<
" Fact is NULL in" << __func__ << __FILE__ << __LINE__;
89 int pwmMax = pFact->
rawValue().toInt();
91 pFact =
getParameterFact(-1, QString(
"RC%1_TRIM").arg(flightModeChannel + 1));
94 qCritical() << QString(
"RC%1_TRIM").arg(flightModeChannel + 1) <<
"Fact is NULL in" << __FILE__ << __LINE__;
96 qCritical() << QString(
"RC%1_TRIM").arg(flightModeChannel + 1) <<
" Fact is NULL in" << __func__ << __FILE__ << __LINE__;
101 int pwmTrim = pFact->
rawValue().toInt();
103 if (flightModeChannel < 0 || flightModeChannel > channelCount) {
107 _activeFlightMode = 0;
108 int channelValue = pwmValues[flightModeChannel];
110 if (channelValue != -1) {
115 const unsigned num_slots = 6;
117 const float slot_width_half = 2.0f / num_slots / 2.0f;
120 const float slot_min = -1.0f - 0.05f;
121 const float slot_max = 1.0f + 0.05f;
129 float calibrated_value;
131 if (channelValue > pwmTrim) {
132 calibrated_value = (channelValue - pwmTrim) / (
float)(pwmMax - pwmTrim);
134 }
else if (channelValue < pwmTrim) {
135 calibrated_value = (channelValue - pwmTrim) / (
float)(pwmTrim - pwmMin);
139 calibrated_value = 0.0f;
142 calibrated_value *= pwmRev;
144 _activeFlightMode = (((((calibrated_value - slot_min) * num_slots) + slot_width_half) /
145 (slot_max - slot_min)) + (1.0f / num_slots));
147 if (_activeFlightMode >=
static_cast<int>(num_slots)) {
148 _activeFlightMode = num_slots - 1;
bool _allParametersExists(int componentId, const QStringList &names) const
Q_INVOKABLE Fact * getParameterFact(int componentId, const QString &name, bool reportMissing=true) const
A Fact is used to hold a single value within the system.
QVariant rawValue() const
Value after translation.
void channelCountChanged()
PX4SimpleFlightModesController(void)
void rcChannelValuesChanged(void)
void activeFlightModeChanged(int activeFlightMode)
static constexpr int defaultComponentId
void rcChannelsClampedChanged(QVector< int > channelValues)