|
|
@ -1,13 +1,16 @@ |
|
|
|
#include "ServoController.h" |
|
|
|
|
|
|
|
ModbusConfig ServoController::initiateConfig() |
|
|
|
ModbusConfig ServoController::initiateConfig(QString serialPort) |
|
|
|
{ |
|
|
|
ModbusConfig _config; |
|
|
|
_config.baud =QSerialPort::Baud19200; |
|
|
|
_config.baud = QSerialPort::Baud19200; |
|
|
|
_config.parity = QSerialPort::EvenParity; |
|
|
|
_config.dataBits = QSerialPort::Data8; |
|
|
|
_config.stopBits = QSerialPort::OneStop; |
|
|
|
_config.responseTime = 2000; |
|
|
|
_config.serialPort = serialPort; |
|
|
|
_config.clientAddress = 1; |
|
|
|
|
|
|
|
return _config; |
|
|
|
} |
|
|
|
|
|
|
@ -35,20 +38,25 @@ void ServoController::setStartStop(bool start) |
|
|
|
void ServoController::setStartAngle(double angle) |
|
|
|
{ |
|
|
|
_modbusWrapper.setSingleRegister(SRV_START_ANGLE_INT_PART_REG, static_cast<quint16>(angle)); |
|
|
|
_modbusWrapper.setSingleRegister(SRV_START_ANGLE_FRAC_PART_REG, static_cast<quint16>((angle - (static_cast<int>(angle))) * 100)); |
|
|
|
_modbusWrapper.setSingleRegister(SRV_START_ANGLE_FRAC_PART_REG, |
|
|
|
static_cast<quint16>((angle - (static_cast<int>(angle))) * |
|
|
|
100)); |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
void ServoController::setStopAngle(double angle) |
|
|
|
{ |
|
|
|
_modbusWrapper.setSingleRegister(SRV_STOP_ANGLE_INT_PART_REG, static_cast<quint16>(angle)); |
|
|
|
_modbusWrapper.setSingleRegister(SRV_STOP_ANGLE_FRAC_PART_REG, static_cast<quint16>((angle - (static_cast<int>(angle))) * 100)); |
|
|
|
_modbusWrapper.setSingleRegister(SRV_STOP_ANGLE_FRAC_PART_REG, |
|
|
|
static_cast<quint16>((angle - (static_cast<int>(angle))) * |
|
|
|
100)); |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
void ServoController::setSpeed(double speed) |
|
|
|
{ |
|
|
|
_modbusWrapper.setSingleRegister(SRV_AZIMUTH_SPEED_REG, static_cast<quint16>(speed * SRV_SPEED_FACTOR)); |
|
|
|
_modbusWrapper.setSingleRegister(SRV_AZIMUTH_SPEED_REG, |
|
|
|
static_cast<quint16>(speed * SRV_SPEED_FACTOR)); |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
@ -63,10 +71,10 @@ void ServoController::changeMode(double startAngle, double stopAngle, double spe |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
void ServoController::init() |
|
|
|
void ServoController::init(QString serialPort) |
|
|
|
{ |
|
|
|
_modbusWrapper.init(); |
|
|
|
_modbusWrapper.connectToDevice(initiateConfig()); |
|
|
|
_modbusWrapper.connectToDevice(initiateConfig(serialPort)); |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
@ -103,6 +111,7 @@ void ServoController::sector(double startAngle, double stopAngle, double speed) |
|
|
|
double ServoController::getSpeed() |
|
|
|
{ |
|
|
|
auto speedVector = _modbusWrapper.getHoldingRegister(SRV_AZIMUTH_SPEED_REG, 1); |
|
|
|
|
|
|
|
return (speedVector[0] / SRV_SPEED_FACTOR); |
|
|
|
} |
|
|
|
|
|
|
@ -111,6 +120,7 @@ double ServoController::getStopAngle() |
|
|
|
{ |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
@ -119,6 +129,7 @@ double ServoController::getStartAngle() |
|
|
|
{ |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
@ -126,18 +137,21 @@ double ServoController::getStartAngle() |
|
|
|
double ServoController::getAngleOffset() |
|
|
|
{ |
|
|
|
auto angleOffsetVector = _modbusWrapper.getHoldingRegister(SRV_ZERO_OFFSET_ANGLE, 1); |
|
|
|
|
|
|
|
return (angleOffsetVector[0] / SRV_ANGLE_FACTOR); |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
void ServoController::setAngleOffset(double offset) |
|
|
|
{ |
|
|
|
_modbusWrapper.setSingleRegister(SRV_ZERO_OFFSET_ANGLE, static_cast<quint16>(offset * SRV_ANGLE_FACTOR)); |
|
|
|
_modbusWrapper.setSingleRegister(SRV_ZERO_OFFSET_ANGLE, |
|
|
|
static_cast<quint16>(offset * SRV_ANGLE_FACTOR)); |
|
|
|
} |
|
|
|
|
|
|
|
/*************************************************************************************************/ |
|
|
|
double ServoController::getAzimuth() |
|
|
|
{ |
|
|
|
auto azimuthVector = _modbusWrapper.getHoldingRegister(SRV_AZIMUTH_REG, 1); |
|
|
|
|
|
|
|
return (azimuthVector[0] / SRV_ANGLE_FACTOR); |
|
|
|
} |
|
|
|