1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

Merge remote branch 'baseorigin/kenz/math_scope' into basenext

This commit is contained in:
Corvus Corax 2012-06-29 11:22:38 +02:00
commit bf0bea49da
2 changed files with 72 additions and 37 deletions

View File

@ -99,7 +99,7 @@ bool SequentialPlotData::append(UAVObject* obj)
double currentValue = valueAsDouble(obj, field) * pow(10, scalePower);
//Compute boxcar average
//Perform scope math, if necessary
if (mathFunction == "Boxcar average" || mathFunction == "Standard deviation"){
//Put the new value at the front
yDataHistory->append( currentValue );
@ -163,8 +163,8 @@ bool ChronoPlotData::append(UAVObject* obj)
QDateTime NOW = QDateTime::currentDateTime(); //THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
double currentValue = valueAsDouble(obj, field) * pow(10, scalePower);
//Compute boxcar average
if (meanSamples > 1){
//Perform scope math, if necessary
if (mathFunction == "Boxcar average" || mathFunction == "Standard deviation"){
//Put the new value at the front
yDataHistory->append( currentValue );

View File

@ -51,6 +51,7 @@
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>
#include <QMutexLocker>
#include <QWheelEvent>
//using namespace Core;
@ -65,8 +66,8 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
replotTimer = new QTimer(this);
connect(replotTimer, SIGNAL(timeout()), this, SLOT(replotNewData()));
// Listen to telemetry connection/disconnection events, no point
// running the scopes if we are not connected and not replaying logs
// Listen to telemetry connection/disconnection events, no point in
// running the scopes if we are not connected and not replaying logs.
// Also listen to disconnect actions from the user
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(stopPlotting()));
@ -124,12 +125,17 @@ void ScopeGadgetWidget::mouseReleaseEvent(QMouseEvent *e)
void ScopeGadgetWidget::mouseDoubleClickEvent(QMouseEvent *e)
{
//On double-click, toggle legend
mutex.lock();
if (legend())
deleteLegend();
else
addLegend();
mutex.unlock();
//On double-click, reset plot zoom
setAxisAutoScale(QwtPlot::yLeft, true);
update();
QwtPlot::mouseDoubleClickEvent(e);
@ -142,6 +148,33 @@ void ScopeGadgetWidget::mouseMoveEvent(QMouseEvent *e)
void ScopeGadgetWidget::wheelEvent(QWheelEvent *e)
{
//Change zoom on scroll wheel event
QwtInterval yInterval=axisInterval(QwtPlot::yLeft);
if (yInterval.minValue() != yInterval.maxValue()) //Make sure that the two values are never the same. Sometimes axisInterval returns (0,0)
{
//Determine what y value to zoom about. NOTE, this approach has a bug that the in that
//the value returned by Qt includes the legend, whereas the value transformed by Qwt
//does *not*. Thus, when zooming with a legend, there will always be a small bias error.
//In practice, this seems not to be a UI problem.
QPoint mouse_pos=e->pos(); //Get the mouse coordinate in the frame
double zoomLine=invTransform(QwtPlot::yLeft, mouse_pos.y()); //Transform the y mouse coordinate into a frame value.
double zoomScale=1.1; //THIS IS AN ARBITRARY CONSTANT, AND PERHAPS SHOULD BE IN A DEFINE INSTEAD OF BURIED HERE
mutex.lock(); //DOES THIS mutex.lock NEED TO BE HERE? I DON'T KNOW, I JUST COPIED IT FROM THE ABOVE CODE
// Set the scale
if (e->delta()<0){
setAxisScale(QwtPlot::yLeft,
(yInterval.minValue()-zoomLine)*zoomScale+zoomLine,
(yInterval.maxValue()-zoomLine)*zoomScale+zoomLine );
}
else{
setAxisScale(QwtPlot::yLeft,
(yInterval.minValue()-zoomLine)/zoomScale+zoomLine,
(yInterval.maxValue()-zoomLine)/zoomScale+zoomLine );
}
mutex.unlock();
}
QwtPlot::wheelEvent(e);
}
@ -412,7 +445,7 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField
//Keep the curve details for later
m_curvesData.insert(curveNameScaled, plotData);
//Link to the signal of new data only if this UAVObject has not been to connected yet
//Link to the new signal data only if this UAVObject has not been connected yet
if (!m_connectedUAVObjects.contains(obj->getName())) {
m_connectedUAVObjects.append(obj->getName());
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(uavObjectReceived(UAVObject*)));
@ -470,6 +503,7 @@ void ScopeGadgetWidget::replotNewData()
replot();
}
/*
void ScopeGadgetWidget::setupExamplePlot()
{
preparePlot(SequentialPlot);
@ -514,6 +548,7 @@ void ScopeGadgetWidget::setupExamplePlot()
replot();
mutex.unlock();
}
*/
void ScopeGadgetWidget::clearCurvePlots()
{