1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-05 21:52:10 +01:00

Update the MagicWaypoint gadget to use PathDesired instead of PositionDesired

This commit is contained in:
James Cotton 2012-05-09 10:58:24 -05:00
parent 406b5a00f5
commit a857530832
2 changed files with 38 additions and 32 deletions

View File

@ -47,7 +47,7 @@ MagicWaypointGadgetWidget::MagicWaypointGadgetWidget(QWidget *parent) : QLabel(p
m_magicwaypoint->setupUi(this); m_magicwaypoint->setupUi(this);
// Connect object updated event from UAVObject to also update check boxes // Connect object updated event from UAVObject to also update check boxes
connect(getPositionDesired(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionObjectChanged(UAVObject*))); connect(getPathDesired(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionObjectChanged(UAVObject*)));
connect(getPositionActual(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionObjectChanged(UAVObject*))); connect(getPositionActual(), SIGNAL(objectUpdated(UAVObject*)), this, SLOT(positionObjectChanged(UAVObject*)));
// Connect updates from the position widget to this widget // Connect updates from the position widget to this widget
@ -57,6 +57,9 @@ MagicWaypointGadgetWidget::MagicWaypointGadgetWidget(QWidget *parent) : QLabel(p
// Catch changes in scale for visualization // Catch changes in scale for visualization
connect(m_magicwaypoint->horizontalSliderScale, SIGNAL(valueChanged(int)), this, SLOT(scaleChanged(int))); connect(m_magicwaypoint->horizontalSliderScale, SIGNAL(valueChanged(int)), this, SLOT(scaleChanged(int)));
// Make sure the scale is correctly visualized
m_magicwaypoint->horizontalSliderScale->setValue(10);
} }
MagicWaypointGadgetWidget::~MagicWaypointGadgetWidget() MagicWaypointGadgetWidget::~MagicWaypointGadgetWidget()
@ -67,11 +70,12 @@ MagicWaypointGadgetWidget::~MagicWaypointGadgetWidget()
/*! /*!
\brief Returns the @ref PositionDesired UAVObject \brief Returns the @ref PositionDesired UAVObject
*/ */
PositionDesired* MagicWaypointGadgetWidget::getPositionDesired() PathDesired* MagicWaypointGadgetWidget::getPathDesired()
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
PositionDesired* obj = dynamic_cast<PositionDesired*>( objManager->getObject(QString("PositionDesired")) ); PathDesired* obj = PathDesired::GetInstance(objManager);
Q_ASSERT(obj != NULL); // Save crashes later
return obj; return obj;
} }
@ -82,7 +86,8 @@ PositionActual* MagicWaypointGadgetWidget::getPositionActual()
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
PositionActual* obj = dynamic_cast<PositionActual*>( objManager->getObject(QString("PositionActual")) ); PositionActual *obj = PositionActual::GetInstance(objManager);
Q_ASSERT(obj != NULL);
return obj; return obj;
} }
@ -91,45 +96,45 @@ PositionActual* MagicWaypointGadgetWidget::getPositionActual()
*/ */
void MagicWaypointGadgetWidget::scaleChanged(int scale) { void MagicWaypointGadgetWidget::scaleChanged(int scale) {
Q_UNUSED(scale); Q_UNUSED(scale);
positionObjectChanged(getPositionDesired()); pathDesiredChanged(getPathDesired());
positionObjectChanged(getPositionActual()); positionActualChanged(getPositionActual());
} }
/** /**
* Emit a position changed signal when @ref PositionDesired or @ref PositionActual object is changed * Emit a position changed signal when @ref PositionActual object is changed
*/ */
void MagicWaypointGadgetWidget::positionObjectChanged(UAVObject* obj) void MagicWaypointGadgetWidget::positionActualChanged(UAVObject *)
{ {
PositionActual::DataFields positionActual = getPositionActual()->getData();
double scale = m_magicwaypoint->horizontalSliderScale->value(); double scale = m_magicwaypoint->horizontalSliderScale->value();
double north = obj->getField("North")->getDouble() / scale;
double east = obj->getField("East")->getDouble() / scale;
if(obj->getName().compare("PositionDesired")) {
emit positionDesiredObjectChanged(north,east);
} else {
emit positionActualObjectChanged(north,east);
}
emit positionActualObjectChanged(positionActual.North / scale,
positionActual.East / scale);
} }
/** /**
* Slot called by visualization when a new @ref PositionDesired is requested * Emit a position changed signal when @ref PathDesired is changed
*/
void MagicWaypointGadgetWidget::pathDesiredChanged(UAVObject *)
{
PathDesired::DataFields pathDesired = getPathDesired()->getData();
double scale = m_magicwaypoint->horizontalSliderScale->value();
emit positionDesiredObjectChanged(pathDesired.End[PathDesired::END_NORTH] / scale,
pathDesired.End[PathDesired::END_EAST] / scale);
}
/**
* Slot called by visualization when a new @ref PathDesired is requested
*/ */
void MagicWaypointGadgetWidget::positionSelected(double north, double east) { void MagicWaypointGadgetWidget::positionSelected(double north, double east) {
double scale = m_magicwaypoint->horizontalSliderScale->value(); double scale = m_magicwaypoint->horizontalSliderScale->value();
PositionDesired * posDesired = getPositionDesired(); PathDesired::DataFields pathDesired = getPathDesired()->getData();
if(posDesired) { pathDesired.End[PathDesired::END_NORTH] = north * scale;
UAVObjectField * field = posDesired->getField("North"); pathDesired.End[PathDesired::END_EAST] = east * scale;
if(field) pathDesired.Mode = PathDesired::MODE_ENDPOINT;
field->setDouble(north * scale); getPathDesired()->setData(pathDesired);
field = posDesired->getField("East");
if(field)
field->setDouble(east * scale);
posDesired->updated();
}
} }
/** /**

View File

@ -29,7 +29,7 @@
#define MagicWaypointGADGETWIDGET_H_ #define MagicWaypointGADGETWIDGET_H_
#include <QtGui/QLabel> #include <QtGui/QLabel>
#include "positiondesired.h" #include "pathdesired.h"
#include "positionactual.h" #include "positionactual.h"
class Ui_MagicWaypoint; class Ui_MagicWaypoint;
@ -48,11 +48,12 @@ signals:
protected slots: protected slots:
void scaleChanged(int scale); void scaleChanged(int scale);
void positionObjectChanged(UAVObject *); void positionActualChanged(UAVObject *);
void pathDesiredChanged(UAVObject *);
void positionSelected(double north, double east); void positionSelected(double north, double east);
private: private:
PositionDesired * getPositionDesired(); PathDesired * getPathDesired();
PositionActual * getPositionActual(); PositionActual * getPositionActual();
Ui_MagicWaypoint * m_magicwaypoint; Ui_MagicWaypoint * m_magicwaypoint;
}; };