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

Swap Mutex for Semaphore to manage multithreading. #1467

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions Grbl_Esp32/src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Some features should not be changed. See notes below.
// For example B1101 will invert the function of the Reset pin.
#define INVERT_CONTROL_PIN_MASK B00001111

// #define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable.
#define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable.
#define CONTROL_SW_DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds

#define USE_RMT_STEPS
Expand Down Expand Up @@ -93,8 +93,8 @@ const int MAX_N_AXIS = 6;
#define BAUD_RATE 115200

//Connect to your local AP with these credentials
//#define CONNECT_TO_SSID "your SSID"
//#define SSID_PASSWORD "your SSID password"
#define CONNECT_TO_SSID "your SSID"
#define SSID_PASSWORD "your SSID password"
//CONFIGURE_EYECATCH_BEGIN (DO NOT MODIFY THIS LINE)
#define ENABLE_BLUETOOTH // enable bluetooth

Expand Down Expand Up @@ -202,7 +202,7 @@ enum class Cmd : uint8_t {
// 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
// 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.
// This help in preventing overshoot and should improve repeatability. This value should be one or
Expand Down Expand Up @@ -264,7 +264,7 @@ static const uint8_t NHomingLocateCycle = 1; // Integer (1-128)
// will be applied to all of them. This is useful when a user has a mixed set of limit pins with both
// normally-open(NO) and normally-closed(NC) switches installed on their machine.
// NOTE: PLEASE DO NOT USE THIS, unless you have a situation that needs it.
// #define INVERT_LIMIT_PIN_MASK (bit(X_AXIS)|bit(Y_AXIS)) // Default disabled. Uncomment to enable.
#define INVERT_LIMIT_PIN_MASK (bit(X_AXIS)|bit(Y_AXIS)|bit(Z_AXIS)) // Default disabled. Uncomment to enable.

// Inverts the selected coolant pin from low-disabled/high-enabled to low-enabled/high-disabled. Useful
// for some pre-built electronic boards.
Expand Down Expand Up @@ -486,7 +486,7 @@ const int DWELL_TIME_STEP = 50; // Integer (1-255) (milliseconds)
// 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
// a short delay. Default disabled
//#define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable.
#define ENABLE_SOFTWARE_DEBOUNCE // Default disabled. Uncomment to enable.
const int DEBOUNCE_PERIOD = 32; // in milliseconds default 32 microseconds

// Configures the position after a probing cycle during Grbl's check mode. Disabled sets
Expand Down Expand Up @@ -523,7 +523,7 @@ const int DEBOUNCE_PERIOD = 32; // in milliseconds default 32 microseconds
// Some senders may not be able to parse anything different from the original set
// You can still set these like $33=5000, but you cannot read them back.
// Default is off to limit support issues...you can enable here or in your machine definition file
// #define SHOW_EXTENDED_SETTINGS
#define SHOW_EXTENDED_SETTINGS

// Writing to non-volatile storage (NVS) can take a long time and interfere with timely instruction
// execution, causing problems for the stepper ISRs and serial comm ISRs and subsequent loss of
Expand Down Expand Up @@ -590,19 +590,31 @@ const double PARKING_PULLOUT_INCREMENT = 5.0; // Spindle pull-out and plunge
// Enables a piecewise linear model of the spindle PWM/speed output. Requires a solution by the
// 'fit_nonlinear_spindle.py' script in the /doc/script folder of the repo. See file comments
// on how to gather spindle data and run the script to generate a solution.
// #define ENABLE_PIECEWISE_LINEAR_SPINDLE // Default disabled. Uncomment to enable.
//#define ENABLE_PIECEWISE_LINEAR_SPINDLE // Not implemented yet

// N_PIECES, RPM_MAX, RPM_MIN, RPM_POINTxx, and RPM_LINE_XX constants are all set and given by
// the 'fit_nonlinear_spindle.py' script solution. Used only when ENABLE_PIECEWISE_LINEAR_SPINDLE
// is enabled. Make sure the constant values are exactly the same as the script solution.
// NOTE: When N_PIECES < 4, unused RPM_LINE and RPM_POINT defines are not required and omitted.


/*
#define N_PIECES 4 // Integer (1-4). Number of piecewise lines used in script solution.
#define RPM_MAX 11686.4 // Max RPM of model. $30 > RPM_MAX will be limited to RPM_MAX.
#define RPM_MIN 202.5 // Min RPM of model. $31 < RPM_MIN will be limited to RPM_MIN.
#define N_PIECES 4
#define RPM_MAX 24162.9
#define RPM_MIN 118.4
#define RPM_POINT12 3177.2
#define RPM_POINT23 13581.6
#define RPM_POINT34 21467.2
#define RPM_LINE_A1 5.878084e-01
#define RPM_LINE_B1 6.759473e+01
#define RPM_LINE_A2 9.803514e-01
#define RPM_LINE_B2 1.314789e+03
#define RPM_LINE_A3 1.014510e+00
#define RPM_LINE_B3 1.778715e+03
#define RPM_LINE_A4 1.483485e+00
#define RPM_LINE_B4 1.184633e+04
*/

const int N_PIECES = 3;

const double RPM_MAX = 23935.2;
const double RPM_MIN = 2412.2;
//const int N_PIECES = 4;
//const double RPM_MAX = 24513.2;
//const double RPM_MIN = 125.2;
66 changes: 33 additions & 33 deletions Grbl_Esp32/src/Defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

// Grbl generic default settings. Should work across different machines.
#ifndef DEFAULT_STEP_PULSE_MICROSECONDS
# define DEFAULT_STEP_PULSE_MICROSECONDS 3 // $0
# define DEFAULT_STEP_PULSE_MICROSECONDS 5 // $0
#endif

#ifndef DEFAULT_STEP_ENABLE_DELAY
Expand All @@ -51,7 +51,7 @@
#endif

#ifndef DEFAULT_STEPPER_IDLE_LOCK_TIME
# define DEFAULT_STEPPER_IDLE_LOCK_TIME 250 // $1 msec (0-254, 255 keeps steppers enabled)
# define DEFAULT_STEPPER_IDLE_LOCK_TIME 255 // $1 msec (0-254, 255 keeps steppers enabled)
#endif

#ifndef DEFAULT_STEPPING_INVERT_MASK
Expand All @@ -71,7 +71,7 @@
#endif

#ifndef DEFAULT_INVERT_PROBE_PIN
# define DEFAULT_INVERT_PROBE_PIN 0 // $6 boolean
# define DEFAULT_INVERT_PROBE_PIN 1 // $6 boolean
#endif

#ifndef DEFAULT_STATUS_REPORT_MASK
Expand Down Expand Up @@ -99,11 +99,11 @@
#endif

#ifndef DEFAULT_HARD_LIMIT_ENABLE
# define DEFAULT_HARD_LIMIT_ENABLE 0 // $21 false
# define DEFAULT_HARD_LIMIT_ENABLE 1 // $21 false
#endif

#ifndef DEFAULT_HOMING_ENABLE
# define DEFAULT_HOMING_ENABLE 0 // $22 false
# define DEFAULT_HOMING_ENABLE 1 // $22 false
#endif

#ifndef DEFAULT_HOMING_DIR_MASK
Expand All @@ -123,7 +123,7 @@
#endif

#ifndef DEFAULT_HOMING_PULLOFF
# define DEFAULT_HOMING_PULLOFF 1.0 // $27 mm
# define DEFAULT_HOMING_PULLOFF 3.0 // $27 mm
#endif

#ifndef DEFAULT_HOMING_SQUARED_AXES
Expand Down Expand Up @@ -156,11 +156,11 @@

// ======== SPINDLE STUFF ====================
#ifndef SPINDLE_TYPE
# define SPINDLE_TYPE SpindleType::NONE
# define SPINDLE_TYPE SpindleType::PWM
#endif

#ifndef DEFAULT_SPINDLE_RPM_MIN // $31
# define DEFAULT_SPINDLE_RPM_MIN 0.0 // rpm
# define DEFAULT_SPINDLE_RPM_MIN 1.0 // rpm
#endif

#ifndef DEFAULT_LASER_MODE // $32
Expand All @@ -172,11 +172,11 @@
#endif

#ifndef DEFAULT_SPINDLE_RPM_MAX // $30
# define DEFAULT_SPINDLE_RPM_MAX 1000.0 // rpm
# define DEFAULT_SPINDLE_RPM_MAX 24000.0 // rpm
#endif

#ifndef DEFAULT_SPINDLE_FREQ
# define DEFAULT_SPINDLE_FREQ 5000.0 // $33 Hz (extended set)
# define DEFAULT_SPINDLE_FREQ 1000.0 // $33 Hz (extended set)
#endif

#ifndef DEFAULT_SPINDLE_OFF_VALUE
Expand Down Expand Up @@ -259,13 +259,13 @@
// =========== AXIS RESOLUTION ======

#ifndef DEFAULT_X_STEPS_PER_MM
# define DEFAULT_X_STEPS_PER_MM 100.0
# define DEFAULT_X_STEPS_PER_MM 60.0
#endif
#ifndef DEFAULT_Y_STEPS_PER_MM
# define DEFAULT_Y_STEPS_PER_MM 100.0
# define DEFAULT_Y_STEPS_PER_MM 60.0
#endif
#ifndef DEFAULT_Z_STEPS_PER_MM
# define DEFAULT_Z_STEPS_PER_MM 100.0
# define DEFAULT_Z_STEPS_PER_MM 400.0
#endif
#ifndef DEFAULT_A_STEPS_PER_MM
# define DEFAULT_A_STEPS_PER_MM 100.0
Expand All @@ -280,10 +280,10 @@
// ============ AXIS MAX SPPED =========

#ifndef DEFAULT_X_MAX_RATE
# define DEFAULT_X_MAX_RATE 1000.0 // mm/min
# define DEFAULT_X_MAX_RATE 2500.0 // mm/min
#endif
#ifndef DEFAULT_Y_MAX_RATE
# define DEFAULT_Y_MAX_RATE 1000.0 // mm/min
# define DEFAULT_Y_MAX_RATE 2500.0 // mm/min
#endif
#ifndef DEFAULT_Z_MAX_RATE
# define DEFAULT_Z_MAX_RATE 1000.0 // mm/min
Expand All @@ -302,13 +302,13 @@
#define SEC_PER_MIN_SQ (60.0 * 60.0) // Seconds Per Minute Squared, for acceleration conversion
// Default accelerations are expressed in mm/sec^2
#ifndef DEFAULT_X_ACCELERATION
# define DEFAULT_X_ACCELERATION 200.0
# define DEFAULT_X_ACCELERATION 80.0
#endif
#ifndef DEFAULT_Y_ACCELERATION
# define DEFAULT_Y_ACCELERATION 200.0
# define DEFAULT_Y_ACCELERATION 80.0
#endif
#ifndef DEFAULT_Z_ACCELERATION
# define DEFAULT_Z_ACCELERATION 200.0
# define DEFAULT_Z_ACCELERATION 50.0
#endif
#ifndef DEFAULT_A_ACCELERATION
# define DEFAULT_A_ACCELERATION 200.0
Expand All @@ -323,13 +323,13 @@
// ========= AXIS MAX TRAVEL ============

#ifndef DEFAULT_X_MAX_TRAVEL
# define DEFAULT_X_MAX_TRAVEL 300.0 // $130 mm NOTE: Must be a positive value.
# define DEFAULT_X_MAX_TRAVEL 550.0 // $130 mm NOTE: Must be a positive value.
#endif
#ifndef DEFAULT_Y_MAX_TRAVEL
# define DEFAULT_Y_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
# define DEFAULT_Y_MAX_TRAVEL 570.0 // mm NOTE: Must be a positive value.
#endif
#ifndef DEFAULT_Z_MAX_TRAVEL
# define DEFAULT_Z_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
# define DEFAULT_Z_MAX_TRAVEL 100.0 // mm NOTE: Must be a positive value.
#endif
#ifndef DEFAULT_A_MAX_TRAVEL
# define DEFAULT_A_MAX_TRAVEL 300.0 // mm NOTE: Must be a positive value.
Expand Down Expand Up @@ -386,43 +386,43 @@

// ========== Motor current (SPI Drivers ) =============
#ifndef DEFAULT_X_CURRENT
# define DEFAULT_X_CURRENT 0.8 // $140 current in amps (extended set)
# define DEFAULT_X_CURRENT 0.25 // $140 current in amps (extended set)
#endif
#ifndef DEFAULT_Y_CURRENT
# define DEFAULT_Y_CURRENT 0.8 // $141 current in amps (extended set)
# define DEFAULT_Y_CURRENT 0.25 // $141 current in amps (extended set)
#endif
#ifndef DEFAULT_Z_CURRENT
# define DEFAULT_Z_CURRENT 0.8 // $142 current in amps (extended set)
# define DEFAULT_Z_CURRENT 0.25 // $142 current in amps (extended set)
#endif
#ifndef DEFAULT_A_CURRENT
# define DEFAULT_A_CURRENT 0.8 // $143 current in amps (extended set)
# define DEFAULT_A_CURRENT 0.25 // $143 current in amps (extended set)
#endif
#ifndef DEFAULT_B_CURRENT
# define DEFAULT_B_CURRENT 0.8 // $144 current in amps (extended set)
# define DEFAULT_B_CURRENT 0.25 // $144 current in amps (extended set)
#endif
#ifndef DEFAULT_C_CURRENT
# define DEFAULT_C_CURRENT 0.8 // $145 current in amps (extended set)
# define DEFAULT_C_CURRENT 0.25 // $145 current in amps (extended set)
#endif

// ========== Motor hold current (SPI Drivers ) =============

#ifndef DEFAULT_X_HOLD_CURRENT
# define DEFAULT_X_HOLD_CURRENT 0.4 // $150 current in amps (extended set)
# define DEFAULT_X_HOLD_CURRENT 0.125 // $150 current in amps (extended set)
#endif
#ifndef DEFAULT_Y_HOLD_CURRENT
# define DEFAULT_Y_HOLD_CURRENT 0.4 // $151 current in amps (extended set)
# define DEFAULT_Y_HOLD_CURRENT 0.125 // $151 current in amps (extended set)
#endif
#ifndef DEFAULT_Z_HOLD_CURRENT
# define DEFAULT_Z_HOLD_CURRENT 0.4 // $152 current in amps (extended set)
# define DEFAULT_Z_HOLD_CURRENT 0.125 // $152 current in amps (extended set)
#endif
#ifndef DEFAULT_A_HOLD_CURRENT
# define DEFAULT_A_HOLD_CURRENT 0.4 // $153 current in amps (extended set)
# define DEFAULT_A_HOLD_CURRENT 0.125 // $153 current in amps (extended set)
#endif
#ifndef DEFAULT_B_HOLD_CURRENT
# define DEFAULT_B_HOLD_CURRENT 0.4 // $154 current in amps (extended set)
# define DEFAULT_B_HOLD_CURRENT 0.125 // $154 current in amps (extended set)
#endif
#ifndef DEFAULT_C_HOLD_CURRENT
# define DEFAULT_C_HOLD_CURRENT 0.4 // $154 current in amps (extended set)
# define DEFAULT_C_HOLD_CURRENT 0.125 // $154 current in amps (extended set)
#endif

// ========== Microsteps (SPI Drivers ) ================
Expand Down
5 changes: 3 additions & 2 deletions Grbl_Esp32/src/Machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
// !!! For initial testing, start with test_drive.h which disables
// all I/O pins
// #include "Machines/atari_1020.h"
# include "Machines/test_drive.h"
//# include "Machines/test_drive.h"

// !!! For actual use, change the line above to select a board
// from Machines/, for example:
// #include "Machines/3axis_v4.h"
#include "Machines/makerfr_v2_XYZA.h"


// === OEM Single File Configuration Option
// OEMs that wish to publish source code that is configured for a
Expand Down
68 changes: 68 additions & 0 deletions Grbl_Esp32/src/Machines/makerfr_v2_XYYZ.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#pragma once
// clang-format off

/*
makerfr_v2_XYYZ.h
Part of Grbl_ESP32

Pin assignments for the RS-CNC32 board (4 axis with external drivers)
https://github.com/bdring/4_Axis_SPI_CNC

2018 - Bart Dring
2020 - Mitch Bradley

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 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_ESP32. If not, see <http://www.gnu.org/licenses/>.
*/

#define MACHINE_NAME "MakerFr GRBL 32 bits Board V2 XYYZ"

#ifdef N_AXIS
#undef N_AXIS
#endif
#define N_AXIS 4

#define X_STEP_PIN GPIO_NUM_33
#define X_DIRECTION_PIN GPIO_NUM_25
#define Y_STEP_PIN GPIO_NUM_26
#define Y_DIRECTION_PIN GPIO_NUM_27
#define Z_STEP_PIN GPIO_NUM_14
#define Z_DIRECTION_PIN GPIO_NUM_12
#define Y2_STEP_PIN GPIO_NUM_13 // ganged motor
#define Y2_DIRECTION_PIN GPIO_NUM_32 // ganged motor
#define STEPPERS_DISABLE_PIN GPIO_NUM_15

#define USE_GANGED_AXES
#define Y_AXIS_SQUARING

#define SPINDLE_OUTPUT_PIN GPIO_NUM_2 // labeled SpinPWM
#define SPINDLE_ENABLE_PIN GPIO_NUM_17 // labeled SpinEnbl
#define LASER_OUTPUT_PIN GPIO_NUM_21

#define X_LIMIT_PIN GPIO_NUM_36
#define Y_LIMIT_PIN GPIO_NUM_39
#define Z_LIMIT_PIN GPIO_NUM_34
//#define A_LIMIT_PIN GPIO_NUM_35

#define PROBE_PIN GPIO_NUM_16
#define COOLANT_MIST_PIN GPIO_NUM_22

#ifdef INVERT_CONTROL_PIN_MASK
#undef INVERT_CONTROL_PIN_MASK
#endif

#define INVERT_CONTROL_PIN_MASK B1110

#define CONTROL_RESET_PIN GPIO_NUM_4 //4 labeled Reset
#define CONTROL_FEED_HOLD_PIN GPIO_NUM_21 //21 labeled Hold
#define CONTROL_CYCLE_START_PIN GPIO_NUM_0 //0 labeled Start
Loading