ArduPlanePidConfig.cc 3.59 KB
Newer Older
1 2 3 4 5 6
#include "ArduPlanePidConfig.h"


ArduPlanePidConfig::ArduPlanePidConfig(QWidget *parent) : AP2ConfigWidget(parent)
{
    ui.setupUi(this);
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    m_nameToBoxMap["RLL2SRV_P"] = ui.servoRollPSpinBox;
    m_nameToBoxMap["RLL2SRV_I"] = ui.servoRollISpinBox;
    m_nameToBoxMap["RLL2SRV_D"] = ui.servoRollDSpinBox;
    m_nameToBoxMap["RLL2SRV_IMAX"] = ui.servoRollIMAXSpinBox;

    m_nameToBoxMap["PTCH2SRV_P"] = ui.servoPitchPSpinBox;
    m_nameToBoxMap["PTCH2SRV_I"] = ui.servoPitchISpinBox;
    m_nameToBoxMap["PTCH2SRV_D"] = ui.servoPitchDSpinBox;
    m_nameToBoxMap["PTCH2SRV_IMAX"] = ui.servoPitchIMAXSpinBox;

    m_nameToBoxMap["YW2SRV_P"] = ui.servoYawPSpinBox;
    m_nameToBoxMap["YW2SRV_I"] = ui.servoYawISpinBox;
    m_nameToBoxMap["YW2SRV_D"] = ui.servoYawDSpinBox;
    m_nameToBoxMap["YW2SRV_IMAX"] = ui.servoYawIMAXSpinBox;

    m_nameToBoxMap["ALT2PTCH_P"] = ui.navAltPSpinBox;
    m_nameToBoxMap["ALT2PTCH_I"] = ui.navAltISpinBox;
    m_nameToBoxMap["ALT2PTCH_D"] = ui.navAltDSpinBox;
    m_nameToBoxMap["ALT2PTCH_IMAX"] = ui.navAltIMAXSpinBox;

    m_nameToBoxMap["ARSP2PTCH_P"] = ui.navASPSpinBox;
    m_nameToBoxMap["ARSP2PTCH_I"] = ui.navASISpinBox;
    m_nameToBoxMap["ARSP2PTCH_D"] = ui.navASDSpinBox;
    m_nameToBoxMap["ARSP2PTCH_IMAX"] = ui.navASIMAXSpinBox;

    m_nameToBoxMap["ENRGY2THR_P"] = ui.energyPSpinBox;
    m_nameToBoxMap["ENRGY2THR_I"] = ui.energyISpinBox;
    m_nameToBoxMap["ENRGY2THR_D"] = ui.energyDSpinBox;
    m_nameToBoxMap["ENRGY2THR_IMAX"] = ui.energyIMAXSpinBox;

    m_nameToBoxMap["KFF_PTCH2THR"] = ui.otherPitchCompSpinBox;
    m_nameToBoxMap["KFF_PTCHCOMP"] = ui.otherPtTSpinBox;
    m_nameToBoxMap["KFF_RDDRMIX"] = ui.otherRudderMixSpinBox;

    m_nameToBoxMap["TRIM_THROTTLE"] = ui.throttleCruiseSpinBox;
    m_nameToBoxMap["THR_FS_VALUE"] = ui.throttleFSSpinBox;
    m_nameToBoxMap["THR_MAX"] = ui.throttleMaxSpinBox;
    m_nameToBoxMap["THR_MIN"] = ui.throttleMinSpinBox;

    m_nameToBoxMap["TRIM_ARSPD_CM"] = ui.airspeedCruiseSpinBox;
    m_nameToBoxMap["ARSPD_FBW_MAX"] = ui.airspeedFBWMaxSpinBox;
    m_nameToBoxMap["ARSPD_FBW_MIN"] = ui.airspeedFBWMinSpinBox;
    m_nameToBoxMap["ARSPD_RATIO"] = ui.airspeedRatioSpinBox;

    m_nameToBoxMap["NAVL1_DAMPING"] = ui.l1DampingSpinBox;
    m_nameToBoxMap["NAVL1_PERIOD"] = ui.l1PeriodSpinBox;

    m_nameToBoxMap["LIM_ROLL_CD"] = ui.navBankMaxSpinBox;
    m_nameToBoxMap["LIM_PITCH_MAX"] = ui.navPitchMaxSpinBox;
    m_nameToBoxMap["LIM_PITCH_MIN"] = ui.navPitchMinSpinBox;
58

59 60
    connect(ui.writePushButton,SIGNAL(clicked()),this,SLOT(writeButtonClicked()));
    connect(ui.refreshPushButton,SIGNAL(clicked()),this,SLOT(refreshButtonClicked()));
61
    initConnections();
62 63 64 65 66
}

ArduPlanePidConfig::~ArduPlanePidConfig()
{
}
67
void ArduPlanePidConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
68
{
69 70 71
    Q_UNUSED(uas);
    Q_UNUSED(component);
    
72
    if (m_nameToBoxMap.contains(parameterName))
73
    {
74
        m_nameToBoxMap[parameterName]->setValue(value.toDouble());
75 76 77 78 79 80
    }
}
void ArduPlanePidConfig::writeButtonClicked()
{
    if (!m_uas)
    {
81
        showNullMAVErrorMessageBox();
82 83
        return;
    }
84
    for (QMap<QString,QDoubleSpinBox*>::const_iterator i=m_nameToBoxMap.constBegin();i!=m_nameToBoxMap.constEnd();i++)
85 86 87 88
    {
        m_uas->getParamManager()->setParameter(1,i.key(),i.value()->value());
    }
}
89

90 91 92 93
void ArduPlanePidConfig::refreshButtonClicked()
{
    if (!m_uas)
    {
94
        showNullMAVErrorMessageBox();
95
        return;
96
    }
97
    for (QMap<QString,QDoubleSpinBox*>::const_iterator i=m_nameToBoxMap.constBegin();i!=m_nameToBoxMap.constEnd();i++)
98 99 100 101
    {
        m_uas->getParamManager()->requestParameterUpdate(1,i.key());
    }

102
}