AccelCalibrationConfig.cc 2.76 KB
Newer Older
1 2 3
#include "AccelCalibrationConfig.h"


4
AccelCalibrationConfig::AccelCalibrationConfig(QWidget *parent) : AP2ConfigWidget(parent)
5 6
{
    ui.setupUi(this);
7 8 9 10
    connect(ui.calibrateAccelButton,SIGNAL(clicked()),this,SLOT(calibrateButtonClicked()));

    connect(UASManager::instance(),SIGNAL(activeUASSet(UASInterface*)),this,SLOT(activeUASSet(UASInterface*)));
    activeUASSet(UASManager::instance()->getActiveUAS());
11
    m_accelAckCount=0;
12 13 14 15 16
}

AccelCalibrationConfig::~AccelCalibrationConfig()
{
}
17 18
void AccelCalibrationConfig::activeUASSet(UASInterface *uas)
{
19
    if (m_uas)
20
    {
21
        disconnect(m_uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(uasTextMessageReceived(int,int,int,QString)));
22
    }
23 24
    AP2ConfigWidget::activeUASSet(uas);
    if (!uas)
25
    {
26
        return;
27 28
    }
    connect(m_uas,SIGNAL(textMessageReceived(int,int,int,QString)),this,SLOT(uasTextMessageReceived(int,int,int,QString)));
29

30 31 32 33
}

void AccelCalibrationConfig::calibrateButtonClicked()
{
34 35 36 37 38 39
    if (!m_uas)
    {
        showNullMAVErrorMessageBox();
        return;
    }
    if (m_accelAckCount == 0)
40 41 42
    {
        MAV_CMD command = MAV_CMD_PREFLIGHT_CALIBRATION;
        int confirm = 0;
43 44 45 46 47 48 49
        float param1 = 0.0;
        float param2 = 0.0;
        float param3 = 0.0;
        float param4 = 0.0;
        float param5 = 1.0;
        float param6 = 0.0;
        float param7 = 0.0;
50 51 52
        int component = 1;
        m_uas->executeCommand(command, confirm, param1, param2, param3, param4, param5, param6, param7, component);
    }
53
    else if (m_accelAckCount <= 5)
54
    {
55
        m_uas->executeCommandAck(m_accelAckCount++,true);
56 57 58
    }
    else
    {
59
        m_uas->executeCommandAck(m_accelAckCount++,true);
60 61 62 63 64 65 66 67 68 69 70
        ui.calibrateAccelButton->setText("Calibrate\nAccelerometer");
    }

}
void AccelCalibrationConfig::uasTextMessageReceived(int uasid, int componentid, int severity, QString text)
{
    //command received: " Severity 1
    //Place APM Level and press any key" severity 5
    if (severity == 5)
    {
        //This is a calibration instruction
71
        if (m_accelAckCount == 0)
72 73 74
        {
            //Calibration Sucessful\r"
            ui.calibrateAccelButton->setText("Any\nKey");
75
            m_accelAckCount++;
76
        }
77
        if (m_accelAckCount == 7)
78 79 80 81
        {
            //All finished
            //ui.outputLabel->setText(ui.outputLabel->text() + "\n" + text);
            ui.outputLabel->setText(text);
82
            m_accelAckCount++;
83
        }
84
        if (m_accelAckCount == 8)
85 86 87
        {
            if (text.contains("Calibration") && text.contains("successful"))
            {
88
                m_accelAckCount = 0;
89 90 91 92 93 94 95 96 97 98
            }
            ui.outputLabel->setText(ui.outputLabel->text() + "\n" + text);
        }
        else
        {
            ui.outputLabel->setText(text);
        }
    }

}