Automate workpiece setup

I have my stock always at a known fixed location from machine’s home in the LR2. I would like to automate the initial setup so that no matter where the machine’s head is when I turn it on, it homes itself, sets the predefined WCS offset (G54?), probes the ‘Z’ height of the material and starts the job. I think the following recipe by @jamiek should do though it does not automatically probe the Z height.

  • Home your machine
  • Invoke G54 to switch to machine coordinates
  • Perform G92 to set the home position to 0,0 in machine coordinates
  • Jog to your workpiece origin (or the machine automatically goes to the workpiece origin at the predefined location)
  • Start your g-code after adding these to your start/end g-code:
    • Perform G55 to switch to workpiece coordinates
    • Perform G92 to set your current position to 0,0 in workpiece coordinates
    • Run your CAM commands (runs in workpiece coordinates)
    • After finishing, perform G54 to switch back to machine coordinates
    • Move to your safe machine location in a safe way, e.g. G1 Z100 (or whatever your maximum height) followed by G1 X0 Y0

Questions:

  • First of all is it possible to automate the above at all or there is still some manual intervention needed? Pls note that I have independently tested homing and z probe and they work ok.
  • If so, how do I add the above recipe to the gcode generated by Fusion 360? I am using guffy post processor but could not see any place I can add a custom code at the beginning/end.
1 Like

You can add custom code by putting it in a separate file and referencing it in these two settings:

image

The last time I played with these settings, they did not handle absolute file paths, so these files need to be in the same directory where you write out the g-code file. I don’t know what you are using to send the g-code, but some senders also have provisions for start/end code.

I’ve played with the codes you specify in my head for repeated work, but since I’m a hobbyist that mostly does one-off creations, it has never been a priority to figure out. There is a phrase in the g-code reference for G54 that is tantalizing to me:

with EEPROM support they may be restored from a previous session

I’m not sure what needs to happen to enable this feature…maybe a simple M500, maybe enable a feature in Marlin. Once enabled and set, the (0,0,0) coordinate in workpiece coordinates would be the same offset from the machine coordinates, so no G92 in workspace coordinates, and you could have multiple fixtures, each with its own workspace.

is still some manual intervention

The one fly in the ointment I see is Z height. You say, “testing homing and z probe…,” but I’m not sure what that means. Typically attaching the clip and setting the touch plate is a manual operation. You could ground the router bit and attach a touch plate at a known location, or you could use a switch at a known location, but this only allows you to set the Z height at the spoilboard. Some carving is best done by setting the Z height at the top of the stock. For wood anyway, I see a lot of variation in thickness.

Please post back your results.

Curious to see what you come up with as I’ve been thinking of doing this also. I can tell you that in the makita you can’t ground the router body as there is no electrical contact between the cutter and router body so for z height I think a switch is the only option to prevent having to clip on a lead.

Are you using Marlin from the website here with SDCARD? I have been studying up on auto0.g auto1.g etc.
This could work for you. You place what code you want to run on start and it should run. Now, right now I do not have endstops on mine, I am planning on adding them.

My plan was to do what you are stating, home, then set x, y to a specified coordinate, then zero at that coordinate.

So Just for Clarification, this could make your CNC MOVE on START, so just be very CAREFUL with anyone around you that may turn it on!!

What I am thinkin I may try,
On start
Home,
pause (make screen pause until I press button)
then move to corner where I place markers to start all material I cut
Reset Zero to here,
Then maybe pause (press button)
and now Set z with a touchplate.

this was given to me here: Z probing with 10mm block height - #6 by jortijn

Autostart | Marlin Firmware (the file naming for sd card)

I do this exact process on my LR. I use cnc.js (v1pi) macros to do the initial setup…

Here’s My Setup G-Code for zeroing to the spoil board corner. Be sure to scroll the code window below it cuts off after about 20 lines.


;Load Defaults from EEPROM
M501

;Set Homing Offsets
; This squares the 2 motors if endsstops aren't perfect.
; XOfset 
M666X-.12
M666Z-3.46

;Set Acceleration
M201X3000Y3000Z40

;Set Motor Current
M906 I1X1000
M906 X1000
M906 Y1300
M906 Z1300
M906 I1Z1300

;Max Speed
;M203 X3000 Y3000 Z40

;Sensorless Endstop Sensitivity
M914 X65 Y40 Z30

;FeedRate
G0F3000

;Switch to Machine Native Space
G53

;Home All and zero
G28.2 Z0
G28.2 X0
G28.2 Y0
G92 Z0

;Move to Corner of Spoil Board
G0Z-60X18.150Y48.3

; Switch to Coordinate System 1 (Spoil Board)
G54

; Zero All
M92 X0Y0Z0

;Save
M500

I use the G55 workspace 2 for a right angle fence with another macro and G56 for the actual workspace.

In the header of each job I put the following snippet to save the origin for the job (THIS IS THE MAGIC SAUCE)

;Switch to Workspace Coordinate System 
G56
;Zero Out the Workspace
M92X0Y0Z0
;Save to EEPROM
M500

Now if I have to hard kill a job. I can just run my startup script to get the machine into a known state then run:

G56
G0X0Y0Z0

And I can start over in the exact spot.

Hope this helps!

2 Likes

It is good to know that an M500 saves the offset to a workspace. Thank you. I look to incorporate it into my workflow.

The code you posted has some weirdness. I don’t know if this is something you have missed, or you are doing something sophisticated beyond the context of this script segment. Typically, M666, M906, M203, and M914 are set just once and then saved using an M500. After that, they become the defaults loaded by Marlin. Typically, a M501 is not needed since Marlin loads the defaults when it starts. There is no G28.2 g-code in the Marlin reference. There is a G38.2. My guess is that Marlin is forgiving enough to make it work. To home, you can do:

G28 X Y Z

Yeah I use the M501 to reset to a know state as I sometimes mess with settings in my gcode.

The script has some redundancies that aren’t needed every job but they keep everything in one place in case I need to tweak a setting.

I’ll look at the 28.2, it works for me but I’m no expert and can’t remember where I got it from.

1 Like

:upside_down_face:
I didn’t understand this stuff when I started with my LR a year+ ago. So I’ve just been working in one workspace, starting from a hard stop on my table, moving a set distance to a known corner where I place rectangular workpieces, and writing down any “custom” origins I set. At the end of my cuts I would reverse the steps to bring the gantry back to the hard stops. Not too complicated as I used a macro for the standard positions I was using. But…

After reading this I switched my workspace to G55 (from G54) in cnc.js and saw the machine coordinates relative to the original origin at the stops. Gah!
Almost more important than the x-y origin is the z-origin. I don’t have endstop switches so I always jog the z at the end to park it. The possibilities now!

2 Likes

I’ve got a magnet superglued inside the clip of my Tiny Touchplate so there’s no longer any need to actually clip it to the bit. Just get close to the bit or collet nut and it grabs hold, and a quick jerk pops it off again.

I just use the clip on the tiny touchplate to hold the magnet with it’s teeth. I should probably epoxy it in place.

I tried that to begin with, but the magnet kept slipping out of the teeth.

To be clear, the magnet is glued to


the body of the clip, so it can still “bite” on to things if needed.

3 Likes

Check just for continuity after I had mine epoxied to a small bolt head and it worked great but eventually caused intermittent contact failure resulting in my v but going through my touch pad… Went back to clipping it onto the bit to be safe

Good reminder! Mine is CA’ed along the edge of the magnet with accelerator fillets. I used a gel glue, so I don’t think it was thin enough to wick under the magnet, but I check it each time I use it.

1 Like

Good point.

Thanks for all the suggestions. I was intrigued by the idea of using macros. So, I installed cnc.js on a Raspberry Pi and connected it to the machine. The interface is easy to use and so is the list of Marlin commands. After a quick read up of the doc, I wrote the following macros that should alleviate the pain of going through these operations manually.

  • Power On Test: Due to lack of space, I have to stack my 8’ x 5’ LR2 vertically against a wall. This forces me to align it every time I intend to use it. A Power On Test will help me ensure that my endstops are working fine, the wheels and the bearings are not binding, the pulleys are not loose, the cords and the vacuum hose are not coming in the way, etc.

; Switch to MCS

G53

; Absolute positioning

G90

; Verify the connections of the endstops

; Home Z explicitly before X & Y

G28 Z

G28 X Y

; Set relative positioning. Get closer to the work surface without worrying about the height set as default on power up

G91

G0 F100 Z-100

; Validate the X axis travel at the near end of the Y axis

G0 F1800 X1370

G0 F1800 X-1370

; Validate the X axis travel at the far end of the Y axis

G0 F1200 Y1400

G0 F1800 X1370

G0 F1800 X-1370

; Return to the start and bring down the Z axis to its rest position

G28 Y

G0 F600 Z-28

; Return to absolute coordinates

G90
  • Setup Stock: This essentially establishes a WCS with its origin at the corner of the stock and aligned to the top surface.

; Switch to MCS

G53

; Absolute positioning

G90

; Home Z explicitly before X & Y

G28 Z

G28 X Y

; Move to the corner of the spoil board. The stock is also aligned to start from this corner

G0 F1500 X73

; Switch to the WCS

G54

; Establish this point as the home position (Z will be established after probing)

G92 X0 Y0

; Move to the center of the stock

G0 F1500 X610 Y700

;G0 F1500 Y700

; Relative positioning

G91

; Initiate Z probe after getting closer to the work surface

G0 F300 Z-80

G38.2 Z-20 F30

; Absolute positioning

G90

; Set the position of the probe to the height of the probe block

G92 Z20

; Move up by 10 mm and travel to the beginning of the stock

G0 F300 Z30

G0 F1500 X0 Y0

; Move to the top of the stock

G0 F100 Z0

; Store in EEPROM

M500
  • Resume Job: This will help resume the machine from a known good state if a job gets terminated prematurely due to an unexpected failure or if I have to execute a long job with breaks in between.

; Retrieve the stored settings from EEPROM

M501

; Absolute positioning

G90

; Home all axes

G28 X Y Z

; Switch to WCS

G54

; Move to the stock's origin

G0 F1500 X0 Y0

G0 F100 Z0
  • Shutdown: Brings the machine to a safe position where I can just yank out the power without worrying about the Z axis falling under its own weight and damaging the stock or the endmill.

; Switch to MCS

G53

; Absolute positioning

G90

; Move to machine's origin

G0 F1500 X0 Y0

G0 F100 Z0

I will be doing my first cut on wood with this machine over the weekend. Very excited and keeping my fingers crossed!

1 Like