Skip to content

Commit

Permalink
Changed names and made them consistent. This also removes them from I…
Browse files Browse the repository at this point in the history
…RAM.
  • Loading branch information
Stefan de Bruijn committed Sep 19, 2024
1 parent b0b194a commit 109950d
Show file tree
Hide file tree
Showing 16 changed files with 74 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
General setup of the VFD is covered in https://files.danfoss.com/download/Drives/doc_B_1_MG28E902.pdf
*/

#include "DanfossSpindle.h"
#include "DanfossVLT2800Protocol.h"
#include "../../Platform.h"

#include <algorithm>
Expand All @@ -23,23 +23,23 @@

namespace Spindles {
namespace VFD {
void DanfossVLT2800::set_speed_command(uint32_t dev_speed, VFDDetail::ModbusCommand& data) {
void DanfossVLT2800Protocol::set_speed_command(uint32_t dev_speed, VFDDetail::ModbusCommand& data) {
// Cache received speed
cachedSpindleState.speed = dev_speed;

// Write speed and direction from cache to VFD
writeVFDState(cachedSpindleState, data);
}

void DanfossVLT2800::direction_command(SpindleState mode, VFDDetail::ModbusCommand& data) {
void DanfossVLT2800Protocol::direction_command(SpindleState mode, VFDDetail::ModbusCommand& data) {
// Cache received direction
cachedSpindleState.state = mode;

// Write speed and direction from cache to VFD
writeVFDState(cachedSpindleState, data);
}

VFDDetail::response_parser DanfossVLT2800::get_current_speed(VFDDetail::ModbusCommand& data) {
VFDDetail::response_parser DanfossVLT2800Protocol::get_current_speed(VFDDetail::ModbusCommand& data) {
data.tx_length = 6; // including automatically set client_id, excluding crc
data.rx_length = 3 + 2; // excluding crc

Expand All @@ -61,7 +61,7 @@ namespace Spindles {
};
}

VFDDetail::response_parser DanfossVLT2800::get_status_ok_and_init(VFDDetail::ModbusCommand& data, bool init) {
VFDDetail::response_parser DanfossVLT2800Protocol::get_status_ok_and_init(VFDDetail::ModbusCommand& data, bool init) {
data.tx_length = 6; // including automatically set client_id, excluding crc
data.rx_length = 5; // excluding crc

Expand All @@ -76,7 +76,7 @@ namespace Spindles {
return [](const uint8_t* response, VFDSpindle* vfd, VFDDetail* detail) -> bool {
// The VFD is responsive. Initialize speeds.

auto df = static_cast<DanfossVLT2800*>(detail);
auto df = static_cast<DanfossVLT2800Protocol*>(detail);
vfd->setupSpeeds(df->_maxFrequency);

return true;
Expand Down Expand Up @@ -110,7 +110,7 @@ namespace Spindles {

// The VLT2800 expects speed, direction and enable to be sent together at all times.
// This function uses a combined cached spindle state that includes the speed and sends it to the VFD.
void DanfossVLT2800::writeVFDState(combinedSpindleState spindle, ModbusCommand& data) {
void DanfossVLT2800Protocol::writeVFDState(combinedSpindleState spindle, ModbusCommand& data) {
SpindleControl cword;
cword.flags.coasting_stop = 1;
cword.flags.dc_braking_stop = 1;
Expand Down Expand Up @@ -160,7 +160,7 @@ namespace Spindles {
data.msg[10] = spindle.speed >> 8;
}
namespace {
SpindleFactory::DependentInstanceBuilder<VFDSpindle, DanfossVLT2800> registration("DanfossVLT2800");
SpindleFactory::DependentInstanceBuilder<VFDSpindle, DanfossVLT2800Protocol> registration("DanfossVLT2800");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Spindles {
namespace VFD {
class DanfossVLT2800 : public VFDDetail {
class DanfossVLT2800Protocol : public VFDDetail {
union SpindleStatus {
struct {
bool control_ready : 1; // bit 00 = 0: "" | Bit = 1: "Control ready"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
Remove power before changing bits.
*/

#include "H100Spindle.h"
#include "H100Protocol.h"

#include <algorithm> // std::max

namespace Spindles {
namespace VFD {
void H100Spindle::direction_command(SpindleState mode, ModbusCommand& data) {
void H100Protocol::direction_command(SpindleState mode, ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 6;
data.rx_length = 6;
Expand Down Expand Up @@ -45,7 +45,7 @@ namespace Spindles {
}
}

void H100Spindle::set_speed_command(uint32_t dev_speed, ModbusCommand& data) {
void H100Protocol::set_speed_command(uint32_t dev_speed, ModbusCommand& data) {
data.tx_length = 6;
data.rx_length = 6;

Expand All @@ -69,7 +69,7 @@ namespace Spindles {
}

// This gets data from the VFD. It does not set any values
VFDDetail::response_parser H100Spindle::initialization_sequence(int index, ModbusCommand& data) {
VFDDetail::response_parser H100Protocol::initialization_sequence(int index, ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 6;
data.rx_length = 5;
Expand Down Expand Up @@ -98,7 +98,7 @@ namespace Spindles {
log_info("VFD: Max speed:" << (value / 10 * 60) << "rpm");

// Set current RPM value? Somewhere?
auto h100 = static_cast<H100Spindle*>(detail);
auto h100 = static_cast<H100Protocol*>(detail);
h100->_maxFrequency = value;

return true;
Expand All @@ -117,7 +117,7 @@ namespace Spindles {
log_info("VFD: Min speed:" << (value / 10 * 60) << "rpm");

// Set current RPM value? Somewhere?
auto h100 = static_cast<H100Spindle*>(detail);
auto h100 = static_cast<H100Protocol*>(detail);
h100->_minFrequency = value;

h100->updateRPM(vfd);
Expand All @@ -130,7 +130,7 @@ namespace Spindles {
return nullptr;
}

void H100Spindle::updateRPM(VFDSpindle* vfd) {
void H100Protocol::updateRPM(VFDSpindle* vfd) {
if (_minFrequency > _maxFrequency) {
_minFrequency = _maxFrequency;
}
Expand All @@ -147,7 +147,7 @@ namespace Spindles {
log_info("VFD: VFD settings read: Freq range(" << _minFrequency << " , " << _maxFrequency << ")]");
}

VFDDetail::response_parser H100Spindle::get_current_speed(ModbusCommand& data) {
VFDDetail::response_parser H100Protocol::get_current_speed(ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
// [01] [04] [0000] [0002] -- output frequency
data.tx_length = 6;
Expand All @@ -172,7 +172,7 @@ namespace Spindles {

// Configuration registration
namespace {
SpindleFactory::DependentInstanceBuilder<VFDSpindle, H100Spindle> registration("H100");
SpindleFactory::DependentInstanceBuilder<VFDSpindle, H100Protocol> registration("H100");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Spindles {
namespace VFD {
class H100Spindle : public VFDDetail {
class H100Protocol : public VFDDetail {
private:
int reg = 0;

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
managed to piece together.
*/

#include "H2ASpindle.h"
#include "H2AProtocol.h"

namespace Spindles {
namespace VFD {
void H2A::direction_command(SpindleState mode, ModbusCommand& data) {
void H2AProtocol::direction_command(SpindleState mode, ModbusCommand& data) {
data.tx_length = 6;
data.rx_length = 6;

Expand All @@ -30,7 +30,7 @@ namespace Spindles {
data.msg[5] = (mode == SpindleState::Ccw) ? 0x02 : (mode == SpindleState::Cw ? 0x01 : 0x06);
}

void H2A::set_speed_command(uint32_t dev_speed, ModbusCommand& data) {
void H2AProtocol::set_speed_command(uint32_t dev_speed, ModbusCommand& data) {
// NOTE: H2A inverters are a-symmetrical. You set the speed in 1/100
// percentages, and you get the speed in RPM. So, we need to convert
// the RPM using maxRPM to a percentage. See MD document for details.
Expand All @@ -55,7 +55,7 @@ namespace Spindles {
data.msg[5] = speed & 0xFF;
}

VFDDetail::response_parser H2A::initialization_sequence(int index, ModbusCommand& data) {
VFDDetail::response_parser H2AProtocol::initialization_sequence(int index, ModbusCommand& data) {
if (index == -1) {
data.tx_length = 6;
data.rx_length = 8;
Expand All @@ -79,7 +79,7 @@ namespace Spindles {
vfd->setupSpeeds(maxRPM); // The speed is given directly in RPM
vfd->_slop = 300; // 300 RPM

static_cast<H2A*>(detail)->_maxRPM = uint32_t(maxRPM);
static_cast<H2AProtocol*>(detail)->_maxRPM = uint32_t(maxRPM);

log_info("H2A spindle initialized at " << maxRPM << " RPM");

Expand All @@ -90,7 +90,7 @@ namespace Spindles {
}
}

VFDDetail::response_parser H2A::get_current_speed(ModbusCommand& data) {
VFDDetail::response_parser H2AProtocol::get_current_speed(ModbusCommand& data) {
data.tx_length = 6;
data.rx_length = 8;

Expand All @@ -109,7 +109,7 @@ namespace Spindles {
};
}

VFDDetail::response_parser H2A::get_current_direction(ModbusCommand& data) {
VFDDetail::response_parser H2AProtocol::get_current_direction(ModbusCommand& data) {
data.tx_length = 6;
data.rx_length = 6;

Expand All @@ -129,7 +129,7 @@ namespace Spindles {

// Configuration registration
namespace {
SpindleFactory::DependentInstanceBuilder<VFDSpindle, H2A> registration("H2A");
SpindleFactory::DependentInstanceBuilder<VFDSpindle, H2AProtocol> registration("H2A");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Spindles {
namespace VFD {
class H2A : public VFDDetail {
class H2AProtocol : public VFDDetail {
protected:
void direction_command(SpindleState mode, ModbusCommand& data) override;
void set_speed_command(uint32_t dev_speed, ModbusCommand& data) override;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
If the frequency is -say- 25 Hz, Huanyang wants us to send 2500 (eg. 25.00 Hz).
*/

#include "HuanyangSpindle.h"
#include "HuanyangProtocol.h"

#include <algorithm> // std::max

Expand All @@ -145,7 +145,7 @@ namespace Spindles {
// Baud rate is set in the PD164 setting. If it is not 9600, add, for example,
// _baudrate = 19200;

void Huanyang::direction_command(SpindleState mode, ModbusCommand& data) {
void HuanyangProtocol::direction_command(SpindleState mode, ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 4;
data.rx_length = 4;
Expand All @@ -167,7 +167,7 @@ namespace Spindles {
}
}

void Huanyang::set_speed_command(uint32_t dev_speed, ModbusCommand& data) {
void HuanyangProtocol::set_speed_command(uint32_t dev_speed, ModbusCommand& data) {
// The units for setting Huanyang speed are Hz * 100. For a 2-pole motor,
// RPM is Hz * 60 sec/min. The maximum possible speed is 400 Hz so
// 400 * 60 = 24000 RPM.
Expand Down Expand Up @@ -208,7 +208,7 @@ namespace Spindles {
}

// This gets data from the VFS. It does not set any values
VFDDetail::response_parser Huanyang::initialization_sequence(int index, ModbusCommand& data) {
VFDDetail::response_parser HuanyangProtocol::initialization_sequence(int index, ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 6;
data.rx_length = 6;
Expand All @@ -228,7 +228,7 @@ namespace Spindles {
uint16_t value = (response[4] << 8) | response[5];

// Set current RPM value? Somewhere?
auto huanyang = static_cast<Huanyang*>(detail);
auto huanyang = static_cast<HuanyangProtocol*>(detail);
huanyang->_maxFrequency = value;
return true;
};
Expand All @@ -240,7 +240,7 @@ namespace Spindles {
uint16_t value = (response[4] << 8) | response[5];

// Set current RPM value? Somewhere?
auto huanyang = static_cast<Huanyang*>(detail);
auto huanyang = static_cast<HuanyangProtocol*>(detail);
huanyang->_minFrequency = value;

log_info("Huanyang PD0011, PD005 Freq range ("
Expand All @@ -257,7 +257,7 @@ namespace Spindles {
uint16_t value = (response[4] << 8) | response[5];

// Set current RPM value? Somewhere?
auto huanyang = static_cast<Huanyang*>(detail);
auto huanyang = static_cast<HuanyangProtocol*>(detail);
huanyang->_maxRpmAt50Hz = value;

log_info("Huanyang PD144 Rated RPM @ 50Hz:" << huanyang->_maxRpmAt50Hz);
Expand All @@ -279,7 +279,7 @@ namespace Spindles {

return [](const uint8_t* response, VFDSpindle* vfd, VFDDetail* detail) -> bool {
uint8_t value = response[4]; // Single byte response.
auto huanyang = static_cast<Huanyang*>(detail);
auto huanyang = static_cast<HuanyangProtocol*>(detail);
// Sanity check. We expect something like 2 or 4 poles.
if (value <= 4 && value >= 2) {
// Set current RPM value? Somewhere?
Expand All @@ -303,7 +303,7 @@ namespace Spindles {
return [](const uint8_t* response, VFDSpindle* vfd, VFDDetail* detail) -> bool {
uint16_t value = (response[4] << 8) | response[5];

auto huanyang = static_cast<Huanyang*>(detail);
auto huanyang = static_cast<HuanyangProtocol*>(detail);
log_info("Huanyang PD014 Accel:" << float(value) / 10.0);
return true;
};
Expand All @@ -314,7 +314,7 @@ namespace Spindles {
return [](const uint8_t* response, VFDSpindle* vfd, VFDDetail* detail) -> bool {
uint16_t value = (response[4] << 8) | response[5];

auto huanyang = static_cast<Huanyang*>(detail);
auto huanyang = static_cast<HuanyangProtocol*>(detail);
log_info("Huanyang PD015 Decel:" << float(value) / 10.0);
return true;
};
Expand All @@ -327,7 +327,7 @@ namespace Spindles {
return nullptr;
}

void Huanyang::updateRPM(VFDSpindle* vfd) {
void HuanyangProtocol::updateRPM(VFDSpindle* vfd) {
/*
PD005 = 400.00 ; max frequency the VFD will allow
MaxRPM = PD005 * 60; but see PD176
Expand All @@ -348,7 +348,7 @@ namespace Spindles {
vfd->_slop = std::max(_maxFrequency / 40, 1);
}

VFDDetail::response_parser Huanyang::get_status_ok(ModbusCommand& data) {
VFDDetail::response_parser HuanyangProtocol::get_status_ok(ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 6;
data.rx_length = 6;
Expand All @@ -368,7 +368,7 @@ namespace Spindles {
return [](const uint8_t* response, VFDSpindle* vfd, VFDDetail* detail) -> bool { return true; };
}

VFDDetail::response_parser Huanyang::get_current_speed(ModbusCommand& data) {
VFDDetail::response_parser HuanyangProtocol::get_current_speed(ModbusCommand& data) {
// NOTE: data length is excluding the CRC16 checksum.
data.tx_length = 6;
data.rx_length = 6;
Expand All @@ -391,7 +391,7 @@ namespace Spindles {

// Configuration registration
namespace {
SpindleFactory::DependentInstanceBuilder<VFDSpindle, Huanyang> registration("Huanyang");
SpindleFactory::DependentInstanceBuilder<VFDSpindle, HuanyangProtocol> registration("Huanyang");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Spindles {
namespace VFD {
class Huanyang : public VFDDetail {
class HuanyangProtocol : public VFDDetail {
private:
int reg = 0;

Expand Down
Loading

0 comments on commit 109950d

Please sign in to comment.