Skip to content

Commit

Permalink
Saving PID angle state
Browse files Browse the repository at this point in the history
  • Loading branch information
seedship committed Mar 24, 2021
1 parent 3482215 commit 29f8553
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 125 deletions.
14 changes: 12 additions & 2 deletions include/uavGS/PID/Widgets/PIDConfigPlot.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
#include "uavAP/FlightControl/Controller/PIDController/PIDHandling.h"
#include <cpsCore/Aggregation/AggregatableObject.hpp>

#include <uavGS/PID/PIDConfigurator.h>
#include "uavGS/ParameterSets/NamedLineEdit.h"
#include "uavGS/ParameterSets/NamedCheckbox.h"
#include "uavGS/PID/PIDConfigurator.h"

namespace Ui
{
class PIDConfigPlot;
}

class PIDConfigPlot : public QWidget, public AggregatableObject<PIDConfigurator>
class PIDConfigPlot: public QWidget, public AggregatableObject<PIDConfigurator>
{
Q_OBJECT

Expand Down Expand Up @@ -75,6 +77,14 @@ private slots:
on_send_clicked();

private:

NamedLineEdit* kp_;
NamedLineEdit* ki_;
NamedLineEdit* kd_;
NamedLineEdit* imax_;
NamedLineEdit* ff_;
bool angle_;

Ui::PIDConfigPlot* ui;
int key_;
QString title;
Expand Down
77 changes: 50 additions & 27 deletions src/PID/Widgets/PIDConfigPlot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,41 @@ PIDConfigPlot::setParams(PIDs pid, const Control::PIDParameters& params)
key_ = static_cast<int>(pid);
auto name = EnumMap<PIDs>::convert(pid);
ui->customPlot->setTitle(name);
//ui->customPlot->setTname
title = QString::fromStdString(name);

// Set title and PID params
ui->kP->setText(QString::number(params.kp()));
ui->kP->setStyleSheet(QString("border: 1px solid gray; width: 60px; height:25px;"));
ui->kI->setText(QString::number(params.ki()));
ui->kI->setStyleSheet(QString("border: 1px solid gray; width: 60px; height:25px;"));
ui->kD->setText(QString::number(params.kd()));
ui->kD->setStyleSheet(QString("border: 1px solid gray; width: 60px; height:25px;"));
ui->IMax->setText(QString::number(params.imax()));
ui->IMax->setStyleSheet(QString("border: 1px solid gray; width: 60px; height:25px;"));
ui->FF->setText(QString::number(params.ff()));
ui->FF->setStyleSheet(QString("border: 1px solid gray; width: 60px; height:25px;"));
title = QString::fromStdString(name);
angle_ = params.isAngle.value;
// Maybe we want to automate this using the techniques from WidgetGeneric
kp_ = new NamedLineEdit(params.kp.id, this);
ki_ = new NamedLineEdit(params.ki.id, this);
kd_ = new NamedLineEdit(params.kd.id, this);
imax_ = new NamedLineEdit(params.imax.id, this);
ff_ = new NamedLineEdit(params.ff.id, this);

kp_->set(params.kp.value);
ki_->set(params.ki.value);
kd_->set(params.kd.value);
imax_->set(params.imax.value);
ff_->set(params.ff.value);

QString stylesheet = tr("border: 1px solid gray; height:25px;");

kp_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
ki_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
kd_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
ff_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
imax_->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
kp_->setStyleSheet(stylesheet);
ki_->setStyleSheet(stylesheet);
kd_->setStyleSheet(stylesheet);
ff_->setStyleSheet(stylesheet);
imax_->setStyleSheet(stylesheet);

ui->verticalLayout->insertWidget(1, ff_);
ui->verticalLayout->insertWidget(1, imax_);
ui->verticalLayout->insertWidget(1, kd_);
ui->verticalLayout->insertWidget(1, ki_);
ui->verticalLayout->insertWidget(1, kp_);
}

PIDConfigPlot::~PIDConfigPlot()
Expand Down Expand Up @@ -56,31 +78,31 @@ PIDConfigPlot::connect()
double
PIDConfigPlot::getkP()
{
return ui->kP->text().toDouble();
return kp_->getDouble();
}

double
PIDConfigPlot::getkI()
{
return ui->kI->text().toDouble();
return ki_->getDouble();
}

double
PIDConfigPlot::getkD()
{
return ui->kD->text().toDouble();;
return kd_->getDouble();;
}

double
PIDConfigPlot::getFF()
{
return ui->FF->text().toDouble();
return ff_->getDouble();
}

double
PIDConfigPlot::getIMax()
{
return ui->IMax->text().toDouble();
return imax_->getDouble();
}

void
Expand All @@ -92,42 +114,43 @@ PIDConfigPlot::resetGraph()
void
PIDConfigPlot::setkP(double kP)
{
ui->kP->setText(QString::number(kP));
kp_->set(kP);
}

void
PIDConfigPlot::setkI(double kI)
{
ui->kI->setText(QString::number(kI));
ki_->set(kI);
}

void
PIDConfigPlot::setkD(double kD)
{
ui->kD->setText(QString::number(kD));
kd_->set(kD);
}

void
PIDConfigPlot::setFF(double ff)
{
ui->FF->setText(QString::number(ff));
ff_->set(ff);
}

void
PIDConfigPlot::setIMax(double iMax)
{
ui->IMax->setText(QString::number(iMax));
imax_->set(iMax);
}

void
PIDConfigPlot::on_send_clicked()
{
Control::PIDParameters a;
a.kp = ui->kP->text().toDouble();
a.ki = ui->kI->text().toDouble();
a.kd = ui->kD->text().toDouble();
a.ff = ui->FF->text().toDouble();
a.imax = ui->IMax->text().toDouble();
a.kp = getkP();
a.ki = getkI();
a.kd = getkD();
a.ff = getFF();
a.imax = getIMax();
a.isAngle = angle_;
PIDTuning tune;
tune.pid = key_;
tune.params = a;
Expand Down
97 changes: 3 additions & 94 deletions src/PID/Widgets/PIDConfigPlot.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>218</width>
<height>366</height>
<width>92</width>
<height>204</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -49,100 +49,9 @@
<height>160</height>
</size>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2"/>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="spacing">
<number>0</number>
</property>
<item row="1" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QLabel" name="kILabel">
<property name="text">
<string>I Gain</string>
</property>
</widget>
</item>
<item row="3" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QLabel" name="FFLabel">
<property name="text">
<string>FF Gain</string>
</property>
</widget>
</item>
<item row="2" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QLabel" name="kDLabel">
<property name="text">
<string>D Gain</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="IMax">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="FF">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="4" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QLabel" name="IMaxLabel">
<property name="text">
<string>Max I</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="kD">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="kP">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="0" column="0" alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QLabel" name="kPLabel">
<property name="text">
<string>P Gain</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="kI">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="send">
<property name="text">
Expand Down
2 changes: 0 additions & 2 deletions src/ParameterSets/WidgetGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
// Created by mirco on 30.06.20.
//

#include <uavGS/ParameterSets/NamedLineEdit.h>
#include "uavGS/ParameterSets/WidgetGeneric.h"
#include "uavGS/ParameterSets/WidgetPopulator.h"
#include "uavGS/ParameterSets/WidgetTreeParser.h"


Expand Down

0 comments on commit 29f8553

Please sign in to comment.