Hello Guest it is December 26, 2024, 01:22:18 PM

Author Topic: Macro for coordinating mach and external logic, syntax and other problems  (Read 4006 times)

0 Members and 1 Guest are viewing this topic.

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
« Last Edit: April 28, 2015, 02:43:29 PM by moorea21 »

Offline BR549

*
  •  6,965 6,965
There is no such call as  Activate(output2)

It would be ActivateSignal(output2)
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.

Offline BR549

*
  •  6,965 6,965
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
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?
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.

Offline BR549

*
  •  6,965 6,965
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
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.

Offline BR549

*
  •  6,965 6,965
yep if it was Lua then you would need  , or ..

(;-) TP