Browse Source

Add code to servoControler class

test
nasi 3 years ago
parent
commit
06427c64e5
  1. 46
      Servo/src/ServoController.cpp
  2. 1
      Test/MainWindow.h
  3. 44
      Test/MainWindow.h.autosave

46
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)
@ -76,7 +75,6 @@ void ServoController::init()
{
_modbusWrapper.init();
_modbusWrapper.connectToDevice(initiateConfig());
}
/*************************************************************************************************/
@ -112,44 +110,31 @@ void ServoController::sector(double startAngle, double stopAngle, double speed)
/*************************************************************************************************/
double ServoController::getSpeed()
{
double speed;
QVector<quint16> 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<quint16> 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<quint16> 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<quint16> 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<quint16> 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);
}

1
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

44
Test/MainWindow.h.autosave

@ -1,44 +0,0 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#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<quint16> 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
Loading…
Cancel
Save