Skip to content
Snippets Groups Projects
QGCXPlaneLink.cc 34.4 KiB
Newer Older
  • Learn to ignore specific revisions
  •  * Sets a random position with an offset of max 1/1000 degree
     * and max 100 m altitude
     */
    void QGCXPlaneLink::setRandomPosition()
    {
        // Initialize generator
        srand(0);
    
        double offLat = rand() / static_cast<double>(RAND_MAX) / 500.0 + 1.0/500.0;
        double offLon = rand() / static_cast<double>(RAND_MAX) / 500.0 + 1.0/500.0;
        double offAlt = rand() / static_cast<double>(RAND_MAX) * 200.0 + 100.0;
    
    
        if (mav->getAltitudeAMSL() + offAlt < 0)
    
        {
            offAlt *= -1.0;
        }
    
        setPositionAttitude(mav->getLatitude() + offLat,
                            mav->getLongitude() + offLon,
    
                            mav->getRoll(),
                            mav->getPitch(),
                            mav->getYaw());
    }
    
    void QGCXPlaneLink::setRandomAttitude()
    {
        // Initialize generator
        srand(0);
    
        double roll = rand() / static_cast<double>(RAND_MAX) * 2.0 - 1.0;
        double pitch = rand() / static_cast<double>(RAND_MAX) * 2.0 - 1.0;
        double yaw = rand() / static_cast<double>(RAND_MAX) * 2.0 - 1.0;
    
        setPositionAttitude(mav->getLatitude(),
                            mav->getLongitude(),
    
    /**
     * @brief Connect the connection.
     *
     * @return True if connection has been established, false if connection couldn't be established.
     **/
    bool QGCXPlaneLink::connectSimulation()
    {
    
        if (connectState) {
            qDebug() << "Simulation already active";
        } else {
            qDebug() << "STARTING X-PLANE LINK, CONNECTING TO" << remoteHost << ":" << remotePort;
            // XXX Hack
            storeSettings();
    
            start(HighPriority);
        }
    
    }
    
    /**
     * @brief Check if connection is active.
     *
     * @return True if link is connected, false otherwise.
     **/
    bool QGCXPlaneLink::isConnected()
    {
        return connectState;
    }
    
    QString QGCXPlaneLink::getName()
    {
        return name;
    }
    
    void QGCXPlaneLink::setName(QString name)
    {
        this->name = name;
        //    emit nameChanged(this->name);
    }