UASControlParameters.cpp 3.92 KB
Newer Older
Mariano Lizarraga's avatar
Mariano Lizarraga committed
1
#include "UASControlParameters.h"
2 3 4 5
#include "ui_UASControlParameters.h"

#define CONTROL_MODE_LOCKED "MODE LOCKED"
#define CONTROL_MODE_MANUAL "MODE MANUAL"
6

7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#define CONTROL_MODE_READY  "MODE TEST3"
#define CONTROL_MODE_RC_TRAINING  "RC SIMULATION"

#define CONTROL_MODE_LOCKED_INDEX 1
#define CONTROL_MODE_MANUAL_INDEX 2
#define CONTROL_MODE_GUIDED_INDEX 3
#define CONTROL_MODE_AUTO_INDEX   4
#define CONTROL_MODE_TEST1_INDEX  5
#define CONTROL_MODE_TEST2_INDEX  6
#define CONTROL_MODE_TEST3_INDEX  7
#define CONTROL_MODE_READY_INDEX  8
#define CONTROL_MODE_RC_TRAINING_INDEX  9

UASControlParameters::UASControlParameters(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::UASControlParameters)
{
    ui->setupUi(this);

26 27
    ui->btSetCtrl->setStatusTip(tr("Set Passthrough"));

28 29
    connect(ui->btGetCommands, SIGNAL(clicked()), this, SLOT(getCommands()));

30
    connect(ui->btSetCtrl, SIGNAL(clicked()), this, SLOT(setPassthrough()));
31 32 33 34 35 36 37 38 39 40 41
}

UASControlParameters::~UASControlParameters()
{
    delete ui;
}

void UASControlParameters::changedMode(int mode)
{
    QString modeTemp;

42
    switch (mode) {
43
    case (uint8_t)MAV_MODE_PREFLIGHT:
44 45
        modeTemp = "LOCKED MODE";
        break;
lm's avatar
lm committed
46 47 48 49 50
    case (uint8_t)MAV_MODE_MANUAL_ARMED:
        modeTemp = "A/MANUAL MODE";
        break;
    case (uint8_t)MAV_MODE_MANUAL_DISARMED:
        modeTemp = "D/MANUAL MODE";
51 52
        break;
    default:
lm's avatar
lm committed
53
        modeTemp = "UNKNOWN MODE";
54
        break;
55 56
    }

57

58
    if(modeTemp != this->mode) {
59
        ui->lbMode->setStyleSheet("background-color: rgb(165, 42, 42)");
60
    } else {
61
        ui->lbMode->setStyleSheet("background-color: rgb(85, 107, 47)");
62 63 64 65 66
    }
}

void UASControlParameters::activeUasSet(UASInterface *uas)
{
67
    if(uas) {
68
        connect(uas, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,double,quint64)), this, SLOT(updateGlobalPosition(UASInterface*,double,double,double,double,quint64)));
69
        connect(uas, SIGNAL(velocityChanged_NED(UASInterface*,double,double,double,quint64)), this, SLOT(speedChanged(UASInterface*,double,double,double,quint64)));
70 71 72
        connect(uas, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(updateAttitude(UASInterface*,double,double,double,quint64)));
        connect(uas, SIGNAL(modeChanged(int,QString,QString)), this, SLOT(updateMode(int,QString,QString)));
        connect(uas, SIGNAL(thrustChanged(UASInterface*,double)), this, SLOT(thrustChanged(UASInterface*,double)) );
73

74 75
        activeUAS= uas;
    }
76 77 78 79
}

void UASControlParameters::updateGlobalPosition(UASInterface * a, double b, double c, double aa, quint64 ab)
{
80 81 82 83
    Q_UNUSED(a);
    Q_UNUSED(b);
    Q_UNUSED(c);
    Q_UNUSED(ab);
84 85 86 87 88
    this->altitude=aa;
}

void UASControlParameters::speedChanged(UASInterface* uas, double vx, double vy, double vz, quint64 time)
{
89 90
    Q_UNUSED(time);
    Q_UNUSED(uas);
91 92 93 94 95 96 97
    this->speed = sqrt(pow(vx, 2.0) + pow(vy, 2.0) + pow(vz, 2.0));
    //ui->sbAirSpeed->setValue(speed);
}

void UASControlParameters::updateAttitude(UASInterface *uas, double roll, double pitch, double yaw, quint64 time)
{
    Q_UNUSED(uas);
98 99
    Q_UNUSED(pitch);
    Q_UNUSED(yaw);
100 101 102 103 104 105
    Q_UNUSED(time);
    //ui->sbTurnRate->setValue(roll);
    this->roll = roll;
}

void UASControlParameters::setCommands()
106 107
{
}
108 109 110 111 112 113 114 115

void UASControlParameters::getCommands()
{
    ui->sbAirSpeed->setValue(this->speed);
    ui->sbHeight->setValue(this->altitude);
    ui->sbTurnRate->setValue(this->roll);
}

116 117 118 119
void UASControlParameters::setPassthrough()
{
}

120 121 122 123 124 125
void UASControlParameters::updateMode(int uas,QString mode,QString description)
{
    Q_UNUSED(uas);
    Q_UNUSED(description);
    this->mode = mode;
    ui->lbMode->setText(this->mode);
126

127
    ui->lbMode->setStyleSheet("background-color: rgb(85, 107, 47)");
128 129 130 131 132 133 134
}

void UASControlParameters::thrustChanged(UASInterface *uas, double throttle)
{
    Q_UNUSED(uas);
    this->throttle= throttle;
}