SlugsDataSensorView.cc 13.2 KB
Newer Older
1 2 3 4 5 6 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
#include "SlugsDataSensorView.h"
#include "ui_SlugsDataSensorView.h"

#include <UASManager.h>
#include "SlugsMAV.h"

#include <QDebug>

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

    activeUAS = NULL;

    this->setVisible(false);




}

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

void SlugsDataSensorView::addUAS(UASInterface* uas)
{
    SlugsMAV* slugsMav = qobject_cast<SlugsMAV*>(uas);

33
    if (slugsMav != NULL) {
34

35
        connect(slugsMav, SIGNAL(slugsRawImu(int, const mavlink_raw_imu_t&)), this, SLOT(slugRawDataChanged(int, const mavlink_raw_imu_t&)));
36

37
#ifdef MAVLINK_ENABLED_SLUGS
38 39

        //connect standar messages
40
        connect(slugsMav, SIGNAL(localPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(slugLocalPositionChanged(UASInterface*,double,double,double,quint64)));
41
        connect(slugsMav, SIGNAL(velocityChanged_NED(UASInterface*,double,double,double,quint64)), this, SLOT(slugSpeedLocalPositionChanged(UASInterface*,double,double,double,quint64)));
42 43 44 45 46 47 48 49 50 51 52
        connect(slugsMav, SIGNAL(attitudeChanged(UASInterface*,double,double,double,quint64)), this, SLOT(slugAttitudeChanged(UASInterface*,double,double,double,quint64)));
        connect(slugsMav, SIGNAL(globalPositionChanged(UASInterface*,double,double,double,quint64)), this, SLOT(slugsGlobalPositionChanged(UASInterface*,double,double,double,quint64)));
        connect(slugsMav,SIGNAL(slugsGPSCogSog(int,double,double)),this,SLOT(slugsGPSCogSog(int,double,double)));

        //connect slugs especial messages
        connect(slugsMav, SIGNAL(slugsSensorBias(int,const mavlink_sensor_bias_t&)), this, SLOT(slugsSensorBiasChanged(int,const mavlink_sensor_bias_t&)));
        connect(slugsMav, SIGNAL(slugsDiagnostic(int,const mavlink_diagnostic_t&)), this, SLOT(slugsDiagnosticMessageChanged(int,const mavlink_diagnostic_t&)));
        connect(slugsMav, SIGNAL(slugsCPULoad(int,const mavlink_cpu_load_t&)), this, SLOT(slugsCpuLoadChanged(int,const mavlink_cpu_load_t&)));

        connect(slugsMav, SIGNAL(slugsNavegation(int,const mavlink_slugs_navigation_t&)),this,SLOT(slugsNavegationChanged(int,const mavlink_slugs_navigation_t&)));
        connect(slugsMav, SIGNAL(slugsDataLog(int,const mavlink_data_log_t&)), this, SLOT(slugsDataLogChanged(int,const mavlink_data_log_t&)));
53 54
//    connect(slugsMav, SIGNAL(slugsPWM(int,const mavlink_pwm_commands_t&)),this,SLOT(slugsPWMChanged(int,const mavlink_pwm_commands_t&)));
//    connect(slugsMav, SIGNAL(slugsFilteredData(int,const mavlink_filtered_data_t&)),this,SLOT(slugsFilteredDataChanged(int,const mavlink_filtered_data_t&)));
55 56
        connect(slugsMav, SIGNAL(slugsGPSDateTime(int,const mavlink_gps_date_time_t&)),this,SLOT(slugsGPSDateTimeChanged(int,const mavlink_gps_date_time_t&)));
        connect(slugsMav,SIGNAL(slugsAirData(int, const mavlink_air_data_t&)),this,SLOT(slugsAirDataChanged(int, const mavlink_air_data_t&)));
57 58


59 60 61
        connect(slugsMav, SIGNAL(slugsChannels(int, const mavlink_rc_channels_raw_t&)), this, SLOT(slugsRCRawChannels(int, const mavlink_rc_channels_raw_t&)));
        connect(slugsMav, SIGNAL(slugsServo(int, const mavlink_servo_output_raw_t&)), this, SLOT(slugsRCServo(int,const mavlink_servo_output_raw_t&)));
        connect(slugsMav, SIGNAL(slugsScaled(int, const mavlink_scaled_imu_t&)), this, SLOT(slugsFilteredDataChanged(int, const mavlink_scaled_imu_t&)));
62

63
#endif // MAVLINK_ENABLED_SLUGS
64
        // Set this UAS as active if it is the first one
65
        if(activeUAS == 0) {
66 67 68 69 70 71
            activeUAS = uas;
        }

    }
}

72 73 74
void SlugsDataSensorView::slugRawDataChanged(int uasId, const mavlink_raw_imu_t &rawData)
{
    Q_UNUSED(uasId);
75

76 77 78
    ui->m_Axr->setText(QString::number(rawData.xacc));
    ui->m_Ayr->setText(QString::number(rawData.yacc));
    ui->m_Azr->setText(QString::number(rawData.zacc));
79

80 81 82
    ui->m_Mxr->setText(QString::number(rawData.xmag));
    ui->m_Myr->setText(QString::number(rawData.ymag));
    ui->m_Mzr->setText(QString::number(rawData.zmag));
83

84 85 86
    ui->m_Gxr->setText(QString::number(rawData.xgyro));
    ui->m_Gyr->setText(QString::number(rawData.ygyro));
    ui->m_Gzr->setText(QString::number(rawData.zgyro));
87 88 89

}

90
#ifdef MAVLINK_ENABLED_SLUGS
91
void SlugsDataSensorView::slugsRCRawChannels(int systemId, const mavlink_rc_channels_raw_t &gpsDateTime)
92 93
{
    Q_UNUSED(systemId);
94 95 96 97 98 99 100 101

    ui->tbRCThrottle->setText(QString::number(gpsDateTime.chan1_raw));
    ui->tbRCAileron->setText(QString::number(gpsDateTime.chan2_raw));
    ui->tbRCRudder->setText(QString::number(gpsDateTime.chan3_raw));
    ui->tbRCElevator->setText(QString::number(gpsDateTime.chan4_raw));
}

void SlugsDataSensorView::slugsRCServo(int systemId, const mavlink_servo_output_raw_t &gpsDateTime)
102 103
{
    Q_UNUSED(systemId);
104 105 106 107 108 109 110 111 112 113 114

    ui->m_pwmThro->setText(QString::number(gpsDateTime.servo1_raw));
    ui->m_pwmAile->setText(QString::number(gpsDateTime.servo2_raw));
    ui->m_pwmRudd->setText(QString::number(gpsDateTime.servo3_raw));
    ui->m_pwmElev->setText(QString::number(gpsDateTime.servo4_raw));

    ui->m_pwmThroTrim->setText(QString::number(gpsDateTime.servo5_raw));
    ui->m_pwmAileTrim->setText(QString::number(gpsDateTime.servo6_raw));
    ui->m_pwmRuddTrim->setText(QString::number(gpsDateTime.servo7_raw));
    ui->m_pwmElevTrim->setText(QString::number(gpsDateTime.servo8_raw));
}
115
#endif
116

117 118
void SlugsDataSensorView::setActiveUAS(UASInterface* uas)
{
119 120 121 122 123 124 125
    activeUAS = uas;
    addUAS(activeUAS);
}

#ifdef MAVLINK_ENABLED_SLUGS

void SlugsDataSensorView::slugsGlobalPositionChanged(UASInterface *uas,
126 127 128 129 130 131 132 133 134 135 136 137 138
        double lat,
        double lon,
        double alt,
        quint64 time)
{
    Q_UNUSED(uas);
    Q_UNUSED(time);

    ui->m_GpsLatitude->setText(QString::number(lat));
    ui->m_GpsLongitude->setText(QString::number(lon));
    ui->m_GpsHeight->setText(QString::number(alt));

//qDebug()<<"GPS Position = "<<lat<<" - "<<lon<<" - "<<alt;
139 140 141 142
}


void SlugsDataSensorView::slugLocalPositionChanged(UASInterface* uas,
143 144 145 146 147 148 149
        double x,
        double y,
        double z,
        quint64 time)
{
    Q_UNUSED(uas);
    Q_UNUSED(time);
150

151 152 153
    ui->ed_x->setText(QString::number(x));
    ui->ed_y->setText(QString::number(y));
    ui->ed_z->setText(QString::number(z));
154 155 156 157

}

void SlugsDataSensorView::slugSpeedLocalPositionChanged(UASInterface* uas,
158 159 160 161 162
        double vx,
        double vy,
        double vz,
        quint64 time)
{
163
    Q_UNUSED( uas);
164
    Q_UNUSED(time);
165

166 167 168
    ui->ed_vx->setText(QString::number(vx));
    ui->ed_vy->setText(QString::number(vy));
    ui->ed_vz->setText(QString::number(vz));
169

170
    //qDebug()<<"Speed Local Position = "<<vx<<" - "<<vy<<" - "<<vz;
171 172 173 174 175


}

void SlugsDataSensorView::slugAttitudeChanged(UASInterface* uas,
176 177 178 179
        double slugroll,
        double slugpitch,
        double slugyaw,
        quint64 time)
180 181 182 183 184 185 186 187 188 189 190 191 192 193
{
    Q_UNUSED( uas);
    Q_UNUSED(time);

    ui->m_Roll->setText(QString::number(slugroll));
    ui->m_Pitch->setText(QString::number(slugpitch));
    ui->m_Yaw->setText(QString::number(slugyaw));

    // qDebug()<<"Attitude change = "<<slugroll<<" - "<<slugpitch<<" - "<<slugyaw;

}


void SlugsDataSensorView::slugsSensorBiasChanged(int systemId,
194 195 196
        const mavlink_sensor_bias_t& sensorBias)
{
    Q_UNUSED( systemId);
197

198 199 200 201 202 203
    ui->m_AxBiases->setText(QString::number(sensorBias.axBias));
    ui->m_AyBiases->setText(QString::number(sensorBias.ayBias));
    ui->m_AzBiases->setText(QString::number(sensorBias.azBias));
    ui->m_GxBiases->setText(QString::number(sensorBias.gxBias));
    ui->m_GyBiases->setText(QString::number(sensorBias.gyBias));
    ui->m_GzBiases->setText(QString::number(sensorBias.gzBias));
204 205 206 207 208

}


void SlugsDataSensorView::slugsDiagnosticMessageChanged(int systemId,
209 210
        const mavlink_diagnostic_t& diagnostic)
{
211 212
    Q_UNUSED(systemId);

213 214 215
    ui->m_Fl1->setText(QString::number(diagnostic.diagFl1));
    ui->m_Fl2->setText(QString::number(diagnostic.diagFl2));
    ui->m_Fl3->setText(QString::number(diagnostic.diagFl2));
216

217 218 219
    ui->m_Sh1->setText(QString::number(diagnostic.diagSh1));
    ui->m_Sh2->setText(QString::number(diagnostic.diagSh2));
    ui->m_Sh3->setText(QString::number(diagnostic.diagSh3));
220 221 222 223
}


void SlugsDataSensorView::slugsCpuLoadChanged(int systemId,
224 225 226 227 228 229
        const mavlink_cpu_load_t& cpuLoad)
{
    Q_UNUSED(systemId);
    ui->ed_sens->setText(QString::number(cpuLoad.sensLoad));
    ui->ed_control->setText(QString::number(cpuLoad.ctrlLoad));
    ui->ed_batvolt->setText(QString::number(cpuLoad.batVolt));
230 231 232
}

void SlugsDataSensorView::slugsNavegationChanged(int systemId,
233 234 235 236 237 238 239 240 241 242 243 244
        const mavlink_slugs_navigation_t& slugsNavigation)
{
    Q_UNUSED(systemId);
    ui->m_Um->setText(QString::number(slugsNavigation.u_m));
    ui->m_PhiC->setText(QString::number(slugsNavigation.phi_c));
    ui->m_PitchC->setText(QString::number(slugsNavigation.theta_c));
    ui->m_PsidC->setText(QString::number(slugsNavigation.psiDot_c));
    ui->m_AyBody->setText(QString::number(slugsNavigation.ay_body));
    ui->m_TotRun->setText(QString::number(slugsNavigation.totalDist));
    ui->m_DistToGo->setText(QString::number(slugsNavigation.dist2Go));
    ui->m_FromWP->setText(QString::number(slugsNavigation.fromWP));
    ui->m_ToWP->setText(QString::number(slugsNavigation.toWP));
245 246 247 248 249
}



void SlugsDataSensorView::slugsDataLogChanged(int systemId,
250 251 252 253 254 255 256 257 258
        const mavlink_data_log_t& dataLog)
{
    Q_UNUSED(systemId);
    ui->m_logFl1->setText(QString::number(dataLog.fl_1));
    ui->m_logFl2->setText(QString::number(dataLog.fl_2));
    ui->m_logFl3->setText(QString::number(dataLog.fl_3));
    ui->m_logFl4->setText(QString::number(dataLog.fl_4));
    ui->m_logFl5->setText(QString::number(dataLog.fl_5));
    ui->m_logFl6->setText(QString::number(dataLog.fl_6));
259 260
}

261 262 263 264 265 266 267
//void SlugsDataSensorView::slugsPWMChanged(int systemId,
//                                          const mavlink_servo_output_raw_t& pwmCommands){
//       Q_UNUSED(systemId);
//  ui->m_pwmThro->setText(QString::number(pwmCommands.servo1_raw));//.dt_c));
//  ui->m_pwmAile->setText(QString::number(pwmCommands.servo2_raw));//dla_c));
//  ui->m_pwmElev->setText(QString::number(pwmCommands.servo4_raw));//dle_c));
//  ui->m_pwmRudd->setText(QString::number(pwmCommands.servo3_raw));//dr_c));
268

269 270 271 272
//  ui->m_pwmThroTrim->setText(QString::number(pwmCommands.servo5_raw));//dre_c));
//  ui->m_pwmAileTrim->setText(QString::number(pwmCommands.servo6_raw));//dlf_c));
//  ui->m_pwmElevTrim->setText(QString::number(pwmCommands.servo8_raw));//drf_c));
//  ui->m_pwmRuddTrim->setText(QString::number(pwmCommands.servo7_raw));//aux1));
273

274
//}
275 276

void SlugsDataSensorView::slugsFilteredDataChanged(int systemId,
277 278 279 280 281 282 283 284 285 286 287 288
        const mavlink_scaled_imu_t& filteredData)
{
    Q_UNUSED(systemId);
    ui->m_Axf->setText(QString::number(filteredData.xacc/1000.0f));
    ui->m_Ayf->setText(QString::number(filteredData.yacc/1000.0f));
    ui->m_Azf->setText(QString::number(filteredData.zacc/1000.0f));
    ui->m_Gxf->setText(QString::number(filteredData.xgyro/1000.0f));
    ui->m_Gyf->setText(QString::number(filteredData.ygyro/1000.0f));
    ui->m_Gzf->setText(QString::number(filteredData.zgyro/1000.0f));
    ui->m_Mxf->setText(QString::number(filteredData.xmag/1000.0f));
    ui->m_Myf->setText(QString::number(filteredData.ymag/1000.0f));
    ui->m_Mzf->setText(QString::number(filteredData.zmag/1000.0f));
289 290 291
}

void SlugsDataSensorView::slugsGPSDateTimeChanged(int systemId,
292 293
        const mavlink_gps_date_time_t& gpsDateTime)
{
294 295 296 297 298 299 300 301 302 303 304 305
    Q_UNUSED(systemId);

    QString month, day;

    month = QString::number(gpsDateTime.month);
    day = QString::number(gpsDateTime.day);

    if(gpsDateTime.month < 10) month = "0" + QString::number(gpsDateTime.month);
    if(gpsDateTime.day < 10) day = "0" + QString::number(gpsDateTime.day);


    ui->m_GpsDate->setText(day + "/" +
306 307
                           month + "/" +
                           QString::number(gpsDateTime.year));
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322

    QString hour, min, sec;

    hour = QString::number(gpsDateTime.hour);
    min =  QString::number(gpsDateTime.min);
    sec =  QString::number(gpsDateTime.sec);

    if(gpsDateTime.hour < 10) hour = "0" + QString::number(gpsDateTime.hour);
    if(gpsDateTime.min < 10) min = "0" + QString::number(gpsDateTime.min);
    if(gpsDateTime.sec < 10) sec = "0" + QString::number(gpsDateTime.sec);

    ui->m_GpsTime->setText(hour + ":" +
                           min + ":" +
                           sec);

323
    ui->m_GpsSat->setText(QString::number(gpsDateTime.visSat));
324 325 326 327 328 329 330 331 332


}

/**
     * @brief Updates the air data widget - 171
*/
void SlugsDataSensorView::slugsAirDataChanged(int systemId, const mavlink_air_data_t &airData)
{
333 334 335 336
    Q_UNUSED(systemId);
    ui->ed_dynamic->setText(QString::number(airData.dynamicPressure));
    ui->ed_static->setText(QString::number(airData.staticPressure));
    ui->ed_temp->setText(QString::number(airData.temperature));
337 338 339 340 341 342 343
}

/**
     * @brief set COG and SOG values
     *
     * COG and SOG GPS display on the Widgets
*/
344
void SlugsDataSensorView::slugsGPSCogSog(int systemId, double cog, double sog)
345
{
346
    Q_UNUSED(systemId);
347

348 349
    ui->m_GpsCog->setText(QString::number(cog));
    ui->m_GpsSog->setText(QString::number(sog));
350 351 352
}

#endif // MAVLINK_ENABLED_SLUGS