Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Gcode begins with move before raising spindle

eratus
Participant

Gcode begins with move before raising spindle

eratus
Participant
Participant

Hi, this is happening both in 2d and 3d contour cuts. The gcode moves the x/y spindle to the position where the cut begins, then raises the spindle to the transit height, then to the cut depth. It should raise then move x/y. Is there an option I'm missing? It's easy enough to fix the gcode manually, but it seems wrong.

 

Here's what is happening:

 

(CONTOUR1)
T1 M6
M3 S11459
G0 X-289.65 Y-280.188
G0 Z6
G1 Z-6 F250.

 

 

0 Likes
Reply
2,965 Views
14 Replies
Replies (14)

seth.madore
Community Manager
Community Manager

When you post process, set your Retract option to "Clearance Height"


Seth Madore
Customer Advocacy Manager - Manufacturing
0 Likes

eratus
Participant
Participant

I've tried it using G28 and Clearance Height, but the problem persists. From reading some of the responses in other threads, I think there is a misunderstanding between us hobbyists and the professionals responding. The limit switch for the z axis on my machine is at z=0, when the tool is closest to the bed.

 

So regardless of clearance height vs G28, when the z axis is homed there is the least amount of clearance. This causes the bit on the first xy move to crash into or scrape across the surface of the work piece. A simple fix would be an option to go to the clearance height before the first xy move. Or maybe the misunderstanding is solely with me, as I'm still trying to figure this bit out.

 

Here's the start of the gcode with g28:

N25 G28 G91 Z0
N30 G90

(2D Pocket1)
N35 T1
N40 S12000 M3
N45 G0 X715.071 Y304.798
N50 Z28.7

 

And here's the start with Clearance Height:


(2D Pocket1)
N25 T1
N30 S12000 M3
N35 G0 X715.071 Y304.798
N40 Z28.7

0 Likes

engineguy
Mentor
Mentor

@eratus 

 

The problem will be how you have your CNC Control setup, you have two Z Zero coordinates, one is the "Home" position of the machine and the second one is the "Part Zero", a common position for "Part Zero" is to set it to the Lower Left corner of the Stock on the X and Y axis and the Z to the top of the stock. That would also be set in the Setup for your programs in Fusion, set the WCS in Fusion to the same as your "Touch Off" position that you are going to use at the machine, really easy if you keep stuff the same at each location :slightly_smiling_face:

Also be aware that the Tool lengths that you use in Fusion are NOT transferred over to your CNC Control, those you need to set at the Control. These are usually "Called up" by a G43 Z** H** line of code so it is for example for tool #1 would look like G43 Z28.7 H1, this is the control moving the Z axis to Z28.7 and taking into account the length of the tool that you have set in the control, so for example if you have a tool length set to say 60mm the the CNC Control will stop the Z axis movement at 88.7mm above the stock.

Hope you can understand all that, not trying to insult anyone but there is no way to know anyones level of expertise :slightly_smiling_face:

 

What control and Post Processor are you using and is there not a switch at the highest point of travel actually on the machine ??

 

If there is only a single switch at the lower end of your Z axis travel then that is simply a "Limit" switch and should be set so that the spindle with a tool in it can not hit the table, often that switch is on a slide so that it is adjustable.

 

If you have no switch at the top of your Z axis travel then you need to setup and use "Soft Limits" for Homing your machine, the X/Y axis can be anywhere you like (Usually somewhere you can easily access it for tool changes if you have no ATC) but the Z axis must be set at a safe height so that either a G28 G91 Z0 or G53 Z0 command will send your Z axis up to the safe height you want it to go to for tool changes and X/Y safe lateral movement, so if you have your machine control setup correctly the first thing the machine should do is go to the Z axis "Home" position, this is no different for either a "Hobbyist" or a "Professional", this is the basics of setting up and running any CNC Machine be it Mill/Lathe/Router etc, etc.

 

Lets look at your code :-

Here's the start of the gcode with g28:

N25 G28 G91 Z0  This is the correct line of code that will lift the Z axis to the safe/Home position, this is good and safe (This could also be a G53 Z0 command)
N30 G90

(2D Pocket1)
N35 T1
N40 S12000 M3
N45 G0 X715.071 Y304.798  Now the X/Y linear moves can be done safely
N50 Z28.7    Now the Z axis should move DOWN to the Z28.7 Clearance height, this is correct and safe

 

And here's the start with Clearance Height:


(2D Pocket1)
N25 T1
N30 S12000 M3
N35 G0 X715.071 Y304.798  Here you have the X/Y linear move being done with nothing before it for a Z height so where is the spindle at this point, if it is left at the height of the Z Stock top then the tool will just drag across the Stock before it goes to the Z28.7 position
N40 Z28.7      Now it goes to the Z28.7 height but is it going UP or DOWN to go there?

 

What CNC Control are you using ?? The above will apply to most Hobby CNC Controls such as Mach3/Mach4/UCCNC/CSMIO etc, etc,.

Get your CNC Machine setup correctly and you will get to enjoy it much more :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face:

0 Likes

Laurens-3DTechDraw
Mentor
Mentor

Picking G53 and setting up your safe plane correctly in the machine configuration should be a good solution as well.

As you can then easily set the Z value to the maximum of your machine.

Laurens Wijnschenk
3DTechDraw

AutoDesk CAM user & Post editor.
René for Legend.


0 Likes

engineguy
Mentor
Mentor

@Laurens-3DTechDraw 

 

The issue the Poster is having is that use of the G28 (or G53) sends the Z axis down towards the table which is why he is trying to use the "Clearance Height", but he doesn`t seem to have anything set up correctly at the machine, so that doesn`t work correctly either :disappointed_face:

Must be time for some serious reading/understanding of the "Operators Manual" :slightly_smiling_face: :slightly_smiling_face:

0 Likes

Laurens-3DTechDraw
Mentor
Mentor

While I fully agree with your statement of setting up the machine better.

If you setup your machine config correctly for the MACH3 post for example you get G53 Z215 instead of G53 Z0 for example. Making G53 a viable option even if your machine home is on the lower side of the Z-Stroke.

Laurens Wijnschenk
3DTechDraw

AutoDesk CAM user & Post editor.
René for Legend.


0 Likes

eratus
Participant
Participant

Hi, thanks for the replies. I'm using Duet Web Control 3.3 with a Duet 6HC and RepRap post. I'll read up on G53 and see if I can get my machine configured correctly.

0 Likes

eratus
Participant
Participant

I'm still having trouble. Reading on G53 brought me back to G28. I thought I understood the solution after reading this:

https://discuss.inventables.com/t/learning-about-g28/12205

 

But then I discovered RepRap doesn't use G28.1, so G28 always goes to the limit switches.  My z limit switch is at the point of least clearance.

 

https://duet3d.dozuki.com/Wiki/G28

https://www.reprap.org/wiki/G-code#G28:_Move_to_Origin_.28Home.29

 

So, now I'm trying to figure out why there isn't a G53 in the .nc file when I select Clearance Height. I'll have to ask you to excuse my ignorance, as I have no training or experience in any of this, and I don't know JavaScript, just a little bit of C++. I took a look at the post file and I'm wondering if the "return" should be contained within the previous "if" statement:

 

/** Output block to do safe retract and/or move to home position. */
function writeRetract() {
   var words = []; // store all retracted axes in an array
   var retractAxes = new Array(false, false, false);
   var method = getProperty("safePositionMethod");
   if (method == "clearanceHeight") {
      if (!is3D()) {
         error(localize("Safe retract option 'Clearance Height' is only supported when all operations are along the setup Z-axis."));
      }
      return;
   }

0 Likes

eratus
Participant
Participant

I believe I found the problem. At least I'm getting G53 at the start of the .nc file now.

 

It seems the RepRep post processor was edited at some point, commenting out "G53" as a menu option and replacing it with "Clearance Height":

 

values : [
{title:"G28", id:"G28"},
//{title: "G53", id: "G53"},
{title:"Clearance Height", id:"clearanceHeight"}

 

Then in the writeRetract function, the if  statement I pasted in my above comment references "clearanceHeight", but where the cases are listed, it's still "G53" , with no mention of clearanceHeight:

 

switch (method) {
case "G28":
  gMotionModal.reset();
  gAbsIncModal.reset();
  writeBlock(gFormat.format(28), gAbsIncModal.format(91), words);
  writeBlock(gAbsIncModal.format(90));
  break;
case "G53":
  gMotionModal.reset();
  writeBlock(gAbsIncModal.format(90), gFormat.format(53), gMotionModal.format(0), words);
  break;
default:
  error(localize("Unsupported safe position method."));
  return;
}

 

I commented out the "Clearance Height" menu option and uncommented the "G53" option. In the "if" statement, I changed "clearanceHeight" to "G53" and commented out the "return". Now the .nc file includes a G53 at the beginning.  The modified post is attached.

 

0 Likes

eratus
Participant
Participant

I'm still misunderstanding something. No matter how I adjust my heights, the G53 code is always:

 

G53 G0 Z0

 

Do I need to change my machine config so that when the spindle is at the highest point, Z=0? If so, do I then have Z operate in negative space? Thanks to anyone who can help me get over this hump.

 

 

0 Likes

engineguy
Mentor
Mentor

@eratus 

 

Not sure why you have got this fixation with G53, the original options of G28 and Clearance height are fine and working correctly.

 

Yes, unless there is something very different with your machine then the Z axis Zero should be set to the top of it`s travel or a to a height that you consider safe depending on just how much actual Z travel you have at the machine, some Routers have only a small Z axis travel.

 

Yes again, unless there is something different with your machine then the Z axis (Most CNC Machines I know of) does usually move in the Positive (Upwards) direction to it`s Home position and a Negative (Downwards) direction to cut, if you have jogged the spindle down and set your Stock with the Probe to Part Zero Z top of the material then on your Z axis read out it should show a Minus value for your "Machine Position" and a Z0 value for your Stock position.

When you start to cut the machine should start at the Part Z0 and cut downwards so it is for example taking a 1mm cut so the Z axis will show Z-1.00 on your control readout.

 

All you need to do is jog your machine to an X/Y/Z point that you want it to Home to, most Routers for example have the Y axis as the longest running towards/away from the operator so lets say the machine has 1000mm in the X and 2000mm in the Y and 300mm in the Z then a likely setting would be with the X/Y to the Left front corner and the Z to the top of it`s travel. You could set the X to the halfway point so that it will go to X500/Y0/Z300 for easier acess for toolchanging, just an example, up to the user as to what is best for the operator.

 

All you should need to do is move your machine to whatever position you want it to go to and set that as your Home position, then, whenever a G28 G91 Z0 (or a G53 Z0) command appears in the code your machine will move to that position.

 

If it is not possible for some odd reason to do the above and the only way you can Home your machine is to the switch at the bottom of your Z axis travel then you can change the Z0 part of the G28/G53 commands to a Positive value as @Laurens-3DTechDraw mentioned earlier, to do that go to the area of the PP that sets the Home positions and change the Z value to say 300 as in the first image below, that will result in the code shown in the second image, see how you go with just that modification. That will work for the G28, if you also want to do the same with the G53 look at the third image and where it has the case G53 change the ,words); to "Z300); and you will get the same Z300 with the G53 setting.

The Clearance Height should work OK as long as you have your Stock set correctly.

Hopefully the above will be of some help, it is difficult to sort without being at the Control and having the Operators Manual :slightly_smiling_face: :slightly_smiling_face: :slightly_smiling_face:

RepRap-1.jpg

 

RepRap-2.jpg

 

RepRap-3.jpg

 

0 Likes

eratus
Participant
Participant

Thanks

0 Likes

eratus
Participant
Participant

I have it working by editing the homing file to raise the z at the end of homeall.g. G28 is not implemented correctly in the RepRap post processor. Here's what the Operator's Manual says:

 

https://docs.duet3d.com/User_manual/Reference/Gcodes

 

G28    ; Home all axes
G28 XZ ; Home the X and Z axes

The X and Z parameters in this example act only as flags. Any coordinates given are ignored. For example, G28 Z10 results in the same behavior as G28 Z.

 

The purpose of homing is to move the specified axes in such a way as to establish a known position for them, for example by moving an axis motor until an endstop switch is triggered. Homing an axis normally leaves it in a fixed position, however this position needs not be the zero position.

 

The way in which each axis is homed is completely configurable using the homing macro files, which specify what actions are taken. Execution of the G28 command is as follows:

 

  • If there are no G28 parameters that correspond to axes that exist, or if the printer is a delta, then all axes are to be homed. Otherwise, the axes to be homed are determined by enumerating parameters of the G28 command.
  • Each axis or delta tower to be homed is flagged as "position not known".
  • If all axes or towers are to be homed, the file homeall.g is processed, except that on a delta printer homedelta.g is processed. If this process results in some but not all axes become flagged as "position known", an attempt will be made to home the remaining axes as if the G28 command had listed those axes.
  • For each remaining axis flagged as "to be homed" the appropriate homing file is executed (homex.g, homey.g, homez.g etc.).

 

 

 

By luck, "G28 G91 Z0" runs homeall.g and not homez.g as one would expect from the above. This allows me to keep my homing file for the z axis intact. The end of the .nc file also contains "G28 G91 Z0" and "G28 G91 X0 Y0", both of which run homeall.g

 

So when I go to mill a piece of stock say, 10mm tall, the generated code tells my machine to home, then raise to 150mm, then at the finish it homes, raises to 150mm, then homes and raises to 150mm.

 

In regards to Clearance Height, regardless of how I set my heights in the Heights or Linking tabs, there is never a z move before an xy move. Has anyone else tried it?

0 Likes

renzodelli
Community Visitor
Community Visitor

If you change the code by puting the Z6 instruction before G0 X-289.65 Y-280.188, the problem is solved. The real problem is that the start point is actually the one you see in the simulation and even in the setup page. It doesn't really care where you start. The real problem is trying to reach that start point from your HOME position BEFORE raising the spindle, and that is a Fusion issu. Despite the fact that you choose the origin in your setup, Fusion will choose his own starting point, and the gCode generated does exactly what you see in the similuation page. There is no way to tell Fusion to RAISE the spindle BEFORE moving anywhere to the start point, you have to do it manually in your gCode.

0 Likes