1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-03 11:22:38 +02:00

Initial release with custom machine

This commit is contained in:
Jens Hauser
2020-07-27 11:43:23 +02:00
parent 7919e46f55
commit 76847b2fbd
4 changed files with 227 additions and 7 deletions

View File

@@ -0,0 +1,142 @@
/*
custom_code_template.cpp (copy and use your machine name)
Part of Grbl_ESP32
*/
uint8_t AmountOfToolChanges;
#ifdef USE_MACHINE_INIT
/*
machine_init() is called when Grbl_ESP32 first starts. You can use it to do any
special things your machine needs at startup.
*/
void machine_init()
{
// First call means AmountOfToolChanges=0.
AmountOfToolChanges=0;
grbl_send(CLIENT_ALL, "machine_init");
}
#endif
#ifdef USE_TOOL_CHANGE
/*
user_tool_change() is called when tool change gcode is received,
to perform appropriate actions for your machine.
*/
float getCurrentZPos()
{
int32_t current_position[N_AXIS]; // copy of current location
float m_pos[N_AXIS]; // machine position in mm
memcpy(current_position, sys_position, sizeof(sys_position)); // get current position in step
system_convert_array_steps_to_mpos(m_pos, sys_position); // convert to millimeters
return m_pos[Z_AXIS];
}
float getLastZProbePos()
{
float m_pos[N_AXIS]; // machine position in mm
char output[200];
//memcpy(current_position, sys_position, sizeof(sys_position)); // get current position in step
system_convert_array_steps_to_mpos(m_pos, sys_probe_position); // convert to millimeters
return m_pos[Z_AXIS];
}
float getG54Zvalue()
{
float coord_data[N_AXIS];
settings_read_coord_data(0, coord_data); //0=G54
return coord_data[Z_AXIS];
}
void user_tool_change(uint8_t new_tool)
{
// Variables
char temp[200];
float value1, value2, diff;
// Start of function
// AmountOfToolChanges=AmountOfToolChanges+1 each time.
AmountOfToolChanges=+1;
sprintf(temp, "Tool change amount=%d\r\n", AmountOfToolChanges);
grbl_send(CLIENT_ALL, temp);
// Init. Safe start block. G54, XY plane, mm mode, relative addressing mode
inputBuffer.push("G54\r\n");
inputBuffer.push("G17 G21 G91\r\n");
// Switch off spindle
inputBuffer.push("M05\r\n");
/*
// Set speed
inputBuffer.push("F100\r\n");
// Place spindle directly above button in X/Y and a few mm above Z
inputBuffer.push("G53 G0 Z-5 F500\r\n");
inputBuffer.push("G53 G0 X-29 Y-410 F100\r\n");
inputBuffer.push("G53 G0 Z-60 F100\r\n");
// Z probe, max. 50mm to find button
inputBuffer.push("G38.2 Z-50 F250\r\n");
// Raise spindle a little bit
inputBuffer.push("G0 Z1.5\r\n");
// Z probe again
inputBuffer.push("G38.2 Z-2 F30\r\n");
*/
protocol_buffer_synchronize(); // wait for all previous moves to complete
// Z Probe Pos.
value1=getCurrentZPos();
sprintf(temp, "z probe pos=%4.3f\r\n", value1);
grbl_send(CLIENT_ALL, temp); // send the report
// Raise spindle a little bit
inputBuffer.push("G0 Z1.5\r\n");
protocol_buffer_synchronize(); // wait for all previous moves to complete
// Z Probe Pos.
value2=getCurrentZPos();
sprintf(temp, "z probe pos neu=%4.3f\r\n", value2);
grbl_send(CLIENT_ALL, temp); // send the report
diff = value2 - value1;
sprintf(temp, "diff=%4.3f mm\r\n", diff);
grbl_send(CLIENT_ALL, temp); // send the report
//sprintf(temp, "z pos=%4.3f\r\n", getCurrentZPos());
//grbl_send(CLIENT_ALL, temp); // send the report
//sprintf(temp, "z G54=%4.3f\r\n", getG54Zvalue());
//grbl_send(CLIENT_ALL, temp); // send the report
// Clean up
inputBuffer.push("G90\r\n");
protocol_buffer_synchronize(); // wait for all previous moves to complete
return;
}
#endif

View File

@@ -0,0 +1,77 @@
/*
* 4 Achsen CNC Fr<46>se von Jens
* Infos zur Benutzung einer Spindel mit Relais https://github.com/bdring/Grbl_Esp32/wiki/Spindle-Types
*/
#define MACHINE_NAME "MACHINE_ESP32 Jens XYZA"
#ifdef N_AXIS
#undef N_AXIS
#endif
// M<>chte ich mit 3 oder 4 Achsen arbeiten?
// Beides ist eingerichtet.
#define N_AXIS 3
#define CUSTOM_CODE_FILENAME "Custom/4axis_xyxz.cpp"
/*
* Zuordnung Schrittmotoren
*/
#define X_STEP_PIN GPIO_NUM_12
#define X_DIRECTION_PIN GPIO_NUM_14
#define Y_STEP_PIN GPIO_NUM_26
#define Y_DIRECTION_PIN GPIO_NUM_15
#define Z_STEP_PIN GPIO_NUM_27
#define Z_DIRECTION_PIN GPIO_NUM_33
#define STEPPERS_DISABLE_PIN GPIO_NUM_13 //ok
// Falls die 4. Achse genutzt wird
#if (N_AXIS == 4)
#define A_STEP_PIN GPIO_NUM_25
#define A_DIRECTION_PIN GPIO_NUM_22
#endif
#define SPINDLE_TYPE SPINDLE_TYPE_RELAY
//#define SPINDLE_ENABLE_PIN GPIO_NUM_32
#define SPINDLE_OUTPUT_PIN GPIO_NUM_32
/*
* Zuordnung Endschalter
* The 1 bits in LIMIT_MASK set the axes that have limit switches
* X, Y, Z, A do, the LIMIT_MASK value would be B1111
*/
#define LIMIT_MASK B1111
#define X_LIMIT_PIN GPIO_NUM_17 //ok
#define Y_LIMIT_PIN GPIO_NUM_4 //ok
#define Z_LIMIT_PIN GPIO_NUM_16 //ok
// Falls die 4. Achse genutzt wird
#if (N_AXIS == 4)
#define A_LIMIT_PIN GPIO_NUM_21 //ok
#define LIMIT_MASK B1111
#else
// bei 3 Achsen
#define LIMIT_MASK B111
#endif
/*
* Control pins
*/
#define PROBE_PIN GPIO_NUM_35 //ok
#define CONTROL_SAFETY_DOOR_PIN GPIO_NUM_36 // needs external pullup
#define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup
// #define CONTROL_FEED_HOLD_PIN GPIO_NUM_35 // needs external pullup
#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup
/* Normally Grbl_ESP32 ignores tool changes.
* It just tracks the current tool number.
* If you put #define USE_TOOL_CHANGE in you header file,
* it will call a function void user_tool_change(uint8_t new_tool) when it sees the M6 gcode command.
*/
#define USE_MACHINE_INIT
#define USE_TOOL_CHANGE

View File

@@ -63,12 +63,12 @@ Some features should not be changed. See notes below.
// These homing cycle definitions precede the machine.h file so that the machine // These homing cycle definitions precede the machine.h file so that the machine
// definition can undefine them if necessary. // definition can undefine them if necessary.
#define HOMING_CYCLE_0 bit(Z_AXIS) // TYPICALLY REQUIRED: First move Z to clear workspace. #define HOMING_CYCLE_0 bit(Z_AXIS) // TYPICALLY REQUIRED: First move Z to clear workspace.
#define HOMING_CYCLE_1 bit(X_AXIS) //#define HOMING_CYCLE_1 bit(X_AXIS)
#define HOMING_CYCLE_2 bit(Y_AXIS) //#define HOMING_CYCLE_2 bit(Y_AXIS)
// NOTE: The following is for for homing X and Y at the same time // NOTE: The following is for for homing X and Y at the same time
// #define HOMING_CYCLE_0 bit(Z_AXIS) // first home z by itself // #define HOMING_CYCLE_0 bit(Z_AXIS) // first home z by itself
// #define HOMING_CYCLE_1 (bit(X_AXIS)|bit(Y_AXIS)) // Homes both X-Y in one cycle. NOT COMPATIBLE WITH COREXY!!! #define HOMING_CYCLE_1 (bit(X_AXIS)|bit(Y_AXIS)) // Homes both X-Y in one cycle. NOT COMPATIBLE WITH COREXY!!!
// Inverts pin logic of the control command pins based on a mask. This essentially means you can use // Inverts pin logic of the control command pins based on a mask. This essentially means you can use
// normally-closed switches on the specified pins, rather than the default normally-open switches. // normally-closed switches on the specified pins, rather than the default normally-open switches.
@@ -222,7 +222,7 @@ Some features should not be changed. See notes below.
// If homing is enabled, homing init lock sets Grbl into an alarm state upon power up. This forces // If homing is enabled, homing init lock sets Grbl into an alarm state upon power up. This forces
// the user to perform the homing cycle (or override the locks) before doing anything else. This is // the user to perform the homing cycle (or override the locks) before doing anything else. This is
// mainly a safety feature to remind the user to home, since position is unknown to Grbl. // mainly a safety feature to remind the user to home, since position is unknown to Grbl.
#define HOMING_INIT_LOCK // Comment to disable //#define HOMING_INIT_LOCK // Comment to disable
// Number of homing cycles performed after when the machine initially jogs to limit switches. // Number of homing cycles performed after when the machine initially jogs to limit switches.
// This help in preventing overshoot and should improve repeatability. This value should be one or // This help in preventing overshoot and should improve repeatability. This value should be one or
@@ -567,8 +567,8 @@ Some features should not be changed. See notes below.
// A simple software debouncing feature for hard limit switches. When enabled, the limit // A simple software debouncing feature for hard limit switches. When enabled, the limit
// switch interrupt unblock a waiting task which will recheck the limit switch pins after // switch interrupt unblock a waiting task which will recheck the limit switch pins after
// a short delay. Default disabled // a short delay. Default disabled
//#define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable. #define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable.
#define DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds #define DEBOUNCE_PERIOD 50 // in milliseconds default 32 microseconds
// Configures the position after a probing cycle during Grbl's check mode. Disabled sets // Configures the position after a probing cycle during Grbl's check mode. Disabled sets
// the position to the probe target, when enabled sets the position to the start position. // the position to the probe target, when enabled sets the position to the start position.

View File

@@ -17,7 +17,8 @@ PWM
// !!! For initial testing, start with test_drive.h which disables // !!! For initial testing, start with test_drive.h which disables
// all I/O pins // all I/O pins
// #include "Machines/atari_1020.h" // #include "Machines/atari_1020.h"
#include "Machines/test_drive.h" //#include "Machines/test_drive.h"
#include "Machines/4axis_xyxz.h"
// !!! For actual use, change the line above to select a board // !!! For actual use, change the line above to select a board
// from Machines/, for example: // from Machines/, for example: