Hello Guest it is April 28, 2024, 03:52:20 PM

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - mcardoso

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 »
31
Mach4 General Discussion / Re: Can’t get macros to work
« on: April 27, 2020, 09:12:53 AM »
There are quite a few people here that can help you get your code working. Can you start by writing out a detailed functional description of how you want your solenoid to behave including any edge cases? There are a lot of ways to skin a cat in Mach 4 so you might get some varying answers. Once you do that, I'll give it a go and see what I can come up with.

-Mike

32
My customizations are:
-Pneumatic drawbar release from a pushbutton on the head of the machine
-Serial communications to my motor drives to pull diagnostics
-Spindle load monitoring
-4 axis pendant interface
-Start-up script that does everything I forget to do (like turn on soft limits)
-Custom homing sequence
-Interlocking certain actions with my safety system

I like customizing my stuff so I'm a high use case. I don't know Masso well enough to recommend one over the other, but coming from Mach 3, I have to say I am very impressed by Mach 4.

33
Mach4 General Discussion / Re: Mach4 feature vs Mach3
« on: April 23, 2020, 11:57:37 AM »
LUA vs VBA: I was a heavy custom programmer in Mach 3 VBA and was able to get everything I wanted to do done, but I found that the development process was difficult and even when I got things working, sometimes it just wouldn't run as expected. When I jumped to Mach 4, I was very quickly overwhelmed by how complex LUA seemed. I dove in headfirst and with the support of this forum, got over the learning curve in a month or so. I can definitively say that LUA, the ZeroBrane editor, and most importantly, the Mach 4 API are just lightyears ahead of Mach 3. The documentation is pretty good and centrally located (unlike Mach 3 where all you had was a bunch of cheat sheets people had made). I've coded some pretty complex things in Mach 4 (including a serial communication module for diagnostics with servos) and find that the object oriented structure of LUA allows you to build your code up in logical layers. The custom code executes blindingly fast and I feel unrestricted unlike Mach 3. This was my biggest reason for switching to Mach 4.

Menu and Graphics: Mach 4 is just pretty. The menus are logical and the screens are clean and well laid out. This is contrasted by Mach 3's piecemeal menus and lack of uniform style.

Screen Editor: The screen editors in both Mach 3 and Mach 4 are not great honestly. Mach 4 is quite a bit better than Mach 3, but still is missing a lot of features seen in other software packages. If NFS reads this, can we please add grouping, alignment, layers, shared properties, and an undo button? Thanks!

Online community: Mach 3 has a ton of users but is rather unsupported. A lot of forums will strongly suggest that you switch to Mach 4 before offering help. Mach 4 on the other hand has a vibrant and engaged community, on this forum as well as others. There is a quick and easy way to get your questions answered. NFS is also actively supporting and developing the product.

34
Wanted to check back in with you. Were you able to get this working to your liking?

35
David,

When you use a message box and want the program to do something based on which button is clicked, you need to manually code those conditions. When a button in the message box is clicked, the message box function returns with a value and continues to execute the script. If you don't check the return value, then the program just keeps chugging along.

If you want the cancel button to actually cancel the function, then you need to program an IF statement than looks if the returned value is equal to "cancel" and return from the function early. The message box does not have any of this functionality built in automatically.

https://docs.wxwidgets.org/stable/group__group__funcmacro__dialog.html#ga193c64ed4802e379799cdb42de252647

Copied from that site:

Code: [Select]
int answer = wxMessageBox("Quit program?", "Confirm", wxYES_NO | wxCANCEL, main_frame);
if (answer == wxYES)
    main_frame->Close();

Now obviously the syntax needs to be modified and adjusted for LUA, but see how they capture the return value in "answer"? This lets them check if it is equal to wxYES (really just a constant integer value like 1 or 2, I just forgot which - have a cheat sheet somewhere), and do something based on that information.


36
So it has been quite a few months since I have dove deep into LUA coding, so excuse any inaccuracies, but I'll do my best to draw out an example.

LUA has a feature that is kind of uncommon in other programming languages called "Multiple Returns" or "Multiple Results". This allows a function to pass back more than one piece of data. This opens a lot of doors to your style of programming. Here is a link to the LUA guide on the topic:

https://www.lua.org/pil/5.1.html

It goes something like this. Let's say I write a simple function to return my current coordinates "whereAmI()". Traditional programming might need to specify which axis you want such as xPos = whereAmI(x) and yPos = whereAmI(y), but LUA allows you to do a much more compact call to that function that looks like this xPos, yPos = whereAmI().

The comma denotes each variable that is being assigned a returned value. If you accidentally give it too many variables to return to (such as xPos, yPos, zPos = whereAmI() if the function only returns X and Y), the extra variables will be assigned a value of nil. You do not need to capture all the return values either (such as xPos = whereAmI(), discarding the returned value for Y), however if you want a value that isn't the first one, then you need to capture the first value in a dummy variable (dummy, yPos = whereAmI() ). For this reason it is smart to make sure that your function returns data in the order of importance or likelihood of use.

To get a function to return multiple values, you would enumerate the values on the same return line, delimited by commas. The order of the returned variables will be the same as the order of the function returns. I will show a simple example program below:

Code: [Select]
local x = 0
local y = 0
local z = 0

x, y, z = myFunction()

print(x..", "..y..", "..z)

function myFunction()
   local a = 1
   local b = 2
   local c = 3

   return a, b, c
end

We would expect the output to be "1, 2, 3". This is because the value of "a" has been returned and assigned to "x", "b" to "y", and "c" to "z".

If you don't follow this, let me know and we can discuss deeper.

I'm going to also attach one real function of mine to this if it is helpful. I wrote several modules to work together to handle continuous serial communications with my servo drives to pull diagnostic data. One function (part of the servo communication module) was tasked with reading the DC bus voltage on the servo drive and reporting the number to Mach.

Code: [Select]

function mcServo.GetBusVoltage(address)
--Test Function to read and return Bus Voltage
--Returns Error String and Bus Voltage as a number
local ES = "" --Error String
local RS = "" --Return String
local RV = 0 --Return Value

local parameter = "08B"
local function = "0"
local serialError = "0"
local busVoltage = 0
local busVoltString  = ""
local xmtStr = ""

RS, xmtStr = mcSerial.AppendChecksum(address..parameter..function)
if (RS ~= "") then; ES = "E010101:"..RS ; busVoltage = 0; return ES, busVoltage; end

RS, busVoltString = mcSerial.WriteRead(xmtStr)
if (RS ~= "") then; ES = "E010201:"..RS ; busVoltage = 0; return ES, busVoltage; end

RS, busVoltage = mcSerial.Hex2Num(busVoltString)
if (RS ~= "") then; ES = "E010301:"..RS ; busVoltage = 0; return ES, busVoltage; end

return ES, busVoltage
end


I defined 3 strings "ES" which is a string that may either be empty (no error) or contain an error code that will help me track where the error originated from, "RS" the same error string returned from lower level functions, and "RV" a numerical value returned by Mach 4 functions. Notice after every function call, I check if the RS is empty. If it is, I know the function worked correctly and the data it good. If it is not empty, I append the error string with new information (the location and cause of the error) and return early.

Notice the last line in the code says "return ES, busVoltage". This means I am first returning the error code (hopefully an empty string "") and then the number data for the measured bus voltage.

Whenever I want to know the bus voltage on my address 0 drive, I use the function call errorCode, voltage = mcServo.GetBusVoltage("00"). I must collect the error code first (since it was the first returned value) to determine if the value returned by the function is any good. Sometimes the serial packet comes late and there is an error. By using multiple returns I am able to track when an error occurs and decide what to do about it (I log all the error codes that are returned in case I need to troubleshoot).

This is a rather complicated example of error codes and multiple returns (actually more so than the way NFS handles them) but it gave me a great way to troubleshoot what ended up being some very complicated code.

37
All custom functions I write in Mach use the same layout of multiple returns. Something like "data, error". I always check the state of the function call error code and only continue if zero. Easy to nest your functions so that if one returns an error, it causes the higher level function to error too.

38
Well shoot. Now I feel bad for making Craig write a long response! I haven't used a USB one so I'll defer to his expertise on them being good to use! The longer cable of the USB ones would be nice. My pendant has a 6' pigtail cord that could do to be a little longer.

I do stand by the safety over networks comment though. All the safety signals that go over Ethernet/IP, EtherCAT, Profibus, CANOpen, etc. are all specially formatted for extra CRC and packet redundancy, as well as strict timing requirements for packet arrival. Lots of the leading companies in Industrial Automation have their own protocols for accomplishing this (the one I am most familiar with is CIPSafety on Ethernet/IP). This COULD be implemented with Mach 4 and USB but it certainly isn't at this time. I know most of us don't even use a safety system beyond wiring into Mach 4's ESTOP input, but coming from industry and designing safety systems for industrial equipment, I can't feel comfortable trusting a USB signal with safety encoding to stop my machine (especially if my hand was stuck in it!).

39
Those USB or Serial ones require a plugin for Mach 4 (unless you plan on writing your own interface - which is doable if you are very comfortable in LUA and embedded programming). There are only a few supported ones right now, and I can't remember which off the top of my head. I know the normal complaints are lag between the device and Mach 4 due to the communications.

My biggest reason for selecting a wired unit was that I could use the ESTOP in my safety string. An ESTOP over a network (like
USB or wireless) is absolutely no good from a safety perspective.

40
I personally like the generic pendants that come with a big pigtail and a ton of wires. If you aren't using the 3rd port of your ESS, this is a great use for it.

https://www.ebay.com/itm/Universal-CNC-6-Axis-MPG-Manual-Pulse-Generator-Pendant-Encoder-for-FANUC-System/182325817276

https://www.ebay.com/itm/HEDSS-6-AXIS-CNC-Pendant-100-MPG-JOG-Encoder-ISMM2080-5V-TTL-Line-Driver-E-STOP/261853344399

Andy did a great write up of LUA scripting a pendant.

https://warp9td.com/index.php/faq/faq-pendants-and-mpgs

Pages: « 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 »