Machsupport Forum
Mach Discussion => Mach4 General Discussion => Topic started by: Toshio.K on October 05, 2021, 05:28:13 AM
-
I want to align the origin using a USB camera.
Therefore, I embedded the script below in the button (Orijin).
How are you doing?
Please tell me how.
-------------------------------------------------- -------------
--Camera Origin. Add2021.10.3
-------------------------------------------------- -------------
local inst = mc.mcGetInstance ()
mc.mcCntlGcodeExecute (inst, "G91 G0 Z0.0 \ n G0 Y1.7 \ n G0 X7 2.0")
-
Did it work?
I am not sure what you are asking.
Do you want to know how to do it?
Are you asking if that is the correct code?
-
Hello.
My idea is that the axis of the camera and the axis of the main axis are off, so I command the distance to move.
I have to install the camera vertically on the table and it's working fine.
However, I wanted to know your thoughts because my thoughts may be wrong.
This is the YouTube that I referred to.
https://www.youtube.com/watch?v=ZgWkOa7EgDA
-
Use the head shift feature
You will need to write some code.
This is for the Y axis;
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, TKOSftYVal)
TKOSftYVal is just a variable.
-
When I pasted the program on the button, an error occurred.
What should I do?
-
you might need to put "10" or '10'
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, "10")
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, '10')
or just change this mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, 10)
to this
YShift = 10
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, YShift)
-
I changed the program, but I get an error.
I was in trouble.
-
I do not think the error is from the button.
It looks like it is saying the problem is at line 239.
The script you posted does not have 239 lines.
I do not know what the problem is.
-
Where is line 239?
-
In line 6, do you have commas separating each of the parameters in the mc.mcCntlSetPoundVar() call? I can't really tell from the pic.
-
local inst = mc.mcGetInstance ()
YShift = 10
mc.mcCntlSetPoundVar(inst,mc.SV_HEAD_SHIFT_Y,YShift)
I put a colon, but I get an error.
-
Line 239 is likely in the COMPLIED Lua script that Mach 4 compiles from all your Lua parts on run.
And, in this line of code:
mc.mcCntlGcodeExecute (inst, "G91 G0 Z0.0 \ n G0 Y1.7 \ n G0 X7 2.0")
What is \n G0 X7 2.0? Is it supposed to be something like Y2.0?
Just poking around!!!
Tom
-
Delete the button and see if you get the same error.
-
I can't move the camera after removing the button.
-
Really?
You take out the button that moves things and it doesnt work any more?
Look, you have an error in the code.
Take out the button and see if the error goes away.
Then we can work on getting the button back in correctly.
-
> Take out the button and see if the error goes away.
Please tell me how to do it.
-
Who put it in?
Who it putting in the code?
If you are doing it this might help some.
Use the one from 6_22_2020 part way down.
https://www.machsupport.com/forum/index.php?topic=43260.msg279695#msg279695
-
Hello,
Thank you for the useful information.
Now,
About this problem solving method
As a method, should I use the example in the space between ************ below?
****************
• Macros can use a name instead of a number. Name ()
Example: toolheightset ()
• Here is the format of a macro.
function m # ()
your code
end
if (mc.mcInEditor () == 1) then
m # ()
end
The last 3 lines let you run or step through the macro while in the editor.
*******************
-
This is the only part that is the code.
function m # ()
your code
end
if (mc.mcInEditor () == 1) then
m # ()
end
-
Please tell me the meaning of "mcInEditor".
-
Please tell me the meaning of this function.
mc.mcCntlSetPoundVar (inst, mc.SV_HEAD_SHIFT_Y, YShift)
-
"mcInEditor"
that section lets you run the code while in editor
it is for macros
"mc.mcCntlSetPoundVar (inst, mc.SV_HEAD_SHIFT_Y, YShift)"
this one thing added in Mach4
it lets you use multiple heads
it shifts the home position
-
question 1
The meaning of mc.mcCntlSetPoundVar (inst, mc.SV_HEAD_SHIFT_Y, YShift) is shown in the picture. Is this way of thinking all right?
I'm using Mach4 Hobby.
Question 2
Is it okay if the script without using the button is as follows?
function YShift ()
YShift = 10
mc.mcCntlSetPoundVar (inst, mc.SV_HEAD_SHIFT_Y, Y Shift)
if (mc.mcInEditor () == 1) then
YShift ()
end
-
1) Yes. It moves where the machine thinks the axis is positioned. It does not actually move it just changes where it thinks it is located.
2) The code looks correct. I would not use a variable named the same as the macro. Then the button just calls the macro.
-
I don't know what to do in the future.
Would you like to paste this script into a button?
"The last 3 lines let you run or step through the macro while in the editor."
What is an editor?
-
To make and edit a macro go to Operator then Edit/Debug Macro Scrips
That is the editor.
That is where you will make and save your YShift macro.
I suggest you not use a name for your macro use a number like m111
To make and add a button go to Operator then Edit Screen.
Add your button and program it to do what you want.
Your button will just run that macro.
The code on your button will be like this;
inst = mc.mcGetInstance()
mc.mcCntlGcodeExecute(inst, "m111")
-
I ran as follows, but an error occurred.
I don't know the cause.
function m111 ()
YShift = 10
mc.mcCntlSetPoundVar (inst, mc.SV_HEAD_SHIFT_Y, YShift)
if (mc.mcInEditor () == 1) then
m111 ()
end
Button script
local inst = mc.mcGetInstance ()
mc.mcCntlGcodeExecute (inst, "m111")
Is mcCntlGcodeExecute bad?
How to execute with macro button mach4
-
Hello.
There was a full-width "(" in the code to write to the button.
This was the cause of the error. Fixed to half-width "(".
Now you can press the button.
However, the Y axis doesn't move at all. Is this normal?
The photo is the proof.
-
It will not move.
It is just supposed to put a value in the head shift so the machine knows how much to compensate.
I did not see a value in the head shift.
Exactly what code did you put in and where?
-
Hello.
The left side of the photo is in the macro script.
I put the right side of the photo in the Orijin button.
-
Go to the Parameters.ini in your profile.
Look for [5081] and [5082]
Those are the head shift parameters for x and y
-
Never mind.
Mine does not have them either and it works.
Are you actually hooked up to a machine?
Some things will not function in demo mode.
-
Multiple things are wrong with your macro
1. You don't declare 'inst' so this will likely be nil and cause the API to fail - you should check the return code to test for this
2. You are missing 'end' from the function
3. I would declare YShift as a local variable
If you hit F7 on your keyboard in ZeroBraneEditor it will compile the code and tell you if there are any mistakes... but won't tell you all the mistakes ;)
Try the following
function m111 ()
local inst = mc.mcGetInstance()
local YShift = 10
mc.mcCntlSetPoundVar(inst, mc.SV_HEAD_SHIFT_Y, YShift)
end
if (mc.mcInEditor () == 1) then
m111 ()
end
-
Thanks Swifty
-
Mach4 worked.
Current Position
From 0 to -10
Head Shift
From 0 to +10
Is this result normal?
The motor didn't work, only the numbers seemed to change.
* What should I do with the X-axis code?
-
It does not make the motor move.
It just changes where the machine thinks it is.
You do the same thing for the x axis just use the x shift.
If you want it to move you need to tell it to move.
-
Should the code be as follows?
function m111 ()
local inst = mc.mcGetInstance ()
local YShift = 10
mc.mcCntlSetPoundVar (inst, mc.SV_HEAD_SHIFT_Y, YShift)
--X axis
local inst = mc.mcGetInstance ()
local XShift = 10
mc.mcCntlSetPoundVar (inst, mc.SV_HEAD_SHIFT_X, XShift)
end
.
if (mc.mcInEditor () == 1) then
m111 ()
end
-
Mr. Bill_O. Hello.
I understand that this program is a program that changes the "Current Position" to the value after movement even though the head is not moving.
Thank you.