Hello Guest it is January 19, 2022, 05:51:07 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.

Topics - ChrisLT

Pages: 1
VB and the development of wizards / Reentrant code
« on: March 03, 2008, 05:52:06 AM »
VB functions and subroutines should allocate local variables on the stack so that they can be called reentrantly. Cypress doesn't seem to be doing this. My current code is rather long to post here, but essentially I'm trying to do something like this:

sub divide(byval a as double, byval b as double)
   Dim c as double
   if abs(b-a)>0.1 then
    divide (a,c)
    divide (c,b)
    Code "G1 X" & b
  end if
end sub

What happens is that, after the first recursive call to divide(a,c), c gets set to 0 so the second call is divide(0,d), not divide(c,d). Indeed, the values of all local variables get reset to 0 after the first recursive call. I could recalculate them but that really shouldn't be necessary.
Have I missed something you need to do in VB to make routines recursive? Or is this a bug?
Thanks for any input
Chris Lusby Taylor

VB and the development of wizards / Code Execution order is reversed
« on: February 25, 2008, 06:29:25 AM »
I've found what, to me, seems a strange behaviour in M3. In a macro I have, in effect, the following sequence:

for i%=1 to 2
  Call SetVar(123, i%)
  Code "M98 (mysub" & i% & ".tap) L1"
next i%

The problem is that neither of the subroutines get executed until after the entire macro has run. And then they are run in reverse order: mysub2.tap first, then mysub1.tap . And when they read #123 they see value2. It is as though I had asked for:

  Call SetVar(123, 1)
  Call SetVar(123, 2)
  Code "M98 (mysub2.tap) L1"
  Code "M98 (mysub1.tap) L1"

I have found a solution that works for my present situation. Change the above to:
    for i%=1 to 2
      Code "#123=" & i%
      Code  "M98  (mysub" & i% & ".tap) L1"
    next i%

I haven't experimented to see how the execution of other Code works, but it seems you can't count on it being executed in order or at the time the Code function is executed. The Mach2 Customization Guide says you're not advised to call another script from within a script. But is M98 a script? Does this mean you shouildn't use any M commands in a Code function in a macro? Or does it affect only M98(file) ?

Can anyone enlighten me please?


VB and the development of wizards / Macro code problems
« on: February 20, 2008, 06:56:33 PM »
Wonder if anyone can help, please. I'm developing macros for Mach3. I've found several problems:

1. ELSEIF isn't recognised in the VB editor as a keyword (i.e. it appears as black, not blue text). I'm having to use ELSE IF, which then needs another nested END IF.

2. I frequently get multiple instances of the VB editor window open. As many as eight windows just pop open. I think it happens when I execute a macro with an error in it. Does that sound right?

3. I often get Syntax error messages (because my syntax may well be wrong), but the cursor doesn't go to the line in error. It can be very difficult to pin down the error if I've done a lot of editing. For instance, I thought I had to declare external functions as they appear in the documentation, such as SUB Code (text as string). That line would cause a syntax error with no pointer to the line.

4 If I declare my functions before the main code of the macro, the editor is happy, but my macro never executes.
For instance, if the file M1000.m1s consisted of nothing but:
Function Max(a,b) as double
  if a>b then Max=a else Max=b
End Function
Code "G1 Z" & Max(Param1(), Param2())

...the Code "G1.." line would never execute, whereas if I put all function declarations after the main code there is no problem. Is this a feature? Is it documented?

5. This isn't a problem, but a query: Sometimes I could implement some logic either in Gcode in the part file or in VB in a macro. Gcode logic is very primitive, though. For instance, you can code a 'For i=a to b' loop or 'if a>b then c' entirely in Gcode. Are there any guidelines / rules of thumb as to where to put one's logic? Portability of the Gcode isn't important to me. I'm very inclined to put all my logic in macros or to create wizards. Readability is far far better, for one thing, but I lose the ability to single step, I think. Or can I put breakpoints in macros that are invoked during execution of a part file?

Any thoughts very welcome
Chris Lusby Taylor

I'm using Formulas to wrap 2D engravings (e.g. HPGL and DXF imports) and text (e.g. the Write wizard) around curved surfaces such as cylinders, using a 3 axis machine.

Formula Axis Correction seems to have absolutely no documentation, so I'll start by stating my understanding of how it works.
With Formulas enabled, all gcode moves have the formulae applied before execution. The (X,Y,Z,A,B,C) endpoint calculated by the formulae is then used as the destination of the move. Mach3 does linear interpolation from the current point to this endpoint. The axis DROs show the physical mapped coordinates, not the coordinates commanded by the gcode. Jog buttons continue to move only one axis.
I find this display by the DROs potentially confusing. It would be nice also to be able to see the logical coordinates. For instance, in MDI mode, if the Z DRO shows -1 and you command G0 Z0 you might be surprised if the tool moves downwards.

Anyway, my first use of this feature is to engrave on the surface of a cylinder, using 2D engraving gcode, such as the Write wizard or DXF or HPGL import. By telling Mach3 that the Z height is affected by the X or Y value, I can make it curve the engraving correctly so it is at constant depth.
Start by fixing the workpiece parallel to the X (or Y) axis. Set Y (or X) and Z to zero with the tool centred above and just brushing the top of the work.
In Config>Formulas... set:

...where R is the radius of the cylindrical workpiece. This makes y equal to the distance around the circumference. For workpieces that are only curved a little, you'll have to calculate the radius from the curvature.

With a 3 axis machine, the tool is going to remain vertical, so you don't want to use this method too far off axis except with a ball-ended tool.

As Mach3 does linear interpolation, it will gouge if you do a long cutting move, but for engraving text this hasn't been a problem for me. To draw a box around the text, you have to split the circumferential lines into little pieces. And don't be tempted to jog.

The same method can be used to engrave on the inside of a curved surface. Use:

As I'm not using the A, B and C axes on my 3-axis machine, I believe I could use any of them to hold R, making it a variable, as in:

...where A can be set by G0 A1000 for instance, and can be seen in a DRO, which is helpful.

If the radius is great and the curvature is slight, you can simplify the equations. Use:

I'm very new here, so perhaps these ideas are already known, and maybe there are issues I haven't yet run into, but I couldn't find them written up anywhere.

Chris Lusby Taylor

Pages: 1