UASActionsWidget.cpp 3.28 KB
Newer Older
1
#include "UASActionsWidget.h"
2 3
#include <QMessageBox>
#include <UAS.h>
4 5
UASActionsWidget::UASActionsWidget(QWidget *parent) : QWidget(parent)
{
6
    m_uas = 0;
7
    ui.setupUi(this);
8 9 10 11 12 13 14 15 16 17 18 19 20 21
    connect(ui.changeAltitudeButton,SIGNAL(clicked()),this,SLOT(changeAltitudeClicked()));
    connect(ui.changeSpeedButton,SIGNAL(clicked()),this,SLOT(changeSpeedClicked()));
    connect(ui.goToWaypointButton,SIGNAL(clicked()),this,SLOT(goToWaypointClicked()));
    connect(ui.armDisarmButton,SIGNAL(clicked()),this,SLOT(armButtonClicked()));
    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    if (UASManager::instance()->getActiveUAS())
    {
        activeUASSet(UASManager::instance()->getActiveUAS());
    }
}

void UASActionsWidget::activeUASSet(UASInterface *uas)
{
    m_uas = uas;
22 23 24 25 26 27 28
    if (uas)
    {
        connect(m_uas->getWaypointManager(),SIGNAL(waypointEditableListChanged()),this,SLOT(updateWaypointList()));
        connect(m_uas->getWaypointManager(),SIGNAL(currentWaypointChanged(quint16)),this,SLOT(currentWaypointChanged(quint16)));
        connect(m_uas,SIGNAL(armingChanged(bool)),this,SLOT(armingChanged(bool)));
        armingChanged(m_uas->isArmed());
    }
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
    updateWaypointList();
}
void UASActionsWidget::armButtonClicked()
{
    if (m_uas)
    {
        if (m_uas->isArmed())
        {
            ((UAS*)m_uas)->disarmSystem();
        }
        else
        {
            ((UAS*)m_uas)->armSystem();
        }
    }
}

void UASActionsWidget::armingChanged(bool state)
{
    //TODO:
    //Figure out why arm/disarm is in UAS.h and not part of the interface, and fix.
    if (state)
    {
        ui.armDisarmButton->setText("DISARM\nCurrently Armed");
    }
    else
    {
        ui.armDisarmButton->setText("ARM\nCurrently Disarmed");
    }

}

void UASActionsWidget::currentWaypointChanged(quint16 wpid)
{
    ui.currentWaypointLabel->setText("Current: " + QString::number(wpid));
}

void UASActionsWidget::updateWaypointList()
{
    ui.waypointComboBox->clear();
69
    if (m_uas)
70
    {
71 72 73 74
        for (int i=0;i<m_uas->getWaypointManager()->getWaypointEditableList().size();i++)
        {
            ui.waypointComboBox->addItem(QString::number(i));
        }
75
    }
76 77 78 79 80
}

UASActionsWidget::~UASActionsWidget()
{
}
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
void UASActionsWidget::goToWaypointClicked()
{
    if (!m_uas)
    {
        return;
    }
    m_uas->getWaypointManager()->setCurrentWaypoint(ui.waypointComboBox->currentIndex());
}

void UASActionsWidget::changeAltitudeClicked()
{
    QMessageBox::information(0,"Error","No implemented yet.");
}

void UASActionsWidget::changeSpeedClicked()
{
    if (!m_uas)
    {
        return;
    }
    if (m_uas->getSystemType() == MAV_TYPE_QUADROTOR)
    {
        m_uas->setParameter(1,"WP_SPEED_MAX",QVariant(((float)ui.altitudeSpinBox->value() * 100)));
        return;
    }
    else if (m_uas->getSystemType() == MAV_TYPE_FIXED_WING)
    {
        QVariant variant;
        if (m_uas->getParamManager()->getParameterValue(1,"ARSPD_ENABLE",variant))
        {
            if (variant.toInt() == 1)
            {
                m_uas->setParameter(1,"TRIM_ARSPD_CN",QVariant(((float)ui.altitudeSpinBox->value() * 100)));
                return;
            }

        }
        m_uas->setParameter(1,"TRIM_ARSPD_CN",QVariant(((float)ui.altitudeSpinBox->value() * 100)));
    }
}