From 0f664b1427fa574315894eec6b460716d1c55e95 Mon Sep 17 00:00:00 2001 From: me Date: Tue, 16 Mar 2021 16:28:52 -0700 Subject: [PATCH 01/21] changing to EXTENDED type from GRBL type to prevent sender issues when running 1585 --- Grbl_Esp32/src/SettingsDefinitions.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Grbl_Esp32/src/SettingsDefinitions.cpp b/Grbl_Esp32/src/SettingsDefinitions.cpp index 340ecf1a..cb83afcc 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.cpp +++ b/Grbl_Esp32/src/SettingsDefinitions.cpp @@ -360,8 +360,8 @@ void make_settings() { spindle_enable_invert = new FlagSetting(GRBL, WG, NULL, "Spindle/Enable/Invert", DEFAULT_INVERT_SPINDLE_ENABLE_PIN, checkSpindleChange); // GRBL Non-numbered settings - startup_line_0 = new StringSetting(GRBL, WG, "N0", "GCode/Line0", "", checkStartupLine); - startup_line_1 = new StringSetting(GRBL, WG, "N1", "GCode/Line1", "", checkStartupLine); + startup_line_0 = new StringSetting(EXTENDED, WG, "N0", "GCode/Line0", "", checkStartupLine); + startup_line_1 = new StringSetting(EXTENDED, WG, "N1", "GCode/Line1", "", checkStartupLine); // GRBL Numbered Settings laser_mode = new FlagSetting(GRBL, WG, "32", "GCode/LaserMode", DEFAULT_LASER_MODE); From 28dcf0bd5176c952524a37cf759dff9fb9f5385a Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 06:02:17 -0700 Subject: [PATCH 02/21] need to override set_rpm --- .gitignore | 1 + Grbl_Esp32/src/Machine.h | 2 +- Grbl_Esp32/src/Spindles/Spindle.cpp | 5 + Grbl_Esp32/src/Spindles/Spindle.h | 1 + Grbl_Esp32/src/Spindles/TecoL510.cpp | 193 +++++++++++++++++++++++++++ Grbl_Esp32/src/Spindles/TecoL510.h | 45 +++++++ platformio.ini | 7 + 7 files changed, 253 insertions(+), 1 deletion(-) create mode 100644 Grbl_Esp32/src/Spindles/TecoL510.cpp create mode 100644 Grbl_Esp32/src/Spindles/TecoL510.h diff --git a/.gitignore b/.gitignore index 44cc0076..d11902c0 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ __vm/ *.suo Grbl_Esp32.ino.cpp /packages +Grbl_Esp32/src/Machine.h diff --git a/Grbl_Esp32/src/Machine.h b/Grbl_Esp32/src/Machine.h index 11ab8406..a684b000 100644 --- a/Grbl_Esp32/src/Machine.h +++ b/Grbl_Esp32/src/Machine.h @@ -8,7 +8,7 @@ // !!! For initial testing, start with test_drive.h which disables // all I/O pins // #include "Machines/atari_1020.h" -# include "Machines/test_drive.h" +# include "Machines/jesse_6pack.h" // !!! For actual use, change the line above to select a board // from Machines/, for example: diff --git a/Grbl_Esp32/src/Spindles/Spindle.cpp b/Grbl_Esp32/src/Spindles/Spindle.cpp index 7dfd8f6b..c783309b 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.cpp +++ b/Grbl_Esp32/src/Spindles/Spindle.cpp @@ -39,6 +39,7 @@ #include "BESCSpindle.h" #include "10vSpindle.h" #include "YL620Spindle.h" +#include "TecoL510.h" namespace Spindles { // An instance of each type of spindle is created here. @@ -53,6 +54,7 @@ namespace Spindles { BESC besc; _10v _10v; YL620 yl620; + L510 l510; void Spindle::select() { switch (static_cast(spindle_type->get())) { @@ -83,6 +85,9 @@ namespace Spindles { case SpindleType::YL620: spindle = &yl620; break; + case SpindleType::L510: + spindle = &l510; + break; case SpindleType::NONE: default: spindle = &null; diff --git a/Grbl_Esp32/src/Spindles/Spindle.h b/Grbl_Esp32/src/Spindles/Spindle.h index 200e99cd..ff2ea5d4 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.h +++ b/Grbl_Esp32/src/Spindles/Spindle.h @@ -39,6 +39,7 @@ enum class SpindleType : int8_t { _10V, H2A, YL620, + L510 }; #include "../Grbl.h" diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp new file mode 100644 index 00000000..3dd6de6e --- /dev/null +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -0,0 +1,193 @@ +#include "TecoL510.h" + +/* + TecoL510.cpp + + Part of Grbl_ESP32 + 2021 - Jesse Schoch + + Grbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Grbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Grbl. If not, see . + + WARNING!!!! + VFDs are very dangerous. They have high voltages and are very powerful + Remove power before changing bits. + + See TecoL510.md for details +*/ + +namespace Spindles { + L510::L510() : VFD() { + _baudrate = 9600; + _parity = Uart::Parity::None; + _max_rpm = 24000; + _max_freq = 40000; + } + + void L510::direction_command(SpindleState mode, ModbusCommand& data) { + // NOTE: data length is excluding the CRC16 checksum. + data.tx_length = 6; + data.rx_length = 6; + + data.msg[1] = 0x06; // WRITE + data.msg[2] = 0x25; // Command ID 0x2501 + data.msg[3] = 0x01; + data.msg[4] = 0x01; + if(mode == SpindleState::Ccw){ + data.msg[5] = 1; + }else{ + data.msg[5] = 0; + } + grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"sending dir: state: %d",mode; + } + + void L510::start_command(ModbusCommand& data){ + data.tx_length = 6; + data.rx_length = 6; + data.msg[1] = 0x06; + data.msg[2] = 0x25; + data.msg[3] = 0x01; + data.msg[4] = 0x00; + data.msg[5] = 0x01; + + } + + void L510::set_speed_command(uint32_t rpm, ModbusCommand& data) { + + // NOTE: data length is excluding the CRC16 checksum. + data.tx_length = 6; + data.rx_length = 6; + + // We have to know the max RPM before we can set the current RPM: + auto max_rpm = this->_max_rpm; + auto max_freq = this->_max_freq; + + // Assuming max frequncy is 400Hz + // Speed is in [0..40,000] + uint16_t speed = (uint16_t(rpm) * max_freq) / uint32_t(max_rpm); + if (speed < 0) { + speed = 0; + } + if (speed > 40000) { + speed = 40000; + } + + data.msg[1] = 0x06; // WRITE + data.msg[2] = 0x25; // Command ID 0x2502 + data.msg[3] = 0x02; + data.msg[4] = uint8_t(speed >> 8); // RPM + data.msg[5] = uint8_t(speed & 0xFF); + + grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"setting speed to: %d",speed); + } + uint16_t L510::rpm_to_frequency(uint32_t rpm){ + auto max_rpm = this->_max_rpm; + uint16_t freq = (uint32_t(rpm) * 40000L) / uint32_t(max_rpm); + return freq; + } + + uint32_t L510::freq_to_rpm(uint16_t freq){ + auto max_rpm = this->_max_rpm; + auto max_freq = this->_max_freq; + uint32_t rpm = (freq/max_freq)/max_rpm; + } + + VFD::response_parser L510::initialization_sequence(int index, ModbusCommand& data) { + if (index == -1) { + // NOTE: data length is excluding the CRC16 checksum. + data.tx_length = 6; + data.rx_length = 5; + + + // Send: + data.msg[1] = 0x03; // READ + data.msg[2] = 0x02; // 0x0203 = Get RPM + data.msg[3] = 0x03; + data.msg[4] = 0x00; // Read 1 value + data.msg[5] = 0x01; + + /* + // Hack to see if a known working register can be read + data.msg[1] = 0x03; // READ + data.msg[2] = 0x25; // 0x2523 = Get RPM + data.msg[3] = 0x23; + data.msg[4] = 0x00; // Read 1 value + data.msg[5] = 0x01; + */ + + + // Recv: ?? + + return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { + //uint16_t rpm = (uint16_t(response[4]) << 8) | uint16_t(response[5]); + //TODO remove hardcoding + //vfd->_max_rpm = rpm; + vfd->_max_rpm = 24000; + + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 spindle hardcoded 24000 %d ", vfd->_max_rpm); + + return true; + }; + } else { + return nullptr; + } + } + + VFD::response_parser L510::get_current_rpm(ModbusCommand& data) { + // NOTE: data length is excluding the CRC16 checksum. + data.tx_length = 6; + data.rx_length = 5; + + // Send: 01 03 700C 0002 + data.msg[1] = 0x03; // READ + data.msg[2] = 0x25; // 0x2523 = Get RPM + data.msg[3] = 0x23; + data.msg[4] = 0x00; // Read 1 value + data.msg[5] = 0x01; + + return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { + uint16_t freq = (response[3] << 8) | response[4]; + grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"current frequency: %d",freq); + + // Set current RPM value? Somewhere? + //vfd->_sync_rpm = vfd->freq_to_rpm(freq); + + //TODO: how do get access to the object I was in before wandering into this lambda? + // undo hardcoded garbage + vfd->_sync_rpm = (freq/40000)*24000; + return true; + }; + } + + VFD::response_parser L510::get_current_direction(ModbusCommand& data) { + // NOTE: data length is excluding the CRC16 checksum. + data.tx_length = 6; + data.rx_length = 6; + + // Send: 01 03 30 00 00 01 + data.msg[1] = 0x03; // READ + data.msg[2] = 0x25; // 0x2520 + data.msg[3] = 0x20; + data.msg[4] = 0x00; // Message ID + data.msg[5] = 0x01; + + // Receive: 01 03 00 02 00 02 + // ----- status + + // TODO: this doesn't seem to do anything in H2A + return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { + uint16_t got = (uint16_t(response[4]) << 8) | uint16_t(response[5]); + bool dir = bitRead(got,1); + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 dir %d", int(dir)); + return true; + }; + } +} \ No newline at end of file diff --git a/Grbl_Esp32/src/Spindles/TecoL510.h b/Grbl_Esp32/src/Spindles/TecoL510.h new file mode 100644 index 00000000..743139ea --- /dev/null +++ b/Grbl_Esp32/src/Spindles/TecoL510.h @@ -0,0 +1,45 @@ +#pragma once + +#include "VFDSpindle.h" + +/* + TecoL510.h + + Part of Grbl_ESP32 + 2021 - Jesse Schoch + + Grbl is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + Grbl is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + You should have received a copy of the GNU General Public License + along with Grbl. If not, see . + +*/ + +namespace Spindles { + class L510 : public VFD { + protected: + void direction_command(SpindleState mode, ModbusCommand& data) override; + void set_speed_command(uint32_t rpm, ModbusCommand& data) override; + + response_parser initialization_sequence(int index, ModbusCommand& data) override; + response_parser get_current_rpm(ModbusCommand& data) override; + response_parser get_current_direction(ModbusCommand& data) override; + response_parser get_status_ok(ModbusCommand& data) override { return nullptr; } + + // what is this, what should it do? + bool supports_actual_rpm() const override { return true; } + bool safety_polling() const override { return false; } + uint16_t rpm_to_frequency(uint32_t rpm); + uint32_t freq_to_rpm(uint16_t); + + public: + L510(); + uint16_t _max_freq; + }; +} diff --git a/platformio.ini b/platformio.ini index ddf3a854..a99cf2a3 100644 --- a/platformio.ini +++ b/platformio.ini @@ -70,3 +70,10 @@ build_type = debug lib_deps = TMCStepper@>=0.7.0,<1.0.0 ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 + + +[env:ota] +upload_protocol = espota +upload_port = 192.168.1.61 +lib_deps = + TMCStepper@>=0.7.0,<1.0.0 From 6c029d8f980fa2efc3f9c8b7921977b152416776 Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 06:29:07 -0700 Subject: [PATCH 03/21] trying set_rpm override --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 70 ++++++++++++++++++++++++++++ Grbl_Esp32/src/Spindles/TecoL510.h | 2 + 2 files changed, 72 insertions(+) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 3dd6de6e..85191605 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -190,4 +190,74 @@ namespace Spindles { return true; }; } + void start_spindle(){ + if(!spindle_started){ + // send start to VFD + ModbusCommand start_cmd; + start_cmd[0] = VFD_RS485_ADDR; + start_command(start_cmd); + if (xQueueSend(vfd_cmd_queue, &start_cmd, 0) != pdTRUE) { + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD Queue Full"); + } + + } + } + + uint32_t LF510::set_rpm(uint32_t rpm){ + if (!vfd_ok) { + return 0; + } + // Hack to start spindle running + SpindleState sstate = get_state(); + if(sstate != SpindleState::Disabled){ + start_spindle(); + } + // apply override + rpm = rpm * sys.spindle_speed_ovr / 100; // Scale by spindle speed override value (uint8_t percent) + + if (rpm != 0 && (rpm < _min_rpm || rpm > _max_rpm)) { + // NOTE: Don't add a info message here; this method is called from the stepper_pulse_func ISR method, so + // emitting debug information could crash the ESP32. + + rpm = constrain(rpm, _min_rpm, _max_rpm); + } + + // apply limits + // if ((_min_rpm >= _max_rpm) || (rpm >= _max_rpm)) { + // rpm = _max_rpm; + // } else if (rpm != 0 && rpm <= _min_rpm) { + // rpm = _min_rpm; + // } + + sys.spindle_speed = rpm; + + if (rpm == _current_rpm) { // prevent setting same RPM twice + return rpm; + } + +#ifdef VFD_DEBUG_MODE2 + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Setting spindle speed to %d rpm (%d, %d)", int(rpm), int(_min_rpm), int(_max_rpm)); +#endif + + _current_rpm = rpm; + + // TODO add the speed modifiers override, linearization, etc. + + ModbusCommand rpm_cmd; + rpm_cmd.msg[0] = VFD_RS485_ADDR; + + set_speed_command(rpm, rpm_cmd); + + // Sometimes sync_rpm is retained between different set_speed_command's. We don't want that - we want + // spindle sync to kick in after we set the speed. This forces that. + _sync_rpm = UINT32_MAX; + + rpm_cmd.critical = (rpm == 0); + + if (xQueueSend(vfd_cmd_queue, &rpm_cmd, 0) != pdTRUE) { + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD Queue Full"); + } + + return rpm; + } } \ No newline at end of file diff --git a/Grbl_Esp32/src/Spindles/TecoL510.h b/Grbl_Esp32/src/Spindles/TecoL510.h index 743139ea..23287234 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.h +++ b/Grbl_Esp32/src/Spindles/TecoL510.h @@ -37,6 +37,8 @@ namespace Spindles { bool safety_polling() const override { return false; } uint16_t rpm_to_frequency(uint32_t rpm); uint32_t freq_to_rpm(uint16_t); + uint32_t set_rpm(uint32_t rpm) override; + void start_spindle(); public: L510(); From ed459bd68ba0c95cfcd3ec8d7311d00e20cd4a9b Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 07:17:04 -0700 Subject: [PATCH 04/21] it turns on! --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 55 ++++++++++++++++------------ Grbl_Esp32/src/Spindles/TecoL510.h | 2 +- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 85191605..b5581459 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -33,6 +33,11 @@ namespace Spindles { } void L510::direction_command(SpindleState mode, ModbusCommand& data) { + // Note: The direction command is always called on M3,M4, and M5 + // This is where the spindle start/stop should be sent + + + // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; data.rx_length = 6; @@ -40,15 +45,23 @@ namespace Spindles { data.msg[1] = 0x06; // WRITE data.msg[2] = 0x25; // Command ID 0x2501 data.msg[3] = 0x01; - data.msg[4] = 0x01; - if(mode == SpindleState::Ccw){ - data.msg[5] = 1; - }else{ - data.msg[5] = 0; + data.msg[4] = 0x00; + switch(mode){ + case SpindleState::Disable: + //data.msg[4] = 0x00; + data.msg[5] = 0x00; + break; + case SpindleState::Cw: + data.msg[5] = 0x01; + break; + case SpindleState::Ccw: + data.msg[5] = 0x03; + break; } - grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"sending dir: state: %d",mode; + grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"sending dir: state: %d",mode); } + /* void L510::start_command(ModbusCommand& data){ data.tx_length = 6; data.rx_length = 6; @@ -59,6 +72,7 @@ namespace Spindles { data.msg[5] = 0x01; } + */ void L510::set_speed_command(uint32_t rpm, ModbusCommand& data) { @@ -97,7 +111,7 @@ namespace Spindles { uint32_t L510::freq_to_rpm(uint16_t freq){ auto max_rpm = this->_max_rpm; auto max_freq = this->_max_freq; - uint32_t rpm = (freq/max_freq)/max_rpm; + uint32_t rpm = (freq*max_rpm)/max_freq; } VFD::response_parser L510::initialization_sequence(int index, ModbusCommand& data) { @@ -109,28 +123,20 @@ namespace Spindles { // Send: data.msg[1] = 0x03; // READ - data.msg[2] = 0x02; // 0x0203 = Get RPM + data.msg[2] = 0x02; // 0x0203 = Get max rpm data.msg[3] = 0x03; data.msg[4] = 0x00; // Read 1 value data.msg[5] = 0x01; - /* - // Hack to see if a known working register can be read - data.msg[1] = 0x03; // READ - data.msg[2] = 0x25; // 0x2523 = Get RPM - data.msg[3] = 0x23; - data.msg[4] = 0x00; // Read 1 value - data.msg[5] = 0x01; - */ // Recv: ?? return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { - //uint16_t rpm = (uint16_t(response[4]) << 8) | uint16_t(response[5]); + uint32_t rpm = (response[3] << 8) | response[4]; //TODO remove hardcoding - //vfd->_max_rpm = rpm; - vfd->_max_rpm = 24000; + vfd->_max_rpm = rpm; + //vfd->_max_rpm = 24000; grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 spindle hardcoded 24000 %d ", vfd->_max_rpm); @@ -157,12 +163,9 @@ namespace Spindles { uint16_t freq = (response[3] << 8) | response[4]; grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"current frequency: %d",freq); - // Set current RPM value? Somewhere? - //vfd->_sync_rpm = vfd->freq_to_rpm(freq); + auto l510 = static_cast(vfd); - //TODO: how do get access to the object I was in before wandering into this lambda? - // undo hardcoded garbage - vfd->_sync_rpm = (freq/40000)*24000; + vfd->_sync_rpm = l510->freq_to_rpm(freq); return true; }; } @@ -190,6 +193,7 @@ namespace Spindles { return true; }; } + /* void start_spindle(){ if(!spindle_started){ // send start to VFD @@ -202,7 +206,9 @@ namespace Spindles { } } + */ + /* uint32_t LF510::set_rpm(uint32_t rpm){ if (!vfd_ok) { return 0; @@ -260,4 +266,5 @@ namespace Spindles { return rpm; } + */ } \ No newline at end of file diff --git a/Grbl_Esp32/src/Spindles/TecoL510.h b/Grbl_Esp32/src/Spindles/TecoL510.h index 23287234..8a17832b 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.h +++ b/Grbl_Esp32/src/Spindles/TecoL510.h @@ -37,7 +37,7 @@ namespace Spindles { bool safety_polling() const override { return false; } uint16_t rpm_to_frequency(uint32_t rpm); uint32_t freq_to_rpm(uint16_t); - uint32_t set_rpm(uint32_t rpm) override; + //uint32_t set_rpm(uint32_t rpm) override; void start_spindle(); public: From 104eddedf5e62a7a8a9a45424b61817dc793f62b Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 08:31:12 -0700 Subject: [PATCH 05/21] start/stop and set speed all working --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 91 +++------------------------- 1 file changed, 9 insertions(+), 82 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index b5581459..3feb951b 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -78,7 +78,7 @@ namespace Spindles { // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; - data.rx_length = 6; + data.rx_length = 5; // We have to know the max RPM before we can set the current RPM: auto max_rpm = this->_max_rpm; @@ -112,6 +112,7 @@ namespace Spindles { auto max_rpm = this->_max_rpm; auto max_freq = this->_max_freq; uint32_t rpm = (freq*max_rpm)/max_freq; + return rpm; } VFD::response_parser L510::initialization_sequence(int index, ModbusCommand& data) { @@ -134,11 +135,10 @@ namespace Spindles { return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { uint32_t rpm = (response[3] << 8) | response[4]; - //TODO remove hardcoding + //TODO also get max_frequency vfd->_max_rpm = rpm; - //vfd->_max_rpm = 24000; - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 spindle hardcoded 24000 %d ", vfd->_max_rpm); + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 spindle max_rpm %d ", vfd->_max_rpm); return true; }; @@ -154,10 +154,11 @@ namespace Spindles { // Send: 01 03 700C 0002 data.msg[1] = 0x03; // READ - data.msg[2] = 0x25; // 0x2523 = Get RPM - data.msg[3] = 0x23; + data.msg[2] = 0x25; // 0x2524 = Get output frequency + data.msg[3] = 0x24; data.msg[4] = 0x00; // Read 1 value data.msg[5] = 0x01; + //grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"get_rpm"); return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { uint16_t freq = (response[3] << 8) | response[4]; @@ -173,7 +174,7 @@ namespace Spindles { VFD::response_parser L510::get_current_direction(ModbusCommand& data) { // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; - data.rx_length = 6; + data.rx_length = 5; // Send: 01 03 30 00 00 01 data.msg[1] = 0x03; // READ @@ -187,84 +188,10 @@ namespace Spindles { // TODO: this doesn't seem to do anything in H2A return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { - uint16_t got = (uint16_t(response[4]) << 8) | uint16_t(response[5]); + uint16_t got = (uint16_t(response[3]) << 8) | uint16_t(response[4]); bool dir = bitRead(got,1); grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 dir %d", int(dir)); return true; }; } - /* - void start_spindle(){ - if(!spindle_started){ - // send start to VFD - ModbusCommand start_cmd; - start_cmd[0] = VFD_RS485_ADDR; - start_command(start_cmd); - if (xQueueSend(vfd_cmd_queue, &start_cmd, 0) != pdTRUE) { - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD Queue Full"); - } - - } - } - */ - - /* - uint32_t LF510::set_rpm(uint32_t rpm){ - if (!vfd_ok) { - return 0; - } - // Hack to start spindle running - SpindleState sstate = get_state(); - if(sstate != SpindleState::Disabled){ - start_spindle(); - } - // apply override - rpm = rpm * sys.spindle_speed_ovr / 100; // Scale by spindle speed override value (uint8_t percent) - - if (rpm != 0 && (rpm < _min_rpm || rpm > _max_rpm)) { - // NOTE: Don't add a info message here; this method is called from the stepper_pulse_func ISR method, so - // emitting debug information could crash the ESP32. - - rpm = constrain(rpm, _min_rpm, _max_rpm); - } - - // apply limits - // if ((_min_rpm >= _max_rpm) || (rpm >= _max_rpm)) { - // rpm = _max_rpm; - // } else if (rpm != 0 && rpm <= _min_rpm) { - // rpm = _min_rpm; - // } - - sys.spindle_speed = rpm; - - if (rpm == _current_rpm) { // prevent setting same RPM twice - return rpm; - } - -#ifdef VFD_DEBUG_MODE2 - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Setting spindle speed to %d rpm (%d, %d)", int(rpm), int(_min_rpm), int(_max_rpm)); -#endif - - _current_rpm = rpm; - - // TODO add the speed modifiers override, linearization, etc. - - ModbusCommand rpm_cmd; - rpm_cmd.msg[0] = VFD_RS485_ADDR; - - set_speed_command(rpm, rpm_cmd); - - // Sometimes sync_rpm is retained between different set_speed_command's. We don't want that - we want - // spindle sync to kick in after we set the speed. This forces that. - _sync_rpm = UINT32_MAX; - - rpm_cmd.critical = (rpm == 0); - - if (xQueueSend(vfd_cmd_queue, &rpm_cmd, 0) != pdTRUE) { - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD Queue Full"); - } - - return rpm; - } - */ } \ No newline at end of file From 9d16064c38535b7024808a04e6de07eb47adcfee Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 08:59:20 -0700 Subject: [PATCH 06/21] cleanup --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 46 +++++++++++++--------- Grbl_Esp32/src/Spindles/TecoL510.h | 4 +- Grbl_Esp32/src/Spindles/TecoL510_README.md | 19 +++++++++ 3 files changed, 49 insertions(+), 20 deletions(-) create mode 100644 Grbl_Esp32/src/Spindles/TecoL510_README.md diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 3feb951b..b0ca7ff4 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -61,19 +61,6 @@ namespace Spindles { grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"sending dir: state: %d",mode); } - /* - void L510::start_command(ModbusCommand& data){ - data.tx_length = 6; - data.rx_length = 6; - data.msg[1] = 0x06; - data.msg[2] = 0x25; - data.msg[3] = 0x01; - data.msg[4] = 0x00; - data.msg[5] = 0x01; - - } - */ - void L510::set_speed_command(uint32_t rpm, ModbusCommand& data) { // NOTE: data length is excluding the CRC16 checksum. @@ -100,7 +87,9 @@ namespace Spindles { data.msg[4] = uint8_t(speed >> 8); // RPM data.msg[5] = uint8_t(speed & 0xFF); +#ifdef VFD_DEBUG_MODE2 grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"setting speed to: %d",speed); +#endif } uint16_t L510::rpm_to_frequency(uint32_t rpm){ auto max_rpm = this->_max_rpm; @@ -138,7 +127,7 @@ namespace Spindles { //TODO also get max_frequency vfd->_max_rpm = rpm; - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 spindle max_rpm %d ", vfd->_max_rpm); + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d ", vfd->_max_rpm); return true; }; @@ -146,6 +135,30 @@ namespace Spindles { return nullptr; } } + VFD::response_parser L510::get_status_ok(ModbusCommand& data){ + // NOTE: data length is excluding the CRC16 checksum. + data.tx_length = 6; + data.rx_length = 5; + + + // Send: + data.msg[1] = 0x03; // READ + data.msg[2] = 0x25; // 0x2520 = Get state + data.msg[3] = 0x20; + data.msg[4] = 0x00; // Read 1 value + data.msg[5] = 0x01; + + return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { + uint32_t vfd_state = (response[3] << 8) | response[4]; + //TODO also get max_frequency + + if(bitRead(vfd_state,3)){ + grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"L510 Fault detected"); + return false; + } + return true; + }; + } VFD::response_parser L510::get_current_rpm(ModbusCommand& data) { // NOTE: data length is excluding the CRC16 checksum. @@ -158,11 +171,9 @@ namespace Spindles { data.msg[3] = 0x24; data.msg[4] = 0x00; // Read 1 value data.msg[5] = 0x01; - //grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"get_rpm"); return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { uint16_t freq = (response[3] << 8) | response[4]; - grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"current frequency: %d",freq); auto l510 = static_cast(vfd); @@ -172,6 +183,7 @@ namespace Spindles { } VFD::response_parser L510::get_current_direction(ModbusCommand& data) { + // does this run ever?? // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; data.rx_length = 5; @@ -186,11 +198,9 @@ namespace Spindles { // Receive: 01 03 00 02 00 02 // ----- status - // TODO: this doesn't seem to do anything in H2A return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { uint16_t got = (uint16_t(response[3]) << 8) | uint16_t(response[4]); bool dir = bitRead(got,1); - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 dir %d", int(dir)); return true; }; } diff --git a/Grbl_Esp32/src/Spindles/TecoL510.h b/Grbl_Esp32/src/Spindles/TecoL510.h index 8a17832b..219812b7 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.h +++ b/Grbl_Esp32/src/Spindles/TecoL510.h @@ -30,11 +30,11 @@ namespace Spindles { response_parser initialization_sequence(int index, ModbusCommand& data) override; response_parser get_current_rpm(ModbusCommand& data) override; response_parser get_current_direction(ModbusCommand& data) override; - response_parser get_status_ok(ModbusCommand& data) override { return nullptr; } // what is this, what should it do? bool supports_actual_rpm() const override { return true; } - bool safety_polling() const override { return false; } + bool safety_polling() const override { return true; } + response_parser get_status_ok(ModbusCommand& data) override; uint16_t rpm_to_frequency(uint32_t rpm); uint32_t freq_to_rpm(uint16_t); //uint32_t set_rpm(uint32_t rpm) override; diff --git a/Grbl_Esp32/src/Spindles/TecoL510_README.md b/Grbl_Esp32/src/Spindles/TecoL510_README.md new file mode 100644 index 00000000..b6cd5fe4 --- /dev/null +++ b/Grbl_Esp32/src/Spindles/TecoL510_README.md @@ -0,0 +1,19 @@ +# VFD setup + +Change these values: +1) 00-02, Main Run Command Source Selection, Default = 0 Change to 2 +2) 00-05, Main Freq Command Source Selection, Default = 0 Change to 5 + +Check that these are set to the default factory values: +3) 00-07, Main and Alternative Freq Cmnd Source Selection, Default = 0 +4) 09-00, Assigned Communication Number, Default = 1 this is defined as VFD_RS485_ADDR +5) 09-01, RTU/ASCII Code Selection, Default = 0 Should be 0 (We are using hex "RTU" commands, not ASCII commands) +6) 09-02, Baud Rate Setting, Default = 1 Should be 1 (9600 baud) but can be changed in the TecoL510.cpp +7) 09-03, Stop Bit Selection, Default = 0 Should be 0 (1 stop bit) +8) 09-04, Parity Selection, Default = 0 Should be 0 (Without parity) +9) 09-05, Data Format Selection, Default = 0 Should be 0 (8 data bits) + +# Implementation details + +not sure how to detect and parse error messages +max frequency is currenly hardcode \ No newline at end of file From 3e6c5caedca73b694cbc3b8660a2e034bdb0e437 Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 10:14:47 -0700 Subject: [PATCH 07/21] fixing machine.h --- Grbl_Esp32/src/Machine.h | 2 +- Grbl_Esp32/src/Spindles/TecoL510.cpp | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Grbl_Esp32/src/Machine.h b/Grbl_Esp32/src/Machine.h index a684b000..11ab8406 100644 --- a/Grbl_Esp32/src/Machine.h +++ b/Grbl_Esp32/src/Machine.h @@ -8,7 +8,7 @@ // !!! For initial testing, start with test_drive.h which disables // all I/O pins // #include "Machines/atari_1020.h" -# include "Machines/jesse_6pack.h" +# include "Machines/test_drive.h" // !!! For actual use, change the line above to select a board // from Machines/, for example: diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index b0ca7ff4..75d67f0b 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -28,8 +28,11 @@ namespace Spindles { L510::L510() : VFD() { _baudrate = 9600; _parity = Uart::Parity::None; + // TODO: should defaults be set here? What happens if the motor settings in the VFD are wrong or default? + /* _max_rpm = 24000; _max_freq = 40000; + */ } void L510::direction_command(SpindleState mode, ModbusCommand& data) { @@ -108,15 +111,17 @@ namespace Spindles { if (index == -1) { // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; - data.rx_length = 5; + data.rx_length = 11; + + // read parameters 02-03..02-06 // Send: data.msg[1] = 0x03; // READ data.msg[2] = 0x02; // 0x0203 = Get max rpm data.msg[3] = 0x03; - data.msg[4] = 0x00; // Read 1 value - data.msg[5] = 0x01; + data.msg[4] = 0x00; // Read 4 values + data.msg[5] = 0x04; @@ -124,10 +129,16 @@ namespace Spindles { return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { uint32_t rpm = (response[3] << 8) | response[4]; - //TODO also get max_frequency - vfd->_max_rpm = rpm; - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d ", vfd->_max_rpm); + // NOTE: the frequency is stored xxx.x but the input command is frequency * 100; + uint16_t freq = (response[9] << 8) | response[10]; + freq = freq * 10; + auto l510 = static_cast(vfd); + + l510->_max_rpm = rpm; + l510->_max_freq = freq; + + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d max_freq %d", vfd->_max_rpm,l510->_max_freq); return true; }; @@ -150,7 +161,6 @@ namespace Spindles { return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { uint32_t vfd_state = (response[3] << 8) | response[4]; - //TODO also get max_frequency if(bitRead(vfd_state,3)){ grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"L510 Fault detected"); From 2d4af675e6d9f3b357dd72c3bf1d2784af372e6d Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 10:17:43 -0700 Subject: [PATCH 08/21] fix .gitignore *&vi .gitignore didn't work anyway --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index d11902c0..44cc0076 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,3 @@ __vm/ *.suo Grbl_Esp32.ino.cpp /packages -Grbl_Esp32/src/Machine.h From 91b3b9d037896ed99d19f7906a7b0696ab754c28 Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 10:20:19 -0700 Subject: [PATCH 09/21] forgot to get rid of hard coded max_freq, fixed now --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 75d67f0b..0a8799d3 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -80,8 +80,8 @@ namespace Spindles { if (speed < 0) { speed = 0; } - if (speed > 40000) { - speed = 40000; + if (speed > max_freq) { + speed = max_freq; } data.msg[1] = 0x06; // WRITE @@ -96,7 +96,8 @@ namespace Spindles { } uint16_t L510::rpm_to_frequency(uint32_t rpm){ auto max_rpm = this->_max_rpm; - uint16_t freq = (uint32_t(rpm) * 40000L) / uint32_t(max_rpm); + auto max_freq = this->_max_freq; + uint16_t freq = (uint32_t(rpm) * max_freq) / uint32_t(max_rpm); return freq; } From bc1d70f36d05a0e91f7ac7e57e8145125883b0d1 Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 10:38:27 -0700 Subject: [PATCH 10/21] changed 'speed' to 'freq' --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 0a8799d3..720f7c65 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -76,19 +76,19 @@ namespace Spindles { // Assuming max frequncy is 400Hz // Speed is in [0..40,000] - uint16_t speed = (uint16_t(rpm) * max_freq) / uint32_t(max_rpm); - if (speed < 0) { - speed = 0; + uint16_t freq = (uint16_t(rpm) * max_freq) / uint32_t(max_rpm); + if (freq < 0) { + freq = 0; } - if (speed > max_freq) { - speed = max_freq; + if (freq > max_freq) { + freq = max_freq; } data.msg[1] = 0x06; // WRITE data.msg[2] = 0x25; // Command ID 0x2502 data.msg[3] = 0x02; - data.msg[4] = uint8_t(speed >> 8); // RPM - data.msg[5] = uint8_t(speed & 0xFF); + data.msg[4] = uint8_t(freq >> 8); // RPM + data.msg[5] = uint8_t(freq & 0xFF); #ifdef VFD_DEBUG_MODE2 grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"setting speed to: %d",speed); From d4547168ef8a69cd68c423969d607dd96253d603 Mon Sep 17 00:00:00 2001 From: me Date: Wed, 21 Apr 2021 12:03:00 -0700 Subject: [PATCH 11/21] reverting platformio.ini --- platformio.ini | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/platformio.ini b/platformio.ini index a99cf2a3..37ffa908 100644 --- a/platformio.ini +++ b/platformio.ini @@ -69,11 +69,4 @@ lib_deps = build_type = debug lib_deps = TMCStepper@>=0.7.0,<1.0.0 - ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 - - -[env:ota] -upload_protocol = espota -upload_port = 192.168.1.61 -lib_deps = - TMCStepper@>=0.7.0,<1.0.0 + ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 \ No newline at end of file From 6d4388081a2ee1fe2fc449c97c5fc46f1e1f8334 Mon Sep 17 00:00:00 2001 From: me Date: Thu, 22 Apr 2021 10:55:49 -0700 Subject: [PATCH 12/21] minor readme update --- Grbl_Esp32/src/Spindles/TecoL510_README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Grbl_Esp32/src/Spindles/TecoL510_README.md b/Grbl_Esp32/src/Spindles/TecoL510_README.md index b6cd5fe4..87becce9 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510_README.md +++ b/Grbl_Esp32/src/Spindles/TecoL510_README.md @@ -15,5 +15,14 @@ Check that these are set to the default factory values: # Implementation details +this was tested with pin 16 RX and 26 TX mapped in the machine config file. Pin 4 was used for RTS but it is not used on the rs485 module I tested with. + +``` +#define VFD_RS485_TXD_PIN GPIO_NUM_26 +#define VFD_RS485_RTS_PIN GPIO_NUM_4 +#define VFD_RS485_RXD_PIN GPIO_NUM_16 + +``` + not sure how to detect and parse error messages max frequency is currenly hardcode \ No newline at end of file From f1b56a7a00520ba51384fbb5228f5c399b879f27 Mon Sep 17 00:00:00 2001 From: me Date: Thu, 22 Apr 2021 14:00:57 -0700 Subject: [PATCH 13/21] removed debug msg --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 720f7c65..e1f9deaf 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -61,7 +61,6 @@ namespace Spindles { data.msg[5] = 0x03; break; } - grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"sending dir: state: %d",mode); } void L510::set_speed_command(uint32_t rpm, ModbusCommand& data) { From b2d4ad2c65a6e44c1e2b42629dc6a2628b43169e Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Sat, 31 Jul 2021 15:13:37 -0700 Subject: [PATCH 14/21] fixes for RPM --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index e1f9deaf..a8030e94 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -29,10 +29,9 @@ namespace Spindles { _baudrate = 9600; _parity = Uart::Parity::None; // TODO: should defaults be set here? What happens if the motor settings in the VFD are wrong or default? - /* _max_rpm = 24000; + _min_rpm = 6000; _max_freq = 40000; - */ } void L510::direction_command(SpindleState mode, ModbusCommand& data) { @@ -104,6 +103,10 @@ namespace Spindles { auto max_rpm = this->_max_rpm; auto max_freq = this->_max_freq; uint32_t rpm = (freq*max_rpm)/max_freq; + if(rpm < 0){ + // sometimes it returns -1 which causes an alarm + rpm = 0; + } return rpm; } From a36f1bea448b407c40c52a32a054c8255a30d4b3 Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Sat, 31 Jul 2021 15:15:47 -0700 Subject: [PATCH 15/21] note --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index a8030e94..31238484 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -29,6 +29,7 @@ namespace Spindles { _baudrate = 9600; _parity = Uart::Parity::None; // TODO: should defaults be set here? What happens if the motor settings in the VFD are wrong or default? + // I think they are overloaded with DEFAULT_SPINDLE_RPM_MAX and DEFAULT_SPINDLE_RPM_MIN _max_rpm = 24000; _min_rpm = 6000; _max_freq = 40000; From 07fd65b57a0e592fcb2eafd7e2862df11a3fee13 Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Thu, 5 Aug 2021 10:49:48 -0700 Subject: [PATCH 16/21] fixed rx length --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 31238484..156fcb3d 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -67,7 +67,7 @@ namespace Spindles { // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; - data.rx_length = 5; + data.rx_length = 6; // We have to know the max RPM before we can set the current RPM: auto max_rpm = this->_max_rpm; From 68f934d71497103c4899934b8120ff47ece52747 Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Thu, 5 Aug 2021 11:42:10 -0700 Subject: [PATCH 17/21] fix smell and update readme --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 20 +++++++------------- Grbl_Esp32/src/Spindles/TecoL510_README.md | 4 +++- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 156fcb3d..1c3e65b6 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -69,19 +69,7 @@ namespace Spindles { data.tx_length = 6; data.rx_length = 6; - // We have to know the max RPM before we can set the current RPM: - auto max_rpm = this->_max_rpm; - auto max_freq = this->_max_freq; - - // Assuming max frequncy is 400Hz - // Speed is in [0..40,000] - uint16_t freq = (uint16_t(rpm) * max_freq) / uint32_t(max_rpm); - if (freq < 0) { - freq = 0; - } - if (freq > max_freq) { - freq = max_freq; - } + uint16_t freq = rpm_to_frequency(rpm); data.msg[1] = 0x06; // WRITE data.msg[2] = 0x25; // Command ID 0x2502 @@ -97,6 +85,12 @@ namespace Spindles { auto max_rpm = this->_max_rpm; auto max_freq = this->_max_freq; uint16_t freq = (uint32_t(rpm) * max_freq) / uint32_t(max_rpm); + if (freq < 0) { + freq = 0; + } + if (freq > max_freq) { + freq = max_freq; + } return freq; } diff --git a/Grbl_Esp32/src/Spindles/TecoL510_README.md b/Grbl_Esp32/src/Spindles/TecoL510_README.md index 87becce9..1fdafb87 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510_README.md +++ b/Grbl_Esp32/src/Spindles/TecoL510_README.md @@ -21,7 +21,9 @@ this was tested with pin 16 RX and 26 TX mapped in the machine config file. Pin #define VFD_RS485_TXD_PIN GPIO_NUM_26 #define VFD_RS485_RTS_PIN GPIO_NUM_4 #define VFD_RS485_RXD_PIN GPIO_NUM_16 - +// Not sure why this isn't a setting +#define DEFAULT_SPINDLE_RPM_MAX 24000.0 // rpm +#define DEFAULT_SPINDLE_RPM_MIN 6000.0 // rpm ``` not sure how to detect and parse error messages From a26d86f607310fe786ccbc294ac6855908079763 Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Thu, 5 Aug 2021 12:55:33 -0700 Subject: [PATCH 18/21] clang format --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 78 +++++++++++++--------------- Grbl_Esp32/src/Spindles/TecoL510.h | 8 +-- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 1c3e65b6..0e730c82 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -30,16 +30,14 @@ namespace Spindles { _parity = Uart::Parity::None; // TODO: should defaults be set here? What happens if the motor settings in the VFD are wrong or default? // I think they are overloaded with DEFAULT_SPINDLE_RPM_MAX and DEFAULT_SPINDLE_RPM_MIN - _max_rpm = 24000; - _min_rpm = 6000; + _max_rpm = 24000; + _min_rpm = 6000; _max_freq = 40000; } void L510::direction_command(SpindleState mode, ModbusCommand& data) { // Note: The direction command is always called on M3,M4, and M5 - // This is where the spindle start/stop should be sent - - + // This is where the spindle start/stop should be sent // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; @@ -49,7 +47,7 @@ namespace Spindles { data.msg[2] = 0x25; // Command ID 0x2501 data.msg[3] = 0x01; data.msg[4] = 0x00; - switch(mode){ + switch (mode) { case SpindleState::Disable: //data.msg[4] = 0x00; data.msg[5] = 0x00; @@ -64,8 +62,7 @@ namespace Spindles { } void L510::set_speed_command(uint32_t rpm, ModbusCommand& data) { - - // NOTE: data length is excluding the CRC16 checksum. + // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; data.rx_length = 6; @@ -78,13 +75,13 @@ namespace Spindles { data.msg[5] = uint8_t(freq & 0xFF); #ifdef VFD_DEBUG_MODE2 - grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"setting speed to: %d",speed); + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "setting speed to: %d", speed); #endif } - uint16_t L510::rpm_to_frequency(uint32_t rpm){ - auto max_rpm = this->_max_rpm; - auto max_freq = this->_max_freq; - uint16_t freq = (uint32_t(rpm) * max_freq) / uint32_t(max_rpm); + uint16_t L510::rpm_to_frequency(uint32_t rpm) { + auto max_rpm = this->_max_rpm; + auto max_freq = this->_max_freq; + uint16_t freq = (uint32_t(rpm) * max_freq) / uint32_t(max_rpm); if (freq < 0) { freq = 0; } @@ -94,11 +91,11 @@ namespace Spindles { return freq; } - uint32_t L510::freq_to_rpm(uint16_t freq){ - auto max_rpm = this->_max_rpm; - auto max_freq = this->_max_freq; - uint32_t rpm = (freq*max_rpm)/max_freq; - if(rpm < 0){ + uint32_t L510::freq_to_rpm(uint16_t freq) { + auto max_rpm = this->_max_rpm; + auto max_freq = this->_max_freq; + uint32_t rpm = (freq * max_rpm) / max_freq; + if (rpm < 0) { // sometimes it returns -1 which causes an alarm rpm = 0; } @@ -111,32 +108,30 @@ namespace Spindles { data.tx_length = 6; data.rx_length = 11; - // read parameters 02-03..02-06 - - // Send: + + // Send: data.msg[1] = 0x03; // READ data.msg[2] = 0x02; // 0x0203 = Get max rpm data.msg[3] = 0x03; data.msg[4] = 0x00; // Read 4 values data.msg[5] = 0x04; - - // Recv: ?? return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { - uint32_t rpm = (response[3] << 8) | response[4]; + uint32_t rpm = (response[3] << 8) | response[4]; // NOTE: the frequency is stored xxx.x but the input command is frequency * 100; uint16_t freq = (response[9] << 8) | response[10]; - freq = freq * 10; - auto l510 = static_cast(vfd); + freq = freq * 10; + auto l510 = static_cast(vfd); - l510->_max_rpm = rpm; + l510->_max_rpm = rpm; l510->_max_freq = freq; - grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d max_freq %d", vfd->_max_rpm,l510->_max_freq); + grbl_msg_sendf( + CLIENT_SERIAL, MsgLevel::Info, "L510 initialized: spindle max_rpm %d max_freq %d", vfd->_max_rpm, l510->_max_freq); return true; }; @@ -144,13 +139,12 @@ namespace Spindles { return nullptr; } } - VFD::response_parser L510::get_status_ok(ModbusCommand& data){ + VFD::response_parser L510::get_status_ok(ModbusCommand& data) { // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; data.rx_length = 5; - - // Send: + // Send: data.msg[1] = 0x03; // READ data.msg[2] = 0x25; // 0x2520 = Get state data.msg[3] = 0x20; @@ -158,14 +152,14 @@ namespace Spindles { data.msg[5] = 0x01; return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { - uint32_t vfd_state = (response[3] << 8) | response[4]; + uint32_t vfd_state = (response[3] << 8) | response[4]; - if(bitRead(vfd_state,3)){ - grbl_msg_sendf(CLIENT_SERIAL,MsgLevel::Info,"L510 Fault detected"); - return false; - } - return true; - }; + if (bitRead(vfd_state, 3)) { + grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 Fault detected"); + return false; + } + return true; + }; } VFD::response_parser L510::get_current_rpm(ModbusCommand& data) { @@ -206,10 +200,10 @@ namespace Spindles { // Receive: 01 03 00 02 00 02 // ----- status - return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { + return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { uint16_t got = (uint16_t(response[3]) << 8) | uint16_t(response[4]); - bool dir = bitRead(got,1); - return true; - }; + bool dir = bitRead(got, 1); + return true; + }; } } \ No newline at end of file diff --git a/Grbl_Esp32/src/Spindles/TecoL510.h b/Grbl_Esp32/src/Spindles/TecoL510.h index 219812b7..99eabe77 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.h +++ b/Grbl_Esp32/src/Spindles/TecoL510.h @@ -32,11 +32,11 @@ namespace Spindles { response_parser get_current_direction(ModbusCommand& data) override; // what is this, what should it do? - bool supports_actual_rpm() const override { return true; } - bool safety_polling() const override { return true; } + bool supports_actual_rpm() const override { return true; } + bool safety_polling() const override { return true; } response_parser get_status_ok(ModbusCommand& data) override; - uint16_t rpm_to_frequency(uint32_t rpm); - uint32_t freq_to_rpm(uint16_t); + uint16_t rpm_to_frequency(uint32_t rpm); + uint32_t freq_to_rpm(uint16_t); //uint32_t set_rpm(uint32_t rpm) override; void start_spindle(); From b7d65bbaaca74a48ba36cbb8bccfc09b390503dd Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Thu, 5 Aug 2021 15:53:47 -0700 Subject: [PATCH 19/21] trying to fix newlines --- Grbl_Esp32/src/Spindles/Spindle.cpp | 7 ++++--- Grbl_Esp32/src/Spindles/TecoL510.cpp | 3 ++- Grbl_Esp32/src/Spindles/TecoL510.h | 1 + Grbl_Esp32/src/Spindles/TecoL510_README.md | 3 ++- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/Spindle.cpp b/Grbl_Esp32/src/Spindles/Spindle.cpp index c783309b..bc15ab96 100644 --- a/Grbl_Esp32/src/Spindles/Spindle.cpp +++ b/Grbl_Esp32/src/Spindles/Spindle.cpp @@ -44,6 +44,7 @@ namespace Spindles { // An instance of each type of spindle is created here. // This allows the spindle to be dynamicly switched + Null null; PWM pwm; Relay relay; @@ -53,8 +54,8 @@ namespace Spindles { H2A h2a; BESC besc; _10v _10v; - YL620 yl620; - L510 l510; + YL620 yl620; + L510 l510; void Spindle::select() { switch (static_cast(spindle_type->get())) { @@ -114,4 +115,4 @@ namespace Spindles { void Spindle::deinit() { stop(); } } - Spindles::Spindle* spindle; +Spindles::Spindle* spindle; diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 0e730c82..90516908 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -38,6 +38,7 @@ namespace Spindles { void L510::direction_command(SpindleState mode, ModbusCommand& data) { // Note: The direction command is always called on M3,M4, and M5 // This is where the spindle start/stop should be sent + // NOTE: data length is excluding the CRC16 checksum. data.tx_length = 6; @@ -206,4 +207,4 @@ namespace Spindles { return true; }; } -} \ No newline at end of file +} diff --git a/Grbl_Esp32/src/Spindles/TecoL510.h b/Grbl_Esp32/src/Spindles/TecoL510.h index 99eabe77..f89de262 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.h +++ b/Grbl_Esp32/src/Spindles/TecoL510.h @@ -19,6 +19,7 @@ You should have received a copy of the GNU General Public License along with Grbl. If not, see . + */ namespace Spindles { diff --git a/Grbl_Esp32/src/Spindles/TecoL510_README.md b/Grbl_Esp32/src/Spindles/TecoL510_README.md index 1fdafb87..9cdfd6e9 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510_README.md +++ b/Grbl_Esp32/src/Spindles/TecoL510_README.md @@ -22,9 +22,10 @@ this was tested with pin 16 RX and 26 TX mapped in the machine config file. Pin #define VFD_RS485_RTS_PIN GPIO_NUM_4 #define VFD_RS485_RXD_PIN GPIO_NUM_16 // Not sure why this isn't a setting + #define DEFAULT_SPINDLE_RPM_MAX 24000.0 // rpm #define DEFAULT_SPINDLE_RPM_MIN 6000.0 // rpm ``` not sure how to detect and parse error messages -max frequency is currenly hardcode \ No newline at end of file +max frequency is currenly hardcode From 2e91c5674839ec881132138b0094db274c5cc254 Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Thu, 5 Aug 2021 15:58:44 -0700 Subject: [PATCH 20/21] trying to fix newlines part 2 --- platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 37ffa908..ddf3a854 100644 --- a/platformio.ini +++ b/platformio.ini @@ -69,4 +69,4 @@ lib_deps = build_type = debug lib_deps = TMCStepper@>=0.7.0,<1.0.0 - ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 \ No newline at end of file + ESP8266 and ESP32 OLED driver for SSD1306 displays@^4.2.0 From 38d1c88bc2f1334026cf42aae07dd002aef3f47c Mon Sep 17 00:00:00 2001 From: Jesse Schoch Date: Fri, 6 Aug 2021 09:16:14 -0700 Subject: [PATCH 21/21] fix cast issue --- Grbl_Esp32/src/Spindles/TecoL510.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Grbl_Esp32/src/Spindles/TecoL510.cpp b/Grbl_Esp32/src/Spindles/TecoL510.cpp index 90516908..aa6c3d36 100644 --- a/Grbl_Esp32/src/Spindles/TecoL510.cpp +++ b/Grbl_Esp32/src/Spindles/TecoL510.cpp @@ -124,7 +124,7 @@ namespace Spindles { uint32_t rpm = (response[3] << 8) | response[4]; // NOTE: the frequency is stored xxx.x but the input command is frequency * 100; - uint16_t freq = (response[9] << 8) | response[10]; + uint16_t freq = ((uint16_t)response[9] << 8) | (uint16_t)response[10]; freq = freq * 10; auto l510 = static_cast(vfd); @@ -153,7 +153,7 @@ namespace Spindles { data.msg[5] = 0x01; return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { - uint32_t vfd_state = (response[3] << 8) | response[4]; + uint16_t vfd_state = ((uint16_t)response[3] << 8) | (uint16_t)response[4]; if (bitRead(vfd_state, 3)) { grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "L510 Fault detected"); @@ -176,7 +176,7 @@ namespace Spindles { data.msg[5] = 0x01; return [](const uint8_t* response, Spindles::VFD* vfd) -> bool { - uint16_t freq = (response[3] << 8) | response[4]; + uint16_t freq = ((uint16_t)response[3] << 8) | (uint16_t)response[4]; auto l510 = static_cast(vfd);