1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-08-23 22:52:58 +02:00

Fixing problems with N_AXIS values

- Some of the defined values were causing problems
- Added support for using WPOS in servos. Helpful for initial pen up.
This commit is contained in:
Bart Dring
2019-08-30 21:12:17 -05:00
parent e2c7ea1c89
commit 431fad28b4
8 changed files with 50 additions and 28 deletions

View File

@@ -40,7 +40,7 @@ Some features should not be changed. See notes below.
#include <Arduino.h> #include <Arduino.h>
//#define ESP_DEBUG //#define ESP_DEBUG
#define N_AXIS 3 // Number of axes defined #define N_AXIS 3 // Number of axes defined (valid range: 3 to 6)
// Define CPU pin map and default settings. // Define CPU pin map and default settings.
// NOTE: OEMs can avoid the need to maintain/update the defaults.h and cpu_map.h files and use only // NOTE: OEMs can avoid the need to maintain/update the defaults.h and cpu_map.h files and use only

View File

@@ -380,10 +380,15 @@
#define CPU_MAP_NAME "CPU_MAP_MIDTBOT" #define CPU_MAP_NAME "CPU_MAP_MIDTBOT"
#define USE_RMT_STEPS
#define X_STEP_PIN GPIO_NUM_12 #define X_STEP_PIN GPIO_NUM_12
#define Y_STEP_PIN GPIO_NUM_14 #define Y_STEP_PIN GPIO_NUM_14
#define X_RMT_CHANNEL 0
#define X_DIRECTION_PIN GPIO_NUM_26 #define X_DIRECTION_PIN GPIO_NUM_26
#define Y_DIRECTION_PIN GPIO_NUM_25 #define Y_DIRECTION_PIN GPIO_NUM_25
#define Y_RMT_CHANNEL 1
#ifndef COREXY // maybe set in config.h #ifndef COREXY // maybe set in config.h
#define COREXY #define COREXY
@@ -403,6 +408,7 @@
#define SERVO_Z_CHANNEL_NUM 5 #define SERVO_Z_CHANNEL_NUM 5
#define SERVO_Z_RANGE_MIN 0.0 #define SERVO_Z_RANGE_MIN 0.0
#define SERVO_Z_RANGE_MAX 5.0 #define SERVO_Z_RANGE_MAX 5.0
#define SERVO_Z_MPOS false
#ifndef IGNORE_CONTROL_PINS // maybe set in config.h #ifndef IGNORE_CONTROL_PINS // maybe set in config.h
#define IGNORE_CONTROL_PINS #define IGNORE_CONTROL_PINS

View File

@@ -379,21 +379,21 @@ uint8_t gc_execute_line(char *line, uint8_t client)
legal g-code words and stores their value. Error-checking is performed later since some legal g-code words and stores their value. Error-checking is performed later since some
words (I,J,K,L,P,R) have multiple connotations and/or depend on the issued commands. */ words (I,J,K,L,P,R) have multiple connotations and/or depend on the issued commands. */
switch(letter) { switch(letter) {
#ifdef A_AXIS #ifdef N_AXIS > A_AXIS
case 'A': case 'A':
word_bit = WORD_A; word_bit = WORD_A;
gc_block.values.xyz[A_AXIS] = value; gc_block.values.xyz[A_AXIS] = value;
axis_words |= (1<<A_AXIS); axis_words |= (1<<A_AXIS);
break; break;
#endif #endif
#ifdef B_AXIS #ifdef N_AXIS > B_AXIS
case 'B': case 'B':
word_bit = WORD_B; word_bit = WORD_B;
gc_block.values.xyz[B_AXIS] = value; gc_block.values.xyz[B_AXIS] = value;
axis_words |= (1<<B_AXIS); axis_words |= (1<<B_AXIS);
break; break;
#endif #endif
#ifdef C_AXIS #ifdef N_AXIS > A_AXIS
case 'C': case 'C':
word_bit = WORD_C; word_bit = WORD_C;
gc_block.values.xyz[C_AXIS] = value; gc_block.values.xyz[C_AXIS] = value;

View File

@@ -20,7 +20,7 @@
// Grbl versioning system // Grbl versioning system
#define GRBL_VERSION "1.1f" #define GRBL_VERSION "1.1f"
#define GRBL_VERSION_BUILD "20190829" #define GRBL_VERSION_BUILD "20190830"
//#include <sdkconfig.h> //#include <sdkconfig.h>
#include <Arduino.h> #include <Arduino.h>

View File

@@ -52,7 +52,7 @@ void init_servos()
{ {
//grbl_send(CLIENT_SERIAL, "[MSG: Init Servos]\r\n"); //grbl_send(CLIENT_SERIAL, "[MSG: Init Servos]\r\n");
#ifdef SERVO_X_PIN #ifdef SERVO_X_PIN
grbl_send(CLIENT_SERIAL, "[MSG: Init X Servo]\r\n"); grbl_send(CLIENT_SERIAL, "[MSG:Init X Servo]\r\n");
X_Servo_Axis.init(); X_Servo_Axis.init();
X_Servo_Axis.set_range(SERVO_X_RANGE_MIN, SERVO_X_RANGE_MAX); X_Servo_Axis.set_range(SERVO_X_RANGE_MIN, SERVO_X_RANGE_MAX);
X_Servo_Axis.set_homing_type(SERVO_HOMING_OFF); X_Servo_Axis.set_homing_type(SERVO_HOMING_OFF);
@@ -60,20 +60,23 @@ void init_servos()
X_Servo_Axis.set_disable_with_steppers(false); X_Servo_Axis.set_disable_with_steppers(false);
#endif #endif
#ifdef SERVO_Y_PIN #ifdef SERVO_Y_PIN
grbl_send(CLIENT_SERIAL, "[MSG: Init Y Servo]\r\n"); grbl_send(CLIENT_SERIAL, "[MSG:Init Y Servo]\r\n");
Y_Servo_Axis.init(); Y_Servo_Axis.init();
Y_Servo_Axis.set_range(SERVO_Y_RANGE_MIN, SERVO_Y_RANGE_MAX); Y_Servo_Axis.set_range(SERVO_Y_RANGE_MIN, SERVO_Y_RANGE_MAX);
#endif #endif
#ifdef SERVO_Z_PIN #ifdef SERVO_Z_PIN
grbl_send(CLIENT_SERIAL, "[MSG: Init Z Servo]\r\n"); grbl_send(CLIENT_SERIAL, "[MSG:Init Z Servo]\r\n");
Z_Servo_Axis.init(); Z_Servo_Axis.init();
Z_Servo_Axis.set_range(SERVO_Z_RANGE_MIN, SERVO_Z_RANGE_MAX); Z_Servo_Axis.set_range(SERVO_Z_RANGE_MIN, SERVO_Z_RANGE_MAX);
Z_Servo_Axis.set_homing_type(SERVO_HOMING_TARGET); Z_Servo_Axis.set_homing_type(SERVO_HOMING_TARGET);
Z_Servo_Axis.set_homing_position(SERVO_Z_RANGE_MAX); Z_Servo_Axis.set_homing_position(SERVO_Z_RANGE_MAX);
#ifdef SERVO_Z_MPOS // value should be true or false
Z_Servo_Axis.set_use_mpos(SERVO_Z_MPOS);
#endif
#endif #endif
#ifdef SERVO_A_PIN #ifdef SERVO_A_PIN
grbl_send(CLIENT_SERIAL, "[MSG: Init A Servo]\r\n"); grbl_send(CLIENT_SERIAL, "[MSG:Init A Servo]\r\n");
A_Servo_Axis.init(); A_Servo_Axis.init();
A_Servo_Axis.set_range(SERVO_A_RANGE_MIN, SERVO_A_RANGE_MAX); A_Servo_Axis.set_range(SERVO_A_RANGE_MIN, SERVO_A_RANGE_MAX);
A_Servo_Axis.set_homing_type(SERVO_HOMING_OFF); A_Servo_Axis.set_homing_type(SERVO_HOMING_OFF);
@@ -81,12 +84,12 @@ void init_servos()
A_Servo_Axis.set_disable_with_steppers(false); A_Servo_Axis.set_disable_with_steppers(false);
#endif #endif
#ifdef SERVO_B_PIN #ifdef SERVO_B_PIN
grbl_send(CLIENT_SERIAL, "[MSG: Init B Servo]\r\n"); grbl_send(CLIENT_SERIAL, "[MSG:Init B Servo]\r\n");
B_Servo_Axis.init(); B_Servo_Axis.init();
B_Servo_Axis.set_range(SERVO_B_RANGE_MIN, SERVO_B_RANGE_MAX); B_Servo_Axis.set_range(SERVO_B_RANGE_MIN, SERVO_B_RANGE_MAX);
#endif #endif
#ifdef SERVO_C_PIN #ifdef SERVO_C_PIN
grbl_send(CLIENT_SERIAL, "[MSG: Init C Servo]\r\n"); grbl_send(CLIENT_SERIAL, "[MSG:Init C Servo]\r\n");
C_Servo_Axis.init(); C_Servo_Axis.init();
C_Servo_Axis.set_range(SERVO_C_RANGE_MIN, SERVO_C_RANGE_MAX); C_Servo_Axis.set_range(SERVO_C_RANGE_MIN, SERVO_C_RANGE_MAX);
C_Servo_Axis.set_homing_type(SERVO_HOMING_TARGET); C_Servo_Axis.set_homing_type(SERVO_HOMING_TARGET);
@@ -167,6 +170,8 @@ void ServoAxis::set_location()
uint32_t servo_pulse_len; uint32_t servo_pulse_len;
float servo_pos, mpos, offset; float servo_pos, mpos, offset;
// skip location if we are in alarm mode // skip location if we are in alarm mode
if (_disable_on_alarm && (sys.state == STATE_ALARM)) { if (_disable_on_alarm && (sys.state == STATE_ALARM)) {
disable(); disable();
@@ -189,8 +194,9 @@ void ServoAxis::set_location()
servo_pos = mpos; servo_pos = mpos;
} }
else { else {
offset = gc_state.coord_system[_axis]+gc_state.coord_offset[_axis]; // get the current axis work offset offset = gc_state.coord_system[_axis] + gc_state.coord_offset[_axis]; // get the current axis work offset
servo_pos = mpos - offset; // determine the current work position servo_pos = mpos - offset; // determine the current work position
} }
} }
@@ -319,5 +325,14 @@ void ServoAxis::set_disable_with_steppers(bool disable_with_steppers) {
_disable_with_steppers = disable_with_steppers; _disable_with_steppers = disable_with_steppers;
} }
/*
If true, servo position will alway be calculated in machine position
Offsets will not be applied
*/
void ServoAxis::set_use_mpos(bool use_mpos) {
_use_mpos = use_mpos;
}
#endif #endif

View File

@@ -262,13 +262,13 @@ void IRAM_ATTR onStepperDriverTimer(void *para) // ISR It is time to take a ste
st.steps[Y_AXIS] = st.exec_block->steps[Y_AXIS] >> st.exec_segment->amass_level; st.steps[Y_AXIS] = st.exec_block->steps[Y_AXIS] >> st.exec_segment->amass_level;
st.steps[Z_AXIS] = st.exec_block->steps[Z_AXIS] >> st.exec_segment->amass_level; st.steps[Z_AXIS] = st.exec_block->steps[Z_AXIS] >> st.exec_segment->amass_level;
#ifdef A_AXIS #if (N_AXIS > A_AXIS)
st.steps[A_AXIS] = st.exec_block->steps[A_AXIS] >> st.exec_segment->amass_level; st.steps[A_AXIS] = st.exec_block->steps[A_AXIS] >> st.exec_segment->amass_level;
#endif #endif
#ifdef B_AXIS #if (N_AXIS > B_AXIS)
st.steps[B_AXIS] = st.exec_block->steps[B_AXIS] >> st.exec_segment->amass_level; st.steps[B_AXIS] = st.exec_block->steps[B_AXIS] >> st.exec_segment->amass_level;
#endif #endif
#ifdef C_AXIS #if (N_AXIS > C_AXIS)
st.steps[C_AXIS] = st.exec_block->steps[C_AXIS] >> st.exec_segment->amass_level; st.steps[C_AXIS] = st.exec_block->steps[C_AXIS] >> st.exec_segment->amass_level;
#endif #endif

View File

@@ -440,7 +440,8 @@ uint8_t get_limit_pin_mask(uint8_t axis_idx)
if ( axis_idx == Z_AXIS ) { return((1<<Z_LIMIT_BIT)); } if ( axis_idx == Z_AXIS ) { return((1<<Z_LIMIT_BIT)); }
if ( axis_idx == A_AXIS ) { return((1<<A_LIMIT_BIT)); } if ( axis_idx == A_AXIS ) { return((1<<A_LIMIT_BIT)); }
if ( axis_idx == B_AXIS ) { return((1<<B_LIMIT_BIT)); } if ( axis_idx == B_AXIS ) { return((1<<B_LIMIT_BIT)); }
return((1<<C_LIMIT_BIT)); if ( axis_idx == C_AXIS ) { return((1<<C_LIMIT_BIT)); }
return 0;
} }
// CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps. // CoreXY calculation only. Returns x or y-axis "steps" based on CoreXY motor steps.