-
-
Notifications
You must be signed in to change notification settings - Fork 161
Limit switches and homing
grbl-Mega-5X is an evolution of the original grlbl program which has only one limit switch connection per axis.
This development is based on the use of the RAMPS expansion card which offers 2 limit switch connections per axis, a minimum limit and another maximum. The software does not differentiate between the min and max limits and behaves as if the 2 switches were connected in series.
by default, the limit switches must be wired between ground and the following pins on the Arduino board:
Axis | Pin min | Pin max |
---|---|---|
AXIS_1 (X) | D3 | D2 |
AXIS_2 (Y) | D14 | D15 |
AXIS_3 (Z) | D18 | D19 |
AXIS_4 | D42 | D40 |
AXIS_5 | D44 | D59 |
AXIS_6 | D57 | D58 |
cf. https://github.com/fra589/grbl-Mega-5X/wiki/grbl-Mega-5X-pinout
cf. https://github.com/fra589/grbl-Mega-5X/wiki/Pinout-mapping-in-cpu_map.h
When taking origin or any other movement using the material limits, the program does not need to know the min or max direction of the limit switch encountered, it simply depends on the direction of the movement in progress. It must simply detect "end of travel on the moving axis" since it already knows which direction the movement is in progress and therefore does not need any other information.
The grbl parameter for choosing the type of limit switch is $5:
- if $5 = 0, (default value) the end-of-trip sensors operate in "Normally Open" (NO) mode.
- if $5 = 1, the limit switches operate in "Normally closed" (NC) mode.
This parameter reverses the operating logic (NO or NC) of ALL switches.
- In the normally open mode, the behavior is simple: when idle, the 2 switches are open and it's enough that one of the 2 switches is closed for the program to detect the limit switch.
- In the normally closed mode, all the switches being closed when idle. If a switch is open, the limit is trigered for the axis.
This effectively assumes that ALL switches are effectively closed when idle.
⚠️ Warning! If one of the contactors is missing, the coresponding pin must be connected to the ground in order for the NF logic to be respected. Otherwise, the limit switch on the axis concerned will be trigered permanently.
If all the limit switches are not of the same type (all NO or all NC), the use of the $5 parameter is not possible.
In this case, you must define the specific hardware configuration when compiling the program using the following definitions in config.h:
#define INVERT_MIN_LIMIT_PIN_MASK
#define INVERT_MAX_LIMIT_PIN_MASK
These 2 constants define a binary mask giving the logic of each limit switch used.
- A bit at 0 defines a normally open limit switch,
- a bit at 1 defines a normally closed limit switch.
For example, if the limits are: AXIS_3 min (Z min), AXIS_4 min, AXIS_1 max (X max), AXIS_2 max (Y max) and AXIS_3 max (Z max) limit switches are normally closed switches and the others being normally open or absent, use the following definitions:
#define INVERT_MIN_LIMIT_PIN_MASK ((1<<AXIS_3) | (1<<AXIS_4))
#define INVERT_MAX_LIMIT_PIN_MASK ((1<<AXIS_1) | (1<<AXIS_2) | (1<<AXIS_3))
If all the bits of one of these constants must be 0, leave the constant in comment (// at the beginning of the line).
Standard CNC milling machines use the maximum limits of their axes for homing, usually Z first, then X and Y and then, the other axes.
This makes it possible to free up the working space and to avoid as much as possible the collision with a part or a recurring machining assembly which would have remained clamped on the table of the machine.
The homing directions are controlled by the $23 parameter.
When $23 equals 0, all homing directions go towards the maximum (direction +) for each axis.
Each bit of the $23 parameter controls the direction of an axis, starting with the right (low weight bit) for axis 1 (X)
Axis N° +/-,... | Binary | Decimal |
---|---|---|
1+, 2+, 3+, 4+, 5+, 6+ | 00000000 | 0 |
1-, 2+, 3+, 4+, 5+, 6+ | 00000001 | 1 |
1+, 2-, 3+, 4+, 5+, 6+ | 00000010 | 2 |
1+, 2+, 3-, 4+, 5+, 6+ | 00000100 | 4 |
1+, 2+, 3+, 4-, 5+, 6+ | 00001000 | 8 |
1+, 2+, 3+, 4+, 5-, 6+ | 00010000 | 16 |
1+, 2+, 3+, 4+, 5+, 6- | 00100000 | 32 |
If several axes must go in the direction of the min, simply add the values.
Examples:
Axis N° +/-,... | Binary | Decimal |
---|---|---|
1-, 2-, 3+, 4+, 5+, 6+ | 00000011 | 2 + 1 = 3 |
1-, 2+, 3-, 4+, 5+, 6+ | 00000101 | 4 + 1 = 5 |
1-, 2+, 3-, 4-, 5+, 6- | 00101101 | 1 + 4 + 8 + 32 = 45 |
The homing for an axis takes place in 5 steps:
- The axis moves towards the limit switch at a moderately fast speed defined by $25,
- When the limit switch is detected, the axis stops for a short time (debounce) defined by $26,
- The axis emerges from the limit switch from a distance defined by $27,
- The axis moves again towards the limit switch at a slow speed defined by $24 until it touches the switch again,
- The axis is released again from the limit switch by a distance defined by $27.
The complete axis origin cycle is defined when compiled, in the config.h file.
All the axes do not necessarily need a homing, especially in the case of rotary axes which could have no limit in rotation and not have limit switches.
By default, the definition of the homing cycle is as follows:
5 defined axes, 3 linear X, Y and Z, and 2 rotary A and B, only the linear axes have a homing, the homing origins of the rotary axes are disabled because they are commented out:
#elif N_AXIS == 5 // 5 axis : homing
#define HOMING_CYCLE_0 (1<<AXIS_3) // Home Z axis first to clear workspace.
#define HOMING_CYCLE_1 (1<<AXIS_1) // Home X axis
#define HOMING_CYCLE_2 (1<<AXIS_2) // Home Y axis
//#define HOMING_CYCLE_3 (1<<AXIS_4) // Home 4th axis (A)
//#define HOMING_CYCLE_4 (1<<AXIS_5) // Home 5th axis (B)
To activate the homing of 2 simultaneous axes, necessary in particular when using cloned axes, for example 5 axes including X and Y clones defined as follows:
#define N_AXIS 5 // Number of axes
#define N_AXIS_LINEAR 5 // Number of linear axes
(...)
#define AXIS_1 0 // Axis indexing value. Must start with 0 and be continuous.
#define AXIS_1_NAME 'X' // Axis names must be in X, Y, Z, A, B, C, U, V & W.
#define AXIS_2 1
#define AXIS_2_NAME 'Y'
#define AXIS_3 2
#define AXIS_3_NAME 'Z'
#if N_AXIS <3
#error "N_AXIS must be >= 3. N_AXIS < 3 is not implemented."
#endif
#if N_AXIS > 3
#define AXIS_4 3
#define AXIS_4_NAME 'X' // Letter of axis number 4
#endif
#if N_AXIS > 4
#define AXIS_5 4
#define AXIS_5_NAME 'Y' // Letter of axis number 5
#endif
The normal definition of homing cycle for this configuration would be:
#elif N_AXIS == 5 // 5 axis : homing
#define HOMING_CYCLE_0 (1<<AXIS_3) // Home Z axis first to clear workspace.
#define HOMING_CYCLE_1 ((1<<AXIS_1)|(1<<AXIS_4)) // Home X axis
#define HOMING_CYCLE_2 ((1<<AXIS_2)|(1<<AXIS_5)) // Home Y axis
As described above, there are 2 main homing phases per axis: feed and seek.
The first phase (feed) whose speed is defined by $25 is used to contact the limit in a reasonable time. Quite quickly if possible, but not too much, taking into account the accelerations and decelerations necessary so as not to damage the structure of the machine.
After this phase, we repeat the same thing, but this time at slow speed, controlled by the parameter $24, in order to be much more precise in determining the position.
Grbl defines a maximum distance for the search for limit switches with a value of 1.5 times the maximum distance of each axis. The maximum distance of each axis is controlled by the parameters $130 to $135 for, respectively, axis 1 to 6 if defined.
If in this distance, the limit switch is not actuated, Grbl will lock and trigger the alarm 9.
After this phase, each axis will reverse by a distance defined by $27 to ensure that the end sensors are disengaged.