Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented mesh leveling for working region #343

Merged
2 changes: 1 addition & 1 deletion makefiles/virtual/uCNC.dev
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ IncludeVersionInfo=0
SupportXPThemes=0
CompilerSet=1
CompilerSettings=000000e0a0000000001000000
UnitCount=78
UnitCount=77

[VersionInfo]
Major=1
Expand Down
96 changes: 96 additions & 0 deletions tests/gcode/motion-tests-hmap.ngc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
G90G21G54M48
G39Z-1R5I10J10F50
G0X0Y0Z0
(SQUARE)
F1000
G1X10
Y10
X0
Y0
M1
(CROSS)
X10Y10
G0Z1
X0
G1Z0
Y0X10
M1
(PLUS)
G0Z1
X5Y0
G1Z0
Y10
G0Z1
X0Y5
G1Z0
X10
M1
(CIRCLE)
G0X10Y5Z0
F1000
G17G3X5Y10I-5
G3X5Y0J-5
G0Z1
X10Y5
G1Z0
G2X5Y0I-5
M1
(SPIRAL)
G0Z5
X2.5Y5
(DWELL 1S)
G4P3
G2X7.5Z2.5I2.5
G2X2.5Z0I-2.5
M1
(CIRCLE WITH R)
G2X7.5R2.5
G2X2.5R2.5
M1
G0X0Y0Z0
(RELATIVE)
F1000
G91
G1X10
Y10
X-10
Y-10
M1
(CROSS)
X10Y10
G0Z1
X-10
G1Z-1
Y-10X10
M1
(PLUS)
G0Z1
X-5
G1Z-1
X0Y10
G0Z1
X-5Y-5
G1Z-1
X10
M1
(CIRCLE)
G91F1000
G17G3X-5Y5I-5
X0Y-10J-5
G0Z1
X5Y5
G0Z-1
G2X-5Y-5I-5
(SPIRAL)
G0Z5
X-2.5Y5
(DWELL)
G4P3
G2X5Z-2.5I2.5
X-5Z-2.5I-2.5
M1
(CIRCLE WITH R)
G2X5R2.5
X-5R2.5
M1
G90
34 changes: 30 additions & 4 deletions uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,32 @@ extern "C"
#ifdef ENABLE_SKEW_COMPENSATION
// uncomment to correct only in the xy axis
//#define SKEW_COMPENSATION_XY_ONLY
#endif

/**
* Uncomment to enable surface height mapping compensation
* This enables G39 gcode and is useful for PCB milling and similar jobs
* It uses a 9 point matrix and bilinear interpolation to compensate for Z height deformations
* To map a region do G39 X<left bottom corner> Y<left bottom corner> Z<max-depth> I<X region offset> J<Y region offset>
* G39.1 will disable HMAP
* G39.2 will re-enable it
*
* It's an error if:
* - I and J are missing
* - I or J are negative
* - Z is missing
* - cutter radius compensation is active (not implemented)
*
* The map will not be stored in memory and will be reset on any of the following conditions
* - a hardware or software reset
* - a homing command
**/
// #define ENABLE_G39_H_MAPPING
#ifdef ENABLE_G39_H_MAPPING
// set the grid size factor
// this sets the size of the Hmap -> H_MAPING_GRID_FACTOR ^ 2
// the minimum value is 2 (4 points) and the maximum is 6 (36 points)
#define H_MAPING_GRID_FACTOR 3
#endif

/**
Expand Down Expand Up @@ -288,8 +314,8 @@ extern "C"
* (performs 0 steps in the ISR tick) and skips calculations
* */

#define STEP_ISR_SKIP_MAIN
#define STEP_ISR_SKIP_IDLE
// #define STEP_ISR_SKIP_MAIN
// #define STEP_ISR_SKIP_IDLE

/**
* Sets the maximum number of step doubling loops carried by the DSS (Dynamic
Expand Down Expand Up @@ -379,15 +405,15 @@ extern "C"
* that uCNC is recognized a Grbl protocol controller device)
* */

#define EMULATE_GRBL_STARTUP
// #define EMULATE_GRBL_STARTUP

/**
*
* Enables $I Grbl info command on µCNC.
*
* */

#define ENABLE_SYSTEM_INFO
// #define ENABLE_SYSTEM_INFO

/**
* Enables additional core grbl system commands
Expand Down
11 changes: 8 additions & 3 deletions uCNC/src/core/interpolator.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ static itp_segment_t *itp_rt_sgm;
#if (defined(ENABLE_DUAL_DRIVE_AXIS) || defined(IS_DELTA_KINEMATICS))
static volatile uint8_t itp_step_lock;
#endif
// keeps track if the itp timer is running or not (prevent restarting)
static volatile bool itp_is_running;

#ifdef ENABLE_RT_SYNC_MOTIONS
volatile int32_t itp_sync_step_counter;
Expand Down Expand Up @@ -212,7 +214,6 @@ static bool itp_sgm_is_full(void)

static bool itp_sgm_is_empty(void)
{

return (itp_sgm_data_read == itp_sgm_data_write);
}

Expand Down Expand Up @@ -1058,6 +1059,8 @@ void itp_stop(void)
cnc_set_exec_state(EXEC_HALT);
}

cnc_clear_exec_state(EXEC_RUN);

io_set_steps(g_settings.step_invert_mask);
#if TOOL_COUNT > 0
if (g_settings.laser_mode)
Expand All @@ -1067,6 +1070,7 @@ void itp_stop(void)
#endif

mcu_stop_itp_isr();
itp_is_running = false;
}

void itp_stop_tools(void)
Expand Down Expand Up @@ -1711,14 +1715,15 @@ MCU_CALLBACK void mcu_step_cb(void)
void itp_start(bool is_synched)
{
// starts the step isr if is stopped and there are segments to execute
if (!cnc_get_exec_state(EXEC_HOLD | EXEC_ALARM | EXEC_RUN | EXEC_RESUMING) && !itp_sgm_is_empty()) // exec state is not hold or alarm and not already running
if (!cnc_get_exec_state(EXEC_HOLD | EXEC_ALARM | EXEC_RESUMING) && !itp_sgm_is_empty() && !itp_is_running) // exec state is not hold or alarm and not already running
{
// check if the start is controlled by synched motion before start
if (!is_synched)
{
cnc_set_exec_state(EXEC_RUN); // flags that it started running
__ATOMIC__
{
cnc_set_exec_state(EXEC_RUN); // flags that it started running
itp_is_running = true;
mcu_start_itp_isr(itp_sgm_data[itp_sgm_data_read].timer_counter, itp_sgm_data[itp_sgm_data_read].timer_prescaller);
}
}
Expand Down
38 changes: 25 additions & 13 deletions uCNC/src/core/io_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ static volatile uint8_t io_spindle_speed;
static uint8_t io_lock_limits_mask;
static uint8_t io_invert_limits_mask;

#if ASSERT_PIN(PROBE)
static volatile bool io_last_probe;
static bool io_probe_enabled;
#endif

#ifdef ENABLE_IO_ALARM_DEBUG
uint8_t io_alarm_limits;
uint8_t io_alarm_controls;
Expand Down Expand Up @@ -226,23 +231,26 @@ MCU_IO_CALLBACK void mcu_controls_changed_cb(void)

MCU_IO_CALLBACK void mcu_probe_changed_cb(void)
{
#ifdef DISABLE_PROBE
#if !ASSERT_PIN(PROBE)
return;
#endif
#else

if (!io_probe_enabled)
{
return;
}

#if ASSERT_PIN(PROBE)
static bool prev_probe = false;
bool probe = io_get_probe();

if (prev_probe == probe)
if (io_last_probe == probe)
{
return;
}

prev_probe = probe;
io_last_probe = probe;

// on hit enables hold (directly)
cnc_set_exec_state(EXEC_HOLD);
// stops the machine
itp_stop();
// stores rt position
parser_sync_probe();
#endif
Expand Down Expand Up @@ -452,39 +460,43 @@ uint8_t io_get_controls(void)

void io_enable_probe(void)
{
#if ASSERT_PIN(PROBE)
io_last_probe = io_get_probe();
#ifdef ENABLE_IO_MODULES
EVENT_INVOKE(probe_enable, NULL);
#endif
#ifndef FORCE_SOFT_POLLING
#if ASSERT_PIN(PROBE)
mcu_enable_probe_isr();
#endif
io_probe_enabled = true;
#endif
}

void io_disable_probe(void)
{
#ifndef FORCE_SOFT_POLLING
#if ASSERT_PIN(PROBE)
io_probe_enabled = false;
#ifndef FORCE_SOFT_POLLING
mcu_disable_probe_isr();
#endif
#endif
#ifdef ENABLE_IO_MODULES
EVENT_INVOKE(probe_disable, NULL);
#endif
#endif
}

bool io_get_probe(void)
{
#ifdef DISABLE_PROBE
#if !ASSERT_PIN(PROBE)
return false;
#endif
#else
#if ASSERT_PIN(PROBE)
bool probe = (mcu_get_input(PROBE) != 0);
return (!g_settings.probe_invert_mask) ? probe : !probe;
#else
return false;
#endif
#endif
}

// outputs
Expand Down
Loading