Hello Guest it is April 19, 2024, 01:09:41 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 - simpson36

51
Mach4 General Discussion / Re: need a little bit of help
« on: June 02, 2015, 05:38:04 PM »
In my example code above, it uses a semaphore like var to control the execution.  

Very much on point. I put another example of this in the preceding code  where the var 'counter' is acting as a timer and as a semaphore.

There may be confusion about program control if, as it seems, 'semaphore' is viewed as a 'thing' rather than a concept or method.

I added a few paragraphs to install instructions explaining that 'Modbus' is not a 'thing' that needs to be purchased separately. It is just methodology and rules which allow those (devices) that speak it to communicate with each other.

Virtual entities can be difficult to comprehend if a person is anticipating something tangible.


BTW, I am currently going thru all of my Mach4 code adding error traps where needed now that the information is available to do so . . .  and a brief wave of ambition has overtaken me . .   :)

Edit: and also making some routines into functions and deciding what parts of the code might be better executed form the screen load script instead of the PLC, now that I have some concept of the difference.     i.e. basically getting the 'virtual mop' out and cleaning up the place.

52
Mach4 General Discussion / Re: need a little bit of help
« on: June 02, 2015, 04:27:37 PM »
It occurs to me that the apples vs oranges might be using 'delay' and 'flag' (semaphore) interchangeably and they are not the same thing.

Using delays (ex. 'sleep' in VB) is simply a finite pause in execution and using same could cause all of the symptoms described. Based solely on the descriptions provided, I would speculate that delays are being used which cause additional problems wherein use of flags would eliminate the problems altogether. If you are scripting anything, you have access to the method. I have never heard of a 'sync semaphore', or any other specific kind of flag. The programmer makes them up as needed, for the purpose.

In my code, and much of what I have seen of other's code, typically the routine generating  the data sets a flag and the routine gathering the data reads the flag. In this way, the routine receiving the data CANNOT act prematurely and there is NO reason to have delays or slow a program to a crawl in an attempt to guarantee the 'race' is won by one contestant or the other.

There are certainly other methods of program control, but unless I encounter some good reason to use an alternate, I stick with flags.

A method to consider in the DRO example is to use a 'comparative change'. If you want to know when a value has changed, just save the old value and compare it with the new until it changes. I use this a lot in MACH3 VB scripts.

OldValue  = GetUserDRO(*********x)
NewValue = question "Where do you want to go?"   (script will not advance until user answers)

If NewValue != OldValue
 do as requested
else
 Message ("You are already there")
end

Without an 'event' (user entering data, input going high, etc), you can create a 'flag' on-the-fly


OldValue = GetUserDRO(*********x)
NewValue = Oldvalue

Call routine that will enter new data into the DRO

counter=0
while NewValue == OldValue 
 NewValue = GetUserDRO(*********x)
 counter ++
 if counter > 1000 then
  break
 end
  sleep(100)    '<- this is a delay
wend

'Blah,blah do other stuff until you need that new DRO number

if counter > 1000          ' routine timed out, so there is no new data
 messageText =  "Current DRO*********x data unavailable"
 DataXReadyFlag = false
else
 messageText = "Data X Update verified"
 DataXReadyFlag = true
end



' Time to use the data . .

if DataXReadyFlag and AxisEnabled and (whatever else needs to be ready)
 do the deed
else
 call error handler    'messageText will have the error
end


Note that I have nested 'flags' (not typically a good idea) and that the var 'counter' is actually acting as a flag, but hopefully the method is clear.

This stuff is a PIA and is boring and time consuming, but as has been said, this is the programmer's responsibility.

When  I first perused the new API manual, I was pleased and relieved to see that the MACH4 functions have multiple error codes. Most certainly the footprint of professional programming. Yet, I have seen NO code posted since that document was released that actually shows the available error returns being used  . . . uh  . . including my own  :-[  And within that document is fair warning, by function, of which ones do not wait on execution.

the long list on MACH4 functions is in essence, just another of many libraries. The programmer still must write in C and/or Lua to use these routines. The developers of MACH4 cannot dictate how C or Lua work unless they want to write their own compiler. It would seem that writing MACH4 is enough challenge.

53
Mach4 General Discussion / Re: need a little bit of help
« on: June 02, 2015, 02:02:26 PM »
You end up having to RUN mulitple lines of Gcode  from a single line with \n.

THAT should never happen . You should be able to simply stack as many lines of Gcode in the script that you need to use AND have each run in proper order SAME as running the Code From the Gcode side.


Terry, I really don't want to get into another argument with you, but I am just curious as to why you see a difference between a pre-written G-code program in a file and 'stacking' lines of G-code in a single string separated by \n.

The interpreter sees the same thing, I would imagine. The only difference is that one set of blocks is read out of a file and one is sent as a delimited string.

In a text file, each line is delimited by some character, typically 'newline' which is just a carriage return and linefeed.

Said another way, the interpreter gets the code a block at a time and executes with no in input from the operator., so why would it matter is the blocks were strung together rather than submitted line by line by successive 'execGcode' functions?

You mentioned 'out of order', I think. Are you suggesting that the string of commands separated by \n is given to the interpreter in a different order that it was in the string? That would be mucho bad.

54
Mach4 General Discussion / Re: need a little bit of help
« on: June 02, 2015, 07:39:18 AM »
If there is a way for a subroutine (or function or module, etc) to know when a var has changed, I don't know what it might be. If subsequent processing or actions might pick up stale data, it is the programmers responsibility to control that pick-up until the var has the current data. A normal way to do this is with a semaphore (I just call them flags).

The routine that is generating the data sets a 'data is ready' flag when the data is made current. The routing that uses that data waits for the flag before reading the var and resets the flag to 'data is not ready'. This is flow control 101, and is indeed the programmer's responsibility.

Buying a hammer and saw does not make the buyer into a carpenter. Buying a CAD program does not make the buyer into a designer. These are tools, not skills.

It is evident to me that MACH4 has a design goal of supplying tools. One area where they have restricted what a user can do is the screen editor. This is a place where the average user might do 'programming' to modify their screen, and it amounts to 'checkbox programming'. These restrictions make the editor unsuitable for my purpose. Just because I am unhappy about it does not mean I don't understand why it was done and that it makes sense in that application.

However, if similar 'save the programmer from himself' philosophy was extended to scripting, the flexibility would indeed be out the window. The long list of MACH functions is essentially one of many libraries created for a specific purpose. It still requires programming in C and/or Lua to use them and therefor the statement 'when you script, you are the programmer' is accurate, in my opinion.

55
The only options are the ones provided from the drop down menu.

If you are talking about adding an LED to the MACH4 screen, and you want to have a script behind it, one solution is to use a bitmapped button in place of the LED. You can add far better looking image of an indicator light than the horrible round LED and you can script the behavior.

You can learn more about this technique in a thread about 'makin it purdy' where you will find actual code examples.

The pre-defined choices in the MACH4 screen editor are certainly adequate for the vast majority of user needs, so please do jump in there and experiment. The 'checkbox programming' process makes good sense as a method by which non-programmers can quickly and easily make their own screen mods.  

There are many more parameters available for screen items (buttons. led, etc) than are made available in the pre-defined list provided in the MACH4 screen editor. If you need a parameter that the Mach4 editor does not have a checkbox for, or a graphics function is partially or completely broken, then it becomes a roadblock and consequently a frustration.

Despite the restrictions, making a custom screen set, whether you are adding one LED or an extensive set of interactive controls, is far easier in MACH4 than in MACH3. The speed and capabilities of the MACH4 screens far exceed anything available in MACH3.  

56
Mach4 Videos / Re: Mach4 - Arduino and Touchscreen
« on: May 30, 2015, 05:40:20 AM »
To add my two cents worth to the topic of board choices, I don't think there is an answer to the 'which board is best' question. Like the age old Chevy vs Ford debate, it is opene ended and always will be.

In my view the best board choice is application dependent. If you need an OS, and you have not the skill or time to be porting stuff, then it is wise to [purchase a board that already has an available OS that will run your software.

Really, processor wars are all fine and good, and dual or quad core processors are spectacular IF you have an OS that supports them or an appropriate compiler, otherwise they are essentially single core processor. The overall success of a given board in a given application boils down to what support chips you need for your application and which are integrated into the board. For example, there are no single chip solutions for Modbus (that I know of) and the calculations are integer math so that playing field is fairly level, however, there are a number of single chip USB, Ethernet, Bluetooth, and so on. Some Atmel processors (Arduino) have I2C built in as well as very fast high resolution (in the case od DUE0 A/D converters and interrupt controllers that are supported by available libraries.

My application requires a lot of FP math, so that is weighted heavily when choosing a processor, but I also need Ethernet and non-volatile storage, so integrated Ethernet and either EEPROM or an SD card reader is a distinct advantage. I do not need blue tooth, so that has zero weight. The next application might need blue tooth and no Ethernet, so the choice might be different.

Unless you want to spend the liion's share of your development time 're-inventing the wheel', available (and working) libraries for the functions that you need should be at the top of the list. Modbus is a good example of that.



57
yah, Lua is an extension of C++ and the I'd bet you the core is written in C++.

Lua is written in C per its publisher. I find it to be very similar to C in structure and function although the syntax has a dash of this and a dollop of that for whatever reason. Lua is designed to be an embedded scripting language. That is the singular fundamental difference.
The flavor of VB script used in MACH3 is the worst language I have ever used. Just hideous. However, it does serve to make the contrast with Lua all that much greater.

That was Simpson36's point when he asked for open code or if we already have it...then, where is it?

Just to clarify; what I was asking about was access to the source code for the screen only, not the core. The screen is a separate entity from MAHC4 core and is written in C and/or Lua or some combination thereof. The screen editor certainly appears to be wx.Lua and MACH4 comes with an entirely separate sample wx.Lua screen. However, it is rather Spartan and is not editable, so I really don't see the point in providing it. Without the source code, it is literally useless. Providing source code examples in the embedded scripting language is hardly an outrageous request. The product already comes with examples of several Lua scripts for common tasks as well as a rather complex widget with its own pop-up screen.

I started working with the editable GUI screen to add some attractive and ergonomic controls, but soon gave up on that effort due to the developer's effectively refusing to add tools or fix problems. The bottom line is that, by their own admission,  the screen is not a priority for the developers.

The solution is to write new screens from scratch and thereby not be constrained by whatever few tools and choices the developer's think necessary. As an interim step, integrating widgets into the screen gets past some of the MACH induced restrictions, so I am no longer interested in the source code for the screens or pursuing tools and bug fixes for use with the current screens.

58
Tim,

I'm sure I would get arguments over this statement, but Lua is a dream compared to MACH3's implementation of VB script.

To resolve your jog increment issue, a good approach would be to use the Lua editor to change all of the axis increments to say 1 and then then change them one at a time while watching the On Screen Increment dro (assuming it is real time) and you will then know what is being read.

This method will answer an important question for you and also give you a tiny taste of what working with Lua is like. The editor has step by step debugging so you can cut and paste the  'Set' functions 6 times and then just change the axis numbers and step down thru one at a time.

Notes: choose 'debug' from the drop down and step thru using the F11 key. Remember to 'stop debugging' before you try to edit again.

The Lua editor will give you a rather vague error message if you try to do the debugging without first saving the file. There is some trick (you can search  it out if you are curious) that you can add to the bottom of the script that tells Lua that the script you want to run is actually IN the editor and (as if it should not already know that) and then it will run the script. However, simply saving the file first accomplished the same thing and ALSO protects you against the Lua editor locking up and loosing the script . . . because it was never saved.  And the Lua editor locks up . . a lot . . . . in my opinion

59

 - or -

use the built in register diagnostics window in which you can view  . . and change . .  any register  . . . . in real time . . .  ;)

60
Mach4 General Discussion / Re: Mach4 Executing Gcode from LUA
« on: May 29, 2015, 07:29:03 AM »
This topic has already been reported and discussed in the 'Bug Report' thread, and a bit of research turned up that the proper use of this function is actually documented. Specifically [emphasis added]:

"If the control is in the idle state, this function will execute the G code in MDI mode.

It is important to note that this function does not wait for the G code to complete. It is an error to execute G code with this function one line after another. Instead, the lines should be combined into one string separeated with newline characters (\n)."


It's hard to say whether the code is executed in the MDI as indicated, but there is an explicit function to execute in the MDI, so that's an alternative to try. I have used it in buttons and elsewhere and it works fine.

An important part of the usage statement is does not wait for the G code to complete. and this is the case with either Gcode Execute or MDI execute. It is unclear to me why one would use one method over the other, but in either case, users should make sure to add wait states if needed so that the move completes before subsequent actions take place.