update/import/export parameters
Signed-off-by: matt <matt@matthewgong.com>
This commit is contained in:
+170
-7
@@ -2,6 +2,110 @@
|
||||
#include "./ui_mainwindow.h"
|
||||
#include <QLibrary>
|
||||
#include <QHostAddress>
|
||||
#include <QFileDialog>
|
||||
|
||||
void MainWindow::scan_param()
|
||||
{
|
||||
const rtwCAPI_ModelMappingStaticInfo *sm = (*getmap_func)();
|
||||
if (sm)
|
||||
{
|
||||
//unsigned int n = rtwCAPI_GetNumBlockParametersFromStaticMap(sm);
|
||||
unsigned int m = rtwCAPI_GetNumModelParametersFromStaticMap(sm);
|
||||
ui->tableWidget->setRowCount(512);
|
||||
QStringList hdr;
|
||||
hdr.push_back(tr("Parameter"));
|
||||
hdr.push_back(tr("Value"));
|
||||
ui->tableWidget->setHorizontalHeaderLabels(hdr);
|
||||
int cur = 0;
|
||||
|
||||
rtwCAPI_ModelParameters const *prm = rtwCAPI_GetModelParametersFromStaticMap(sm);
|
||||
rtwCAPI_DataTypeMap const *dtm = rtwCAPI_GetDataTypeMapFromStaticMap(sm);
|
||||
rtwCAPI_DimensionMap const *dmm = rtwCAPI_GetDimensionMapFromStaticMap(sm);
|
||||
uint_T const *dam = rtwCAPI_GetDimensionArrayFromStaticMap(sm);
|
||||
rtwCAPI_ModelMappingInfo *MMI = &(rtmGetDataMapInfo(this->m).mmi);
|
||||
void **da = rtwCAPI_GetDataAddressMap(MMI);
|
||||
for (unsigned int i = 0; i < m; ++i)
|
||||
{
|
||||
const char *name = rtwCAPI_GetModelParameterName(prm, i);
|
||||
int idx = rtwCAPI_GetModelParameterAddrIdx(prm, i);
|
||||
uint16_t dti = rtwCAPI_GetModelParameterDataTypeIdx(prm, i);
|
||||
uint16_t dmi = rtwCAPI_GetModelParameterDimensionIdx(prm, i);
|
||||
uint8_t ss = rtwCAPI_GetDataTypeSLId(dtm, dti);
|
||||
uint16_t dai = rtwCAPI_GetDimArrayIndex(dmm, dmi);
|
||||
uint8_t nd = rtwCAPI_GetNumDims(dmm, dmi);
|
||||
uint16_t n = 1;
|
||||
for (int j = 0; j < nd; ++j)
|
||||
{
|
||||
n *= dam[dai + j];
|
||||
}
|
||||
for (int j = 0; j < n; ++j)
|
||||
{
|
||||
QString param_name = QString::fromLatin1(name);
|
||||
if (j>0)
|
||||
{
|
||||
param_name = param_name+QString("(%1)").arg(j);
|
||||
}
|
||||
QString param_value;
|
||||
switch (ss)
|
||||
{
|
||||
case SS_DOUBLE:
|
||||
{
|
||||
double *d = (double *)da[idx];
|
||||
param_value = QString("%1").arg(d[j]);
|
||||
}
|
||||
break;
|
||||
case SS_SINGLE:
|
||||
{
|
||||
float *s = (float *)da[idx];
|
||||
param_value = QString("%1").arg(s[j]);
|
||||
}
|
||||
break;
|
||||
case SS_INT8:
|
||||
{
|
||||
int8_T *c = (int8_T *)da[idx];
|
||||
param_value = QString("%1").arg(c[j]);
|
||||
}
|
||||
break;
|
||||
case SS_INT16:
|
||||
{
|
||||
int16_T *h = (int16_T *)da[idx];
|
||||
param_value = QString("%1").arg(h[j]);
|
||||
}
|
||||
break;
|
||||
case SS_INT32:
|
||||
{
|
||||
int32_T *I = (int32_T *)da[idx];
|
||||
param_value = QString("%1").arg(I[j]);
|
||||
}
|
||||
break;
|
||||
case SS_UINT8:
|
||||
{
|
||||
uint8_T *c = (uint8_T *)da[idx];
|
||||
param_value = QString("%1").arg(c[j]);
|
||||
}
|
||||
break;
|
||||
case SS_UINT16:
|
||||
{
|
||||
uint16_T *h = (uint16_T *)da[idx];
|
||||
param_value = QString("%1").arg(h[j]);
|
||||
}
|
||||
break;
|
||||
case SS_UINT32:
|
||||
{
|
||||
uint32_T *I = (uint32_T *)da[idx];
|
||||
param_value = QString("%1").arg(I[j]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
QTableWidgetItem *newItem = new QTableWidgetItem(param_name);
|
||||
ui->tableWidget->setItem(cur, 0, newItem);
|
||||
newItem = new QTableWidgetItem(param_value);
|
||||
ui->tableWidget->setItem(cur++, 1, newItem);
|
||||
}
|
||||
}
|
||||
ui->tableWidget->setRowCount(cur);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setup_param(const QVector<QString> &head, const QVector<double> &onecase)
|
||||
@@ -126,16 +230,20 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
getmap_func = &SIL_GetCAPIStaticMap;
|
||||
u = &SIL_U;
|
||||
y = &SIL_Y;
|
||||
m = (RT_MODEL_SIL_T *)SIL_M;
|
||||
X0 = ::X0;
|
||||
Att0 = ::Att0;
|
||||
hground = &::hground;
|
||||
}
|
||||
|
||||
ui->pushButton->setText(QString("Fail"));
|
||||
ui->pushButton_start->setText(QString("Fail"));
|
||||
stage = 0;
|
||||
|
||||
if (init_func && step_func && u && y && getmap_func && X0 && Att0 && hground)
|
||||
{
|
||||
(*init_func)();
|
||||
scan_param();
|
||||
|
||||
ui->lineEditLat->setText(QString("%1").arg(X0[0]));
|
||||
ui->lineEditLon->setText(QString("%1").arg(X0[1]));
|
||||
ui->lineEditAlt->setText(QString("%1").arg(*hground));
|
||||
@@ -145,7 +253,7 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
qgc_sock = new QUdpSocket(this);
|
||||
if (qgc_sock->bind(QHostAddress::LocalHost, 6061))
|
||||
{
|
||||
ui->pushButton->setText(QString("Start"));
|
||||
ui->pushButton_start->setText(QString("Start"));
|
||||
stage = 1;
|
||||
}
|
||||
}
|
||||
@@ -184,9 +292,20 @@ void MainWindow::onFire()
|
||||
{
|
||||
if (stage == 1)
|
||||
{
|
||||
bool ok;
|
||||
real_T val;
|
||||
QVector<QString> head;
|
||||
QVector<double> onecase;
|
||||
|
||||
int n = ui->tableWidget->rowCount();
|
||||
for (int i=0;i<n;++i)
|
||||
{
|
||||
head.push_back(ui->tableWidget->item(i,0)->text());
|
||||
onecase.push_back(ui->tableWidget->item(i,1)->text().toDouble());
|
||||
}
|
||||
|
||||
setup_param(head, onecase);
|
||||
|
||||
double val;
|
||||
bool ok;
|
||||
val = ui->lineEditLat->text().toDouble(&ok);
|
||||
if (ok)
|
||||
{
|
||||
@@ -212,7 +331,6 @@ void MainWindow::onFire()
|
||||
Att0[2] = val/57.3;
|
||||
}
|
||||
|
||||
(*init_func)();
|
||||
seq = 0;
|
||||
|
||||
timer200Hz = new QTimer(this);
|
||||
@@ -220,12 +338,57 @@ void MainWindow::onFire()
|
||||
timer200Hz->start(5);
|
||||
|
||||
stage = 2;
|
||||
ui->pushButton->setText(QString("Launch"));
|
||||
ui->pushButton_start->setText(QString("Launch"));
|
||||
}
|
||||
else if (stage == 2)
|
||||
{
|
||||
u->launch_trigger = 1.0;
|
||||
ui->pushButton->setText(QString("Flying"));
|
||||
ui->pushButton_start->setText(QString("Flying"));
|
||||
stage = 3;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onExport()
|
||||
{
|
||||
QString filename = QFileDialog::getSaveFileName(this, tr("Save to"), QString(), tr("Text File (*.txt)"));
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
QFile data(filename);
|
||||
if (data.open(QFile::WriteOnly | QFile::Truncate)) {
|
||||
QTextStream out(&data);
|
||||
int n = ui->tableWidget->rowCount();
|
||||
for (int i=0;i<n;++i)
|
||||
{
|
||||
out << ui->tableWidget->item(i,0)->text() << ',';
|
||||
out << ui->tableWidget->item(i,1)->text() << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onImport()
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(this, tr("Save to"), QString(), tr("Text File (*.txt)"));
|
||||
if (!filename.isEmpty())
|
||||
{
|
||||
QFile data(filename);
|
||||
if (data.open(QFile::ReadOnly)) {
|
||||
QTextStream stream(&data);
|
||||
QString line;
|
||||
while (stream.readLineInto(&line)) {
|
||||
QStringList items = line.split(QString(","));
|
||||
int n = ui->tableWidget->rowCount();
|
||||
for (int i=0;i<n;++i)
|
||||
{
|
||||
if (ui->tableWidget->item(i,0)->text() == items[0])
|
||||
{
|
||||
ui->tableWidget->item(i,1)->setText(items[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@ public:
|
||||
public slots:
|
||||
void update200Hz();
|
||||
void onFire();
|
||||
void onExport();
|
||||
void onImport();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
@@ -50,6 +52,7 @@ private:
|
||||
real_T gear_height;
|
||||
|
||||
void setup_param(const QVector<QString> &head, const QVector<double> &onecase);
|
||||
void scan_param(void);
|
||||
|
||||
uint8_t seq;
|
||||
|
||||
|
||||
+138
-56
@@ -6,70 +6,118 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>311</width>
|
||||
<height>187</height>
|
||||
<width>800</width>
|
||||
<height>800</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>800</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Proj41 HIL</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,1">
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Latitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEditLat"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Longitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEditLon"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>altitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEditAlt"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>heading</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEditHdg"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="rowCount">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<row/>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Latitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEditLat"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Longitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEditLon"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>altitude</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEditAlt"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>heading</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEditHdg"/>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QPushButton" name="pushButton_import">
|
||||
<property name="text">
|
||||
<string>Import</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<widget class="QPushButton" name="pushButton_export">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
<string>Export</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_start">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
@@ -77,8 +125,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>311</width>
|
||||
<height>22</height>
|
||||
<width>800</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
@@ -87,23 +135,57 @@
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButton</sender>
|
||||
<signal>pressed()</signal>
|
||||
<sender>pushButton_start</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>onFire()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>155</x>
|
||||
<y>153</y>
|
||||
<x>317</x>
|
||||
<y>759</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>255</x>
|
||||
<y>181</y>
|
||||
<x>376</x>
|
||||
<y>775</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>pushButton_import</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>onImport()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>229</x>
|
||||
<y>732</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>246</x>
|
||||
<y>771</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>pushButton_export</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>MainWindow</receiver>
|
||||
<slot>onExport()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>487</x>
|
||||
<y>735</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>516</x>
|
||||
<y>775</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<slots>
|
||||
<slot>onFire()</slot>
|
||||
<slot>onImport()</slot>
|
||||
<slot>onExport()</slot>
|
||||
</slots>
|
||||
</ui>
|
||||
|
||||
Reference in New Issue
Block a user