Machsupport Forum

Mach Discussion => General Mach Discussion => Topic started by: moorea21 on April 28, 2015, 02:38:53 PM

Title: Macro for coordinating mach and external logic, syntax and other problems
Post by: moorea21 on April 28, 2015, 02:38:53 PM
I've written this, to interact with a picaxe and a light sensor that works like this:-

- Outputs are activated, one 5.0V for the picaxe and sensor, etc, the other 3.6V for an LED.
- The picaxe gives a signal to the BOB to say it's switched on
-The picaxe via sensor measures ambient light through a small 'window', records its value
-The machine (Mach3) squirts a sample of paint on the window and compares the amount of light before and afterwards; if the difference is over a certain value, IsSquirtBigEnough sets to 1, and the macro ends, returning focus to the Gcode file that called it
-If the paint deposit was not big enough, IsSquirtBigEnough sets to 0, and the macro returns to the label 'tryagain'. The window self cleans (C drive), and the test starts again

Code attached; there may well be a better way for Mach to look out for signals from external sources, also my gcode pauses may not produce accurate timing as they are probably slow to process. That's my guess anyway.

This code gives me a syntax error, without highlighting where that error is, and I haven't been able to spot it. The missing 'Is' from the start of a variable name isnt it; I fixed that, same result.

Also, my method for coordinating the actions of main machine and picaxe may not be that good; has anyone successfully used somethng like this before? If so, how was it coded to make sure both units work together in time?

Thanks
M21
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: BR549 on April 28, 2015, 09:02:56 PM
There is no such call as  Activate(output2)

It would be ActivateSignal(output2)
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: moorea21 on April 29, 2015, 05:20:01 AM
Thanks, couldn't spot that at all. There is also 'End If' missing after the longer Gcode section. After other changes, I'm left with pauses being ignored. Why is this? Searching 'macro G04 ignore' here hasn't turned up anything.
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: BR549 on April 29, 2015, 12:00:23 PM
You would not use G4 as that is a Gcode Pause. Use SLEEP(1000) being sleep for 1 sec (1000ms)

Using the G4 it could be either secs or ms depending on the setup of mach3.

(;-) TP
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: moorea21 on April 29, 2015, 02:13:14 PM
Thanks, I'll use Sleep.

In a macro, when I want to 'Code' a statement that ends with a variable, I've tried to use this syntax, but it complains about unexpected something or other.

Code "G28.1 X" ,X

What is the correct way to do this?
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: moorea21 on April 29, 2015, 03:25:02 PM
In a similar vein, should not this:-

If Dir ("C:\Users\r\Desktop\Gcode\",2,".cgf")<>"" Then
....

Give the same result as this:-

If Dir ("C:\Users\r\Desktop\Gcode\2.cgf")<>"" Then
....

I had hoped to replace the 2 with the expression "NextFileNum +1", and then increment NextFileNum on each loop to find and load/run the next file in a folder:-

If Dir ("C:\Users\r\Desktop\Gcode\",2,".cgf")<>"" Then
LoadRun ("C:\Users\r\Desktop\Gcode\", NextFileNum +1, ".cgf")

It hasn't worked...sorry to be so clueless, but how do I achieve this? I've looked through the cypress basic 'enduser' pdf, and not surprisingly there's nothing in there.
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: BR549 on April 29, 2015, 06:52:00 PM
IT would be like this

Xx = whatever value

Code"28.1 X" & Xx


AND

If Dir ("C:\Users\r\Desktop\Gcode\" & "2" & ".cgf")<>"" Then

AND

NextFIleNum = 1

LoadRun ("C:\Users\r\Desktop\Gcode\" & (NextFileNum +1) & ".cgf")

NextFileNum = (NextFileNum +1)


(;-) TP
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: moorea21 on April 30, 2015, 03:53:19 AM
Thanks, I hadn't expected it to need ampersands; I ought to have, seeing as VB does. I am rustier than I thought it seems.
Title: Re: Macro for coordinating mach and external logic, syntax and other problems
Post by: BR549 on April 30, 2015, 10:14:43 AM
yep if it was Lua then you would need  , or ..

(;-) TP