Hello Guest it is April 24, 2024, 08:14:11 PM

Author Topic: Saving and replacing a Value  (Read 1035 times)

0 Members and 1 Guest are viewing this topic.

Offline DAAD

*
  •  103 103
    • View Profile
Saving and replacing a Value
« on: March 17, 2020, 03:42:33 PM »
New at programming lua (or other codes for that mather)

I want to use the zero Z value (SV_PROBE_POS_Z) and put it into the Zero A value (SV_PROBE_POS_A).

This in function of swapping Z axis for dual use.

After al long read in various documentation i came up with the following:

Code: [Select]
local pVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_Z, mc.SV_P) --Save the Probe position of Z-Axis in local Val P

local tVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_A, mc.SV_T) --Save the Probe position of Z-Axis in local Val T


--Swap Z-A axis code

mc.mcCntlSetPoundVar(0, mc.SV_P, mc.SV_PROBE_POS_A) --Get the Val P (Probe Z position) and put it in Probe Pos A value

mc.mcCntlSetPoundVar(0, mc.SV_T, mc.SV_PROBE_POS_Z) --Get the Val T (Probe A position) and put it in Probe Pos Z value

to bad i can't get the code working, any input would be appreciated.


Offline Bill_O

*
  •  563 563
    • View Profile
Re: Saving and replacing a Value
« Reply #1 on: March 18, 2020, 08:50:30 AM »
I could be wrong but if you are asking for a pound variable i think you need the number not the words.
I made a short document at the link below that might help.
It has a signal as one of the examples.
https://www.machsupport.com/forum/index.php?topic=39763.msg266718#msg266718

Offline DAAD

*
  •  103 103
    • View Profile
Re: Saving and replacing a Value
« Reply #2 on: March 18, 2020, 01:06:55 PM »
Thanks for the input!

will check it out.

Lua programming book is on ti's way...
I hope it gets me in te right direction.

Re: Saving and replacing a Value
« Reply #3 on: March 18, 2020, 05:13:08 PM »
You can use mc.mcCntlSetLastError() function to print out information into the history log to help you learn what's going on in the code.

You can find out more information about the API functions from the Mach4CoreAPI.chm document located in the Docs folder in the Mach4 installation directory. Pay attention only to what the LUA syntax examples show.

Here is some example code reworked from your original post:

Code: [Select]
--Set the probe position to some value
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_POS_A, -3.14)
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_POS_Z, -2.579)

-- print #var number of probe position vars
mc.mcCntlSetLastError(inst, string.format('SV_PROBE_POS_A #var: %5.0f SV_PROBE_POS_Z #var: %5.0f', mc.SV_PROBE_POS_A, mc.SV_PROBE_POS_Z))

local pVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_Z) -- Get the Probe position of Z-Axis and put in local var P
local tVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_A) -- Get the Probe position of A-Axis and put in local var T
mc.mcCntlSetLastError(inst, string.format('pVal: %s tVal: %s', pVal, tVal))

--Swap Z-A axis code
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_POS_A, pVal) --Get the Val P (Probe Z position) and put it in Probe Pos A value
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_POS_Z, tVal) --Get the Val T (Probe A position) and put it in Probe Pos Z value

pVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_Z) -- Get the Probe position of Z-Axis and put in local var P
tVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_A) -- Get the Probe position of Z-Axis and put in local var T
mc.mcCntlSetLastError(inst, string.format('pVal: %s tVal: %s', pVal, tVal))
« Last Edit: March 18, 2020, 05:16:36 PM by compewter_numerical »

Offline DAAD

*
  •  103 103
    • View Profile
Re: Saving and replacing a Value
« Reply #4 on: March 19, 2020, 09:02:57 AM »
Thanks will check it out.

Where can i find the history log? did look in mach 4 and in zerobrane but didn't find it.



Offline DAAD

*
  •  103 103
    • View Profile
Re: Saving and replacing a Value
« Reply #5 on: March 19, 2020, 04:32:29 PM »
At the moment i got the swap for probe A and Z values working.
The value 5063 swaps with 5064 and 5073 swaps with 5074 if i check them in diagnostics regfile/Variables

I've also wanted to swap the DRO Readout values for the A and Z axis but the values for some reason won't swap.
CURRENT ABS Z #5043) (CURRENT ABS A #5044)

see code below:

Code: [Select]
-- Save variable to local value
local pVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_Z) -- Get the Probe position of Z-Axis and put in local var P
local tVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_POS_A) -- Get the Probe position of A-Axis and put in local var T
local QVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_MACH_POS_Z)
local RVal = mc.mcCntlGetPoundVar(0, mc.SV_PROBE_MACH_POS_A)
local NVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_Z)
local OVal = mc.mcCntlGetPoundVar(0, mc.SV_CURRENT_ABS_A)

--Swap value Z and A axis
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_POS_A, pVal) --Get the Val P (Probe Z position) and put it in Probe Pos A value
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_POS_Z, tVal) --Get the Val T (Probe A position) and put it in Probe Pos Z value
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_MACH_POS_A, QVal)
mc.mcCntlSetPoundVar(0, mc.SV_PROBE_MACH_POS_Z, RVal)
mc.mcCntlSetPoundVar(0, mc.SV_CURRENT_ABS_A, NVal)
mc.mcCntlSetPoundVar(0, mc.SV_CURRENT_ABS_Z, OVal)

Offline DAAD

*
  •  103 103
    • View Profile
Re: Saving and replacing a Value
« Reply #6 on: March 22, 2020, 03:12:26 PM »
This problem is solved,

see topic for the code used :https://www.machsupport.com/forum/index.php?topic=42646.0

Many thanks for the input!

@Bill_O Thanks for the different manuals / documents you've made! Appreciated!

They helpend me in the right direction!