mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-30 01:30:05 +02:00
Reverting some spindle changes...
CLIENT_ALL caused queue issues
This commit is contained in:
@@ -98,7 +98,7 @@ namespace Spindles {
|
|||||||
uint16_t rpm = (uint16_t(response[4]) << 8) | uint16_t(response[5]);
|
uint16_t rpm = (uint16_t(response[4]) << 8) | uint16_t(response[5]);
|
||||||
vfd->_max_rpm = rpm;
|
vfd->_max_rpm = rpm;
|
||||||
|
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "H2A spindle is initialized at %d RPM", int(rpm));
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "H2A spindle is initialized at %d RPM", int(rpm));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
@@ -49,7 +49,6 @@ const int VFD_RS485_POLL_RATE = 200; // in milliseconds between comman
|
|||||||
namespace Spindles {
|
namespace Spindles {
|
||||||
QueueHandle_t VFD::vfd_cmd_queue = nullptr;
|
QueueHandle_t VFD::vfd_cmd_queue = nullptr;
|
||||||
TaskHandle_t VFD::vfd_cmdTaskHandle = nullptr;
|
TaskHandle_t VFD::vfd_cmdTaskHandle = nullptr;
|
||||||
bool VFD::task_active = true;
|
|
||||||
|
|
||||||
// The communications task
|
// The communications task
|
||||||
void VFD::vfd_cmd_task(void* pvParameters) {
|
void VFD::vfd_cmd_task(void* pvParameters) {
|
||||||
@@ -61,12 +60,6 @@ namespace Spindles {
|
|||||||
uint8_t rx_message[VFD_RS485_MAX_MSG_SIZE];
|
uint8_t rx_message[VFD_RS485_MAX_MSG_SIZE];
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!task_active) {
|
|
||||||
uart_driver_delete(VFD_RS485_UART_PORT);
|
|
||||||
xQueueReset(vfd_cmd_queue);
|
|
||||||
vTaskDelete(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
response_parser parser = nullptr;
|
response_parser parser = nullptr;
|
||||||
|
|
||||||
next_cmd.msg[0] = VFD_RS485_ADDR; // Always default to this
|
next_cmd.msg[0] = VFD_RS485_ADDR; // Always default to this
|
||||||
@@ -165,7 +158,7 @@ namespace Spindles {
|
|||||||
|
|
||||||
// Not succesful! Now what?
|
// Not succesful! Now what?
|
||||||
unresponsive = true;
|
unresponsive = true;
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Spindle RS485 did not give a satisfying response");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Spindle RS485 did not give a satisfying response");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifdef VFD_DEBUG_MODE
|
#ifdef VFD_DEBUG_MODE
|
||||||
@@ -174,18 +167,18 @@ namespace Spindles {
|
|||||||
|
|
||||||
if (read_length != 0) {
|
if (read_length != 0) {
|
||||||
if (rx_message[0] != VFD_RS485_ADDR) {
|
if (rx_message[0] != VFD_RS485_ADDR) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 received message from other modbus device");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 received message from other modbus device");
|
||||||
} else if (read_length != next_cmd.rx_length) {
|
} else if (read_length != next_cmd.rx_length) {
|
||||||
grbl_msg_sendf(CLIENT_ALL,
|
grbl_msg_sendf(CLIENT_SERIAL,
|
||||||
MsgLevel::Info,
|
MsgLevel::Info,
|
||||||
"RS485 received message of unexpected length; expected %d, got %d",
|
"RS485 received message of unexpected length; expected %d, got %d",
|
||||||
int(next_cmd.rx_length),
|
int(next_cmd.rx_length),
|
||||||
int(read_length));
|
int(read_length));
|
||||||
} else {
|
} else {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 CRC check failed");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 CRC check failed");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 No response");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 No response");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -194,17 +187,15 @@ namespace Spindles {
|
|||||||
vTaskDelay(VFD_RS485_POLL_RATE);
|
vTaskDelay(VFD_RS485_POLL_RATE);
|
||||||
|
|
||||||
static UBaseType_t uxHighWaterMark = 0;
|
static UBaseType_t uxHighWaterMark = 0;
|
||||||
#ifdef DEBUG_TASK_STACK
|
|
||||||
reportTaskStackSize(uxHighWaterMark);
|
reportTaskStackSize(uxHighWaterMark);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retry_count == MAX_RETRIES) {
|
if (retry_count == MAX_RETRIES) {
|
||||||
if (!unresponsive) {
|
if (!unresponsive) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Spindle RS485 Unresponsive %d", next_cmd.rx_length);
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Spindle RS485 Unresponsive %d", next_cmd.rx_length);
|
||||||
if (next_cmd.critical) {
|
if (next_cmd.critical) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Critical Spindle RS485 Unresponsive");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Critical Spindle RS485 Unresponsive");
|
||||||
sys_rt_exec_alarm = ExecAlarm::SpindleControl;
|
sys_rt_exec_alarm = ExecAlarm::SpindleControl;
|
||||||
}
|
}
|
||||||
unresponsive = true;
|
unresponsive = true;
|
||||||
@@ -227,12 +218,12 @@ namespace Spindles {
|
|||||||
void VFD::init() {
|
void VFD::init() {
|
||||||
vfd_ok = false; // initialize
|
vfd_ok = false; // initialize
|
||||||
|
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Initializing RS485 VFD spindle");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Initializing RS485 VFD spindle");
|
||||||
|
|
||||||
// fail if required items are not defined
|
// fail if required items are not defined
|
||||||
if (!get_pins_and_settings()) {
|
if (!get_pins_and_settings()) {
|
||||||
vfd_ok = false;
|
vfd_ok = false;
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 VFD spindle errors");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 VFD spindle errors");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,37 +246,38 @@ namespace Spindles {
|
|||||||
uart_config.rx_flow_ctrl_thresh = 122;
|
uart_config.rx_flow_ctrl_thresh = 122;
|
||||||
|
|
||||||
if (uart_param_config(VFD_RS485_UART_PORT, &uart_config) != ESP_OK) {
|
if (uart_param_config(VFD_RS485_UART_PORT, &uart_config) != ESP_OK) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 VFD uart parameters failed");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 VFD uart parameters failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uart_set_pin(VFD_RS485_UART_PORT, _txd_pin, _rxd_pin, _rts_pin, UART_PIN_NO_CHANGE) != ESP_OK) {
|
if (uart_set_pin(VFD_RS485_UART_PORT, _txd_pin, _rxd_pin, _rts_pin, UART_PIN_NO_CHANGE) != ESP_OK) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 VFD uart pin config failed");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 VFD uart pin config failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uart_driver_install(VFD_RS485_UART_PORT, VFD_RS485_BUF_SIZE * 2, 0, 0, NULL, 0) != ESP_OK) {
|
if (uart_driver_install(VFD_RS485_UART_PORT, VFD_RS485_BUF_SIZE * 2, 0, 0, NULL, 0) != ESP_OK) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 VFD uart driver install failed");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 VFD uart driver install failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uart_set_mode(VFD_RS485_UART_PORT, UART_MODE_RS485_HALF_DUPLEX) != ESP_OK) {
|
if (uart_set_mode(VFD_RS485_UART_PORT, UART_MODE_RS485_HALF_DUPLEX) != ESP_OK) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "RS485 VFD uart set half duplex failed");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "RS485 VFD uart set half duplex failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialization is complete, so now it's okay to run the queue task:
|
// Initialization is complete, so now it's okay to run the queue task:
|
||||||
task_active = true;
|
if (!_task_running) { // init can happen many times, we only want to start one task
|
||||||
if (vfd_cmd_queue != nullptr) {
|
|
||||||
vfd_cmd_queue = xQueueCreate(VFD_RS485_QUEUE_SIZE, sizeof(ModbusCommand));
|
vfd_cmd_queue = xQueueCreate(VFD_RS485_QUEUE_SIZE, sizeof(ModbusCommand));
|
||||||
}
|
|
||||||
xTaskCreatePinnedToCore(vfd_cmd_task, // task
|
xTaskCreatePinnedToCore(vfd_cmd_task, // task
|
||||||
"vfd_cmdTaskHandle", // name for task
|
"vfd_cmdTaskHandle", // name for task
|
||||||
2048, // size of task stack
|
2048, // size of task stack
|
||||||
this, // parameters
|
this, // parameters
|
||||||
1, // priority
|
1, // priority
|
||||||
&vfd_cmdTaskHandle,
|
&vfd_cmdTaskHandle,
|
||||||
SUPPORT_TASK_CORE);
|
SUPPORT_TASK_CORE // core
|
||||||
|
);
|
||||||
|
_task_running = true;
|
||||||
|
}
|
||||||
|
|
||||||
is_reversable = true; // these VFDs are always reversable
|
is_reversable = true; // these VFDs are always reversable
|
||||||
use_delays = true;
|
use_delays = true;
|
||||||
@@ -307,27 +299,26 @@ namespace Spindles {
|
|||||||
#ifdef VFD_RS485_TXD_PIN
|
#ifdef VFD_RS485_TXD_PIN
|
||||||
_txd_pin = VFD_RS485_TXD_PIN;
|
_txd_pin = VFD_RS485_TXD_PIN;
|
||||||
#else
|
#else
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Undefined VFD_RS485_TXD_PIN");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Undefined VFD_RS485_TXD_PIN");
|
||||||
pins_settings_ok = false;
|
pins_settings_ok = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VFD_RS485_RXD_PIN
|
#ifdef VFD_RS485_RXD_PIN
|
||||||
_rxd_pin = VFD_RS485_RXD_PIN;
|
_rxd_pin = VFD_RS485_RXD_PIN;
|
||||||
#else
|
#else
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Undefined VFD_RS485_RXD_PIN");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Undefined VFD_RS485_RXD_PIN");
|
||||||
pins_settings_ok = false;
|
pins_settings_ok = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef VFD_RS485_RTS_PIN
|
#ifdef VFD_RS485_RTS_PIN
|
||||||
_rts_pin = VFD_RS485_RTS_PIN;
|
_rts_pin = VFD_RS485_RTS_PIN;
|
||||||
#else
|
#else
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Undefined VFD_RS485_RTS_PIN");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Undefined VFD_RS485_RTS_PIN");
|
||||||
pins_settings_ok = false;
|
pins_settings_ok = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// TODO Test no longer required.
|
|
||||||
if (laser_mode->get()) {
|
if (laser_mode->get()) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD spindle disabled in laser mode. Set $GCode/LaserMode=Off and restart");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD spindle disabled in laser mode. Set $GCode/LaserMode=Off and restart");
|
||||||
pins_settings_ok = false;
|
pins_settings_ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -338,7 +329,7 @@ namespace Spindles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void VFD::config_message() {
|
void VFD::config_message() {
|
||||||
grbl_msg_sendf(CLIENT_ALL,
|
grbl_msg_sendf(CLIENT_SERIAL,
|
||||||
MsgLevel::Info,
|
MsgLevel::Info,
|
||||||
"VFD RS485 Tx:%s Rx:%s RTS:%s",
|
"VFD RS485 Tx:%s Rx:%s RTS:%s",
|
||||||
pinName(_txd_pin).c_str(),
|
pinName(_txd_pin).c_str(),
|
||||||
@@ -391,7 +382,7 @@ namespace Spindles {
|
|||||||
|
|
||||||
if (mode == SpindleState::Disable) {
|
if (mode == SpindleState::Disable) {
|
||||||
if (!xQueueReset(vfd_cmd_queue)) {
|
if (!xQueueReset(vfd_cmd_queue)) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD spindle off, queue could not be reset");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD spindle off, queue could not be reset");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -399,7 +390,7 @@ namespace Spindles {
|
|||||||
_current_state = mode;
|
_current_state = mode;
|
||||||
|
|
||||||
if (xQueueSend(vfd_cmd_queue, &mode_cmd, 0) != pdTRUE) {
|
if (xQueueSend(vfd_cmd_queue, &mode_cmd, 0) != pdTRUE) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD Queue Full");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD Queue Full");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -411,7 +402,7 @@ namespace Spindles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VFD_DEBUG_MODE
|
#ifdef VFD_DEBUG_MODE
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Setting spindle speed to %d rpm (%d, %d)", int(rpm), int(_min_rpm), int(_max_rpm));
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "Setting spindle speed to %d rpm (%d, %d)", int(rpm), int(_min_rpm), int(_max_rpm));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// apply override
|
// apply override
|
||||||
@@ -442,7 +433,7 @@ namespace Spindles {
|
|||||||
rpm_cmd.critical = false;
|
rpm_cmd.critical = false;
|
||||||
|
|
||||||
if (xQueueSend(vfd_cmd_queue, &rpm_cmd, 0) != pdTRUE) {
|
if (xQueueSend(vfd_cmd_queue, &rpm_cmd, 0) != pdTRUE) {
|
||||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD Queue Full");
|
grbl_msg_sendf(CLIENT_SERIAL, MsgLevel::Info, "VFD Queue Full");
|
||||||
}
|
}
|
||||||
|
|
||||||
return rpm;
|
return rpm;
|
||||||
@@ -474,11 +465,4 @@ namespace Spindles {
|
|||||||
|
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VFD::deinit() {
|
|
||||||
_current_state = SpindleState::Disable;
|
|
||||||
_current_rpm = 0;
|
|
||||||
|
|
||||||
task_active = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <driver/uart.h>
|
#include <driver/uart.h>
|
||||||
|
|
||||||
|
// #define VFD_DEBUG_MODE
|
||||||
|
|
||||||
namespace Spindles {
|
namespace Spindles {
|
||||||
|
|
||||||
class VFD : public Spindle {
|
class VFD : public Spindle {
|
||||||
@@ -40,17 +42,12 @@ namespace Spindles {
|
|||||||
bool _task_running = false;
|
bool _task_running = false;
|
||||||
bool vfd_ok = true;
|
bool vfd_ok = true;
|
||||||
|
|
||||||
static bool task_active;
|
|
||||||
static QueueHandle_t vfd_cmd_queue;
|
static QueueHandle_t vfd_cmd_queue;
|
||||||
static TaskHandle_t vfd_cmdTaskHandle;
|
static TaskHandle_t vfd_cmdTaskHandle;
|
||||||
static void vfd_cmd_task(void* pvParameters);
|
static void vfd_cmd_task(void* pvParameters);
|
||||||
|
|
||||||
static uint16_t ModRTU_CRC(uint8_t* buf, int msg_len);
|
static uint16_t ModRTU_CRC(uint8_t* buf, int msg_len);
|
||||||
|
|
||||||
void deinit() override;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
struct ModbusCommand {
|
struct ModbusCommand {
|
||||||
bool critical; // TODO SdB: change into `uint8_t critical : 1;`: We want more flags...
|
bool critical; // TODO SdB: change into `uint8_t critical : 1;`: We want more flags...
|
||||||
|
Reference in New Issue
Block a user