35 #include "homelocation.h"
45 Q_ASSERT(objManager != NULL);
46 waypointObj = Waypoint::GetInstance(objManager);
47 Q_ASSERT(waypointObj != NULL);
57 Waypoint *wp = Waypoint::GetInstance(objManager, 0);
63 UAVObject::Metadata initialMeta = wp->getMetadata();
64 UAVObject::Metadata meta = initialMeta;
66 wp->setMetadata(meta);
71 getHomeLocation(homeLLA);
75 int instances = Waypoint::getNumInstances(objManager);
79 int progressMax = myModel->
rowCount();
81 if (instances > progressMax) {
82 progressMax = instances;
85 for (x = 0; x < myModel->
rowCount(); x++) {
93 wp->initialize(x, wp->getMetaObject());
96 wp = Waypoint::GetInstance(objManager, x);
100 Waypoint::DataFields waypoint = wp->getData();
110 waypoint.Position[Waypoint::POSITION_NORTH] = NED[0];
111 waypoint.Position[Waypoint::POSITION_EAST] = NED[1];
112 waypoint.Position[Waypoint::POSITION_DOWN] = NED[2];
115 waypoint.ModeParameters =
118 if (robustUpdate(waypoint, x)) {
119 qDebug() <<
"Successfully updated";
122 qDebug() <<
"Upload failed";
127 QEventLoop m_eventloop;
128 QTimer::singleShot(800, &m_eventloop, &QEventLoop::quit);
135 for (; x < instances; x++) {
136 Waypoint *wp = Waypoint::GetInstance(objManager, x);
139 Waypoint::DataFields waypoint = wp->getData();
141 waypoint.Mode = Waypoint::MODE_INVALID;
142 if (robustUpdate(waypoint, x)) {
143 qDebug() <<
"Successfully updated";
146 qDebug() <<
"Upload failed";
152 wp->setMetadata(initialMeta);
162 bool ModelUavoProxy::robustUpdate(Waypoint::DataFields
data,
int instance)
164 Waypoint *wp = Waypoint::GetInstance(objManager, instance);
165 connect(wp, QOverload<UAVObject *, bool>::of(&Waypoint::transactionCompleted),
this,
168 for (
int i = 0;
i < 10;
i++) {
169 QEventLoop m_eventloop;
170 QTimer::singleShot(1000, &m_eventloop, &QEventLoop::quit);
174 waypointTransactionResult.insert(instance,
false);
178 if (waypointTransactionResult.value(instance)) {
179 disconnect(wp, QOverload<UAVObject *, bool>::of(&Waypoint::transactionCompleted),
this,
185 QTimer::singleShot(500, &m_eventloop, &QEventLoop::quit);
189 disconnect(wp, QOverload<UAVObject *, bool>::of(&Waypoint::transactionCompleted),
this,
202 Q_ASSERT(obj->
getObjID() == Waypoint::OBJID);
203 waypointTransactionResult.insert(obj->
getInstID(), success);
205 qDebug() <<
"Success " << obj->
getInstID();
208 qDebug() <<
"Failed transaction " << obj->
getInstID();
220 getHomeLocation(homeLLA);
226 for (
int x = 0;
x < Waypoint::getNumInstances(objManager); ++
x) {
228 Waypoint::DataFields wpfields;
230 wp = Waypoint::GetInstance(objManager,
x);
237 wpfields = wp->getData();
239 if (wpfields.Mode == Waypoint::MODE_INVALID)
242 myModel->insertRow(
x);
245 double NED[3] = { wpfields.Position[Waypoint::POSITION_NORTH],
246 wpfields.Position[Waypoint::POSITION_EAST],
247 wpfields.Position[Waypoint::POSITION_DOWN] };
268 bool ModelUavoProxy::getHomeLocation(
double *homeLLA)
271 HomeLocation *home = HomeLocation::GetInstance(objManager);
275 HomeLocation::DataFields homeLocation = home->getData();
276 homeLLA[0] = homeLocation.Latitude / 1e7;
277 homeLLA[1] = homeLocation.Longitude / 1e7;
278 homeLLA[2] = homeLocation.Altitude;
static void SetFlightTelemetryAcked(Metadata &meta, quint8 val)
void waypointTransactionSucceeded()
bool registerObject(UAVDataObject *obj)
Core plugin system that manages the plugins, their life cycle and their registered objects...
axis equal end function NED
void LLA2NED_HomeLLA(double LLA[3], double homeLLA[3], double NED[3])
void sendPathPlanToUavProgress(int percent)
int rowCount(const QModelIndex &parent=QModelIndex()) const
Return the number of waypoints.
bool modelToObjects()
Cast from the internal representation to the UAVOs.
bool removeRows(int row, int count, const QModelIndex &parent=QModelIndex())
FlightDataModel::removeRows Remove waypoints from the model.
int NED2LLA_HomeLLA(double homeLLA[3], double NED[3], double LLA[3])
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
FlightDataModel::setData Set the data at a given location.
ModelUavoProxy(QObject *parent, FlightDataModel *model)
Initialize the model uavo proxy.
void pauseValidation(bool pausing)
Prevent validation/correction of data.
void waypointTransactionFailed()
void objectsToModel()
Cast from the UAVOs to the internal representation.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const
FlightDataModel::data Fetch the data from the model.
void waypointTransactionCompleted(UAVObject *, bool)
Whenever a waypoint transaction is completed.