cleanup global var and push probe mode into probe_get_state
This commit is contained in:
parent
b89d194466
commit
5406fa939a
34
gcode.c
34
gcode.c
@ -124,7 +124,7 @@ uint8_t gc_execute_line(char *line)
|
|||||||
float value;
|
float value;
|
||||||
uint8_t int_value = 0;
|
uint8_t int_value = 0;
|
||||||
uint8_t mantissa = 0; // NOTE: For mantissa values > 255, variable type must be changed to uint16_t.
|
uint8_t mantissa = 0; // NOTE: For mantissa values > 255, variable type must be changed to uint16_t.
|
||||||
|
uint8_t probe_mode = 0;
|
||||||
|
|
||||||
while (line[char_counter] != 0) { // Loop until no more g-code words in line.
|
while (line[char_counter] != 0) { // Loop until no more g-code words in line.
|
||||||
|
|
||||||
@ -210,22 +210,21 @@ uint8_t gc_execute_line(char *line)
|
|||||||
case 3: gc_block.modal.motion = MOTION_MODE_CCW_ARC; break; // G3
|
case 3: gc_block.modal.motion = MOTION_MODE_CCW_ARC; break; // G3
|
||||||
case 38:
|
case 38:
|
||||||
switch(mantissa) {
|
switch(mantissa) {
|
||||||
case 20:
|
case 20: // G38.2
|
||||||
sys.probe_away = false;
|
|
||||||
gc_block.modal.motion = MOTION_MODE_PROBE;
|
gc_block.modal.motion = MOTION_MODE_PROBE;
|
||||||
break; // G38.2
|
break;
|
||||||
case 30:
|
case 30: // G38.3
|
||||||
sys.probe_away = false;
|
|
||||||
gc_block.modal.motion = MOTION_MODE_PROBE_NO_ERROR;
|
|
||||||
break; // G38.3
|
|
||||||
case 40:
|
|
||||||
sys.probe_away = true;
|
|
||||||
gc_block.modal.motion = MOTION_MODE_PROBE;
|
gc_block.modal.motion = MOTION_MODE_PROBE;
|
||||||
break; // G38.4
|
probe_mode = PROBE_NO_ERROR;
|
||||||
case 50:
|
break;
|
||||||
sys.probe_away = true;
|
case 40: // G38.4
|
||||||
gc_block.modal.motion = MOTION_MODE_PROBE_NO_ERROR;
|
gc_block.modal.motion = MOTION_MODE_PROBE;
|
||||||
break; // G38.5
|
probe_mode = PROBE_AWAY;
|
||||||
|
break;
|
||||||
|
case 50: // G38.5
|
||||||
|
gc_block.modal.motion = MOTION_MODE_PROBE;
|
||||||
|
probe_mode = PROBE_AWAY | PROBE_NO_ERROR;
|
||||||
|
break;
|
||||||
|
|
||||||
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G38.x command]
|
default: FAIL(STATUS_GCODE_UNSUPPORTED_COMMAND); // [Unsupported G38.x command]
|
||||||
}
|
}
|
||||||
@ -982,13 +981,12 @@ uint8_t gc_execute_line(char *line)
|
|||||||
#endif
|
#endif
|
||||||
break;
|
break;
|
||||||
case MOTION_MODE_PROBE:
|
case MOTION_MODE_PROBE:
|
||||||
case MOTION_MODE_PROBE_NO_ERROR:
|
|
||||||
// NOTE: gc_block.values.xyz is returned from mc_probe_cycle with the updated position value. So
|
// NOTE: gc_block.values.xyz is returned from mc_probe_cycle with the updated position value. So
|
||||||
// upon a successful probing cycle, the machine position and the returned value should be the same.
|
// upon a successful probing cycle, the machine position and the returned value should be the same.
|
||||||
#ifdef USE_LINE_NUMBERS
|
#ifdef USE_LINE_NUMBERS
|
||||||
mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, gc_block.values.n);
|
mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, probe_mode, gc_block.values.n);
|
||||||
#else
|
#else
|
||||||
mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate);
|
mc_probe_cycle(gc_block.values.xyz, gc_state.feed_rate, gc_state.modal.feed_rate, probe_mode);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
gcode.h
5
gcode.h
@ -71,9 +71,8 @@
|
|||||||
#define MOTION_MODE_LINEAR 1 // G1
|
#define MOTION_MODE_LINEAR 1 // G1
|
||||||
#define MOTION_MODE_CW_ARC 2 // G2
|
#define MOTION_MODE_CW_ARC 2 // G2
|
||||||
#define MOTION_MODE_CCW_ARC 3 // G3
|
#define MOTION_MODE_CCW_ARC 3 // G3
|
||||||
#define MOTION_MODE_PROBE 4 // G38.2, G38.4
|
#define MOTION_MODE_PROBE 4 // G38.2, G38.3, G38.4, G38.5
|
||||||
#define MOTION_MODE_PROBE_NO_ERROR 5 // G38.3, G38.5
|
#define MOTION_MODE_NONE 5 // G80
|
||||||
#define MOTION_MODE_NONE 6 // G80
|
|
||||||
|
|
||||||
// Modal Group G2: Plane select
|
// Modal Group G2: Plane select
|
||||||
#define PLANE_SELECT_XY 0 // G17 (Default: Must be zero)
|
#define PLANE_SELECT_XY 0 // G17 (Default: Must be zero)
|
||||||
|
@ -276,9 +276,9 @@ void mc_homing_cycle()
|
|||||||
// Perform tool length probe cycle. Requires probe switch.
|
// Perform tool length probe cycle. Requires probe switch.
|
||||||
// NOTE: Upon probe failure, the program will be stopped and placed into ALARM state.
|
// NOTE: Upon probe failure, the program will be stopped and placed into ALARM state.
|
||||||
#ifdef USE_LINE_NUMBERS
|
#ifdef USE_LINE_NUMBERS
|
||||||
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, int32_t line_number)
|
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, uint8_t mode, int32_t line_number)
|
||||||
#else
|
#else
|
||||||
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate)
|
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, uint8_t mode)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// TODO: Need to update this cycle so it obeys a non-auto cycle start.
|
// TODO: Need to update this cycle so it obeys a non-auto cycle start.
|
||||||
@ -289,7 +289,7 @@ void mc_homing_cycle()
|
|||||||
uint8_t auto_start_state = sys.auto_start; // Store run state
|
uint8_t auto_start_state = sys.auto_start; // Store run state
|
||||||
|
|
||||||
// After syncing, check if probe is already triggered. If so, halt and issue alarm.
|
// After syncing, check if probe is already triggered. If so, halt and issue alarm.
|
||||||
if ((sys.probe_away << PROBE_BIT) ^ probe_get_state()) {
|
if (probe_get_state(mode)) {
|
||||||
bit_true_atomic(sys.execute, EXEC_CRIT_EVENT);
|
bit_true_atomic(sys.execute, EXEC_CRIT_EVENT);
|
||||||
protocol_execute_runtime();
|
protocol_execute_runtime();
|
||||||
}
|
}
|
||||||
@ -303,7 +303,7 @@ void mc_homing_cycle()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Activate the probing monitor in the stepper module.
|
// Activate the probing monitor in the stepper module.
|
||||||
sys.probe_state = PROBE_ACTIVE;
|
sys.probe_state = PROBE_ACTIVE | mode;
|
||||||
|
|
||||||
// Perform probing cycle. Wait here until probe is triggered or motion completes.
|
// Perform probing cycle. Wait here until probe is triggered or motion completes.
|
||||||
bit_true_atomic(sys.execute, EXEC_CYCLE_START);
|
bit_true_atomic(sys.execute, EXEC_CYCLE_START);
|
||||||
@ -314,6 +314,7 @@ void mc_homing_cycle()
|
|||||||
|
|
||||||
// Probing motion complete. If the probe has not been triggered, error out.
|
// Probing motion complete. If the probe has not been triggered, error out.
|
||||||
if (sys.probe_state == PROBE_ACTIVE) { bit_true_atomic(sys.execute, EXEC_CRIT_EVENT); }
|
if (sys.probe_state == PROBE_ACTIVE) { bit_true_atomic(sys.execute, EXEC_CRIT_EVENT); }
|
||||||
|
if (sys.probe_state & PROBE_ACTIVE) { bit_true_atomic(sys.execute, EXEC_CRIT_EVENT); }
|
||||||
protocol_execute_runtime(); // Check and execute run-time commands
|
protocol_execute_runtime(); // Check and execute run-time commands
|
||||||
if (sys.abort) { return; } // Check for system abort
|
if (sys.abort) { return; } // Check for system abort
|
||||||
|
|
||||||
|
@ -58,9 +58,9 @@ void mc_homing_cycle();
|
|||||||
|
|
||||||
// Perform tool length probe cycle. Requires probe switch.
|
// Perform tool length probe cycle. Requires probe switch.
|
||||||
#ifdef USE_LINE_NUMBERS
|
#ifdef USE_LINE_NUMBERS
|
||||||
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, int32_t line_number);
|
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, uint8_t motion, int32_t line_number);
|
||||||
#else
|
#else
|
||||||
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate);
|
void mc_probe_cycle(float *target, float feed_rate, uint8_t invert_feed_rate, uint8_t motion);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Performs system reset. If in motion state, kills all motion and sets system alarm.
|
// Performs system reset. If in motion state, kills all motion and sets system alarm.
|
||||||
|
12
probe.c
12
probe.c
@ -37,22 +37,22 @@ void probe_init()
|
|||||||
PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation.
|
PROBE_PORT |= PROBE_MASK; // Enable internal pull-up resistors. Normal high operation.
|
||||||
probe_invert_mask = PROBE_MASK;
|
probe_invert_mask = PROBE_MASK;
|
||||||
}
|
}
|
||||||
|
|
||||||
sys.probe_away = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor.
|
// Returns the probe pin state. Triggered = true. Called by gcode parser and probe state monitor.
|
||||||
uint8_t probe_get_state() { return((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask); }
|
uint8_t probe_get_state(uint8_t mode) {
|
||||||
|
mode = ((mode >> PROBE_AWAY_BIT) & 1) << PROBE_BIT;
|
||||||
|
return mode ^ ((PROBE_PIN & PROBE_MASK) ^ probe_invert_mask);
|
||||||
|
}
|
||||||
|
|
||||||
// Monitors probe pin state and records the system position when detected. Called by the
|
// Monitors probe pin state and records the system position when detected. Called by the
|
||||||
// stepper ISR per ISR tick.
|
// stepper ISR per ISR tick.
|
||||||
// NOTE: This function must be extremely efficient as to not bog down the stepper ISR.
|
// NOTE: This function must be extremely efficient as to not bog down the stepper ISR.
|
||||||
void probe_state_monitor()
|
void probe_state_monitor()
|
||||||
{
|
{
|
||||||
if (sys.probe_state == PROBE_ACTIVE) {
|
if (sys.probe_state != PROBE_OFF) {
|
||||||
if ((sys.probe_away << PROBE_BIT) ^ probe_get_state()) {
|
if (probe_get_state(sys.probe_state)) {
|
||||||
sys.probe_state = PROBE_OFF;
|
sys.probe_state = PROBE_OFF;
|
||||||
memcpy(sys.probe_position, sys.position, sizeof(float)*N_AXIS);
|
memcpy(sys.probe_position, sys.position, sizeof(float)*N_AXIS);
|
||||||
bit_true(sys.execute, EXEC_FEED_HOLD);
|
bit_true(sys.execute, EXEC_FEED_HOLD);
|
||||||
|
8
probe.h
8
probe.h
@ -25,12 +25,18 @@
|
|||||||
#define PROBE_OFF 0 // No probing. (Must be zero.)
|
#define PROBE_OFF 0 // No probing. (Must be zero.)
|
||||||
#define PROBE_ACTIVE 1 // Actively watching the input pin.
|
#define PROBE_ACTIVE 1 // Actively watching the input pin.
|
||||||
|
|
||||||
|
// Probe direction and error modes
|
||||||
|
#define PROBE_AWAY 2 // G38.4, G38.5
|
||||||
|
#define PROBE_NO_ERROR 4 // G38.3, G38.5
|
||||||
|
|
||||||
|
#define PROBE_AWAY_BIT 1
|
||||||
|
#define PROBE_NO_ERROR_BIT 2
|
||||||
|
|
||||||
// Probe pin initialization routine.
|
// Probe pin initialization routine.
|
||||||
void probe_init();
|
void probe_init();
|
||||||
|
|
||||||
// Returns probe pin state.
|
// Returns probe pin state.
|
||||||
uint8_t probe_get_state();
|
uint8_t probe_get_state(uint8_t mode);
|
||||||
|
|
||||||
// Monitors probe pin state and records the system position when detected. Called by the
|
// Monitors probe pin state and records the system position when detected. Called by the
|
||||||
// stepper ISR per ISR tick.
|
// stepper ISR per ISR tick.
|
||||||
|
1
system.h
1
system.h
@ -79,7 +79,6 @@ typedef struct {
|
|||||||
uint8_t auto_start; // Planner auto-start flag. Toggled off during feed hold. Defaulted by settings.
|
uint8_t auto_start; // Planner auto-start flag. Toggled off during feed hold. Defaulted by settings.
|
||||||
volatile uint8_t probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
volatile uint8_t probe_state; // Probing state value. Used to coordinate the probing cycle with stepper ISR.
|
||||||
int32_t probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
|
int32_t probe_position[N_AXIS]; // Last probe position in machine coordinates and steps.
|
||||||
uint8_t probe_away; // probe away from work by reversing the switch direction (G38.4, G38.5)
|
|
||||||
} system_t;
|
} system_t;
|
||||||
extern system_t sys;
|
extern system_t sys;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user