Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: FocusPaul on February 02, 2017, 06:41:14 AM

Title: Is M4 supposed to save axes position on shutdown?
Post by: FocusPaul on February 02, 2017, 06:41:14 AM
Hello,

I'm not sure about the following feature: Is Mach4 supposed to save the axis position of all axes on shutdown and re-load them on start-up?
If not, is this a property of the motion plug-in?

Regards,
Paule
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 on February 02, 2017, 02:03:25 PM
FocusPaul,
What M4 does when you exit is save the last G54 coordinates.  Meaning if you have zero'd your machine prior to a job and set a new work coordinate (0,0) then that G54 setting is saved when you exit M4.  It asks you if you would like to save it when you exit.  If you never did anything but home your machine and used machine coordinates as your 0,0 it does nothing.

Russ
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: FocusPaul on February 06, 2017, 05:05:47 AM
Hello cncman172,

I feel like your answer lead me more close to the resoultion of my problem - still I'm missing something.

In some cases we do not use homing, because it does not allow our work piece to be positioned with precision of less than 10 µm. Instead, we do fine-grained jogging methods to get the exact position, then zero relevant axes and start the process.
I tried to reproduce the scenario like this:
Start M4. G54 offsets are all zero, machine coords are also zero, resulting in all axes being zero'ed.
Then I moved axes X and Y to 79 and 359 and zero'ed them to update G54 offset to 79 and 359. After this I moved both axis to 86 and 1086.
After closing and restarting M4, the axis positions have been set to -79 and -359, which is exactly negative values of G54 offsets. If I now _move_ them to zero positions, they will definitely not be at the position assumed.

I expected M4 to start up at positions 86 and 1086. Also it does not ask me to save G54 offsets (it does this by default).
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 on February 06, 2017, 08:14:27 AM
Very interesting.

When you home the machine do you have homing sensors?  If you don't the machine really never gets an official home location, only where you manually zero the location.  The homing sensor could be a micro switch, optical sensor, proximity switch, etc.  You can tell if it has been officially homed because the X,Y,Z dro indicator will have a GREEN ring around them indicating it was homed.

When you have set you G54 and jog somewhere on the table, and then issue a command
G1 X0 Y0 F50

The machine should go back to the G54 coordinates that you established.  If the home sensor indicators are GREEN and you setup a G54 location when you exit it should ask if you want to save your positions.  Try it.

Russ
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: Steve Stallings on February 06, 2017, 09:34:56 AM
For machines that use stepper motors, the exact location of power down
cannot be reproduced upon power up unless the power down was done
with the stepper motor at the same phase condition that will be stepper
motor driver will establish when it is powered up again. The error involved
can be as much as 2 full steps of the motor due to the 4 quadrants of the
driving sequence of a standard 2 phase stepper motor. Some motor drivers
do provide an output signal to aid in this process, but I have not seen any
hobby grade systems that take advantage of it.


Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 on February 06, 2017, 09:59:14 AM
Steve,
Unless I misunderstood the exchange, I think there issue was the fact they never homed the machine.  They felt they could be more accurate jogging to the exact position they wanted for G54.

The issue with this approach is when you exit Mach it will not ask you to save your G54 coordinates.  Why?  Well as you know, since you never homed the machine, when Mach4 starts again it has no way of finding that location.  If the machine was homed it know it can index over from home to the old G54 location.

Never knew about the stepper issue, but I run servos.  Good to know. 

Russ
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: FocusPaul on February 08, 2017, 09:10:29 AM
Hello all,

the problem is still there. To eliminate misunderstandings, here's what I tried:

- Open M4.
- Machine coords and G54 offsets are all 0.
- Home X axis (yes, we have homing sensors). Machine coords and G54 does not change (as expected).
- Move X axis by 2.91 (or something). This changes machine coords accordingly.
- Disable -> close M4
- Restart M4
- And the machine starts with machine coords / G54 all zero, although X axis should somehow display 2.91 or something similar.

And no, it didn't ask about saving anything on shutdown.
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 on February 08, 2017, 09:48:27 AM
FocusPaul,

That is your issue.  Try things in this order.

- Open M4
- Home Machine this will reset the machine coordinates.  Make sure they turn GREEN and when machine coordinate button is pressed they should read X=0 Y=0
- now jog the machine to somewhere on the table where you would like the G54 coordinate.  Now zero X and Y on the DRO, you have now established your G54 location
- now if you press machine coordinates again you will see you are not at 0,0 but an offset distance on both X and Y.  Turn off machine coordinates
- now close M4
- since you have created a G54 location that is NOT the home location or machine coordinate 0,0 you should see M4 ask if you want to save this location right after you exit.   Say YES.
- now open M4
- now home M4, do not zero the DRO
- now issue the following command.   G0 X0 Y0
- the machine should move to the save G54 location and show 0,0 in the relative DRO.

Russ
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: DazTheGas on February 08, 2017, 09:52:53 AM
Got to laugh Russ, ive just sat and typed basically the same with 1 finger on phone and press post to get

Quote
Warning - while you were typing a new reply has been posted. You may wish to review your post.

I must make my finger go faster.

DazTheGas
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 on February 08, 2017, 10:06:31 AM
DazTheGas,

Thanks for the laugh.  I needed it today.  You answer so many of these type questions figured I would give you a break.  LOL.  How are you doing, you making any more Mach4 videos.  I love watching your videos.  :)

Russ
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: FocusPaul 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.
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 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
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: FocusPaul 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?
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 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







Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: FocusPaul 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.
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 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
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: FocusPaul 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.
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: cncman172 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
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: DazTheGas 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
Title: Re: Is M4 supposed to save axes position on shutdown?
Post by: duritskiy 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