mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-29 17:19:50 +02:00
Laser mode (#692)
* Update Machine.h * spindles now say if in laser mode * name fix * Updates * Getting rid of crosstalk * Update PWMSpindle.cpp * Reset some values at spindle init() * Update SettingsDefinitions.cpp * Update Grbl.h * Return to test_drive.h
This commit is contained in:
@@ -473,7 +473,7 @@ Error gc_execute_line(char* line, uint8_t client) {
|
||||
gc_block.modal.spindle = SpindleState::Cw;
|
||||
break;
|
||||
case 4: // Supported if SPINDLE_DIR_PIN is defined or laser mode is on.
|
||||
if (spindle->is_reversable || laser_mode->get()) {
|
||||
if (spindle->is_reversable || spindle->inLaserMode()) {
|
||||
gc_block.modal.spindle = SpindleState::Ccw;
|
||||
} else {
|
||||
FAIL(Error::GcodeUnsupportedCommand);
|
||||
@@ -1290,7 +1290,7 @@ Error gc_execute_line(char* line, uint8_t client) {
|
||||
return status;
|
||||
}
|
||||
// If in laser mode, setup laser power based on current and past parser conditions.
|
||||
if (laser_mode->get()) {
|
||||
if (spindle->inLaserMode()) {
|
||||
if (!((gc_block.modal.motion == Motion::Linear) || (gc_block.modal.motion == Motion::CwArc) ||
|
||||
(gc_block.modal.motion == Motion::CcwArc))) {
|
||||
gc_parser_flags |= GCParserLaserDisable;
|
||||
|
@@ -23,7 +23,7 @@
|
||||
// Grbl versioning system
|
||||
|
||||
const char* const GRBL_VERSION = "1.3a";
|
||||
const char* const GRBL_VERSION_BUILD = "20201128";
|
||||
const char* const GRBL_VERSION_BUILD = "20201204";
|
||||
|
||||
//#include <sdkconfig.h>
|
||||
#include <Arduino.h>
|
||||
|
@@ -353,11 +353,7 @@ namespace Motors {
|
||||
auto n_axis = number_axis->get();
|
||||
|
||||
xLastWakeTime = xTaskGetTickCount(); // Initialise the xLastWakeTime variable with the current time.
|
||||
while (true) { // don't ever return from this or the task dies
|
||||
if (motorSettingChanged) {
|
||||
motors_read_settings();
|
||||
motorSettingChanged = false;
|
||||
}
|
||||
while (true) { // don't ever return from this or the task dies
|
||||
if (stallguard_debug_mask->get() != 0) {
|
||||
if (sys.state == State::Cycle || sys.state == State::Homing || sys.state == State::Jog) {
|
||||
for (TrinamicDriver* p = List; p; p = p->link) {
|
||||
|
@@ -96,7 +96,7 @@ bool can_park() {
|
||||
#ifdef ENABLE_PARKING_OVERRIDE_CONTROL
|
||||
sys.override_ctrl == Override::ParkingMotion &&
|
||||
#endif
|
||||
homing_enable->get() && !laser_mode->get();
|
||||
homing_enable->get() && !spindle->inLaserMode();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -558,7 +558,7 @@ static void protocol_exec_rt_suspend() {
|
||||
restore_spindle_speed = block->spindle_speed;
|
||||
}
|
||||
#ifdef DISABLE_LASER_DURING_HOLD
|
||||
if (laser_mode->get()) {
|
||||
if (spindle->inLaserMode()) {
|
||||
sys_rt_exec_accessory_override.bit.spindleOvrStop = true;
|
||||
}
|
||||
#endif
|
||||
@@ -661,7 +661,7 @@ static void protocol_exec_rt_suspend() {
|
||||
if (gc_state.modal.spindle != SpindleState::Disable) {
|
||||
// Block if safety door re-opened during prior restore actions.
|
||||
if (!sys.suspend.bit.restartRetract) {
|
||||
if (laser_mode->get()) {
|
||||
if (spindle->inLaserMode()) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
|
||||
sys.step_control.updateSpindleRpm = true;
|
||||
} else {
|
||||
@@ -717,7 +717,7 @@ static void protocol_exec_rt_suspend() {
|
||||
} else if (sys.spindle_stop_ovr.bit.restore || sys.spindle_stop_ovr.bit.restoreCycle) {
|
||||
if (gc_state.modal.spindle != SpindleState::Disable) {
|
||||
report_feedback_message(Message::SpindleRestore);
|
||||
if (laser_mode->get()) {
|
||||
if (spindle->inLaserMode()) {
|
||||
// When in laser mode, ignore spindle spin-up delay. Set to turn on laser when cycle starts.
|
||||
sys.step_control.updateSpindleRpm = true;
|
||||
} else {
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#include "Grbl.h"
|
||||
|
||||
bool motorSettingChanged = false;
|
||||
|
||||
FlagSetting* verbose_errors;
|
||||
|
||||
FakeSetting<int>* number_axis;
|
||||
@@ -177,22 +175,27 @@ static bool checkStartupLine(char* value) {
|
||||
}
|
||||
|
||||
static bool postTMC(char* value) {
|
||||
if (!value) { // No POST functionality
|
||||
motorSettingChanged = true;
|
||||
if (!value) {
|
||||
motors_read_settings();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool checkSpindleChange(char* val) {
|
||||
if (!val) {
|
||||
spindle->deinit();
|
||||
Spindles::Spindle::select();
|
||||
// if not in disable (M5) ...
|
||||
if (gc_state.modal.spindle != SpindleState::Disable) {
|
||||
gc_state.modal.spindle = SpindleState::Disable;
|
||||
if (spindle->use_delays && spindle_delay_spindown->get() != 0) { // old spindle
|
||||
vTaskDelay(spindle_delay_spindown->get() * 1000);
|
||||
}
|
||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Spindle turned off with setting change");
|
||||
}
|
||||
gc_state.spindle_speed = 0; // Set S value to 0
|
||||
spindle->deinit(); // old spindle
|
||||
Spindles::Spindle::select(); // get new spindle
|
||||
return true;
|
||||
}
|
||||
if (gc_state.modal.spindle != SpindleState::Disable) {
|
||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "Spindle must be off to make this change");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern bool motorSettingChanged;
|
||||
|
||||
extern FlagSetting* verbose_errors;
|
||||
|
||||
extern FakeSetting<int>* number_axis;
|
||||
|
@@ -170,20 +170,25 @@ namespace Spindles {
|
||||
|
||||
void _10v::deinit() {
|
||||
#ifdef SPINDLE_OUTPUT_PIN
|
||||
gpio_reset_pin(SPINDLE_OUTPUT_PIN);
|
||||
pinMode(SPINDLE_OUTPUT_PIN, INPUT);
|
||||
#endif
|
||||
#ifdef SPINDLE_ENABLE_PIN
|
||||
gpio_reset_pin(SPINDLE_ENABLE_PIN);
|
||||
pinMode(SPINDLE_ENABLE_PIN, INPUT);
|
||||
#endif
|
||||
|
||||
#ifdef SPINDLE_DIR_PIN
|
||||
gpio_reset_pin(SPINDLE_DIR_PIN);
|
||||
pinMode(SPINDLE_DIR_PIN, INPUT);
|
||||
#endif
|
||||
#ifdef SPINDLE_FORWARD_PIN
|
||||
gpio_reset_pin(SPINDLE_FORWARD_PIN);
|
||||
pinMode(SPINDLE_FORWARD_PIN, INPUT);
|
||||
#endif
|
||||
|
||||
#ifdef SPINDLE_REVERSE_PIN
|
||||
gpio_reset_pin(SPINDLE_FORWARD_PIN);
|
||||
pinMode(SPINDLE_FORWARD_PIN, INPUT);
|
||||
#endif
|
||||
}
|
||||
|
@@ -24,8 +24,8 @@
|
||||
// ===================================== Laser ==============================================
|
||||
|
||||
namespace Spindles {
|
||||
bool Laser::isRateAdjusted() {
|
||||
return true; // can use M4 (CCW) laser mode.
|
||||
bool Laser::inLaserMode() {
|
||||
return laser_mode->get(); // can use M4 (CCW) laser mode.
|
||||
}
|
||||
|
||||
void Laser::config_message() {
|
||||
@@ -89,10 +89,12 @@ namespace Spindles {
|
||||
void Laser::deinit() {
|
||||
stop();
|
||||
#ifdef LASER_OUTPUT_PIN
|
||||
gpio_reset_pin(LASER_OUTPUT_PIN);
|
||||
pinMode(LASER_OUTPUT_PIN, INPUT);
|
||||
#endif
|
||||
|
||||
#ifdef LASER_ENABLE_PIN
|
||||
gpio_reset_pin(LASER_ENABLE_PIN);
|
||||
pinMode(LASER_ENABLE_PIN, INPUT);
|
||||
#endif
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ namespace Spindles {
|
||||
Laser& operator=(const Laser&) = delete;
|
||||
Laser& operator=(Laser&&) = delete;
|
||||
|
||||
bool isRateAdjusted() override;
|
||||
bool inLaserMode() override;
|
||||
void config_message() override;
|
||||
void get_pins_and_settings() override;
|
||||
void deinit() override;
|
||||
|
@@ -42,14 +42,15 @@ namespace Spindles {
|
||||
return;
|
||||
}
|
||||
|
||||
_current_state = SpindleState::Disable;
|
||||
_current_pwm_duty = 0;
|
||||
use_delays = true;
|
||||
|
||||
ledcSetup(_pwm_chan_num, (double)_pwm_freq, _pwm_precision); // setup the channel
|
||||
ledcAttachPin(_output_pin, _pwm_chan_num); // attach the PWM to the pin
|
||||
|
||||
pinMode(_enable_pin, OUTPUT);
|
||||
pinMode(_direction_pin, OUTPUT);
|
||||
|
||||
use_delays = true;
|
||||
|
||||
config_message();
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ namespace Spindles {
|
||||
}
|
||||
}
|
||||
|
||||
set_enable_pin(_current_state != SpindleState::Disable);
|
||||
set_enable_pin(gc_state.modal.spindle != SpindleState::Disable);
|
||||
set_output(pwm_value);
|
||||
|
||||
return 0;
|
||||
@@ -225,6 +226,14 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
void PWM::set_enable_pin(bool enable) {
|
||||
// static bool prev_enable = false;
|
||||
|
||||
// if (prev_enable == enable) {
|
||||
// return;
|
||||
// }
|
||||
|
||||
// prev_enable = enable;
|
||||
|
||||
if (_enable_pin == UNDEFINED_PIN) {
|
||||
return;
|
||||
}
|
||||
@@ -262,13 +271,16 @@ namespace Spindles {
|
||||
void PWM::deinit() {
|
||||
stop();
|
||||
#ifdef SPINDLE_OUTPUT_PIN
|
||||
gpio_reset_pin(SPINDLE_OUTPUT_PIN);
|
||||
pinMode(SPINDLE_OUTPUT_PIN, INPUT);
|
||||
#endif
|
||||
#ifdef SPINDLE_ENABLE_PIN
|
||||
gpio_reset_pin(SPINDLE_ENABLE_PIN);
|
||||
pinMode(SPINDLE_ENABLE_PIN, INPUT);
|
||||
#endif
|
||||
|
||||
#ifdef SPINDLE_DIR_PIN
|
||||
gpio_reset_pin(SPINDLE_DIR_PIN);
|
||||
pinMode(SPINDLE_DIR_PIN, INPUT);
|
||||
#endif
|
||||
}
|
||||
|
@@ -89,7 +89,7 @@ namespace Spindles {
|
||||
|
||||
// ========================= Spindle ==================================
|
||||
|
||||
bool Spindle::isRateAdjusted() {
|
||||
bool Spindle::inLaserMode() {
|
||||
return false; // default for basic spindle is false
|
||||
}
|
||||
|
||||
|
@@ -64,7 +64,7 @@ namespace Spindles {
|
||||
virtual SpindleState get_state() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void config_message() = 0;
|
||||
virtual bool isRateAdjusted();
|
||||
virtual bool inLaserMode();
|
||||
virtual void sync(SpindleState state, uint32_t rpm);
|
||||
virtual void deinit();
|
||||
|
||||
|
@@ -273,10 +273,10 @@ namespace Spindles {
|
||||
}
|
||||
|
||||
// Initialization is complete, so now it's okay to run the queue task:
|
||||
task_active = true;
|
||||
task_active = true;
|
||||
if (vfd_cmd_queue != nullptr) {
|
||||
vfd_cmd_queue = xQueueCreate(VFD_RS485_QUEUE_SIZE, sizeof(ModbusCommand));
|
||||
}
|
||||
}
|
||||
xTaskCreatePinnedToCore(vfd_cmd_task, // task
|
||||
"vfd_cmdTaskHandle", // name for task
|
||||
2048, // size of task stack
|
||||
@@ -323,6 +323,7 @@ namespace Spindles {
|
||||
pins_settings_ok = false;
|
||||
#endif
|
||||
|
||||
// TODO Test no longer required.
|
||||
if (laser_mode->get()) {
|
||||
grbl_msg_sendf(CLIENT_ALL, MsgLevel::Info, "VFD spindle disabled in laser mode. Set $GCode/LaserMode=Off and restart");
|
||||
pins_settings_ok = false;
|
||||
|
@@ -551,7 +551,7 @@ void st_prep_buffer() {
|
||||
prep.current_speed = sqrt(pl_block->entry_speed_sqr);
|
||||
}
|
||||
|
||||
if (spindle->isRateAdjusted()) { // laser_mode->get() {
|
||||
if (spindle->inLaserMode()) { //
|
||||
if (pl_block->spindle == SpindleState::Ccw) {
|
||||
// Pre-compute inverse programmed rate to speed up PWM updating per step segment.
|
||||
prep.inv_rate = 1.0 / pl_block->programmed_rate;
|
||||
|
Reference in New Issue
Block a user