diff --git a/Servo/src/ServoController.cpp b/Servo/src/ServoController.cpp index 2075f8a..63cec08 100644 --- a/Servo/src/ServoController.cpp +++ b/Servo/src/ServoController.cpp @@ -1,6 +1,5 @@ #include "ServoController.h" - ServoController::ServoController() { } @@ -15,7 +14,6 @@ ModbusConfig ServoController::initiateConfig() _config.stopBits = QSerialPort::OneStop; _config.responseTime = 2000; return _config; - } /*************************************************************************************************/ @@ -31,6 +29,7 @@ void ServoController::enableDrive() apply(); } +/*************************************************************************************************/ void ServoController::setStartStop(bool start) { if(start) @@ -57,7 +56,7 @@ void ServoController::setStopAngle(double angle) /*************************************************************************************************/ void ServoController::setSpeed(double speed) { - _modbusWrapper.setSingleRegister(SRV_AZIMUTH_SPEED_REG, static_cast(speed*SRV_SPEED_FACTOR)); + _modbusWrapper.setSingleRegister(SRV_AZIMUTH_SPEED_REG, static_cast(speed * SRV_SPEED_FACTOR)); } /*************************************************************************************************/ @@ -76,7 +75,6 @@ void ServoController::init() { _modbusWrapper.init(); _modbusWrapper.connectToDevice(initiateConfig()); - } /*************************************************************************************************/ @@ -100,7 +98,7 @@ void ServoController::resetAzimuth() /*************************************************************************************************/ void ServoController::fix(double angle) { - changeMode(angle, angle, 5/6.0); + changeMode(angle, angle, 5 / 6.0); } /*************************************************************************************************/ @@ -112,44 +110,31 @@ void ServoController::sector(double startAngle, double stopAngle, double speed) /*************************************************************************************************/ double ServoController::getSpeed() { - double speed; - QVector speedVector; - speedVector = _modbusWrapper.getHoldingRegister(SRV_AZIMUTH_SPEED_REG,1); - speed = speedVector[0] / SRV_SPEED_FACTOR; - return speed; + auto speedVector = _modbusWrapper.getHoldingRegister(SRV_AZIMUTH_SPEED_REG, 1); + return (speedVector[0] / SRV_SPEED_FACTOR); } /*************************************************************************************************/ double ServoController::getStopAngle() { - double speed; - QVector speedVector1, speedVector2; - speedVector1 = _modbusWrapper.getHoldingRegister(SRV_STOP_ANGLE_INT_PART_REG,1); - speedVector2 = _modbusWrapper.getHoldingRegister(SRV_STOP_ANGLE_FRAC_PART_REG,1); - speed = (speedVector1[0] + speedVector2[0]) / SRV_ANGLE_FACTOR; - return speed; + auto speedVector1 = _modbusWrapper.getHoldingRegister(SRV_STOP_ANGLE_INT_PART_REG, 1); + auto speedVector2 = _modbusWrapper.getHoldingRegister(SRV_STOP_ANGLE_FRAC_PART_REG, 1); + return ((speedVector1[0] + speedVector2[0]) / SRV_ANGLE_FACTOR); } /*************************************************************************************************/ double ServoController::getStartAngle() { - double speed; - QVector speedVector1, speedVector2; - speedVector1 = _modbusWrapper.getHoldingRegister(SRV_START_ANGLE_INT_PART_REG,1); - speedVector2 = _modbusWrapper.getHoldingRegister(SRV_START_ANGLE_FRAC_PART_REG,1); - speed = (speedVector1[0] + speedVector2[0]) / SRV_ANGLE_FACTOR; - return speed; + auto speedVector1 = _modbusWrapper.getHoldingRegister(SRV_START_ANGLE_INT_PART_REG, 1); + auto speedVector2 = _modbusWrapper.getHoldingRegister(SRV_START_ANGLE_FRAC_PART_REG, 1); + return ((speedVector1[0] + speedVector2[0]) / SRV_ANGLE_FACTOR); } /*************************************************************************************************/ double ServoController::getAngleOffset() { - double angleOffset; - QVector angleOffsetVector; - angleOffsetVector = _modbusWrapper.getHoldingRegister(SRV_ZERO_OFFSET_ANGLE,1); - angleOffset = angleOffsetVector[0] / SRV_ANGLE_FACTOR; - return angleOffset; - + auto angleOffsetVector = _modbusWrapper.getHoldingRegister(SRV_ZERO_OFFSET_ANGLE, 1); + return (angleOffsetVector[0] / SRV_ANGLE_FACTOR); } /*************************************************************************************************/ @@ -161,13 +146,8 @@ void ServoController::setAngleOffset(double offset) /*************************************************************************************************/ double ServoController::getAzimuth() { - double azimuth; - QVector azimuthVector; - azimuthVector = _modbusWrapper.getHoldingRegister(SRV_AZIMUTH_REG,1); - azimuth = azimuthVector[0] / SRV_ANGLE_FACTOR; - return azimuth; - + auto azimuthVector = _modbusWrapper.getHoldingRegister(SRV_AZIMUTH_REG,1); + return (azimuthVector[0] / SRV_ANGLE_FACTOR); } - diff --git a/Test/MainWindow.h b/Test/MainWindow.h index e959567..af50f2c 100644 --- a/Test/MainWindow.h +++ b/Test/MainWindow.h @@ -38,6 +38,7 @@ private slots: void on_writeSingleRegister_clicked(); void on_writeMultiRegister_clicked(); void on_fix_clicked(); + void on_pushButton_clicked(); }; #endif //MAINWINDOW_H diff --git a/Test/MainWindow.h.autosave b/Test/MainWindow.h.autosave deleted file mode 100644 index af50f2c..0000000 --- a/Test/MainWindow.h.autosave +++ /dev/null @@ -1,44 +0,0 @@ -#ifndef MAINWINDOW_H -#define MAINWINDOW_H - -#include - -#include "ModbusWrapper.h" -#include "ModbusConfig.h" -#include "ServoController.h" - -QT_BEGIN_NAMESPACE -namespace Ui { class MainWindow; -} -QT_END_NAMESPACE - -class MainWindow : public QMainWindow -{ - Q_OBJECT - -private: - Ui::MainWindow* ui; - ModbusWrapper modbusWrapper; - ModbusConfig configDevice; - ServoController _servoControler; - -public: - MainWindow(QWidget* parent = nullptr); - ~MainWindow(); - void printCoilsDataFromClient(QBitArray uiCoils); - void printRegisterDataFromClient(QVector uiHoldingRegisters); - - //uncrustify off -private slots: - void on_connect_clicked(); - //uncrustify on - void on_readButton_clicked(); - void on_writeSingleCoil_clicked(); - void on_writeMultiCoil_clicked(); - void on_writeSingleRegister_clicked(); - void on_writeMultiRegister_clicked(); - void on_fix_clicked(); - void on_pushButton_clicked(); -}; - -#endif //MAINWINDOW_H