Commit f75f4424 authored by LM's avatar LM

Merge branch 'dev-lin' of https://github.com/godbolt/qgroundcontrol into dev

parents 63900c28 d163ee02
......@@ -957,12 +957,12 @@ void UAS::receiveMessage(LinkInterface* link, mavlink_message_t message)
case MAVLINK_MSG_ID_RADIO_CALIBRATION: {
mavlink_radio_calibration_t radioMsg;
mavlink_msg_radio_calibration_decode(&message, &radioMsg);
QVector<float> aileron;
QVector<float> elevator;
QVector<float> rudder;
QVector<float> gyro;
QVector<float> pitch;
QVector<float> throttle;
QVector<uint16_t> aileron;
QVector<uint16_t> elevator;
QVector<uint16_t> rudder;
QVector<uint16_t> gyro;
QVector<uint16_t> pitch;
QVector<uint16_t> throttle;
for (int i=0; i<MAVLINK_MSG_RADIO_CALIBRATION_FIELD_AILERON_LEN; ++i)
aileron << radioMsg.aileron[i];
......
......@@ -120,25 +120,25 @@ void QGCRemoteControlView::setChannelRaw(int channelId, float raw)
redraw();
}
//void QGCRemoteControlView::setChannelScaled(int channelId, float normalized)
//{
// if (this->raw.size() <= channelId) // using raw vector as size indicator
// {
// // This is a new channel, append it
// this->normalized.append(normalized);
// this->raw.append(0);
// appendChannelWidget(channelId);
// }
// else
// {
// // This is an existing channel, update it
// this->normalized[channelId] = normalized;
// }
void QGCRemoteControlView::setChannelScaled(int channelId, float normalized)
{
if (this->raw.size() <= channelId) // using raw vector as size indicator
{
// This is a new channel, append it
this->normalized.append(normalized);
this->raw.append(0);
appendChannelWidget(channelId);
}
else
{
// This is an existing channel, update it
this->normalized[channelId] = normalized;
}
// updated = true;
// // FIXME Will be timer based in the future
// redraw();
//}
}
void QGCRemoteControlView::setRemoteRSSI(float rssiNormalized)
{
......@@ -179,9 +179,9 @@ void QGCRemoteControlView::redraw()
// Update percent bars
for(int i = 0; i < progressBars.count(); i++) {
rawLabels.at(i)->setText(QString("%1 us").arg(raw.at(i), 4, 10, QChar('0')));
//int vv = normalized.at(i)*100.0f;
int vv = normalized.at(i)*100.0f;
//progressBars.at(i)->setValue(vv);
int vv = raw.at(i)*1.0f;
// int vv = raw.at(i)*1.0f;
progressBars.at(i)->setValue(vv);
}
// Update RSSI
......
......@@ -55,7 +55,7 @@ public:
public slots:
void setUASId(int id);
void setChannelRaw(int channelId, float raw);
//void setChannelScaled(int channelId, float normalized);
void setChannelScaled(int channelId, float normalized);
void setRemoteRSSI(float rssiNormalized);
void redraw();
......
......@@ -3,7 +3,7 @@
AbstractCalibrator::AbstractCalibrator(QWidget *parent) :
QWidget(parent),
pulseWidth(new QLabel()),
log(new QVector<float>())
log(new QVector<uint16_t>())
{
}
......@@ -12,17 +12,17 @@ AbstractCalibrator::~AbstractCalibrator()
delete log;
}
float AbstractCalibrator::logAverage()
uint16_t AbstractCalibrator::logAverage()
{
float total = 0;
uint16_t total = 0;
for (int i=0; i<log->size(); ++i)
total += log->value(i);
return floor(total/log->size());
return total/log->size();
}
float AbstractCalibrator::logExtrema()
uint16_t AbstractCalibrator::logExtrema()
{
float extrema = logAverage();
uint16_t extrema = logAverage();
if (logAverage() < 1500) {
for (int i=0; i<log->size(); ++i) {
if (log->value(i) < extrema)
......@@ -40,9 +40,9 @@ float AbstractCalibrator::logExtrema()
return extrema;
}
void AbstractCalibrator::channelChanged(float raw)
void AbstractCalibrator::channelChanged(uint16_t raw)
{
pulseWidth->setText(QString::number(static_cast<double>(raw)));
pulseWidth->setText(QString::number(raw));
if (log->size() == 5)
log->pop_front();
log->push_back(raw);
......
......@@ -36,6 +36,7 @@ This file is part of the QGROUNDCONTROL project
#include <QVector>
#include <math.h>
#include <stdint.h>
/**
@brief Holds the code which is common to all the radio calibration widgets.
......@@ -53,30 +54,30 @@ public:
changing the display from an external source (file/uav).
@param data QVector of setpoints
*/
virtual void set(const QVector<float>& data)=0;
virtual void set(const QVector<uint16_t>& data)=0;
signals:
/** Announce a setpoint change.
@param index setpoint number - 0 based in the current implementation
@param value new value
*/
void setpointChanged(int index, float value);
void setpointChanged(int index, uint16_t value);
public slots:
/** Slot to call when the relevant channel is updated
@param raw current channel value
*/
void channelChanged(float raw);
void channelChanged(uint16_t raw);
protected:
/** Display the current pulse width */
QLabel *pulseWidth;
/** Log of the past few samples for use in averaging and finding extrema */
QVector<float> *log;
QVector<uint16_t> *log;
/** Find the maximum or minimum of the data log */
float logExtrema();
uint16_t logExtrema();
/** Find the average of the log */
float logAverage();
uint16_t logAverage();
};
#endif // ABSTRACTCALIBRATOR_H
......@@ -78,23 +78,23 @@ AirfoilServoCalibrator::AirfoilServoCalibrator(AirfoilType type, QWidget *parent
void AirfoilServoCalibrator::setHigh()
{
highPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
highPulseWidth->setText(QString::number(logExtrema()));
emit setpointChanged(2, logExtrema());
}
void AirfoilServoCalibrator::setCenter()
{
centerPulseWidth->setText(QString::number(static_cast<double>(logAverage())));
centerPulseWidth->setText(QString::number(logAverage()));
emit setpointChanged(1, logAverage());
}
void AirfoilServoCalibrator::setLow()
{
lowPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
lowPulseWidth->setText(QString::number(logExtrema()));
emit setpointChanged(0, logExtrema());
}
void AirfoilServoCalibrator::set(const QVector<float> &data)
void AirfoilServoCalibrator::set(const QVector<uint16_t> &data)
{
if (data.size() == 3) {
lowPulseWidth->setText(QString::number(data[0]));
......
......@@ -58,7 +58,7 @@ public:
explicit AirfoilServoCalibrator(AirfoilType type = AILERON, QWidget *parent = 0);
/** @param data must have exaclty 3 elemets. they are assumed to be low center high */
void set(const QVector<float>& data);
void set(const QVector<uint16_t>& data);
protected slots:
void setHigh();
......
......@@ -2,8 +2,8 @@
CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
AbstractCalibrator(parent),
setpoints(new QVector<double>(5)),
positions(new QVector<double>())
setpoints(new QVector<uint16_t>(5)),
positions(new QVector<uint16_t>())
{
QGridLayout *grid = new QGridLayout(this);
QLabel *title = new QLabel(titleString);
......@@ -32,7 +32,17 @@ CurveCalibrator::CurveCalibrator(QString titleString, QWidget *parent) :
curve = new QwtPlotCurve();
curve->setPen(QPen(QColor(QString("lime"))));
curve->setData(*positions, *setpoints);
QVector<double> pos(positions->size());
QVector<double> set(setpoints->size());
for (int i=0; i<positions->size()&&i<setpoints->size(); i++)
{
pos[i] = static_cast<double>((*positions)[i]);
set[i] = static_cast<double>((*setpoints)[i]);
}
curve->setData(pos, set);
curve->attach(plot);
plot->replot();
......@@ -75,22 +85,40 @@ CurveCalibrator::~CurveCalibrator()
void CurveCalibrator::setSetpoint(int setpoint)
{
if (setpoint == 0 || setpoint == 4) {
setpoints->replace(setpoint, static_cast<double>(logExtrema()));
setpoints->replace(setpoint,logExtrema());
} else {
setpoints->replace(setpoint, static_cast<double>(logAverage()));
setpoints->replace(setpoint, logAverage());
}
curve->setData(*positions, *setpoints);
QVector<double> pos(positions->size());
QVector<double> set(setpoints->size());
for (int i=0; i<positions->size()&&i<setpoints->size(); i++)
{
pos[i] = static_cast<double>((*positions)[i]);
set[i] = static_cast<double>((*setpoints)[i]);
}
curve->setData(pos, set);
plot->replot();
emit setpointChanged(setpoint, static_cast<float>(setpoints->value(setpoint)));
emit setpointChanged(setpoint, setpoints->value(setpoint));
}
void CurveCalibrator::set(const QVector<float> &data)
void CurveCalibrator::set(const QVector<uint16_t> &data)
{
if (data.size() == 5) {
for (int i=0; i<data.size(); ++i)
setpoints->replace(i, static_cast<double>(data[i]));
curve->setData(*positions, *setpoints);
setpoints->replace(i, data[i]);
QVector<double> pos(positions->size());
QVector<double> set(setpoints->size());
for (int i=0; i<positions->size()&&i<setpoints->size(); i++)
{
pos[i] = static_cast<double>((*positions)[i]);
set[i] = static_cast<double>((*setpoints)[i]);
}
curve->setData(pos, set);
plot->replot();
} else {
qDebug() << __FILE__ << __LINE__ << ": wrong data vector size";
......
......@@ -58,14 +58,14 @@ public:
explicit CurveCalibrator(QString title = QString(), QWidget *parent = 0);
~CurveCalibrator();
void set(const QVector<float> &data);
void set(const QVector<uint16_t> &data);
protected slots:
void setSetpoint(int setpoint);
protected:
QVector<double> *setpoints;
QVector<double> *positions;
QVector<uint16_t> *setpoints;
QVector<uint16_t> *positions;
/** Plot to display calibration curve */
QwtPlot *plot;
/** Curve object of calibration curve */
......
......@@ -2,23 +2,23 @@
RadioCalibrationData::RadioCalibrationData()
{
data = new QVector<QVector<float> >(6);
(*data).insert(AILERON, QVector<float>(3));
(*data).insert(ELEVATOR, QVector<float>(3));
(*data).insert(RUDDER, QVector<float>(3));
(*data).insert(GYRO, QVector<float>(2));
(*data).insert(PITCH, QVector<float>(5));
(*data).insert(THROTTLE, QVector<float>(5));
data = new QVector<QVector<uint16_t> >(6);
(*data).insert(AILERON, QVector<uint16_t>(3));
(*data).insert(ELEVATOR, QVector<uint16_t>(3));
(*data).insert(RUDDER, QVector<uint16_t>(3));
(*data).insert(GYRO, QVector<uint16_t>(2));
(*data).insert(PITCH, QVector<uint16_t>(5));
(*data).insert(THROTTLE, QVector<uint16_t>(5));
}
RadioCalibrationData::RadioCalibrationData(const QVector<float> &aileron,
const QVector<float> &elevator,
const QVector<float> &rudder,
const QVector<float> &gyro,
const QVector<float> &pitch,
const QVector<float> &throttle)
RadioCalibrationData::RadioCalibrationData(const QVector<uint16_t> &aileron,
const QVector<uint16_t> &elevator,
const QVector<uint16_t> &rudder,
const QVector<uint16_t> &gyro,
const QVector<uint16_t> &pitch,
const QVector<uint16_t> &throttle)
{
data = new QVector<QVector<float> >();
data = new QVector<QVector<uint16_t> >();
(*data) << aileron
<< elevator
<< rudder
......@@ -30,7 +30,7 @@ RadioCalibrationData::RadioCalibrationData(const QVector<float> &aileron,
RadioCalibrationData::RadioCalibrationData(const RadioCalibrationData &other)
:QObject()
{
data = new QVector<QVector<float> >(*other.data);
data = new QVector<QVector<uint16_t> >(*other.data);
}
RadioCalibrationData::~RadioCalibrationData()
......@@ -38,7 +38,7 @@ RadioCalibrationData::~RadioCalibrationData()
delete data;
}
const float* RadioCalibrationData::operator [](int i) const
const uint16_t* RadioCalibrationData::operator [](int i) const
{
if (i < data->size()) {
return (*data)[i].constData();
......@@ -47,7 +47,7 @@ const float* RadioCalibrationData::operator [](int i) const
return NULL;
}
const QVector<float>& RadioCalibrationData::operator ()(const int i) const throw(std::out_of_range)
const QVector<uint16_t>& RadioCalibrationData::operator ()(const int i) const throw(std::out_of_range)
{
if ((i < data->size()) && (i >=0)) {
return (*data)[i];
......
......@@ -36,6 +36,8 @@ This file is part of the QGROUNDCONTROL project
#include <QString>
#include <stdexcept>
#include <stdint.h>
/**
@brief Class to hold the calibration data.
......@@ -48,12 +50,12 @@ class RadioCalibrationData : public QObject
public:
explicit RadioCalibrationData();
RadioCalibrationData(const RadioCalibrationData&);
RadioCalibrationData(const QVector<float>& aileron,
const QVector<float>& elevator,
const QVector<float>& rudder,
const QVector<float>& gyro,
const QVector<float>& pitch,
const QVector<float>& throttle);
RadioCalibrationData(const QVector<uint16_t>& aileron,
const QVector<uint16_t>& elevator,
const QVector<uint16_t>& rudder,
const QVector<uint16_t>& gyro,
const QVector<uint16_t>& pitch,
const QVector<uint16_t>& throttle);
~RadioCalibrationData();
enum RadioElement {
......@@ -65,33 +67,33 @@ public:
THROTTLE
};
const float* operator[](int i) const;
const uint16_t* operator[](int i) const;
#ifdef _MSC_VER
const QVector<float>& operator()(int i) const;
const QVector<uint16_t>& operator()(int i) const;
#else
const QVector<float>& operator()(int i) const throw(std::out_of_range);
const QVector<uint16_t>& operator()(int i) const throw(std::out_of_range);
#endif
void set(int element, int index, float value) {
(*data)[element][index] = value;
}
public slots:
void setAileron(int index, float value) {
void setAileron(int index, uint16_t value) {
set(AILERON, index, value);
}
void setElevator(int index, float value) {
void setElevator(int index, uint16_t value) {
set(ELEVATOR, index, value);
}
void setRudder(int index, float value) {
void setRudder(int index, uint16_t value) {
set(RUDDER, index, value);
}
void setGyro(int index, float value) {
void setGyro(int index, uint16_t value) {
set(GYRO, index, value);
}
void setPitch(int index, float value) {
void setPitch(int index, uint16_t value) {
set(PITCH, index, value);
}
void setThrottle(int index, float value) {
void setThrottle(int index, uint16_t value) {
set(THROTTLE, index, value);
}
......@@ -100,7 +102,7 @@ public:
QString toString(const RadioElement element) const;
protected:
QVector<QVector<float> > *data;
QVector<QVector<uint16_t> > *data;
void init(const QVector<float>& aileron,
const QVector<float>& elevator,
......
......@@ -43,12 +43,12 @@ RadioCalibrationWindow::RadioCalibrationWindow(QWidget *parent) :
connect(transmit, SIGNAL(clicked()), this, SLOT(send()));
connect(get, SIGNAL(clicked()), this, SLOT(request()));
connect(aileron, SIGNAL(setpointChanged(int,float)), radio, SLOT(setAileron(int,float)));
connect(elevator, SIGNAL(setpointChanged(int,float)), radio, SLOT(setElevator(int,float)));
connect(rudder, SIGNAL(setpointChanged(int,float)), radio, SLOT(setRudder(int,float)));
connect(gyro, SIGNAL(setpointChanged(int,float)), radio, SLOT(setGyro(int,float)));
connect(pitch, SIGNAL(setpointChanged(int,float)), radio, SLOT(setPitch(int,float)));
connect(throttle, SIGNAL(setpointChanged(int,float)), radio, SLOT(setThrottle(int,float)));
connect(aileron, SIGNAL(setpointChanged(int,uint16_t)), radio, SLOT(setAileron(int,uint16_t)));
connect(elevator, SIGNAL(setpointChanged(int,uint16_t)), radio, SLOT(setElevator(int,uint16_t)));
connect(rudder, SIGNAL(setpointChanged(int,uint16_t)), radio, SLOT(setRudder(int,uint16_t)));
connect(gyro, SIGNAL(setpointChanged(int,uint16_t)), radio, SLOT(setGyro(int,uint16_t)));
connect(pitch, SIGNAL(setpointChanged(int,uint16_t)), radio, SLOT(setPitch(int,uint16_t)));
connect(throttle, SIGNAL(setpointChanged(int,uint16_t)), radio, SLOT(setThrottle(int,uint16_t)));
setUASId(0);
}
......
......@@ -44,6 +44,8 @@ This file is part of the QGROUNDCONTROL project
#include <QtXml>
#include <QTextStream>
#include <stdint.h>
#include "AirfoilServoCalibrator.h"
#include "SwitchCalibrator.h"
#include "CurveCalibrator.h"
......
......@@ -38,17 +38,17 @@ SwitchCalibrator::SwitchCalibrator(QString titleString, QWidget *parent) :
void SwitchCalibrator::setDefault()
{
defaultPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
defaultPulseWidth->setText(QString::number(logExtrema()));
emit setpointChanged(0, logExtrema());
}
void SwitchCalibrator::setToggled()
{
toggledPulseWidth->setText(QString::number(static_cast<double>(logExtrema())));
toggledPulseWidth->setText(QString::number(logExtrema()));
emit setpointChanged(1, logExtrema());
}
void SwitchCalibrator::set(const QVector<float> &data)
void SwitchCalibrator::set(const QVector<uint16_t> &data)
{
if (data.size() == 2) {
defaultPulseWidth->setText(QString::number(data[0]));
......
......@@ -49,7 +49,7 @@ class SwitchCalibrator : public AbstractCalibrator
public:
explicit SwitchCalibrator(QString title=QString(), QWidget *parent = 0);
void set(const QVector<float> &data);
void set(const QVector<uint16_t> &data);
protected slots:
void setDefault();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment