Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: Overloaded on April 24, 2014, 09:28:06 PM

Title: DRO Code differences
Post by: Overloaded on April 24, 2014, 09:28:06 PM
What is the difference between "X Position" DRO and "X Multiple Position" DRO ?

Thanks,
Russ

Title: Re: DRO Code differences
Post by: smurph on April 25, 2014, 12:06:39 AM
The X position is the user coordinates only.  It will not toggle between machine, user, and distance to go like X Multi Pos will.

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 27, 2014, 12:58:36 PM
How do you pass a calculated value back to a screen DRO and "in real time"

Button and Image graphics are found where must be embedded? Some of them are corrupt. (not all there)
And there is no provisions to select images in folders using the Properties Images drop down list.
Title: Re: DRO Code differences
Post by: smurph on April 27, 2014, 01:26:44 PM
All GUI objects can be accessed by their name in the LUA script environment.  This can be done as a result of an event (button press, etc...) or part of the PLC script.  The PLC script take the place of macro pumps and brains.

When in the screen editor, Screen->Manage Images.  This is where you add images to your screen set.  Then those images will appear in the Images drop down list.

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 27, 2014, 02:06:06 PM
Thanks, but are there any examples of a PLC script and how to pass data? My dro named "droXY" must be passed a correctly formatted string or float. Just not sure what the proper way to do it is. Not much reference to it in the Docs folder.

Screen Manage Images: I see it now thanks



Title: Re: DRO Code differences
Post by: smurph on April 27, 2014, 02:25:15 PM
A lot of those images were from my computer which had a HD crash.  I just imported all of them and didn't look at each one.  So it is basically a corrupt image that was imported into the screen set.

I guess I don't understand your other issues.  You simply add images to the screen set via "Manage Images".  Then, you create a bitmap button and choose the image that you imported in the Image property drop down list.  LUA has nothing to do with it.  

The LUA comment was on how to update a DRO with a calculated value.  There is a screen objects API that is used.  I do not have it documented yet.  But you can see some of it in action just by looking at the scripts behind some of the buttons and the PLC script.  It is how we make the enable button blink, etc...

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 27, 2014, 03:14:54 PM
Once you mentioned the location of the "screen managed images" and I found it, I understood, not sure what you are confused about.

I'm just not having luck finding out how to pass my computed value to the DRO I created.

local Xval = mc.mcAxisGetPos(0,0);
local Yval = mc.mcAxisGetPos(0,1);
local XYval =math.deg(math.atan(Xval/Yval));

droXY = XYval

Thanks
Title: Re: DRO Code differences
Post by: smurph on April 27, 2014, 03:35:40 PM
number SetProperty(string ctrlName, string propName, string newValue)

The function is int the "scr" table.

scr.SetProperty('droXy', 'Value', tostring(XYval));

All parameters are strings.  So you have to convert the XYVal into a string with tostring().  Now, this does not control the format of the DRO.  That is done with the Format property that should already be set.

Any property of any control can be set this way.  The property names for the controls are what are used in the properties grid in the editor.  There is no documentation that lists the properties of each control yet.  Just look at them in the properties grid and use what you want.

As I said, look to the PLC script as an example of this function where we make the Enable button blink.

Hint:  Where there is SetProperty(), there is also a GetProperty() making it possible to read the properties of any control.

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 27, 2014, 04:30:45 PM
Cool, works now, Thanks

Big help...

Looking forward to that documentation. Because looking on the net shows something different to me.

// Set up a value that may be used by a lexer for some optional feature.
void SetProperty(const wxString& key, const wxString& value);

having the property names and not knowing what to pass makes it a head scratchier.

Thanks again
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 27, 2014, 08:04:03 PM
Thought others might like to see how easy it is done. :)
just add this to the PLC script at the end and the new DRO's get updated when any of the XYZ axis update.
It took me awhile to find where it was. So I circled it for you.
Little tedious to add the screen data but so much easier than macropump or adding a plugin
Thanks Steve & Brian
Did find that I tried to hide a button I created and it does not hide properly, don't need it any more, just used it to develop the script.
So that might be a bug.
I got all this done, and find that G68 does not work? :'(

The more we learn the better the life. :D
Code: [Select]
   local Xval = mc.mcAxisGetPos(0,0);
    local Yval = mc.mcAxisGetPos(0,1);
    local Zval = mc.mcAxisGetPos(0,2);
    
    local XYval = math.deg(math.atan(Xval/Yval));
    local XZval = math.deg(math.atan(Xval/Zval));
    local YZval = math.deg(math.atan(Yval/Zval));
    local XYvalhyp = math.sqrt(math.pow(Xval,2)+math.pow(Yval,2));
    local XZvalhyp = math.sqrt(math.pow(Xval,2)+math.pow(Zval,2));
    local YZvalhyp = math.sqrt(math.pow(Yval,2)+math.pow(Zval,2));
    
    scr.SetProperty('droXY', 'Value', tostring(XYval));
    scr.SetProperty('droXZ', 'Value', tostring(XZval));
    scr.SetProperty('droYZ', 'Value', tostring(YZval));
    scr.SetProperty('droXYhyp', 'Value', tostring(XYvalhyp));
    scr.SetProperty('droXZhyp', 'Value', tostring(XZvalhyp));
    scr.SetProperty('droYZhyp', 'Value', tostring(YZvalhyp));
Title: Re: DRO Code differences
Post by: smurph on April 27, 2014, 08:19:13 PM
The net does not have our API calls.  The documentation is in progress but it is a LOT of slow tedious work.

Here is a quick look at the screen API call available to LUA inside the Mach4GUI:

(All functions return a result code as their first return value.  0 == success)

number scr.ShowPage(string pageName); -- Show a screen page by name.
number, string scr.GetProperty(string ctrlName, string propName); -- Get a control's property value.
number scr.SetProperty(string NctrlName, string propame, string value); -- Set a control's property value.
number scr.ExecMdi(string ctrlName); -- Execute the contents of a named MDI control.
number, number scr.GetCurrentPage(); -- Get the current page.
number, number scr.IsControl(string ctrlName); -- Is this a valid control?
number, number scr.IsProperty(string ctrlName, string propName); -- Is this a valid control and property combination?
number scr.ButtonClick(string ctrlName); -- Simulate a button click event.
number scr.ButtonUp(string ctrlName); -- Simulate a button up event.
number scr.ButtonDown(string ctrlName); -- Simulate a button down event.

A word of warning...  DO NOT use loops in the PLC script.  It is a script that is designed to be executed like a PLC; top down.  The frequency of the script can be set in the screen set properties.  There is a lot of power here.  But with power comes great responsibility because it has the ability to completely ruin your day if you are careless!  There is nothing preventing you from adding loops or setting the PLC script to run every 1 millisecond.  It will happily let you do these things with a smile.  So be careful!

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 27, 2014, 09:27:04 PM
Thanks Steve

How would you use a function call from the PLC script, thought that would be better for computing the angles and distances. But fought that so guess I learned the hard way about the loops.

getAngle(Yval,Zval);
scr.SetProperty('droXY', 'Value', tostring(BaseAngle));

function getAngle(axis1, axis2)
PI=math.pi;
local radians = math.atan(axis1/axis2);
local BaseAngle=radians * (180/PI)
return BaseAngle
end
Title: Re: DRO Code differences
Post by: smurph on April 27, 2014, 10:36:27 PM
A function is not a loop.  And not all loops are bad.  You just have to make sure that the loop will not loop for a long time (or forever).  But functions are a great idea.  Take a look at the Screen Load script.  That is where I put functions that are used by the PLC script.  So put your getAngle() function there and call it from the PLC script.

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 28, 2014, 10:22:49 AM
Functions works much better, Thanks Steve ;D
have a lot more control of the displayed values this way.
this way I can control what quadrant the angle is in.
This took hours as my plugin took DAYS
hope others find it useful.

NOW don't forget to FIX G68 please.  :D

BTW: was expecting it to update when I went into Machine Coord mode but it only computes Fixture offsets, Still a few things to work out.
But I am having FUN

Code: [Select]
--Screen Load Script

function getHypot(axis1, axis2)
    local hypot = math.sqrt(math.pow(axis1,2) + math.pow(axis2,2));
        Hyp = hypot;
    return Hyp;
end

function getAngle(axis1, axis2)
    PI = math.pi;
    local radians = math.atan(axis1/axis2);
    local BaseAngle = radians * (180/PI)

if (axis1 == 0 and axis2 == 0) then
    angle = 0;
end
if (axis2 < 0 and axis1 > 0) then
    BaseAngle = -(90 + BaseAngle);
end
if (BaseAngle < 0) then
    angle = (BaseAngle + 360);
elseif (BaseAngle > 0) then
    angle = BaseAngle;
end
if (angle == 0 or angle == 90 or angle == 180 or angle == 270) then
    if (axis1 > 0 or (axis1 == 0 and axis2 == 0)) then angle = 0;
        elseif (axis1 < 0 and axis2 == 0) then angle = 180;
        elseif (axis1 == 0 and axis2 > 0) then angle = 90;
        elseif (axis1 == 0 and axis2 < 0) then angle = 270;
    end
end
return angle
end

Code: [Select]
--PLC Script

local Xval = mc.mcAxisGetPos(0,0);
local Yval = mc.mcAxisGetPos(0,1);
local Zval = mc.mcAxisGetPos(0,2);

getAngle(Xval,Yval);
scr.SetProperty('droXY', 'Value', tostring(angle));
getAngle(Xval,Zval);
scr.SetProperty('droXZ', 'Value', tostring(angle));
getAngle(Yval,Zval);
scr.SetProperty('droYZ', 'Value', tostring(angle));

getHypot(Xval,Yval);
scr.SetProperty('droXYhyp', 'Value', tostring(Hyp));
getHypot(Xval,Zval);
scr.SetProperty('droXZhyp', 'Value', tostring(Hyp));
getHypot(Yval,Zval);
scr.SetProperty('droYZhyp', 'Value', tostring(Hyp));
Title: Re: DRO Code differences
Post by: smurph on April 28, 2014, 08:13:22 PM
Is G68 not working?  Can you give an example?

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 28, 2014, 08:48:01 PM
zero all axis's
MDI: G68 R45
sets coordinates to a 45 degree angle
DRO turn red in Mach3
if you jog in X you should see both X and Y move the same amount on a 45 degree angle
no luck at all in Mach4

Title: Re: DRO Code differences
Post by: Brian Barker on April 28, 2014, 08:50:24 PM
Looks like it is working in my files

(2PanelNoOffset)
G68 r0
G00 G54
G90 G54
G61
S15000 M3
G4 P3
G0 X2 Y2 Z1
z.1
#10=1
M98 P1000 L20
G0 G90 Z1
G0 X6 Y2
z.1
G68 X6 Y2 R45
#10=1
M98 P1000 L20
X0.0 Y0.0
M5
G68 r0
M30

O1000
G91
G1 F10
Z-.1
X[#10]
Y[#10*-1]
X[#10*-1]
Y[#10]
#10=[#10+.1]
M99

Title: Re: DRO Code differences
Post by: Brian Barker on April 28, 2014, 08:51:36 PM
DRO's don't change in Mach4...
Title: Re: DRO Code differences
Post by: smurph on April 28, 2014, 08:51:51 PM
Thanks!  I'll try it out.

It may be that the jog planners are not picking it up.  Seems to work fine in files.

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 28, 2014, 09:04:44 PM
Your right if I do a
MDI: G1X1F10
it does move correctly
so it has to be in the jog routine.

I like the red DRO's  ;)
Title: Re: DRO Code differences
Post by: Brian Barker on April 28, 2014, 09:11:10 PM
No, If you have G68 the Jog should be by the axis NOT the coordinate system. The last thing we need is to press a jog key and have it go the other way..
MDI and Gcode commands will follow the G68 rotation. We could add a rotated DRO but that may be in a Dot Rev.. We are following how it works on the industrial machines :)
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 28, 2014, 09:28:44 PM
should move in both, I use it a lot like that.
once i establish the coords I can use an indicator to follow the edge at the g68 angle

mach3 has been that way for years
Once you set g68 that is your coord system if I wanted to follow the linear ways I set g68 back to zero.
If you jog off coords you are no longer in reference to your set point. Your DRO will be incorrect. and you would have to jog back to the same point to be correct if you run a part again. all I can say is try it! Unless your keeping track during jogging where your g68 coords are. Once you move your way your screwed.



Title: Re: DRO Code differences
Post by: smurph on April 28, 2014, 09:30:24 PM
Your right if I do a
MDI: G1X1F10
it does move correctly
so it has to be in the jog routine.

I like the red DRO's  ;)

All things are possible in the screen designer.  You can make that happen in the PLC script!  Just look at the modes and see if G68 is in effect and turn the DROs any color you like.

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 28, 2014, 09:43:08 PM
That will work, thanks steve
Title: Re: DRO Code differences
Post by: Brian Barker on April 28, 2014, 09:43:52 PM
You can do MDI moves in INC mode.. that is how it is done on the large CNC machines. I know it is a change and no one likes change :( . We may be able to change this over time but for now it is what it is. Later we will be turning on some of the out of band axis code and we could make a false axis that could be set to the G68 rotation. Then you could jog X Y and the angle axis .... That to me is a much better way! We have the tools in the core :)
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 28, 2014, 09:55:54 PM
Then I would say that when a g68 is active, jog is off or your going to have to write code to keep track of where it jogged too during the g68 coords. Or things will be out of wack and you would see crashes.
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 28, 2014, 10:09:11 PM
I cut 11' long parts that I put from corner to corner on my router and g68 on that found angle. Envision jogging up to an edge without it moving in both axis at a time? Will a MPG work like the Jog? How do I step up to an edge at 90degrees to the side face?  Kind of why I created the Polar function to solve my needs.
Title: Re: DRO Code differences
Post by: Brian Barker on April 29, 2014, 08:03:16 AM
The good news is you can still use the G68 function. Making it jog at that angle is not a big issue but it will be some time before we can get to it. Now if you wanted you could make it jog at an angle. You have the power in the scripting to do it if you want to :)

Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 29, 2014, 08:56:31 AM
Cool... We will see selling of screens with scripts that do things like they should be,  ;D

I like the flexibility of being able to create, and yes it's not everyone.

Could be Mach4 is creating a whole new Revenue Stream for Programmers.

And can we be seeing you dreaming of; Ringing the Bell on Wall Street?  ;)

Brian & Steve you have to love the possibilities. but hate the loss of sleep!

All in jest  ::)
Title: Re: DRO Code differences
Post by: Brian Barker on April 29, 2014, 08:59:56 AM
The idea with Mach4 is that you could code in cool features and share and / or sell your screens. We want to see people doing wonderful things! Keep up the great work!
Title: Re: DRO Code differences
Post by: smurph on April 29, 2014, 01:22:25 PM
And I have to say that some guys have taken Mach4GUI screen design to a level that I didn't even think possible!  There is no way could I have imagined what has already been done.  Simply amazing.

Could it be we are in a screen building renaissance?  :)

Sleep?  What's that? 

Steve
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on April 29, 2014, 01:52:55 PM
Renaissance? Is that your way of saying some of are OLD and have too much time on our hands?

Sleep... that just Naps between nature calling.
Title: Re: DRO Code differences
Post by: smurph on April 29, 2014, 04:24:04 PM
:)
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on May 06, 2014, 07:10:12 AM
DRO Auto Calc (a popup calculator that can be turned on and off), now thats sweet option, thank you  ;D
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on May 06, 2014, 07:42:14 AM
Just so all know:
Select Edit Screen under the Operator menu
Choose the pull down option you desire here under Editor for the DRO you have selected.
After you have left the edit mode.
Turn the calculator on and off using the option DRO Auto Calc under the Operator menu

Steve; Long as I have your attention what is "Z order" refer too?
Title: Re: DRO Code differences
Post by: Ya-Nvr-No on May 06, 2014, 12:34:56 PM
Thank Jeff Birt for providing the answer for Z order

http://www.machsupport.com/forum/index.php/topic,27119.msg191689.html#msg191689