Hello Guest it is March 28, 2024, 07:12:06 AM

Author Topic: Is M4 supposed to save axes position on shutdown?  (Read 6577 times)

0 Members and 1 Guest are viewing this topic.

Re: Is M4 supposed to save axes position on shutdown?
« Reply #10 on: February 09, 2017, 03:07:06 AM »
Thanks for helping hands, Daz and Russ.

I tried exactly the steps described by Russ.
When closing M4, it does not ask me about saving anything. Maybe I once clicked "Do always, don't ask me furthermore".
Or it might be the circumstance that I cannot home all axes, but only a few, because rotational axis does not have homing ...

Still, the system seems to behave wrong after I load up M4 again, because machine coordinates changes between closing and opening M4. That's what should not happen, because they are _machine_ coordinates.

I'll try to explain (only for axis X):
- Zero axis X (G54 X=0).
- Do homing for axis X (both G54 and machine coords are 0 now). Green led is lit.
- Move X to +40.94 and zero X axis. Now both G54 and machine coords say +40.94, while DRO says it it at 0. Correct.
- Close M4 and re-open it.
- Machine coord is now at 0!! Why is that? DRO displays it is at -40.94. If I move back to zero (G0 X0), DRO displays 0, machine coord is 40.94!

This means, I moved the axis by 40.94 units in positive direction to have the machine position as before closing M4?
Next time I reload M4 again from the exact same position, machine coordinates have reset to 0 again. So everytime I restart M4, my machine coords get shifted by G54 position.
Re: Is M4 supposed to save axes position on shutdown?
« Reply #11 on: February 09, 2017, 08:18:36 AM »
FocusPaul,

You must be doing something wrong.  Let me explain a few basics and then I will give you another experiment.

When Mach4 starts it has no idea of where the machine axis are located.  Why?  All machines suffer this issue unless they have absolute encoders on their motors.  What is an absolute encoder?  An absolute encoder is different than an incremental encoder.  The absolute encoder has a battery and it is also designed in such a way that the entire range of that given axis is known.  This has to do with the optical encoding on the disc, but that is beyond what is required in this discussion.  The incremental encoder has 1000, 2000, 2500 pulses per revolution or higher and the electronics monitor these counts to determine if they motor has turned far enough.  The absolute encoder also does this but the difference is when you turn off your machine the incremental encoder does not remember the number of rotations in a given direction that have been moved from the home location.

What does all this mean?  It means unless your are rich and have absolute encoders on  your machine,  you will need to let MACH4 initialize its machine coordinates, by running the homing routine.   As soon as the homing routine is complete Mach4 now knows where it is on your table, with is absolute zero or the machine coordinate zero position.

Now lets look at your experiment.

1) home your machine, when the DRO indicators show a green ring it lets you know the machine has come to the home position.  By default Mach4 will zero the DROs for X and Y after the homing sequence, EXCEPT if a G54 location was saved on a prior exit.  This is normally pretty evident because the X and Y dros will usually have a Negative number populated in them after the initial homing sequence.

2) Why is there a negative number in the X,Y dros?  This is actually the saved G54 position.  All you need to do after the homing and you see the Negative DRO reading is to issue a G0 X0 Y0,  after that move finishes you will be at the saved G54 position.  

Keep in mind that G54 is an offset position from the machine coordinate 0,0 position.

I can tell by your experiment this is all working because you point out when you opened MACH4, you found the X axis with a -40.94.


Now if you start Mach4 and you see the negative DRO positions reported after the homing sequence and you need to set a new G54 position, you zero the DRO when it is at the home position.  Now that the DRO reads zero at machine home you can now jog to the new location you need to setup for G54.  Once you have jogged to where you want you zero the X,Y dros again.  That is what establishes the G54 position.  To prove this to yourself run the following experiment.

home the machine, and zero the DRO for X,Y
move the machine to the center of your table, write down X and Y on paper, now zero the X and Y DRO
now home the machine again, once it is there you will see negative X and Negative Y from the G54 numbers you recorded on paper.
now issue the following command.   G0 X0 Y0, the machine will move to the G54 coordinates you wrote down on your paper.

Do you understand now?

Russ
Re: Is M4 supposed to save axes position on shutdown?
« Reply #12 on: February 09, 2017, 08:47:42 AM »
Fully understood. Everything as you said. Even the fact that I'm not rich and don't have access to absolute encoder motors :D

I really appreciate the time you spent here helping me out.

Still, I have one thing I'd like to get cleared up for me:
While G54 spans a sub-coordinate system relative to my machine position, the machine coordinates are absolute (or at least: only relative to the last homing position). So machine coords actually track the table position (e.g. X;Y). Of course, those machine coords can get corrupted if I drive my mechanics against the limits for a while. But if I work inside those limits, I suspect them to correlate to my table position relative to home.

When I close M4 on machine position (X;Y)=(40;40), am I wrong in suspecting that M4 comes up with that latest machine coordinates it recorded?
Of course, M4 cannot know if I have moved the mechanics while the software has been offline. So is M4 resetting machine coordinates to 0;0 on every start-up because it cannot know the "exact" position (missing encoders)?
That's like I'm going to sit down in my office chair in London. After some hours of work I probably have moved forth and back the chair a little bit, so I proclaim I'm at Greenwich now (zero meridian).

It all comes down to: Why does it zero the machine coords on every start-up?
Re: Is M4 supposed to save axes position on shutdown?
« Reply #13 on: February 09, 2017, 09:37:25 AM »
FocusPaul,

You are getting much closer to understanding how things work.  Good Job.    I am not rich either and do not have absolute encoders on my machines.  Ha Ha

G54 is one set Work Offset Coordinates, you can have others like G55, G56, G57, G58, G59,  see the link below for an entire explanation

http://www.cnccookbook.com/CCCNCGCodeG54G92WorkOffsets.htm

You can actually save work offset coordinates inside of most CNC software programs like Mach3, Mach4, KmotionCNC, LinuxCNC, etc.

In Mach4, if you go to the "Offsets" tab at the top of the screen, and then to the "Fixture Table" button at the top middle of the screen.  You will find a fixture offsets table.  You can record various fixture offsets that you use repeatedly.  Perhaps you have a fixture you position on your table in the same place each time you run a certain job.  It is located at X=14.5, Y=15.6, if you record this in the table then after you home your machine and zero the DROs you can just put a G54 in your gcode and it will move to this offset location.  Think of a garage at your house maybe it is a two car garage and you always park your Mercedes in the right garage and your Porsche in the left garage.  In the case of your machine maybe you build guitars and you also machine the Neck at a certain position on your table, maybe G54, and then you might have another fixture that does the top of the guitar and the hole cut out, and you have that located at G55.

Now many users especially hobby users run one off jobs so they just do the G54 on the fly, they bolt down the material on their table and job over and find the corner of the material and zero the DROs and that is their G54.


"When I close M4 on machine position (X;Y)=(40;40), am I wrong in suspecting that M4 comes up with that latest machine coordinates it recorded?"
YES, Mach4 will come up with the last saved G54 position.  So if you home your machine, zero the DRO and jog to 40,40 and then zero the DRO for X,Y, at that point Mach4 has G54 defined as 40,40
If you exit M4 now it will ask if you want to save the job position, if you say YES it will record 40,40 so when it starts up again it will show -40,-40, if you say NO it will keep that last recorded G54 position used.

If you want M4 to come up and show 0,0 when it starts, you need to home the machine before you turn off the machine and then zero the DROs and then exit.  This way the M4 will know that no G54 position needs to be remembered.


"Of course, M4 cannot know if I have moved the mechanics while the software has been offline. So is M4 resetting machine coordinates to 0;0 on every start-up because it cannot know the "exact" position (missing encoders)?"
Absolutely TRUE, if you move the axis without Mach4 it has no idea of where things are when it starts.  This is why we always must home the machine after startup so that is when it finally knows where it is on your given table.  Very important to home the machine at the beginning.  Let me give you an example of why this is important.

You start cutting a job and it is half way done, and suddenly your spindle hits a clamp you used to secure the material to the table.  It breaks your cutting tool and you react and hit the ESTOP.  After you stop shaking and calm back down you change the broken bit and now MACH4 is flashing because of the estop.  You now need to home the machine, because you might have lost steps due to the accident and the location could be off slightly.  Now after you home M4 again knows it is a absolutely 0,0.    Now how will M4 get back to your G54 location.  One way is to exit and have M4 save the location then start again, home, and G0 X0 Y0 will take you back to your job start location.  I make it a habit to record my G54 location before a big job in Absolute Coordinates and write it on paper.  This is a safeguard, so I know I can get back to the right spot.  Once I zero my X and Y at the corner of my job, I then turn on absolute coordinates and record them, then I turn them off and I am back to zero zero for G54.  Now you can restart the job and you will be exactly lined up again.  You can also use the tool RUN FROM HERE to avoid doing the first part of the job again.

"It all comes down to: Why does it zero the machine coords on every start-up?"
Mach4 zeros machine coordinates when it starts because that is the only way it has of know exactly where it is on the table.  

Think of it this way.  When you turn on a Garmin GPS so you can find that wonderful Bar and Restaurant you have heard so much about, what is the first thing the GPS does?  It has to find out where are you now.  Then after it gets the satellite signals it shows where you are on a map.  Now it can route you to your destination.  If it never found your "HOME" position it has no idea how to send you on your way.

Understand now?


Russ







Re: Is M4 supposed to save axes position on shutdown?
« Reply #14 on: November 30, 2017, 05:38:59 AM »
Seen another Mach4 output device in action, which does not have the problem described above.
When you close M4, it comes up with the exact same motor positions in UI as before ... as expected.

It does not matter whether the user changed the motor positions manually while the machine was offline, but loading M4 with some random motor positions on start-up is absolutely not what I was expecting. Unfortunately that's what ESS does.
Re: Is M4 supposed to save axes position on shutdown?
« Reply #15 on: November 30, 2017, 07:15:20 AM »
FocusPaul,

The only way that can happen is if you use absolute encoders on your servos.  Absolute encoders have batteries as backup power so when you turn off the machine it holds the exact encoder count the machine had when you turned it off.  That way when you turn it back on it has the exact position and the machine knows exactly where it is located.  This is very common on expensive commercial machines.

Russ
Re: Is M4 supposed to save axes position on shutdown?
« Reply #16 on: November 30, 2017, 09:19:23 AM »
The machine we watched the correct (as in "expected") behaviour had simple stepper drives. I don't understand why you insist on battery / mechanics backed-up absolute encoders.
My point is, if you use open-loop encoders, you should still see the last know position in M4 when you start it up, or at least 0, but _never_ at a random position.
Re: Is M4 supposed to save axes position on shutdown?
« Reply #17 on: November 30, 2017, 09:49:32 AM »
FocusPaul,

Mach3 or Mach4 never start up with a "random" position.  When you exit these programs it asks you if you want to save the last G54 position.  This means if you zero'd the machine at some given spot on your table say x=5,  y=5, z=-3, then when you start the program again it will report the offset from the last G54 saved position.  The first thing you do when you start these programs is to home them so they know where home is located.  As soon as you do this you will see the last saved G54 offset on the DROs.  So say you had a 10" x 10" table and you moved to 5,5 the very center of the table.  You zero the DRO so not it says 0,0 this is your G54 location.  You can press machine coordinate button and it will show you 5,5.  Now close out the program and it ask if you want to save the last location, say YES.  Now start the program and home your machine.  The DRO will now way X= -5, Y= -5 and whatever Z was set at when you saved the position.  Now go to the MDI screen and issue the following command.  G1 X0 Y0 F50 and the machine will move to the last saved G54 location which is at machine 5,5 or the very center of this table.

Do you follow how this works?

Russ

Offline DazTheGas

*
  •  778 778
  • DazTheGas
    • View Profile
Re: Is M4 supposed to save axes position on shutdown?
« Reply #18 on: November 30, 2017, 11:59:55 AM »

Quote
but loading M4 with some random motor positions on start-up is absolutely not what I was expecting. Unfortunately that's what ESS does.
I have been using an ESS for 4 years now and have never had a random position set by it.

Quote
Seen another Mach4 output device in action, which does not have the problem described above.
All Motion controllers for Mach4 come with a plugin that controls the controller and each manufacturer has the ability to set what coords they like at startup and can if they wanted too overwrite the G54.

And so can you............

Mach4 has both a Screen Load Script and a Screen Unload Script, so if you feel you would like to start the machine different you can use these scripts to save the coords you want to a profile and then reload these coords from the profile on starting. But like Steve said in an earlier post I would not consider this as good as homing.

DazTheGas
New For 2022 - Instagram: dazthegas
Re: Is M4 supposed to save axes position on shutdown?
« Reply #19 on: December 12, 2022, 03:59:43 AM »
function SaveMachinePosition()   
   local inst = mc.mcGetInstance()
   mc.mcProfileWriteDouble(inst, "MyConfig", "MachinePosX", mc.mcAxisGetMachinePos(inst, mc.X_AXIS))
   mc.mcProfileWriteDouble(inst, "MyConfig", "MachinePosY", mc.mcAxisGetMachinePos(inst, mc.Y_AXIS))
   mc.mcProfileWriteDouble(inst, "MyConfig", "MachinePosZ", mc.mcAxisGetMachinePos(inst, mc.Z_AXIS))
   mc.mcProfileWriteDouble(inst, "MyConfig", "MachinePosA", mc.mcAxisGetMachinePos(inst, mc.A_AXIS))

   mc.mcProfileWriteDouble(inst, "MyConfig", "PosX", mc.mcAxisGetPos(inst, mc.X_AXIS))
   mc.mcProfileWriteDouble(inst, "MyConfig", "PosY", mc.mcAxisGetPos(inst, mc.Y_AXIS))
   mc.mcProfileWriteDouble(inst, "MyConfig", "PosZ", mc.mcAxisGetPos(inst, mc.Z_AXIS))
   mc.mcProfileWriteDouble(inst, "MyConfig", "PosA", mc.mcAxisGetPos(inst, mc.A_AXIS))
   mc.mcProfileSave(inst)
   mc.mcProfileFlush(inst)
end

function LoadMachinePosition()   
   local inst = mc.mcGetInstance()
   
   local MachinePosX = mc.mcProfileGetDouble(inst , "MyConfig", "MachinePosX", 0)
   local MachinePosY = mc.mcProfileGetDouble(inst , "MyConfig", "MachinePosY", 0)
   local MachinePosZ = mc.mcProfileGetDouble(inst , "MyConfig", "MachinePosZ", 0)
   local MachinePosA = mc.mcProfileGetDouble(inst , "MyConfig", "MachinePosA", 0)
   
   local PosX = mc.mcProfileGetDouble(inst , "MyConfig", "PosX", 0)
   local PosY = mc.mcProfileGetDouble(inst , "MyConfig", "PosY", 0)
   local PosZ = mc.mcProfileGetDouble(inst , "MyConfig", "PosZ", 0)
   local PosA = mc.mcProfileGetDouble(inst , "MyConfig", "PosA", 0)

   local HomeOffsetX_Saved, rc = mc.mcAxisGetHomeOffset(inst, mc.X_AXIS)
   local HomeOffsetY_Saved, rc = mc.mcAxisGetHomeOffset(inst, mc.Y_AXIS)
   local HomeOffsetZ_Saved, rc = mc.mcAxisGetHomeOffset(inst, mc.Z_AXIS)
   local HomeOffsetA_Saved, rc = mc.mcAxisGetHomeOffset(inst, mc.A_AXIS)
      
   local HomeInPlaceX_Saved, rc = mc.mcAxisGetHomeInPlace(inst, mc.X_AXIS)
   local HomeInPlaceY_Saved, rc = mc.mcAxisGetHomeInPlace(inst, mc.Y_AXIS)
   local HomeInPlaceZ_Saved, rc = mc.mcAxisGetHomeInPlace(inst, mc.Z_AXIS)
   local HomeInPlaceA_Saved, rc = mc.mcAxisGetHomeInPlace(inst, mc.A_AXIS)
   
   local SoftlimitEnableX_Saved, rc = mc.mcAxisGetSoftlimitEnable(inst, mc.X_AXIS)
   local SoftlimitEnableY_Saved, rc = mc.mcAxisGetSoftlimitEnable(inst, mc.Y_AXIS)
   local SoftlimitEnableZ_Saved, rc = mc.mcAxisGetSoftlimitEnable(inst, mc.Z_AXIS)
   local SoftlimitEnableA_Saved, rc = mc.mcAxisGetSoftlimitEnable(inst, mc.A_AXIS)
         
--   local MachinePosX=math.random()*100
   
   mc.mcAxisSetHomeInPlace(inst, mc.X_AXIS,1)
   mc.mcAxisSetHomeInPlace(inst, mc.Y_AXIS,1)
   mc.mcAxisSetHomeInPlace(inst, mc.Z_AXIS,1)
   mc.mcAxisSetHomeInPlace(inst, mc.A_AXIS,1)
   
   mc.mcAxisSetSoftlimitEnable(inst, mc.X_AXIS,1)
   mc.mcAxisSetSoftlimitEnable(inst, mc.Y_AXIS,1)
   mc.mcAxisSetSoftlimitEnable(inst, mc.Z_AXIS,1)
   mc.mcAxisSetSoftlimitEnable(inst, mc.A_AXIS,1)
   
   mc.mcAxisSetHomeOffset(inst,mc.X_AXIS, MachinePosX)
   mc.mcAxisSetHomeOffset(inst,mc.Y_AXIS, MachinePosY)
   mc.mcAxisSetHomeOffset(inst,mc.Z_AXIS, MachinePosZ)
   mc.mcAxisSetHomeOffset(inst,mc.A_AXIS, MachinePosA)

   rc=mc.mcProfileSave(0)
--   rc=mc.mcProfileFlush(0) --Flush changes to the INI file.

--   rc = mc.mcAxisDeref(inst, mc.X_AXIS);
--   rc = mc.mcAxisDeref(inst, mc.Y_AXIS);
--   rc = mc.mcAxisDeref(inst, mc.Z_AXIS);
--   rc = mc.mcAxisDeref(inst, mc.A_AXIS);

   rc = mc.mcAxisDerefAll(inst);
   
--   Message(HomeOffsetX_Saved.. " -X> ".. MachinePosX .. " mc.mcAxisGetHomeInPlace(inst, mc.X_AXIS)="..mc.mcAxisGetHomeInPlace(inst, mc.X_AXIS))
--   Message(HomeOffsetY_Saved.. " -Y> ".. MachinePosY)
--   Message(HomeOffsetZ_Saved.. " -Z> ".. MachinePosZ)
--   Message(HomeOffsetA_Saved.. " -A> ".. MachinePosA)

   local OSIG_MACHINE_ENABLED_saved = GetSignal(mc.OSIG_MACHINE_ENABLED)
   if (OSIG_MACHINE_ENABLED_saved==0) then
      mc.mcCntlEnable(inst,1)
--      Sleep(100)
   end
   
   mc.mcCntlReset(inst)
   rc = mc.mcAxisHome(   inst, mc.X_AXIS)
   mc.mcCntlReset(inst)
   rc = mc.mcAxisHome(   inst, mc.Y_AXIS)
   mc.mcCntlReset(inst)
   rc = mc.mcAxisHome(   inst, mc.Z_AXIS)
   mc.mcCntlReset(inst)
   rc = mc.mcAxisHome(   inst, mc.A_AXIS)
   mc.mcCntlReset(inst)
   
   mc.mcAxisSetHomeOffset(inst, mc.X_AXIS,HomeOffsetX_Saved)
   mc.mcAxisSetHomeOffset(inst, mc.Y_AXIS,HomeOffsetY_Saved)
   mc.mcAxisSetHomeOffset(inst, mc.Z_AXIS,HomeOffsetZ_Saved)
   mc.mcAxisSetHomeOffset(inst, mc.A_AXIS,HomeOffsetA_Saved)
   
   mc.mcAxisSetSoftlimitEnable(inst, mc.X_AXIS,SoftlimitEnableX_Saved)
   mc.mcAxisSetSoftlimitEnable(inst, mc.Y_AXIS,SoftlimitEnableY_Saved)
   mc.mcAxisSetSoftlimitEnable(inst, mc.Z_AXIS,SoftlimitEnableZ_Saved)
   mc.mcAxisSetSoftlimitEnable(inst, mc.A_AXIS,SoftlimitEnableA_Saved)
         
   mc.mcAxisSetHomeInPlace(inst, mc.X_AXIS,0)
   mc.mcAxisSetHomeInPlace(inst, mc.Y_AXIS,0)
   mc.mcAxisSetHomeInPlace(inst, mc.Z_AXIS,0)
   mc.mcAxisSetHomeInPlace(inst, mc.A_AXIS,0)
   
   rc=mc.mcProfileSave(0)
   rc=mc.mcProfileFlush(0) --Flush changes to the INI file.
   
   mc.mcAxisSetPos(inst, mc.X_AXIS,PosX)
   mc.mcAxisSetPos(inst, mc.Y_AXIS,PosY)
   mc.mcAxisSetPos(inst, mc.Z_AXIS,PosZ)
   mc.mcAxisSetPos(inst, mc.A_AXIS,PosA)
   
   mc.mcCntlEnable(inst,OSIG_MACHINE_ENABLED_saved)
end