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

Update MPCNC homing added custom machine template

- Ganged axes cannot be individually homed
- Started a custom machine template, will add more to it soon.
This commit is contained in:
bdring
2020-02-15 20:38:06 -06:00
parent eea5fb0dca
commit fc798c9946
8 changed files with 298 additions and 15 deletions

View File

@@ -585,6 +585,10 @@
#endif
#define USE_GANGED_AXES // allow two motors on an axis
#ifdef HOMING_SINGLE_AXIS_COMMANDS
#undef HOMING_SINGLE_AXIS_COMMANDS
#endif
#define X_STEP_PIN GPIO_NUM_12
#define X_STEP_B_PIN GPIO_NUM_22 // ganged motor
@@ -653,10 +657,13 @@
// Note: default is #define IGNORE_CONTROL_PINS in config.h
// uncomment to these lines to use them
/*
#ifdef IGNORE_CONTROL_PINS
#undef IGNORE_CONTROL_PINS
#endif
*/
#define CONTROL_RESET_PIN GPIO_NUM_34 // needs external pullup
#define CONTROL_FEED_HOLD_PIN GPIO_NUM_36 // needs external pullup
#define CONTROL_CYCLE_START_PIN GPIO_NUM_39 // needs external pullup
@@ -681,10 +688,10 @@
#define DEFAULT_HOMING_ENABLE 1 // false
#define DEFAULT_HOMING_DIR_MASK 3 // move positive dir Z,negative X,Y
#define DEFAULT_HOMING_FEED_RATE 600.0 // mm/min
#define DEFAULT_HOMING_SEEK_RATE 2000.0 // mm/min
#define DEFAULT_HOMING_FEED_RATE 500.0 // mm/min
#define DEFAULT_HOMING_SEEK_RATE 200.0 // mm/min
#define DEFAULT_HOMING_DEBOUNCE_DELAY 250 // msec (0-65k)
#define DEFAULT_HOMING_PULLOFF 1.5 // mm
#define DEFAULT_HOMING_PULLOFF 2.0 // mm
#ifdef USE_SPINDLE_RELAY
#define DEFAULT_SPINDLE_RPM_MAX 1.0 // must be 1 so PWM duty is alway 100% to prevent relay damage
@@ -1066,6 +1073,10 @@
#include "atari_1020.h"
#endif
#ifdef CPU_MAP_CUSTOM_MACHINE
#include "custom_machine_template.h"
#endif
// ================= common to all machines ================================
// These are some ESP32 CPU Settings that the program needs, but are generally not changed

View File

@@ -0,0 +1,171 @@
/*
custom_machine_template.cpp
Part of Grbl_ESP32
copyright (c) 2020 - Bart Dring. This file was intended for use on the ESP32
CPU. Do not use this with Grbl for atMega328P
Grbl_ESP32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl_ESP32 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
=======================================================================
This is a template of a custom machine file. All of these functions are called by
main Grbl_ESP when enabled via #define statements. The machine designer must fill
in the contents of the functions. Almost all of them are optional. Remove any
unused functions. See each function for more information
Make copies of custom_machine_template.cpp and custom_machine_template.h
and replace the file prefix with your machine's name
Example:
my_machine.h
my_machine.cpp
In cpu_map.h you need to create #include links to your new machine files. This is
done using a CPU_MAP name so that you can switch to it in config.h like any of
the other defined machine. See the template example at the bottom of cpu_map.h
Example
#ifdef CPU_MAP_MY_MACHINE
#include my_machine.h
#endif
in config.h make sure CPU_MAP_MY_MACHINE is the only define cpu map.
To keep your machine organized and cpu_map.h clean, put all of the stuff normally put in
cpu_map.h in your my_machine.h file. There are sections in that template expaining it.
===============================================================================
*/
#ifdef CPU_MAP_CUSTOM_MACHINE // !!! Change this name to your machine map name
/*
This function is called if you have #define USE_MACHINE_INIT in your my_machine.h file
This function will be called when Grbl_ESP32 first starts. You can use it to do any
special things your machine needs at startup.
*/
void machine_init() {
}
/*
This function is called if you have #define USE_CUSTOM_HOMING in your my_machine.h file
This function gets called at the begining of the normal Grbl_ESP32 homing sequence. You
Can skip the rest of normal Grbl_ESP32 homing by returning false. You return true if you
want normal homing to continue. You might do this if you just need to prep the machine
for homing.
*/
bool user_defined_homing() {
return true; // True = done with homing, false = continue with normal Grbl_ESP32 homing
}
/*
Inverse Kinematics converts X,Y,Z cartesian coordinate to the steps on your "joint"
motors.
This function allows you to look at incoming move commands and modify them before
Grbl_ESP32 puts them in the motion planner.
Grbl_ESP32 processes arc by converting them into tiny little line segments.
Kinematics in Grbl_ESP32 works the same way. Search for this function across Grbl_ESP32
for examples. You are basically converting cartesian X,Y,Z... targets to
target = an N_AXIS array of target positions (where the move is supposed to go)
pl_data = planner data (see the definition of this type to see what it is)
position = an N_AXIS array of where the machine is starting from for this move
*/
void inverse_kinematics(target, pl_data, position) {
mc_line(target, pl_data); // this simply moves to the target Replace with your kinematics.
}
/*
Forward Kinematics converts your motor postions to X,Y,Z... cartesian information.
This is used by the status command.
Convert the N_AXIS array of motor positions to cartesian in your code.
*/
void forward_kinematics(float *position) {
// position[X_AXIS] =
// position[Y_AXIS] =
}
/*
This function is required if you have #define USE_KINEMATIC
This function is called before normal homing
You can use it to do special homing or just to set stuff up
cycle_mask = is a bit mask of the axes being homed this time.
*/
bool kinematics_pre_homing(cycle_mask)) {
return false; // finish normal homing cycle
}
/*
This function is required if you have #define USE_KINEMATIC
It is called at the end of normal homing
*/
void kinematics_post_homing() {
}
/*
This function is called if #USE_TOOL_CHANGE is define and
a gcode for a tool change is received
*/
void user_tool_change(uint8_t new_tool) {
}
/*
This will be called if any of the #define MACRO_BUTTON_0_PIN options
are defined
*/
void user_defined_macro(uint8_t index)
{
}
/*
This function is called if #define USE_M30 is defined and
an M30 gcode is received. M30 signals the end of a gcode file.
*/
void user_m30() {
}
/*
Enable this function with #define USE_MACHINE_TRINAMIC_INIT
This will replace the normal setup of trinamic drivers with your own
This is where you could setup StallGaurd
*/
void machine_trinamic_setup() {
}
// feel free to add any additional functions specific to your machine
#endif

View File

@@ -0,0 +1,96 @@
/*
custom_machine_template.h
Part of Grbl_ESP32
copyright (c) 2020 - Bart Dring. This file was intended for use on the ESP32
CPU. Do not use this with Grbl for atMega328P
Grbl_ESP32 is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Grbl_ESP32 is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
====================================================================
See custom_machine_templete.cpp for getting started creating custom
machines
*/
// ================ config.h overrides ========================================
/*
If you want to make some changes to config.h, it might be easier to do it here
so all your changes are in your files.
example to change baud rate
#ifdef BAUD_RATE
#undef BAUDRATE
#endif
#define BAUD_RATE 9600
example to change the number of axes
#idef N_AXIS
#undef N_AXIS
#endif
#define N_AXIS 4
*/
// =============== CPU MAP ========================
// Look at cpu_map.h for all the things that can go here
#define CPU_MAP_NAME "CPU_MAP_MY_MACHINE"
#define LIMIT_MASK B111 // you need this with as many switches you are using
// ============== Enable custom features =======================
// #define #USE_MACHINE_INIT
// #define USE_CUSTOM_HOMING
// #define USE_KINEMATICS
// #define USE_FWD_KINEMATIC
// #define USE_TOOL_CHANGE
// #define USE_M30
// #define USE_MACHINE_TRINAMIC_INIT
// ===================== $$ Defaults ==========================================
/* These are default values for any of the $$ settings.
This will automatically set them when you upload new firmware or if you
reset them with $RST=$.
All default values are set in the defaults.h file. You would only need to
put values here that are different from those values
Below are a few examples
*/
#define DEFAULT_SPINDLE_FREQ 2000.0
#define DEFAULT_X_MAX_TRAVEL 100.0
#ifndef custom_machine_template_h // !!!!!!!!!!!!!!! Change this to your file !!!!!!!!!!!!!
#define custom_machine_template_h // !!! here too !!!!
#include "grbl.h"
// ================ Function Prototypes ================
void machine_init();
bool user_defined_homing();
void inverse_kinematics(float *target, plan_line_data_t *pl_data, float *position);
void forward_kinematics(float *position);
void kinematics_post_homing();
void user_tool_change(uint8_t new_tool);
void user_defined_macro(uint8_t index);
void user_m30();
void machine_trinamic_setup();
#endif

View File

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

View File

@@ -140,6 +140,11 @@ void Trinamic_Init()
SPI.begin();
#ifdef USE_MACHINE_TRINAMIC_INIT
machine_trinamic_setup();
return;
#endif
#ifdef X_TRINAMIC
TRINAMIC_X.begin(); // Initiate pins and registries
testResult = TRINAMIC_X.test_connection();

View File

@@ -24,7 +24,7 @@
#define SEGMENT_LENGTH 0.5 // segment length in mm
#define USE_KINEMATICS
#define FWD_KINEMATICS_REPORTING // report in cartesian
#define USE_FWD_KINEMATIC // report in cartesian
#define USE_M30
// ============= Begin CPU MAP ================

View File

@@ -726,7 +726,7 @@ void report_realtime_status(uint8_t client)
if (bit_istrue(settings.status_report_mask,BITFLAG_RT_STATUS_POSITION_TYPE)) {
strcat(status, "|MPos:");
} else {
#ifdef FWD_KINEMATICS_REPORTING
#ifdef USE_FWD_KINEMATIC
forward_kinematics(print_position);
#endif
strcat(status, "|WPos:");

View File

@@ -233,19 +233,19 @@ uint8_t system_execute_line(char *line, uint8_t client)
break;
case 'H' : // Perform homing cycle [IDLE/ALARM] $H
if (bit_isfalse(settings.flags,BITFLAG_HOMING_ENABLE)) {return(STATUS_SETTING_DISABLED); }
if (system_check_safety_door_ajar()) { return(STATUS_CHECK_DOOR); } // Block if safety door is ajar.
sys.state = STATE_HOMING; // Set system state variable
if (system_check_safety_door_ajar()) { return(STATUS_CHECK_DOOR); } // Block if safety door is ajar.
if (line[2] == 0) {
sys.state = STATE_HOMING; // Set system state variable
mc_homing_cycle(HOMING_CYCLE_ALL);
#ifdef HOMING_SINGLE_AXIS_COMMANDS
} else if (line[3] == 0) {
switch (line[2]) {
case 'X': mc_homing_cycle(HOMING_CYCLE_X); break;
case 'Y': mc_homing_cycle(HOMING_CYCLE_Y); break;
case 'Z': mc_homing_cycle(HOMING_CYCLE_Z); break;
case 'A': mc_homing_cycle(HOMING_CYCLE_A); break;
case 'B': mc_homing_cycle(HOMING_CYCLE_B); break;
case 'C': mc_homing_cycle(HOMING_CYCLE_C); break;
case 'X': sys.state = STATE_HOMING; mc_homing_cycle(HOMING_CYCLE_X); break;
case 'Y': sys.state = STATE_HOMING; mc_homing_cycle(HOMING_CYCLE_Y); break;
case 'Z': sys.state = STATE_HOMING; mc_homing_cycle(HOMING_CYCLE_Z); break;
case 'A': sys.state = STATE_HOMING; mc_homing_cycle(HOMING_CYCLE_A); break;
case 'B': sys.state = STATE_HOMING; mc_homing_cycle(HOMING_CYCLE_B); break;
case 'C': sys.state = STATE_HOMING; mc_homing_cycle(HOMING_CYCLE_C); break;
default: return(STATUS_INVALID_STATEMENT);
}
#endif