Skip to content

Commit

Permalink
Merge branch 'main' into BetterI2SClocking
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley authored Dec 31, 2024
2 parents 0b95935 + 4984788 commit 09c1a4e
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 29 deletions.
156 changes: 156 additions & 0 deletions FluidNC/data/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
board: None
name: Default (Test Drive no I/O)
meta:
stepping:
engine: RMT
idle_ms: 255
pulse_us: 4
dir_delay_us: 0
disable_delay_us: 0
segments: 12

spi:
miso_pin: NO_PIN
mosi_pin: NO_PIN
sck_pin: NO_PIN

sdcard:
cs_pin: NO_PIN
card_detect_pin: NO_PIN
frequency_hz: 8000000

kinematics:
Cartesian:

axes:
shared_stepper_disable_pin: NO_PIN
shared_stepper_reset_pin: NO_PIN
homing_runs: 2
x:
steps_per_mm: 80.000000
max_rate_mm_per_min: 1000.000000
acceleration_mm_per_sec2: 25.000000
max_travel_mm: 1000.000000
soft_limits: false
motor0:
limit_neg_pin: NO_PIN
limit_pos_pin: NO_PIN
limit_all_pin: NO_PIN
hard_limits: false
pulloff_mm: 1.000000
null_motor:

y:
steps_per_mm: 80.000000
max_rate_mm_per_min: 1000.000000
acceleration_mm_per_sec2: 25.000000
max_travel_mm: 1000.000000
soft_limits: false
motor0:
limit_neg_pin: NO_PIN
limit_pos_pin: NO_PIN
limit_all_pin: NO_PIN
hard_limits: false
pulloff_mm: 1.000000
null_motor:

z:
steps_per_mm: 80.000000
max_rate_mm_per_min: 1000.000000
acceleration_mm_per_sec2: 25.000000
max_travel_mm: 1000.000000
soft_limits: false
motor0:
limit_neg_pin: NO_PIN
limit_pos_pin: NO_PIN
limit_all_pin: NO_PIN
hard_limits: false
pulloff_mm: 1.000000
null_motor:

control:
safety_door_pin: NO_PIN
reset_pin: NO_PIN
feed_hold_pin: NO_PIN
cycle_start_pin: NO_PIN
macro0_pin: NO_PIN
macro1_pin: NO_PIN
macro2_pin: NO_PIN
macro3_pin: NO_PIN
fault_pin: NO_PIN
estop_pin: NO_PIN

coolant:
flood_pin: NO_PIN
mist_pin: NO_PIN
delay_ms: 0

probe:
pin: NO_PIN
toolsetter_pin: NO_PIN
check_mode_start: true
hard_stop: false

macros:
startup_line0:
startup_line1:
Macro0:
Macro1:
Macro2:
Macro3:
after_homing:
after_reset:
after_unlock:

start:
must_home: false
deactivate_parking: false
check_limits: true

parking:
enable: false
axis: Z
target_mpos_mm: -5.000000
rate_mm_per_min: 800.000000
pullout_distance_mm: 5.000000
pullout_rate_mm_per_min: 250.000000

user_outputs:
analog0_pin: NO_PIN
analog1_pin: NO_PIN
analog2_pin: NO_PIN
analog3_pin: NO_PIN
analog0_hz: 5000
analog1_hz: 5000
analog2_hz: 5000
analog3_hz: 5000
digital0_pin: NO_PIN
digital1_pin: NO_PIN
digital2_pin: NO_PIN
digital3_pin: NO_PIN
digital4_pin: NO_PIN
digital5_pin: NO_PIN
digital6_pin: NO_PIN
digital7_pin: NO_PIN

user_inputs:
analog0_pin: NO_PIN
analog1_pin: NO_PIN
analog2_pin: NO_PIN
analog3_pin: NO_PIN
digital0_pin: NO_PIN
digital1_pin: NO_PIN
digital2_pin: NO_PIN
digital3_pin: NO_PIN
digital4_pin: NO_PIN
digital5_pin: NO_PIN
digital6_pin: NO_PIN
digital7_pin: NO_PIN

arc_tolerance_mm: 0.002000
junction_deviation_mm: 0.010000
verbose_errors: true
report_inches: false
enable_parking_override_control: false
use_line_numbers: false
planner_blocks: 16
7 changes: 3 additions & 4 deletions FluidNC/esp32/i2s_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,10 @@ static int i2s_out_start() {

static bool timer_running = false;

// i2s_out_delay() is used by synchronous_write(), to ensure that that
// the newly-written data has arrived at the shift register output
void i2s_out_delay() {
// Depending on the timing, it may not be reflected immediately,
// so wait twice as long just in case.
uint32_t wait_counts = timer_running ? FIFO_THRESHOLD + FIFO_RELOAD : 2;
delay_us(i2s_frame_us * wait_counts);
delay_us((FIFO_LENGTH + FIFO_RELOAD) * (I2S_OUT_USEC_PER_PULSE / 2));
}

void IRAM_ATTR i2s_out_write(pinnum_t pin, uint8_t val) {
Expand Down
6 changes: 5 additions & 1 deletion FluidNC/src/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Logging.h"
#include "Job.h"
#include <string_view>
#include <algorithm>

void Channel::flushRx() {
_linelen = 0;
Expand Down Expand Up @@ -328,7 +329,7 @@ void Channel::sendLine(MsgLevel level, const std::string& line) {
}
}

bool Channel::is_visible(const std::string& stem, const std::string& extension, bool isdir) {
bool Channel::is_visible(const std::string& stem, std::string extension, bool isdir) {
if (stem.length() && stem[0] == '.') {
// Exclude hidden files and directories
return false;
Expand All @@ -341,6 +342,9 @@ bool Channel::is_visible(const std::string& stem, const std::string& extension,
return true;
}

// Convert extension to canonical lower case format
std::transform(extension.begin(), extension.end(), extension.begin(), [](unsigned char c) { return std::tolower(c); });

// common gcode extensions
std::string_view extensions(".g .gc .gco .gcode .nc .ngc .ncc .txt .cnc .tap");
int pos = 0;
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Channel : public Stream {
return readBytes(buffer, length);
}

virtual bool is_visible(const std::string& stem, const std::string& extension, bool isdir);
virtual bool is_visible(const std::string& stem, std::string extension, bool isdir);

size_t timedReadBytes(uint8_t* buffer, size_t length, TickType_t timeout) {
return timedReadBytes(reinterpret_cast<char*>(buffer), length, timeout);
Expand Down
10 changes: 10 additions & 0 deletions FluidNC/src/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ std::string Control::report_status() {
return ret;
}

bool Control::pins_block_unlock() {
std::string blockers("FE"); // Fault, E-Stop block unlock and homing
for (auto pin : _pins) {
if (pin->get() && blockers.find(pin->letter()) != std::string::npos) {
return true;
}
}
return false;
}

bool Control::stuck() {
for (auto pin : _pins) {
if (pin->get()) {
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Control : public Configuration::Configurable {

bool stuck();
bool safety_door_ajar();
bool pins_block_unlock();

std::string report_status();

Expand Down
12 changes: 7 additions & 5 deletions FluidNC/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ gc_modal_t modal_defaults = {

void gc_init() {
// Reset parser state:
auto save_tlo = gc_state.tool_length_offset; // we want TLO to persist until reboot.
memset(&gc_state, 0, sizeof(parser_state_t));
gc_state.tool_length_offset = save_tlo;

// Load default G54 coordinate system.
gc_state.modal = modal_defaults;
Expand Down Expand Up @@ -1603,7 +1605,7 @@ Error gc_execute_line(char* line) {
// NOTE: Pass zero spindle speed for all restricted laser motions.
if (!disableLaser) {
pl_data->spindle_speed = gc_state.spindle_speed; // Record data for planner use.
} // else { pl_data->spindle_speed = 0.0; } // Initialized as zero already.
} // else { pl_data->spindle_speed = 0.0; } // Initialized as zero already.
// [5. Select tool ]: NOT SUPPORTED. Only tracks tool value.
// [M6. Change tool ]:
if (gc_block.modal.tool_change == ToolChange::Enable) {
Expand All @@ -1627,9 +1629,9 @@ Error gc_execute_line(char* line) {
}
if (gc_block.modal.set_tool_number == SetToolNumber::Enable) {
gc_state.selected_tool = gc_block.values.q;
bool stopped_spindle = false; // was spindle stopped via the change
bool new_spindle = false; // was the spindle changed
protocol_buffer_synchronize(); // wait for motion in buffer to finish
bool stopped_spindle = false; // was spindle stopped via the change
bool new_spindle = false; // was the spindle changed
protocol_buffer_synchronize(); // wait for motion in buffer to finish
Spindles::Spindle::switchSpindle(gc_state.selected_tool, Spindles::SpindleFactory::objects(), spindle, stopped_spindle, new_spindle);
if (stopped_spindle) {
gc_block.modal.spindle = SpindleState::Disable;
Expand Down Expand Up @@ -1786,10 +1788,10 @@ Error gc_execute_line(char* line) {
switch (gc_block.non_modal_command) {
case NonModal::SetCoordinateData:
coords[coord_select]->set(coord_data);
gc_wco_changed();
// Update system coordinate system if currently active.
if (gc_state.modal.coord_select == coord_select) {
copyAxes(gc_state.coord_system, coord_data);
gc_wco_changed();
}
break;
case NonModal::GoHome0:
Expand Down
31 changes: 31 additions & 0 deletions FluidNC/src/ProcessSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
// WU Readable and writable as user and admin
// WA Readable as user and admin, writable as admin

static Error switchInchMM(const char* value, AuthenticationLevel auth_level, Channel& out);

static Error fakeMaxSpindleSpeed(const char* value, AuthenticationLevel auth_level, Channel& out);

static Error report_init_message_cmd(const char* value, AuthenticationLevel auth_level, Channel& out);

// If authentication is disabled, auth_level will be LEVEL_ADMIN
static bool auth_failed(Word* w, const char* value, AuthenticationLevel auth_level) {
permissions_t permissions = w->getPermissions();
Expand Down Expand Up @@ -193,9 +197,13 @@ static void show_settings(Channel& out, type_t type) {
show_setting(s->getGrblName(), s->getCompatibleValue(), NULL, out);
}
}
// Print Report/Inches
switchInchMM(NULL, AuthenticationLevel::LEVEL_ADMIN, out);

// need this per issue #1036
fakeMaxSpindleSpeed(NULL, AuthenticationLevel::LEVEL_ADMIN, out);
}

static Error report_normal_settings(const char* value, AuthenticationLevel auth_level, Channel& out) {
show_settings(out, GRBL); // GRBL non-axis settings
return Error::Ok;
Expand Down Expand Up @@ -377,6 +385,10 @@ static Error cmd_log_verbose(const char* value, AuthenticationLevel auth_level,
return Error::Ok;
}
static Error home(AxisMask axisMask, Channel& out) {
// see if blocking control switches are active
if (config->_control->pins_block_unlock()) {
return Error::CheckControlPins;
}
if (axisMask != Machine::Homing::AllCycles) { // if not AllCycles we need to make sure the cycle is not prohibited
// if there is a cycle it is the axis from $H<axis>
auto n_axis = Axes::_numberAxis;
Expand Down Expand Up @@ -705,6 +717,22 @@ static Error dump_config(const char* value, AuthenticationLevel auth_level, Chan
return Error::Ok;
}

static Error report_init_message_cmd(const char* value, AuthenticationLevel auth_level, Channel& out) {
report_init_message(out);

return Error::Ok;
}

static Error switchInchMM(const char* value, AuthenticationLevel auth_level, Channel& out) {
if (!value) {
log_stream(out, "$13=" << (config->_reportInches ? "1" : "0"));
} else {
config->_reportInches = ((value[0]=='1') ? true : false);
}

return Error::Ok;
}

static Error fakeMaxSpindleSpeed(const char* value, AuthenticationLevel auth_level, Channel& out) {
if (!value) {
log_stream(out, "$30=" << spindle->maxSpeed());
Expand Down Expand Up @@ -837,9 +865,12 @@ void make_user_commands() {

new UserCommand("RI", "Report/Interval", setReportInterval, anyState);

new UserCommand("13", "Report/Inches", switchInchMM, notIdleOrAlarm);
new UserCommand("30", "FakeMaxSpindleSpeed", fakeMaxSpindleSpeed, notIdleOrAlarm);
new UserCommand("32", "FakeLaserMode", fakeLaserMode, notIdleOrAlarm);

new UserCommand("GS", "GRBL/Show", report_init_message_cmd, notIdleOrAlarm);

new AsyncUserCommand("J", "Jog", doJog, notIdleOrJog);
new AsyncUserCommand("G", "GCode/Modes", report_gcode, anyState);
};
Expand Down
14 changes: 6 additions & 8 deletions FluidNC/src/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,16 +484,17 @@ static void protocol_do_alarm(void* alarmVoid) {
static void protocol_start_holding() {
if (!(sys.suspend.bit.motionCancel || sys.suspend.bit.jogCancel)) { // Block, if already holding.
sys.step_control = {};
if (!Stepper::update_plan_block_parameters()) { // Notify stepper module to recompute for hold deceleration.
sys.step_control.endMotion = true;
}
Stepper::update_plan_block_parameters();
sys.step_control.executeHold = true; // Initiate suspend state with active flag.
}
}

static void protocol_cancel_jogging() {
if (!sys.suspend.bit.motionCancel) {
sys.suspend.bit.jogCancel = true;
if (!(sys.suspend.bit.motionCancel || sys.suspend.bit.jogCancel)) { // Block, if already holding.
sys.step_control = {};
Stepper::update_plan_block_parameters();
sys.step_control.executeHold = true; // Initiate suspend state with active flag.
sys.suspend.bit.jogCancel = true;
}
}

Expand Down Expand Up @@ -525,7 +526,6 @@ void protocol_do_motion_cancel() {
break;

case State::Jog:
protocol_start_holding();
protocol_cancel_jogging();
// When jogging, we do not set motionCancel, hence return not break
return;
Expand Down Expand Up @@ -571,7 +571,6 @@ static void protocol_do_feedhold() {
break;

case State::Jog:
protocol_start_holding();
protocol_cancel_jogging();
return; // Do not change the state to Hold
}
Expand Down Expand Up @@ -623,7 +622,6 @@ static void protocol_do_safety_door() {
protocol_start_holding();
break;
case State::Jog:
protocol_start_holding();
protocol_cancel_jogging();
break;
}
Expand Down
Loading

0 comments on commit 09c1a4e

Please sign in to comment.