FlightModeConfig.cc 11.2 KB
Newer Older
1 2 3
#include "FlightModeConfig.h"


4
FlightModeConfig::FlightModeConfig(QWidget *parent) : AP2ConfigWidget(parent)
5 6
{
    ui.setupUi(this);
7
    connect(ui.savePushButton,SIGNAL(clicked()),this,SLOT(saveButtonClicked()));
8
    initConnections();
9 10 11 12 13
}

FlightModeConfig::~FlightModeConfig()
{
}
14
void FlightModeConfig::activeUASSet(UASInterface *uas)
15 16 17
{
    if (m_uas)
    {
18 19
        disconnect(m_uas,SIGNAL(modeChanged(int,QString,QString)),this,SLOT(modeChanged(int,QString,QString)));
        disconnect(m_uas,SIGNAL(remoteControlChannelRawChanged(int,float)),this,SLOT(remoteControlChannelRawChanged(int,float)));
20
    }
21 22
    AP2ConfigWidget::activeUASSet(uas);
    if (!uas) return;
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
    connect(m_uas,SIGNAL(modeChanged(int,QString,QString)),this,SLOT(modeChanged(int,QString,QString)));
    connect(m_uas,SIGNAL(remoteControlChannelRawChanged(int,float)),this,SLOT(remoteControlChannelRawChanged(int,float)));
    QStringList itemlist;
    if (m_uas->getSystemType() == MAV_TYPE_FIXED_WING)
    {
        itemlist << "Manual";
        itemlist << "Circle";
        itemlist << "Stabilize";
        itemlist << "Training";
        itemlist << "FBW A";
        itemlist << "FBW B";
        itemlist << "Auto";
        itemlist << "RTL";
        itemlist << "Loiter";
        itemlist << "Guided";

        planeModeIndexToUiIndex[0] = 0;
40 41
        planeModeUiIndexToIndex[0] = 0;

42
        planeModeIndexToUiIndex[1] = 1;
43 44
        planeModeUiIndexToIndex[1] = 1;

45
        planeModeIndexToUiIndex[2] = 2;
46 47
        planeModeUiIndexToIndex[2] = 2;

48
        planeModeIndexToUiIndex[3] = 3;
49 50
        planeModeUiIndexToIndex[3] = 3;

51
        planeModeIndexToUiIndex[5] = 4;
52 53
        planeModeUiIndexToIndex[4] = 5;

54
        planeModeIndexToUiIndex[6] = 5;
55 56
        planeModeUiIndexToIndex[5] = 6;

57
        planeModeIndexToUiIndex[10] = 6;
58 59
        planeModeUiIndexToIndex[6] = 10;

60
        planeModeIndexToUiIndex[11] = 7;
61 62
        planeModeUiIndexToIndex[7] = 11;

63
        planeModeIndexToUiIndex[12] = 8;
64 65
        planeModeUiIndexToIndex[8] = 12;

66
        planeModeIndexToUiIndex[15] = 9;
67 68
        planeModeUiIndexToIndex[9] = 15;

69 70 71 72 73 74 75 76 77 78 79 80 81 82
        ui.mode6ComboBox->setEnabled(true);
    }
    else if (m_uas->getSystemType() == MAV_TYPE_GROUND_ROVER)
    {
        itemlist << "Manual";
        itemlist << "Learning";
        itemlist << "Steering";
        itemlist << "Hold";
        itemlist << "Auto";
        itemlist << "RTL";
        itemlist << "Guided";
        itemlist << "Initialising";
        ui.mode6ComboBox->setEnabled(false);
        roverModeIndexToUiIndex[0] = 0;
83 84
        roverModeUiIndexToIndex[0] = 0;

85
        roverModeIndexToUiIndex[2] = 1;
86 87
        roverModeUiIndexToIndex[1] = 2;

88
        roverModeIndexToUiIndex[3] = 2;
89 90
        roverModeUiIndexToIndex[2] = 3;

91
        roverModeIndexToUiIndex[4] = 3;
92 93
        roverModeUiIndexToIndex[3] = 4;

94
        roverModeIndexToUiIndex[10] = 5;
95 96
        roverModeUiIndexToIndex[5] = 10;

97
        roverModeIndexToUiIndex[11] = 6;
98 99
        roverModeUiIndexToIndex[6] = 11;

100
        roverModeIndexToUiIndex[15] = 7;
101 102
        roverModeUiIndexToIndex[7] = 15;

103
        roverModeIndexToUiIndex[16] = 8;
104 105
        roverModeUiIndexToIndex[8] = 16;

106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

    }
    else if (m_uas->getSystemType() == MAV_TYPE_QUADROTOR)
    {
        itemlist << "Stabilize";
        itemlist << "Acro";
        itemlist << "Alt Hold";
        itemlist << "Auto";
        itemlist << "Guided";
        itemlist << "Loiter";
        itemlist << "RTL";
        itemlist << "Circle";
        itemlist << "Pos Hold";
        itemlist << "Land";
        itemlist << "OF_LOITER";
        itemlist << "Toy";
        ui.mode6ComboBox->setEnabled(true);
    }
    ui.mode1ComboBox->addItems(itemlist);
    ui.mode2ComboBox->addItems(itemlist);
    ui.mode3ComboBox->addItems(itemlist);
    ui.mode4ComboBox->addItems(itemlist);
    ui.mode5ComboBox->addItems(itemlist);
    ui.mode6ComboBox->addItems(itemlist);
}
void FlightModeConfig::modeChanged(int sysId, QString status, QString description)
{
    //Unused?
}
135 136 137 138
void FlightModeConfig::saveButtonClicked()
{
    if (m_uas->getSystemType() == MAV_TYPE_FIXED_WING)
    {
139 140 141 142 143 144
        m_uas->getParamManager()->setParameter(1,"FLTMODE1",(char)planeModeUiIndexToIndex[ui.mode1ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"FLTMODE2",(char)planeModeUiIndexToIndex[ui.mode2ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"FLTMODE3",(char)planeModeUiIndexToIndex[ui.mode3ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"FLTMODE4",(char)planeModeUiIndexToIndex[ui.mode4ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"FLTMODE5",(char)planeModeUiIndexToIndex[ui.mode5ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"FLTMODE6",(char)planeModeUiIndexToIndex[ui.mode6ComboBox->currentIndex()]);
145 146 147
    }
    else if (m_uas->getSystemType() == MAV_TYPE_GROUND_ROVER)
    {
148 149 150 151 152
        m_uas->getParamManager()->setParameter(1,"MODE1",(char)roverModeUiIndexToIndex[ui.mode1ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"MODE2",(char)roverModeUiIndexToIndex[ui.mode2ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"MODE3",(char)roverModeUiIndexToIndex[ui.mode3ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"MODE4",(char)roverModeUiIndexToIndex[ui.mode4ComboBox->currentIndex()]);
        m_uas->getParamManager()->setParameter(1,"MODE5",(char)roverModeUiIndexToIndex[ui.mode5ComboBox->currentIndex()]);
153 154 155
    }
    else if (m_uas->getSystemType() == MAV_TYPE_QUADROTOR)
    {
156 157 158 159 160 161
        m_uas->getParamManager()->setParameter(1,"FLTMODE1",(char)ui.mode1ComboBox->currentIndex());
        m_uas->getParamManager()->setParameter(1,"FLTMODE2",(char)ui.mode2ComboBox->currentIndex());
        m_uas->getParamManager()->setParameter(1,"FLTMODE3",(char)ui.mode3ComboBox->currentIndex());
        m_uas->getParamManager()->setParameter(1,"FLTMODE4",(char)ui.mode4ComboBox->currentIndex());
        m_uas->getParamManager()->setParameter(1,"FLTMODE5",(char)ui.mode5ComboBox->currentIndex());
        m_uas->getParamManager()->setParameter(1,"FLTMODE6",(char)ui.mode6ComboBox->currentIndex());
162 163 164
    }
}

165 166
void FlightModeConfig::remoteControlChannelRawChanged(int chan,float val)
{
167
    if (chan == 4)
168
    {
169
        //Channel 5 (0 array) is the mode switch.
170 171 172
        ///TODO: Make this configurable
        if (val <= 1230)
        {
173 174 175 176 177 178
            ui.mode1Label->setStyleSheet("background-color: rgb(0, 255, 0);color: rgb(0, 0, 0);");
            ui.mode2Label->setStyleSheet("");
            ui.mode3Label->setStyleSheet("");
            ui.mode4Label->setStyleSheet("");
            ui.mode5Label->setStyleSheet("");
            ui.mode6Label->setStyleSheet("");
179 180 181
        }
        else if (val <= 1360)
        {
182 183 184 185 186 187
            ui.mode1Label->setStyleSheet("");
            ui.mode2Label->setStyleSheet("background-color: rgb(0, 255, 0);color: rgb(0, 0, 0);");
            ui.mode3Label->setStyleSheet("");
            ui.mode4Label->setStyleSheet("");
            ui.mode5Label->setStyleSheet("");
            ui.mode6Label->setStyleSheet("");
188 189 190
        }
        else if (val <= 1490)
        {
191 192 193 194 195 196
            ui.mode1Label->setStyleSheet("");
            ui.mode2Label->setStyleSheet("");
            ui.mode3Label->setStyleSheet("background-color: rgb(0, 255, 0);color: rgb(0, 0, 0);");
            ui.mode4Label->setStyleSheet("");
            ui.mode5Label->setStyleSheet("");
            ui.mode6Label->setStyleSheet("");
197 198 199
        }
        else if (val <=1620)
        {
200 201 202 203 204 205
            ui.mode1Label->setStyleSheet("");
            ui.mode2Label->setStyleSheet("");
            ui.mode3Label->setStyleSheet("");
            ui.mode4Label->setStyleSheet("background-color: rgb(0, 255, 0);color: rgb(0, 0, 0);");
            ui.mode5Label->setStyleSheet("");
            ui.mode6Label->setStyleSheet("");
206 207 208
        }
        else if (val <=1749)
        {
209 210 211 212 213 214
            ui.mode1Label->setStyleSheet("");
            ui.mode2Label->setStyleSheet("");
            ui.mode3Label->setStyleSheet("");
            ui.mode4Label->setStyleSheet("");
            ui.mode5Label->setStyleSheet("background-color: rgb(0, 255, 0);color: rgb(0, 0, 0);");
            ui.mode6Label->setStyleSheet("");
215 216 217
        }
        else
        {
218 219 220 221 222 223
            ui.mode1Label->setStyleSheet("");
            ui.mode2Label->setStyleSheet("");
            ui.mode3Label->setStyleSheet("");
            ui.mode4Label->setStyleSheet("");
            ui.mode5Label->setStyleSheet("");
            ui.mode6Label->setStyleSheet("background-color: rgb(0, 255, 0);color: rgb(0, 0, 0);");
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
        }
    }
}

void FlightModeConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
    if (m_uas->getSystemType() == MAV_TYPE_FIXED_WING)
    {
        if (parameterName == "FLTMODE1")
        {
            ui.mode1ComboBox->setCurrentIndex(planeModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "FLTMODE2")
        {
            ui.mode2ComboBox->setCurrentIndex(planeModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "FLTMODE3")
        {
            ui.mode3ComboBox->setCurrentIndex(planeModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "FLTMODE4")
        {
            ui.mode4ComboBox->setCurrentIndex(planeModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "FLTMODE5")
        {
            ui.mode5ComboBox->setCurrentIndex(planeModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "FLTMODE6")
        {
            ui.mode6ComboBox->setCurrentIndex(planeModeIndexToUiIndex[value.toInt()]);
        }
    }
    else if (m_uas->getSystemType() == MAV_TYPE_GROUND_ROVER)
    {
        if (parameterName == "MODE1")
        {
            ui.mode1ComboBox->setCurrentIndex(roverModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "MODE2")
        {
            ui.mode2ComboBox->setCurrentIndex(roverModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "MODE3")
        {
            ui.mode3ComboBox->setCurrentIndex(roverModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "MODE4")
        {
            ui.mode4ComboBox->setCurrentIndex(roverModeIndexToUiIndex[value.toInt()]);
        }
        else if (parameterName == "MODE5")
        {
            ui.mode5ComboBox->setCurrentIndex(roverModeIndexToUiIndex[value.toInt()]);
        }
    }
    else if (m_uas->getSystemType() == MAV_TYPE_QUADROTOR)
    {
        if (parameterName == "FLTMODE1")
        {
284
            ui.mode1ComboBox->setCurrentIndex(value.toInt());
285 286 287
        }
        else if (parameterName == "FLTMODE2")
        {
288
            ui.mode2ComboBox->setCurrentIndex(value.toInt());
289 290 291
        }
        else if (parameterName == "FLTMODE3")
        {
292
            ui.mode3ComboBox->setCurrentIndex(value.toInt());
293 294 295
        }
        else if (parameterName == "FLTMODE4")
        {
296
            ui.mode4ComboBox->setCurrentIndex(value.toInt());
297 298 299
        }
        else if (parameterName == "FLTMODE5")
        {
300
            ui.mode5ComboBox->setCurrentIndex(value.toInt());
301 302 303
        }
        else if (parameterName == "FLTMODE6")
        {
304
            ui.mode6ComboBox->setCurrentIndex(value.toInt());
305 306 307
        }
    }
}