AbstractCalibrator.h 2.42 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

/**
 * @file
 *   @brief Common aspects of radio calibration widgets
 *   @author Bryan Godbolt <godbolt@ualberta.ca>
 */

30 31 32 33 34 35
#ifndef ABSTRACTCALIBRATOR_H
#define ABSTRACTCALIBRATOR_H

#include <QWidget>
#include <QString>
#include <QLabel>
36
#include <QVector>
37

38 39
#include <math.h>

40 41 42 43 44
/**
  @brief Holds the code which is common to all the radio calibration widgets.

  @author Bryan Godbolt <godbolt@ece.ualberta.ca>
  */
45 46 47 48 49 50 51
class AbstractCalibrator : public QWidget
{
Q_OBJECT
public:
    explicit AbstractCalibrator(QWidget *parent = 0);
    ~AbstractCalibrator();

52 53 54 55
    /** Change the setpoints of the widget.  Used when
      changing the display from an external source (file/uav).
      @param data QVector of setpoints
      */
56
    virtual void set(const QVector<float>& data)=0;
57
signals:
58 59 60 61
    /** Announce a setpoint change.
      @param index setpoint number - 0 based in the current implementation
      @param value new value
      */
62
    void setpointChanged(int index, float value);
63

64
public slots:
65 66 67
    /** Slot to call when the relevant channel is updated
     @param raw current channel value
     */
68 69 70
    void channelChanged(float raw);

protected:
71
    /** Display the current pulse width */
72 73
    QLabel *pulseWidth;

74
    /** Log of the past few samples for use in averaging and finding extrema */
75
    QVector<float> *log;
76
    /** Find the maximum or minimum of the data log */
77
    float logExtrema();
78
    /** Find the average of the log */
79 80 81 82
    float logAverage();
};

#endif // ABSTRACTCALIBRATOR_H