/** * @brief ModelUavoProxy::modelToObjects Cast from the internal representation of a path * to the UAV objects required to represent it * @return true if all wp were sent ok */ bool ModelUavoProxy::modelToObjects() { Waypoint *wp = Waypoint::GetInstance(objManager,0); Q_ASSERT(wp); if (wp == NULL) return false; // Make sure the object is acked UAVObject::Metadata initialMeta = wp->getMetadata(); UAVObject::Metadata meta = initialMeta; UAVObject::SetFlightTelemetryAcked(meta, true); wp->setMetadata(meta); double homeLLA[3]; double NED[3]; double LLA[3]; getHomeLocation(homeLLA); bool newInstance; // Get the number of existing waypoints int instances = Waypoint::getNumInstances(objManager); int x; // Figure out the total amount of work to do. int progressMax = myModel->rowCount(); if (instances > progressMax) { progressMax = instances; } for(x=0; x<myModel->rowCount(); x++) { newInstance = false; Waypoint *wp = NULL; // Shadows above wp // Create new instances of waypoints if this is more than exist if(x >= instances) { newInstance = true; wp=new Waypoint; wp->initialize(x,wp->getMetaObject()); objManager->registerObject(wp); } else { wp=Waypoint::GetInstance(objManager,x); } Q_ASSERT(wp); Waypoint::DataFields waypoint = wp->getData(); // Convert from LLA to NED for sending to the model LLA[0] = myModel->data(myModel->index(x,FlightDataModel::LATPOSITION)).toDouble(); LLA[1] = myModel->data(myModel->index(x,FlightDataModel::LNGPOSITION)).toDouble(); LLA[2] = myModel->data(myModel->index(x,FlightDataModel::ALTITUDE)).toDouble(); Utils::CoordinateConversions().LLA2NED_HomeLLA(LLA, homeLLA, NED); // Fetch the data from the internal model waypoint.Velocity=myModel->data(myModel->index(x,FlightDataModel::VELOCITY)).toFloat(); waypoint.Position[Waypoint::POSITION_NORTH] = NED[0]; waypoint.Position[Waypoint::POSITION_EAST] = NED[1]; waypoint.Position[Waypoint::POSITION_DOWN] = NED[2]; waypoint.Mode = myModel->data(myModel->index(x,FlightDataModel::MODE), Qt::UserRole).toInt(); waypoint.ModeParameters = myModel->data(myModel->index(x,FlightDataModel::MODE_PARAMS)).toFloat(); if (robustUpdate(waypoint, x)) { qDebug() << "Successfully updated"; emit sendPathPlanToUavProgress(100 * (x + 1) / progressMax); } else { qDebug() << "Upload failed"; emit sendPathPlanToUavProgress(100 * (x + 1) / progressMax); return false; } if(newInstance) { QEventLoop m_eventloop; QTimer::singleShot(800, &m_eventloop, SLOT(quit())); m_eventloop.exec(); } } /* Continue iterating over any instance indices that aren't needed to * represent our model, and mark them invalid. */ for (; x < instances; x++) { Waypoint *wp = Waypoint::GetInstance(objManager, x); // shadows wp above Waypoint::DataFields waypoint = wp->getData(); waypoint.Mode = Waypoint::MODE_INVALID; if (robustUpdate(waypoint, x)) { qDebug() << "Successfully updated"; emit sendPathPlanToUavProgress(100 * (x + 1) / progressMax); } else { qDebug() << "Upload failed"; emit sendPathPlanToUavProgress(100 * (x + 1) / progressMax); return false; } } wp->setMetadata(initialMeta); return true; }
/** * @brief ModelUavoProxy::modelToObjects Cast from the internal representation of a path * to the UAV objects required to represent it */ void ModelUavoProxy::modelToObjects() { Waypoint *wp = Waypoint::GetInstance(objManager,0); Q_ASSERT(wp); if (wp == NULL) return; // Make sure the object is acked UAVObject::Metadata initialMeta = wp->getMetadata(); UAVObject::Metadata meta = initialMeta; UAVObject::SetFlightTelemetryAcked(meta, true); wp->setMetadata(meta); double homeLLA[3]; double NED[3]; double LLA[3]; getHomeLocation(homeLLA); for(int x=0;x<myModel->rowCount();++x) { Waypoint *wp = NULL; // Get the number of existing waypoints int instances=objManager->getNumInstances(Waypoint::OBJID); // Create new instances of waypoints if this is more than exist if(x>instances-1) { wp=new Waypoint; wp->initialize(x,wp->getMetaObject()); objManager->registerObject(wp); } else { wp=Waypoint::GetInstance(objManager,x); } Q_ASSERT(wp); Waypoint::DataFields waypoint = wp->getData(); // Convert from LLA to NED for sending to the model LLA[0] = myModel->data(myModel->index(x,FlightDataModel::LATPOSITION)).toDouble(); LLA[1] = myModel->data(myModel->index(x,FlightDataModel::LNGPOSITION)).toDouble(); LLA[2] = myModel->data(myModel->index(x,FlightDataModel::ALTITUDE)).toDouble(); Utils::CoordinateConversions().LLA2NED_HomeLLA(LLA, homeLLA, NED); // Fetch the data from the internal model waypoint.Velocity=myModel->data(myModel->index(x,FlightDataModel::VELOCITY)).toFloat(); waypoint.Position[Waypoint::POSITION_NORTH] = NED[0]; waypoint.Position[Waypoint::POSITION_EAST] = NED[1]; waypoint.Position[Waypoint::POSITION_DOWN] = NED[2]; waypoint.Mode = myModel->data(myModel->index(x,FlightDataModel::MODE), Qt::UserRole).toInt(); waypoint.ModeParameters = myModel->data(myModel->index(x,FlightDataModel::MODE_PARAMS)).toFloat(); if (robustUpdate(waypoint, x)) qDebug() << "Successfully updated"; else { qDebug() << "Upload failed"; break; } } wp->setMetadata(initialMeta); }