Skip to content
Permalink
Browse files

.

  • Loading branch information
ri
ri committed Nov 11, 2019
1 parent 332a2e8 commit 46cd6c51745b2beef3e5bc70008ab8f3f143f636
Showing with 52 additions and 61 deletions.
  1. +10 −2 gui/RotatorWidget.cpp
  2. +1 −0 gui/RotatorWidget.h
  3. +1 −1 gui/ui/rotator.ui
  4. +6 −0 rotator.json
  5. +32 −57 utils/Rotator.cpp
  6. +2 −1 utils/Rotator.h
@@ -13,6 +13,7 @@ RotatorWidget::RotatorWidget(QWidget *parent) : QDockWidget(parent) {
SLOT(stateSocketChangedSlot(QAbstractSocket::SocketState)));
connect(&m_rotator, SIGNAL(updatedState(const QString &)), this,
SLOT(updatedStateSlot(const QString &)));
connect(ui.buttonSendLine, SIGNAL(clicked()), this, SLOT(sendLine()));
}

RotatorWidget::~RotatorWidget() {
@@ -33,6 +34,13 @@ void RotatorWidget::stateSocketChangedSlot(QAbstractSocket::SocketState socketSt
}

void RotatorWidget::updatedStateSlot(const QString &line) {
ui.lineEditAzimuth->setText(QString("%1").arg(qRadiansToDegrees(m_rotator.getAngle(0)), 7, 'f', 2));
ui.lineEditElevation->setText(QString("%1").arg(qRadiansToDegrees(m_rotator.getAngle(1)), 7, 'f', 2));
ui.lineEditAzimuth->setText(
QString("%1").arg(qRadiansToDegrees(m_rotator.getAngle(0)), 7, 'f', 2));
ui.lineEditElevation->setText(
QString("%1").arg(qRadiansToDegrees(m_rotator.getAngle(1)), 7, 'f', 2));
qWarning() << line;
}

void RotatorWidget::sendLine() {
m_rotator.writeLine(ui.lineEdit->text());
}
@@ -20,6 +20,7 @@ class RotatorWidget : public QDockWidget {
private slots:
void stateSocketChangedSlot(QAbstractSocket::SocketState socketState);
void updatedStateSlot(const QString &line);
void sendLine();
};

#endif /* ROTATOR_WIDGET_H_ */
@@ -240,7 +240,7 @@
<widget class="QLineEdit" name="lineEdit"/>
</item>
<item>
<widget class="QPushButton" name="pushButton_2">
<widget class="QPushButton" name="buttonSendLine">
<property name="text">
<string>Send</string>
</property>
@@ -2,6 +2,12 @@
"name": "zc702",
"host": "192.168.1.5",
"port": 4533,
"init": [
"w AW0,-65 AW1,64 AW2,255 AW3,0 AW4,8192 AW5,11 AW6,400 AW7,15 AW8,50",
"w AC",
"w EW0,-82 EW1,79 EW2,255 EW3,0 EW4,4096 EW5,11 EW6,400 EW7,15 EW8,50",
"w EC"
],
"azm": {
"pwmHoming": -25.5,
"pwmMin": 25.0,
@@ -1,6 +1,7 @@

#include "Rotator.h"
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QtMath>
@@ -11,8 +12,8 @@ Rotator::Rotator() {

connect(this, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));

m_timerSlowId = startTimer(3000);
m_timerFastId = startTimer(200);
m_timerSlowId = startTimer(5000);
m_timerFastId = startTimer(1000);
}

Rotator::~Rotator() {
@@ -21,10 +22,10 @@ Rotator::~Rotator() {

void Rotator::timerEvent(QTimerEvent *event) {
if (event->timerId() == m_timerSlowId) {
requestConfigSlot();
// requestConfigSlot();
reconnect();
} else if (event->timerId() == m_timerFastId) {
requestPosition();
// requestPosition();
}
}

@@ -81,7 +82,9 @@ void Rotator::acceptConfigRegister(uint index, uint addr, int value) {

void Rotator::writeLine(const QString &line) {
if (isOpen() && isWritable()) {
write(("w " + line).toUtf8());
write((line + '\n').toUtf8());
qWarning() << (line + '\n');
flush();
}
}

@@ -134,41 +137,6 @@ void Rotator::readyReadSlot() {
}

emit updatedState(m_stateLine);
// if (m_stateLine.contains("state:")) {
// m_stateLine = m_stateLine.remove("state:");
// QStringList list = m_stateLine.split(QChar(','));
// if (list.count() >= 14) {
// uint position = 0;
// for (size_t i = 0; i < 2; i++) {
// m_mode[i] = static_cast<ControllerMode>(list.at(position++).toUInt(&ok));
// m_error[i] =
// static_cast<ControllerError>(list.at(position++).toUInt(&ok));
// m_currentSensor[i] = list.at(position++).toUInt(&ok);
// m_diag[i] = list.at(position++).toUInt(&ok);
// m_pwm[i] = (qreal)list.at(position++).toUInt(&ok) / 2.55;
// uint ina = list.at(position++).toUInt(&ok) & 0x01;
// uint inb = list.at(position++).toUInt(&ok) & 0x01;
// m_direction[i] = ina | (inb << 1);
// m_angle[i] = (qreal)list.at(position++).toInt(&ok) / -4096.0 * M_PI;
// m_endstop[i] = list.at(position++).toUInt(&ok) > 0;
// }
// }
// }
// else if (m_stateLine.contains("config:")) {
// m_stateLine = m_stateLine.remove("config:");
// QStringList list = m_stateLine.split(QChar(','));
// if (list.count() >= 12) {
// uint position = 0;
// for (size_t i = 0; i < 2; i++) {
// m_pwmHoming[i] = (qreal)list.at(position++).toInt(&ok) / 2.55;
// m_pwmMin[i] = (qreal)list.at(position++).toInt(&ok) / 2.55;
// m_pwmMax[i] = (qreal)list.at(position++).toInt(&ok) / 2.55;
// m_angleMin[i] = (qreal)list.at(position++).toInt(&ok) / 4096.0 * M_PI;
// m_angleMax[i] = (qreal)list.at(position++).toInt(&ok) / 4096.0 * M_PI;
// m_tolerance[i] = (qreal)list.at(position++).toInt(&ok) / 4096.0 * M_PI;
// }
// }
// }
}
}

@@ -293,20 +261,20 @@ qreal Rotator::getTolerance(uint index) {

void Rotator::setMotion(uint index, qreal value) {
int pwm = qRound(value * 2.55);
writeLine(QString("set %1 motion %2\n").arg(index).arg(pwm));
writeLine(QString("w set %1 motion %2\n").arg(index).arg(pwm));
}

void Rotator::setModePid(uint index, int kp, int ki, int kd) {
writeLine(QString("set %1 pid %2,%3,%4\n").arg(index).arg(kp).arg(ki).arg(kd));
writeLine(QString("w set %1 pid %2,%3,%4\n").arg(index).arg(kp).arg(ki).arg(kd));
}

void Rotator::setTarget(uint index, qreal angle) {
int value = qRound(-4096.0 * angle / M_PI);
writeLine(QString("set %1 target %2\n").arg(index).arg(value));
writeLine(QString("w set %1 target %2\n").arg(index).arg(value));
}

void Rotator::setModeDefault(uint index) {
writeLine(QString("set %1 default\n").arg(index));
writeLine(QString("w set %1 default\n").arg(index));
}

void Rotator::setModeHoming(uint index) {
@@ -318,61 +286,61 @@ void Rotator::clearError(uint index) {
}

void Rotator::requestConfigSlot() {
writeLine(QString("AR0 AR1 AR2 AR3 AR4 AR5 AR6 AR7 AR8 \n"));
writeLine(QString("ER0 ER1 ER2 ER3 ER4 ER5 ER6 ER7 ER8 \n"));
writeLine(QString("GE GS \n"));
writeLine(QString("w AR0 AR1 AR2 AR3 AR4 AR5 AR6 AR7 AR8 \n"));
writeLine(QString("w ER0 ER1 ER2 ER3 ER4 ER5 ER6 ER7 ER8 \n"));
writeLine(QString("w GE GS \n"));
}

void Rotator::requestPosition() {
writeLine(QString("AZ EL \n"));
writeLine(QString("w AZ EL \n"));
}

void Rotator::setPwmHoming(uint index, qreal value) {
writeLine(
QString("%1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('0').arg(qRound(value * 2.55)));
QString("w %1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('0').arg(qRound(value * 2.55)));
}

void Rotator::setPwmMin(uint index, qreal value) {
writeLine(
QString("%1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('1').arg(qRound(value * 2.55)));
QString("w %1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('1').arg(qRound(value * 2.55)));
}

void Rotator::setPwmMax(uint index, qreal value) {
writeLine(
QString("%1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('2').arg(qRound(value * 2.55)));
QString("w %1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('2').arg(qRound(value * 2.55)));
}

void Rotator::setAngleMin(uint index, qreal value) {
writeLine(QString("%1%2,%3 \n")
writeLine(QString("w %1%2,%3 \n")
.arg(index == 0 ? "AW" : "EW")
.arg('3')
.arg(qRound(4096.0 * value / M_PI)));
}

void Rotator::setAngleMax(uint index, qreal value) {
writeLine(QString("%1%2,%3 \n")
writeLine(QString("w %1%2,%3 \n")
.arg(index == 0 ? "AW" : "EW")
.arg('4')
.arg(qRound(4096.0 * value / M_PI)));
}

void Rotator::setTolerance(uint index, qreal value) {
writeLine(QString("%1%2,%3 \n")
writeLine(QString("w %1%2,%3 \n")
.arg(index == 0 ? "AW" : "EW")
.arg('5')
.arg(qRound(4096.0 * value / M_PI)));
}

void Rotator::setKp(uint index, int value) {
writeLine(QString("%1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('6').arg(value));
writeLine(QString("w %1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('6').arg(value));
}

void Rotator::setKi(uint index, int value) {
writeLine(QString("%1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('7').arg(value));
writeLine(QString("w %1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('7').arg(value));
}

void Rotator::setKd(uint index, int value) {
writeLine(QString("%1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('8').arg(value));
writeLine(QString("w %1%2,%3 \n").arg(index == 0 ? "AW" : "EW").arg('8').arg(value));
}

void Rotator::setConfig(uint index, qreal pwmHoming, qreal pwmMin, qreal pwmMax, qreal angleMin,
@@ -432,6 +400,13 @@ void Rotator::readSettings(const QString &fileName) {
QJsonDocument jsonDoc = QJsonDocument::fromJson(text.toUtf8());
QJsonObject jsonObject = jsonDoc.object();

m_initList.clear();
value = jsonObject.value("init");
QJsonArray jsonArray = value.toArray();
for (const auto &item: jsonArray) {
m_initList.append(item.toString());
}

value = jsonObject.value("azm");
readConfig(0, value.toObject());
clearError(0);
@@ -14,7 +14,8 @@ class Rotator : public QTcpSocket {
static const QString DEFAULT_HOST;
QHostAddress m_host;
quint16 m_port;

QStringList m_initList;

typedef enum {
StatusUnknown = 0x00,
StatusIdle = 0x01,

0 comments on commit 46cd6c5

Please sign in to comment.
You can’t perform that action at this time.