Commit c4874a48 authored by Bryan Godbolt's avatar Bryan Godbolt

ready to test load save and transmit for rc calibration

parent da1a7153
<!-- Values are ordered low center high --> <!-- Values are ordered low center high -->
<channels> <channels>
<threeSetpoint name="Aileron" number="1">1.0, 1.5, 2.0</threeSetpoint> <threeSetpoint name="Aileron" number="1">1000.0, 1500.0, 2000.0</threeSetpoint>
<twoSetpoint name="Gyro" number="3">2.0, 1.0</twoSetpoint> <threeSetpoint name="Elevator" number="2">1000.0, 1500.0, 2000.0</threeSetpoint>
<fiveSetpoint name="Pitch" number="5">1.0, 1.25, 1.5, 1.75, 2.0</fiveSetpoint> <threeSetpoint name="Rudder" number="4">1000.0, 1500.0, 2000.0</threeSetpoint>
<twoSetpoint name="Gyro" number="5">2000.0, 1000.0</twoSetpoint>
<fiveSetpoint name="Pitch" number="6">1000.0, 1250.0, 1500.0, 1750.0, 2000.0</fiveSetpoint>
<fiveSetpoint name="Throttle" number="3">1000.0, 1250.0, 1500.0, 1750.0, 2000.0</fiveSetpoint>
</channels> </channels>
...@@ -149,6 +149,11 @@ void OpalLink::writeBytes(const char *bytes, qint64 length) ...@@ -149,6 +149,11 @@ void OpalLink::writeBytes(const char *bytes, qint64 length)
mavlink_msg_radio_calibration_decode(&msg, &radio); mavlink_msg_radio_calibration_decode(&msg, &radio);
qDebug() << "RADIO CALIBRATION RECEIVED"; qDebug() << "RADIO CALIBRATION RECEIVED";
qDebug() << "AILERON: " << radio.aileron[0] << " " << radio.aileron[1] << " " << radio.aileron[2]; qDebug() << "AILERON: " << radio.aileron[0] << " " << radio.aileron[1] << " " << radio.aileron[2];
qDebug() << "ELEVATOR: " << radio.elevator[0] << " " << radio.elevator[1] << " " << radio.elevator[2];
qDebug() << "RUDDER: " << radio.rudder[0] << " " << radio.rudder[1] << " " << radio.rudder[2];
qDebug() << "GYRO: " << radio.gyro[0] << " " << radio.gyro[1];
qDebug() << "PITCH: " << radio.pitch[0] << radio.pitch[1] << radio.pitch[2] << radio.pitch[3] << radio.pitch[4];
qDebug() << "THROTTLE: " << radio.throttle[0] << radio.throttle[1] << radio.throttle[2] << radio.throttle[3] << radio.throttle[4];
} }
break; break;
#endif #endif
......
...@@ -92,16 +92,9 @@ void CurveCalibrator::set(const QVector<float> &data) ...@@ -92,16 +92,9 @@ void CurveCalibrator::set(const QVector<float> &data)
{ {
if (data.size() == 5) if (data.size() == 5)
{ {
// delete setpoints;
// QVector<double> dataDouble;
for (int i=0; i<data.size(); ++i) for (int i=0; i<data.size(); ++i)
setpoints->replace(i, static_cast<double>(data[i])); setpoints->replace(i, static_cast<double>(data[i]));
// setpoints = new QVector<double>(dataDouble);
curve->setPen(QPen(QColor(QString("lime"))));
curve->setData(*positions, *setpoints); curve->setData(*positions, *setpoints);
curve->attach(plot);
plot->replot(); plot->replot();
} }
else else
......
...@@ -58,3 +58,13 @@ const QVector<float>& RadioCalibrationData::operator ()(int i) const ...@@ -58,3 +58,13 @@ const QVector<float>& RadioCalibrationData::operator ()(int i) const
// This is not good. If it is ever used after being returned it will cause a crash // This is not good. If it is ever used after being returned it will cause a crash
// return QVector<float>(); // return QVector<float>();
} }
QString RadioCalibrationData::toString(RadioElement element) const
{
QString s;
foreach (float f, (*data)[element])
{
s += QString::number(f) + ", ";
}
return s.mid(0, s.length()-2);
}
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include <QDebug> #include <QDebug>
#include <QVector> #include <QVector>
#include <QString>
class RadioCalibrationData : public QObject class RadioCalibrationData : public QObject
...@@ -43,6 +44,10 @@ public slots: ...@@ -43,6 +44,10 @@ public slots:
void setPitch(int index, float value) {set(PITCH, index, value);} void setPitch(int index, float value) {set(PITCH, index, value);}
void setThrottle(int index, float value) {set(THROTTLE, index, value);} void setThrottle(int index, float value) {set(THROTTLE, index, value);}
public:
/// Creates a comman seperated list of the values for a particular element
QString toString(const RadioElement element) const;
protected: protected:
QVector<QVector<float> > *data; QVector<QVector<float> > *data;
......
...@@ -84,7 +84,80 @@ void RadioCalibrationWindow::setChannel(int ch, float raw, float normalized) ...@@ -84,7 +84,80 @@ void RadioCalibrationWindow::setChannel(int ch, float raw, float normalized)
void RadioCalibrationWindow::saveFile() void RadioCalibrationWindow::saveFile()
{ {
qDebug() << __FILE__ << __LINE__ << "SAVE TO FILE"; QString fileName(QFileDialog::getSaveFileName(this,
tr("Save RC Calibration"),
"settings/",
tr("XML Files (*.xml)")));
if (fileName.isEmpty())
return;
QDomDocument *rcConfig = new QDomDocument();
QFile rcFile(fileName);
if (rcFile.exists())
{
rcFile.remove();
}
if (!rcFile.open(QFile::WriteOnly | QFile::Text))
{
qDebug() << __FILE__ << __LINE__ << "could not open" << rcFile.fileName() << "for writing";
return;
}
QDomElement root;
rcConfig->appendChild(root=rcConfig->createElement("channels"));
QDomElement e;
QDomText t;
// Aileron
e = rcConfig->createElement("threeSetpoint");
e.setAttribute("name", "Aileron");
e.setAttribute("number", "1");
t = rcConfig->createTextNode(radio->toString(RadioCalibrationData::AILERON));
e.appendChild(t);
root.appendChild(e);
// Elevator
e = rcConfig->createElement("threeSetpoint");
e.setAttribute("name", "Elevator");
e.setAttribute("number", "2");
t = rcConfig->createTextNode(radio->toString(RadioCalibrationData::ELEVATOR));
e.appendChild(t);
root.appendChild(e);
// Rudder
e = rcConfig->createElement("threeSetpoint");
e.setAttribute("name", "Rudder");
e.setAttribute("number", "4");
t = rcConfig->createTextNode(radio->toString(RadioCalibrationData::RUDDER));
e.appendChild(t);
root.appendChild(e);
// Gyro Mode/Gain
e = rcConfig->createElement("twoSetpoint");
e.setAttribute("name", "Gyro");
e.setAttribute("number", "5");
t = rcConfig->createTextNode(radio->toString(RadioCalibrationData::GYRO));
e.appendChild(t);
root.appendChild(e);
// Throttle
e = rcConfig->createElement("fiveSetpoint");
e.setAttribute("name", "Throttle");
e.setAttribute("number", "3");
t = rcConfig->createTextNode(radio->toString(RadioCalibrationData::THROTTLE));
e.appendChild(t);
root.appendChild(e);
// Pitch
e = rcConfig->createElement("fiveSetpoint");
e.setAttribute("name", "Pitch");
e.setAttribute("number", "6");
t = rcConfig->createTextNode(radio->toString(RadioCalibrationData::PITCH));
e.appendChild(t);
root.appendChild(e);
QTextStream out(&rcFile);
const int IndentSize = 4;
rcConfig->save(out, IndentSize);
rcFile.close();
} }
void RadioCalibrationWindow::loadFile() void RadioCalibrationWindow::loadFile()
...@@ -121,6 +194,7 @@ void RadioCalibrationWindow::loadFile() ...@@ -121,6 +194,7 @@ void RadioCalibrationWindow::loadFile()
return; return;
} }
rcFile.close();
QDomElement root = rcConfig->documentElement(); QDomElement root = rcConfig->documentElement();
if (root.tagName() != "channels") { if (root.tagName() != "channels") {
qDebug() << __FILE__ << __LINE__ << "This is not a Radio Calibration xml file"; qDebug() << __FILE__ << __LINE__ << "This is not a Radio Calibration xml file";
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include <QFileDialog> #include <QFileDialog>
#include <QFile> #include <QFile>
#include <QtXml> #include <QtXml>
#include <QTextStream>
#include "AirfoilServoCalibrator.h" #include "AirfoilServoCalibrator.h"
#include "SwitchCalibrator.h" #include "SwitchCalibrator.h"
......
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