ArduCopterPidConfig.cc 3.07 KB
Newer Older
1 2
#include "ArduCopterPidConfig.h"

3
ArduCopterPidConfig::ArduCopterPidConfig(QWidget *parent) : AP2ConfigWidget(parent)
4
{
5
    ui.setupUi(this);
6 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
    nameToBoxMap["STB_RLL_P"] = ui.stabilPitchPSpinBox;
    nameToBoxMap["STB_PIT_P"] = ui.stabilRollPSpinBox;
    nameToBoxMap["STB_YAW_P"] = ui.stabilYawPSpinBox;
    nameToBoxMap["HLD_LAT_P"] = ui.loiterPidPSpinBox;

    nameToBoxMap["RATE_RLL_P"] = ui.rateRollPSpinBox;
    nameToBoxMap["RATE_RLL_I"] = ui.rateRollISpinBox;
    nameToBoxMap["RATE_RLL_D"] = ui.rateRollDSpinBox;
    nameToBoxMap["RATE_RLL_IMAX"] = ui.rateRollIMAXSpinBox;

    nameToBoxMap["RATE_PIT_P"] = ui.ratePitchPSpinBox;
    nameToBoxMap["RATE_PIT_I"] = ui.ratePitchISpinBox;
    nameToBoxMap["RATE_PIT_D"] = ui.ratePitchDSpinBox;
    nameToBoxMap["RATE_PIT_IMAX"] = ui.ratePitchIMAXSpinBox;

    nameToBoxMap["RATE_YAW_P"] = ui.rateYawPSpinBox;
    nameToBoxMap["RATE_YAW_I"] = ui.rateYawISpinBox;
    nameToBoxMap["RATE_YAW_D"] = ui.rateYawDSpinBox;
    nameToBoxMap["RATE_YAW_IMAX"] = ui.rateYawIMAXSpinBox;

    nameToBoxMap["LOITER_LAT_P"] = ui.rateLoiterPSpinBox;
    nameToBoxMap["LOITER_LAT_I"] = ui.rateLoiterISpinBox;
    nameToBoxMap["LOITER_LAT_D"] = ui.rateLoiterDSpinBox;
    nameToBoxMap["LOITER_LAT_IMAX"] = ui.rateLoiterIMAXSpinBox;

    nameToBoxMap["THR_ACCEL_P"] = ui.throttleAccelPSpinBox;
    nameToBoxMap["THR_ACCEL_I"] = ui.throttleAccelISpinBox;
    nameToBoxMap["THR_ACCEL_D"] = ui.throttleAccelDSpinBox;
    nameToBoxMap["THR_ACCEL_IMAX"] = ui.throttleAccelIMAXSpinBox;

    nameToBoxMap["THR_RATE_P"] = ui.throttleRatePSpinBox;
    nameToBoxMap["THR_RATE_D"] = ui.throttleDateDSpinBox;

    nameToBoxMap["THR_ALT_P"] = ui.altitudeHoldPSpinBox;

    nameToBoxMap["WPNAV_SPEED"] = ui.wpNavLoiterSpeedSpinBox;
    nameToBoxMap["WPNAV_RADIUS"] = ui.wpNavRadiusSpinBox;
    nameToBoxMap["WPNAV_SPEED_DN"] = ui.wpNavSpeedDownSpinBox;
    nameToBoxMap["WPNAV_LOIT_SPEED"] = ui.wpNavSpeedSpinBox;
    nameToBoxMap["WPNAV_SPEED_UP"] = ui.wpNavSpeedUpSpinBox;

    nameToBoxMap["TUNE_HIGH"] = ui.ch6MaxSpinBox;
    nameToBoxMap["TUNE_LOW"] = ui.ch6MinSpinBox;

    connect(ui.writePushButton,SIGNAL(clicked()),this,SLOT(writeButtonClicked()));
    connect(ui.refreshPushButton,SIGNAL(clicked()),this,SLOT(refreshButtonClicked()));
52 53 54 55 56
}

ArduCopterPidConfig::~ArduCopterPidConfig()
{
}
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
void ArduCopterPidConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
    if (nameToBoxMap.contains(parameterName))
    {
        nameToBoxMap[parameterName]->setValue(value.toDouble());
    }
}
void ArduCopterPidConfig::writeButtonClicked()
{
    if (!m_uas)
    {
        return;
    }
    for (QMap<QString,QDoubleSpinBox*>::const_iterator i=nameToBoxMap.constBegin();i!=nameToBoxMap.constEnd();i++)
    {
        m_uas->getParamManager()->setParameter(1,i.key(),i.value()->value());
    }
}

void ArduCopterPidConfig::refreshButtonClicked()
{
    if (!m_uas)
    {
        return;
    }
    for (QMap<QString,QDoubleSpinBox*>::const_iterator i=nameToBoxMap.constBegin();i!=nameToBoxMap.constEnd();i++)
    {
        m_uas->getParamManager()->requestParameterUpdate(1,i.key());
    }
}