SlugsHilSim.h 3.79 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
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief Definition of the configuration Window for Slugs' HIL Simulator
 *   @author Mariano Lizarraga <malife@gmail.com>
 */

30 31 32 33
#ifndef SLUGSHILSIM_H
#define SLUGSHILSIM_H

#include <QWidget>
34 35
#include <QHostAddress>
#include <QUdpSocket>
36 37
#include <QMessageBox>

38
#include "LinkInterface.h"
39
#include "UAS.h"
40
#include <stdint.h>
41

42

43 44 45 46 47 48 49 50 51 52 53 54
namespace Ui {
    class SlugsHilSim;
}

class SlugsHilSim : public QWidget
{
    Q_OBJECT

public:
    explicit SlugsHilSim(QWidget *parent = 0);
    ~SlugsHilSim();

Alejandro's avatar
Alejandro committed
55 56


57 58
protected:
    LinkInterface* hilLink;
59 60 61
    QHostAddress* simulinkIp;
    QUdpSocket* txSocket;
    QUdpSocket* rxSocket;
62 63
    UAS* activeUas;

Alejandro's avatar
Alejandro committed
64 65 66 67 68 69 70
    mavlink_local_position_t tmpLocalPositionData;
    mavlink_attitude_t tmpAttitudeData;
    mavlink_raw_imu_t tmpRawImuData;
    mavlink_air_data_t tmpAirData;
    mavlink_gps_raw_t tmpGpsData;
    mavlink_gps_date_time_t tmpGpsTime;

71 72 73 74 75 76 77 78 79 80 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
public slots:

    /**
     * @brief Adds a link to the combo box listing so the user can select a link
     *
     * Populates the Combo box that allows the user to select the link with which Slugs will
     * receive the simulated sensor data from Simulink
     *
     * @param theLink the link that is being added to the combo box
     */
    void addToCombo(LinkInterface* theLink);

    /**
     * @brief Puts Slugs in HIL Mode
     *
     * Sends the required messages through the main communication link to set Slugs in HIL Mode
     *
     */
    void putInHilMode(void);

    /**
     * @brief Receives a datagram from Simulink containing the sensor data.
     *
     * Receives a datagram from Simulink containing the simulated sensor data. This data is then
     * forwarded to Slugs to use as input to the attitude estimation and navigation algorithms.
     *
     */
    void readDatagram(void);

    /**
     * @brief Called when the a new UAS is set to active.
     *
     * Called when the a new UAS is set to active.
     *
     * @param uas The new active UAS
     */
    void activeUasSet(UASInterface* uas);
108

109 110 111 112 113 114
    /**
     * @brief Called when the Link combobox selects a new link.
     *
     * @param uas The new index of the selected link
     */
    void linkSelected (int cbIndex);
115

116 117
public slots:

118

119

120
private:
121 122 123 124 125 126 127 128 129 130 131

	typedef union _tFloatToChar {
		unsigned char   chData[4];
		float   		flData;
	} tFloatToChar;

	typedef union _tUint16ToChar {
		unsigned char   chData[2];
		uint16_t   		uiData;
	} tUint16ToChar;

132
    Ui::SlugsHilSim *ui;
Alejandro's avatar
Alejandro committed
133

134 135
    QHash <int, LinkInterface*> linksAvailable;

136 137 138
    void processHilDatagram (const QByteArray* datagram);
    float getFloatFromDatagram (const QByteArray* datagram, unsigned char * i);
    uint16_t getUint16FromDatagram (const QByteArray* datagram, unsigned char * i);
Alejandro's avatar
Alejandro committed
139 140 141 142 143 144
    void setUInt16ToDatagram(QByteArray& datagram, unsigned char* pos, uint16_t value);


    void sendMessageToSlugs();

    void commandToSimulink();
145

146 147 148
};

#endif // SLUGSHILSIM_H