FailSafeConfig.cc 11.3 KB
Newer Older
1 2 3
#include "FailSafeConfig.h"


4
FailSafeConfig::FailSafeConfig(QWidget *parent) : AP2ConfigWidget(parent)
5 6
{
    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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    ui.radio1In->setName("Radio 1");
    ui.radio1In->setMin(800);
    ui.radio1In->setMax(2200);
    ui.radio1In->setOrientation(Qt::Horizontal);
    ui.radio2In->setName("Radio 2");
    ui.radio2In->setMin(800);
    ui.radio2In->setMax(2200);
    ui.radio2In->setOrientation(Qt::Horizontal);
    ui.radio3In->setName("Radio 3");
    ui.radio3In->setMin(800);
    ui.radio3In->setMax(2200);
    ui.radio3In->setOrientation(Qt::Horizontal);
    ui.radio4In->setName("Radio 4");
    ui.radio4In->setMin(800);
    ui.radio4In->setMax(2200);
    ui.radio4In->setOrientation(Qt::Horizontal);
    ui.radio5In->setName("Radio 5");
    ui.radio5In->setMin(800);
    ui.radio5In->setMax(2200);
    ui.radio5In->setOrientation(Qt::Horizontal);
    ui.radio6In->setName("Radio 6");
    ui.radio6In->setMin(800);
    ui.radio6In->setMax(2200);
    ui.radio6In->setOrientation(Qt::Horizontal);
    ui.radio7In->setName("Radio 7");
    ui.radio7In->setMin(800);
    ui.radio7In->setMax(2200);
    ui.radio7In->setOrientation(Qt::Horizontal);
    ui.radio8In->setName("Radio 8");
    ui.radio8In->setMin(800);
    ui.radio8In->setMax(2200);
    ui.radio8In->setOrientation(Qt::Horizontal);

    ui.radio1Out->setName("Radio 1");
    ui.radio1Out->setMin(800);
    ui.radio1Out->setMax(2200);
    ui.radio1Out->setOrientation(Qt::Horizontal);
    ui.radio2Out->setName("Radio 2");
    ui.radio2Out->setMin(800);
    ui.radio2Out->setMax(2200);
    ui.radio2Out->setOrientation(Qt::Horizontal);
    ui.radio3Out->setName("Radio 3");
    ui.radio3Out->setMin(800);
    ui.radio3Out->setMax(2200);
    ui.radio3Out->setOrientation(Qt::Horizontal);
    ui.radio4Out->setName("Radio 4");
    ui.radio4Out->setMin(800);
    ui.radio4Out->setMax(2200);
    ui.radio4Out->setOrientation(Qt::Horizontal);
    ui.radio5Out->setName("Radio 5");
    ui.radio5Out->setMin(800);
    ui.radio5Out->setMax(2200);
    ui.radio5Out->setOrientation(Qt::Horizontal);
    ui.radio6Out->setName("Radio 6");
    ui.radio6Out->setMin(800);
    ui.radio6Out->setMax(2200);
    ui.radio6Out->setOrientation(Qt::Horizontal);
    ui.radio7Out->setName("Radio 7");
    ui.radio7Out->setMin(800);
    ui.radio7Out->setMax(2200);
    ui.radio7Out->setOrientation(Qt::Horizontal);
    ui.radio8Out->setName("Radio 8");
    ui.radio8Out->setMin(800);
    ui.radio8Out->setMax(2200);
    ui.radio8Out->setOrientation(Qt::Horizontal);

    ui.throttleFailSafeComboBox->addItem("Disable");
    ui.throttleFailSafeComboBox->addItem("Enabled - Always TRL");
    ui.throttleFailSafeComboBox->addItem("Enabled - Continue in auto");
76 77 78 79 80 81 82 83 84 85 86 87 88 89

    connect(ui.batteryFailCheckBox,SIGNAL(clicked(bool)),this,SLOT(batteryFailChecked(bool)));
    connect(ui.fsLongCheckBox,SIGNAL(clicked(bool)),this,SLOT(fsLongClicked(bool)));
    connect(ui.fsShortCheckBox,SIGNAL(clicked(bool)),this,SLOT(fsShortClicked(bool)));
    connect(ui.gcsCheckBox,SIGNAL(clicked(bool)),this,SLOT(gcsChecked(bool)));
    connect(ui.throttleActionCheckBox,SIGNAL(clicked(bool)),this,SLOT(throttleActionChecked(bool)));
    connect(ui.throttleCheckBox,SIGNAL(clicked(bool)),this,SLOT(throttleChecked(bool)));
    connect(ui.throttlePwmSpinBox,SIGNAL(editingFinished()),this,SLOT(throttlePwmChanged()));
    connect(ui.throttleFailSafeComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(throttleFailSafeChanged(int)));
}
void FailSafeConfig::gcsChecked(bool checked)
{
    if (!m_uas)
    {
90
        showNullMAVErrorMessageBox();
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
        return;
    }
    if (checked)
    {
        m_uas->setParameter(1,"FS_GCS_ENABL",1);
    }
    else
    {
        m_uas->setParameter(1,"FS_GCS_ENABL",0);
    }
}

void FailSafeConfig::throttleActionChecked(bool checked)
{
    if (!m_uas)
    {
107
        showNullMAVErrorMessageBox();
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
        return;
    }
    if (checked)
    {
        m_uas->setParameter(1,"THR_FS_ACTION",1);
    }
    else
    {
        m_uas->setParameter(1,"THR_FS_ACTION",0);
    }
}

void FailSafeConfig::throttleChecked(bool checked)
{
    if (!m_uas)
    {
124
        showNullMAVErrorMessageBox();
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        return;
    }
    if (checked)
    {
        m_uas->setParameter(1,"THR_FAILSAFE",1);
    }
    else
    {
        m_uas->setParameter(1,"THR_FAILSAFE",0);
    }
}

void FailSafeConfig::throttlePwmChanged()
{
    if (!m_uas)
    {
141
        showNullMAVErrorMessageBox();
142 143 144 145 146 147 148 149 150
        return;
    }
    m_uas->setParameter(1,"THR_FS_VALUE",ui.throttlePwmSpinBox->value());
}

void FailSafeConfig::throttleFailSafeChanged(int index)
{
    if (!m_uas)
    {
151
        showNullMAVErrorMessageBox();
152 153 154 155 156 157 158 159 160
        return;
    }
    m_uas->setParameter(1,"FS_THR_ENABLE",index);
}

void FailSafeConfig::fsLongClicked(bool checked)
{
    if (!m_uas)
    {
161
        showNullMAVErrorMessageBox();
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
        return;
    }
    if (checked)
    {
        m_uas->setParameter(1,"FS_LONG_ACTN",1);
    }
    else
    {
        m_uas->setParameter(1,"FS_LONG_ACTN",0);
    }
}

void FailSafeConfig::fsShortClicked(bool checked)
{
    if (!m_uas)
    {
178
        showNullMAVErrorMessageBox();
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
        return;
    }
    if (checked)
    {
        m_uas->setParameter(1,"FS_SHORT_ACTN",1);
    }
    else
    {
        m_uas->setParameter(1,"FS_SHORT_ACTN",0);
    }
}

void FailSafeConfig::batteryFailChecked(bool checked)
{
    if (!m_uas)
    {
195
        showNullMAVErrorMessageBox();
196 197 198 199 200 201 202 203 204 205
        return;
    }
    if (checked)
    {
        m_uas->setParameter(1,"FS_BATT_ENABLE",1);
    }
    else
    {
        m_uas->setParameter(1,"FS_BATT_ENABLE",0);
    }
206 207 208 209 210
}

FailSafeConfig::~FailSafeConfig()
{
}
211 212
void FailSafeConfig::activeUASSet(UASInterface *uas)
{
213 214 215 216 217 218
    if (m_uas)
    {
        disconnect(m_uas,SIGNAL(remoteControlChannelRawChanged(int,float)),this,SLOT(remoteControlChannelRawChanges(int,float)));
        disconnect(m_uas,SIGNAL(hilActuatorsChanged(uint64_t,float,float,float,float,float,float,float,float)),this,SLOT(hilActuatorsChanged(uint64_t,float,float,float,float,float,float,float,float)));
        disconnect(m_uas,SIGNAL(armingChanged(bool)),this,SLOT(armingChanged(bool)));
    }
219
    AP2ConfigWidget::activeUASSet(uas);
220 221 222 223 224 225 226 227
    if (!uas)
    {
        return;
    }
    connect(m_uas,SIGNAL(remoteControlChannelRawChanged(int,float)),this,SLOT(remoteControlChannelRawChanges(int,float)));
    connect(m_uas,SIGNAL(hilActuatorsChanged(uint64_t,float,float,float,float,float,float,float,float)),this,SLOT(hilActuatorsChanged(uint64_t,float,float,float,float,float,float,float,float)));
    connect(m_uas,SIGNAL(armingChanged(bool)),this,SLOT(armingChanged(bool)));
    if (m_uas->getSystemType() == MAV_TYPE_FIXED_WING)
228 229 230 231 232 233 234 235 236 237 238 239 240 241
    {
        ui.batteryFailCheckBox->setVisible(false);
        ui.throttleFailSafeComboBox->setVisible(false);
        ui.batteryVoltSpinBox->setVisible(false);
        ui.label_6->setVisible(false);

        ui.throttlePwmSpinBox->setVisible(true); //Both

        ui.throttleCheckBox->setVisible(true);
        ui.throttleActionCheckBox->setVisible(true);
        ui.gcsCheckBox->setVisible(true);
        ui.fsLongCheckBox->setVisible(true);
        ui.fsShortCheckBox->setVisible(true);
    }
242
    else if (m_uas->getSystemType() == MAV_TYPE_QUADROTOR)
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
    {
        ui.batteryFailCheckBox->setVisible(true);
        ui.throttleFailSafeComboBox->setVisible(true);
        ui.batteryVoltSpinBox->setVisible(true);
        ui.label_6->setVisible(true);

        ui.throttlePwmSpinBox->setVisible(true); //Both

        ui.throttleCheckBox->setVisible(false);
        ui.throttleActionCheckBox->setVisible(false);
        ui.gcsCheckBox->setVisible(false);
        ui.fsLongCheckBox->setVisible(false);
        ui.fsShortCheckBox->setVisible(false);
    }
    else
    {
        //Show all, just in case
        ui.batteryFailCheckBox->setVisible(true);
        ui.throttleFailSafeComboBox->setVisible(true);
        ui.batteryVoltSpinBox->setVisible(true);
        ui.throttlePwmSpinBox->setVisible(true); //Both
        ui.throttleCheckBox->setVisible(true);
        ui.throttleActionCheckBox->setVisible(true);
        ui.gcsCheckBox->setVisible(true);
        ui.fsLongCheckBox->setVisible(true);
        ui.fsShortCheckBox->setVisible(true);
    }

271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
}
void FailSafeConfig::parameterChanged(int uas, int component, QString parameterName, QVariant value)
{
    //Arducopter
    if (parameterName == "FS_THR_ENABLE")
    {
        ui.throttleFailSafeComboBox->setCurrentIndex(value.toInt());
    }
    else if (parameterName == "FS_THR_VALUE")
    {
        ui.throttlePwmSpinBox->setValue(value.toFloat());
    }
    else if (parameterName == "FS_BATT_ENABLE")
    {
        if (value.toInt() == 0)
        {
            ui.batteryFailCheckBox->setChecked(false);
        }
        else
        {
            ui.batteryFailCheckBox->setChecked(true);
        }
    }
    else if (parameterName == "LOW_VOLT")
    {
        ui.batteryVoltSpinBox->setValue(value.toFloat());
    }
    //Arduplane
    else if (parameterName == "THR_FAILSAFE")
    {
        if (value.toInt() == 0)
        {
            ui.throttleCheckBox->setChecked(false);
        }
        else
        {
            ui.throttleCheckBox->setChecked(true);
        }
    }
    else if (parameterName == "THR_FS_VALUE")
    {
        ui.throttlePwmSpinBox->setValue(value.toFloat());
    }
    else if (parameterName == "THR_FS_ACTION")
    {
        if (value.toInt() == 0)
        {
            ui.throttleActionCheckBox->setChecked(false);
        }
        else
        {
            ui.throttleActionCheckBox->setChecked(true);
        }
    }
    else if (parameterName == "FS_GCS_ENABL")
    {
        if (value.toInt() == 0)
        {
            ui.gcsCheckBox->setChecked(false);
        }
        else
        {
            ui.gcsCheckBox->setChecked(true);
        }
    }
    else if (parameterName == "FS_SHORT_ACTN")
    {
        if (value.toInt() == 0)
        {
            ui.fsShortCheckBox->setChecked(false);
        }
        else
        {
            ui.fsShortCheckBox->setChecked(true);
        }
    }
    else if (parameterName == "FS_LONG_ACTN")
    {
        if (value.toInt() == 0)
        {
            ui.fsLongCheckBox->setChecked(false);
        }
        else
        {
            ui.fsLongCheckBox->setChecked(true);
        }
    }

}

void FailSafeConfig::armingChanged(bool armed)
{
    if (armed)
    {
        ui.armedLabel->setText("<h1>ARMED</h1>");
    }
    else
    {
        ui.armedLabel->setText("<h1>DISARMED</h1>");
    }
}

void FailSafeConfig::remoteControlChannelRawChanges(int chan,float value)
{
    if (chan == 0)
    {
        ui.radio1In->setValue(value);
    }
    else if (chan == 1)
    {
        ui.radio2In->setValue(value);
    }
    else if (chan == 2)
    {
        ui.radio3In->setValue(value);
    }
    else if (chan == 3)
    {
        ui.radio4In->setValue(value);
    }
    else if (chan == 4)
    {
        ui.radio5In->setValue(value);
    }
    else if (chan == 5)
    {
        ui.radio6In->setValue(value);
    }
    else if (chan == 6)
    {
        ui.radio7In->setValue(value);
    }
    else if (chan == 7)
    {
        ui.radio8In->setValue(value);
    }
}
void FailSafeConfig::hilActuatorsChanged(uint64_t time, float act1, float act2, float act3, float act4, float act5, float act6, float act7, float act8)
{
    ui.radio1Out->setValue(act1);
    ui.radio2Out->setValue(act2);
    ui.radio3Out->setValue(act3);
    ui.radio4Out->setValue(act4);
    ui.radio5Out->setValue(act5);
    ui.radio6Out->setValue(act6);
    ui.radio7Out->setValue(act7);
    ui.radio8Out->setValue(act8);
}