Hello Guest it is November 21, 2019, 07:38:56 PM

Author Topic: Can't set machine position in script  (Read 343 times)

0 Members and 1 Guest are viewing this topic.

Can't set machine position in script
« on: January 23, 2019, 03:41:40 PM »
Hi

I have made a button to save the machine position and work offset position into the register. This works!
I have also made a button to load these positions again. It works for the work offset position but not for the machine position.
I use the mc.mcAxisSetMachinePos but it doesn't seem work.
I the ScreenScript.lua there is a WriteRegister & GetRegister function.

Any ideas?

Re: Can't set machine position in script
« Reply #1 on: January 24, 2019, 12:54:09 AM »
Hi,

Quote
I use the mc.mcAxisSetMachinePos but it doesn't seem work.

Have a closer look at the API.chm for msSetMachinePosition, note that there is no 'description' which certainly doesn't
help but look at the usage example. It is of course using C syntax....

Code: [Select]
Usage:

// Set axis 0 fisxture offset.
int mInst = 0;
mcAxisSetMachinePos(mInst, 0, 0.0 /* set part zero */);

Note that it says 'Set axis 0 fixture offset'.....that implies that it does NOT set the machine coordinate. This may seem
strange or contrary to your expectation but my experimentation concludes that you cannot use this API to set the machine
coordinates.

With any sort of luck smurph will read this post and he may be able to confirm my interpretation.

My understanding is that there is only three ways to change the machine coordinates:
1) <Ref All Home> or <Ref Axis>, ie the machine will drive to the home switch location and reset (or alternately set the
    machine coordinate to your programmed offset) your machine coordinate.
2) <Ref All Home> or <Ref Axis> when the axis does not have a home switch in which case it will home in place.
3) Move the machine either by jogging, MDI or Gcode

Note that none of those methods allow you to arbitrarily set the machine coordinates.

Craig
My wife left with my best friend...
     and I miss him!
Re: Can't set machine position in script
« Reply #2 on: January 24, 2019, 08:12:19 AM »
I use these scripts for setting work offsets.
I find the center of almost everything I machine, so I made these buttons to make it go faster; I touch off one side (x,y) and call it zero, then I touch off the other side (respectively) and press these buttons that take the current coordinate position, divide it by two, and update the axis position.

BUTTON SCRIPTS

--X = "X / 2"
local inst = mc.mcGetInstance()
local val = mc.mcAxisGetPos(inst, mc.X_AXIS)
local XPos = (val /2)
local rc = mc.mcAxisSetPos(inst, mc.X_AXIS,  XPos)

But, that's not going to help; I just realized you want to change the Machine Coordinate.  mcAxisSetMachinePos... I've never tested it.
I'm curious, why do you want to set the machine position?  Generally you don't want to mess with the machine coordinates, it will alter any and all work offsets you have set; if you have home switches, using the Axis Position (Work Offset Positions) should work just fine; but like I said, I don't know what your intentions are.
« Last Edit: January 24, 2019, 08:18:11 AM by Cbyrdtopper »
Chad Byrd
Re: Can't set machine position in script
« Reply #3 on: January 24, 2019, 11:52:51 AM »
It sound like it is not possible.
The most important function is to save the work offset position and load it again and that works.
My reason for doing it was to make it possible to save the position for all coordinates and then be able to shut down the machine and pc (for what ever reason) in a random position. Then I could start it all again (the next day maybe) and load all positions and continue where I stopped.
The bad thing about this approch could be that I might loose a step when I turn off and on for the stepper drives.
Now I have to rely on the Homing and proximity sensors. I have seen that they should be quite precise.

I still think it could be nice to have the possibility :)

Brian
Re: Can't set machine position in script
« Reply #4 on: January 24, 2019, 12:37:10 PM »
Hi,

Quote
My reason for doing it was to make it possible to save the position for all coordinates and then be able to shut down the machine and pc (for what ever reason) in a random position. Then I could start it all again (the next day maybe) and load all positions and continue where I stopped.

The correct approach is to at the start of the new session reference (home) your machine and THEN using your stored
work offsets resume the job from where you left off. For this to be effective you need accurate homing. I use roller plunger
microswitches and achieve 0.02mm repeatability. Using index homing would allow even closer (1 um) repeatability
but as it transpires 0.02mm is adequate for me.

You can, as you have done, use persistent registers, or you could write them to a file. I do this with circuit board programs.
The file name of the stored data is the same as the Gcode etch file with "OFFSET' appended.

Note however that such explicit methods are strictly not required because the current Work Offsets (G54, G55, G56....etc)
are stored at shutdown and restored at restart, ie they are stored in persistent registers.

If you shut down your machine and record both the work coordinates and the machine coordinates and then restart the machine
and restore the coordinates at restart. That would work IF the machine did not move, you can usually be assured that is so.
However if you use microstepping with your steppers then in effect your machine will 'move'. Lets say you use 1/8th
microstepping. At the moment of shutdown  (when you recorded your coordinates) the machine was at the third of the eight
microstepps between full step positions. When you restart your stepper driver will be at a fullstep position and you will
have lost that 3/8th of a step. Having said that the loss of precision is likely to be small and may well be tolerable.

There is a workaround that would allow you to proceed with that solution if you wish. It relies on doing an  effective
'home in place' at the end of your session and then at restart programmatically unlinking the motors and doing a 'dummy
move to the stored original machine coordinates' doing another 'home in place'.

I have one this before, it was confusing as hell but it did work. Let me know if you want further details.....you poor sick little
puppy!

Craig
My wife left with my best friend...
     and I miss him!
Re: Can't set machine position in script
« Reply #5 on: January 24, 2019, 12:56:01 PM »
Hi

Quote
The correct approach is to at the start of the new session reference (home) your machine and THEN using your stored
work offsets resume the job from where you left off.

We are fully aligned  8) This will be my way of doing it. Thanks!

Brian
Re: Can't set machine position in script
« Reply #6 on: January 24, 2019, 12:59:19 PM »
Like Craig said,
Having home switches in place will be the best option.  That way you can start your machine in the morning, home it, and your Work Offsets will already be stored into the Machine.
Also, when you home the machine, you are able to use soft limits.
Chad Byrd
Re: Can't set machine position in script
« Reply #7 on: January 25, 2019, 01:48:41 AM »
Hi,

Quote
Quote

The correct approach is to at the start of the new session reference (home) your machine and THEN using your stored
work offsets resume the job from where you left off.



We are fully aligned  8) This will be my way of doing it. Thanks!

Aww crikey Brian, I thought, even sort of hoped, that you were a sick puppy!!!

I recall when I tried to develop a workaround to programmatically set machine coordinates I did have to think very carefully
about homing, coordinate offsets and so on. I learnt a lot as a result.

Even having developed a workaround the standard procedure I and Chad are promoting is still preferred, and how I do it
for instance. I have not found a legitimate use for my workaround.....maybe its only value is what I learned in pursuit of it!

Craig
My wife left with my best friend...
     and I miss him!

Offline Chaoticone

*
  • *
  •  5,630 5,630
  • Precision Chaos
    • View Profile
Re: Can't set machine position in script
« Reply #8 on: January 25, 2019, 09:30:07 AM »
Quote
With any sort of luck smurph will read this post and he may be able to confirm my interpretation.

Craig is right. No way to set machine coordinates via script (on purpose). Well, unless you get very creative and just want the practice.
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!