**RESOLVED** Writing Brains For Spindle and TC?

All things related to Centroid Oak, Allin1DC, MPU11 and Legacy products

Moderator: cnckeith

please no smoke
Posts: 103
Joined: Mon Mar 29, 2010 10:17 pm

**RESOLVED** Writing Brains For Spindle and TC?

Post by please no smoke »

I have been slugging thru writing Brains without much help. Can someone take a look at these brains and tell me if they will work, or will they crash my junk??

Tool Change Brain

I used the mach command for the M92.

1. On the TC LED the z is sent to zero.
2. If spindle is on, tc motor can't run FWD
3. If spindle is on, tc motor can't run REV
4. On tc wait led and z homed DRO (will this work?) and clamp input motor will run FWD
5. On tc wait led and z homed DRO (will this work?) and unclamp input motor will run REV
6. If motor runs in either direction clutch will engage
7. If input 12 PROX goes high clutch will disengage
Tool Change.JPG
Modified Ajax Spindle Brain


1. I modified this brain from AJAX to (hopefully) output a local variable "v0" when the spindle is enabled.
Modified Ajax Spindle Brain.JPG
Hurco Manual Spindle Brain

1. It looks for the v0 (enable) and for a rpm call below 250 from mach and then turns on the low speed relay.
2. If the low speed relay is on and mach wants the spindle to be CW (mod:803) then it reverses the spindle direction (my machine has a low back gear)
3. If the v0 is set and the rpm from mach is 250 or greater then it turns on my high speed relay
4. If v0 is set and the rpm from mach is above 250 and mach wants the spindle reversed (mod:803 =1) then the spindle is reversed ( mod:8 output)
Hurco Manual Spindle Brain.JPG
This is what I have so far. If anyone wants to use what I have for their KMC3 please feel free. These brains will allow a auto braw bar tool change without the changer, and allow the user to operate the auto vari drive with the RPM+/- switch on the front of the machine. I hope! :D

Thanks
diycncscott

Re: Writing Brains For Spindle and TC?

Post by diycncscott »

Hi Matt,

I wouldn't use the M92 to move to a tool change position -the feedrates will be very slow and it will also perform some extra moves that aren't needed (moving to switch and back off)

I can't necessarily address your programs point by point but I will make some specific suggestions -and provide some specific examples- in the posts that follow as I compile Macro/Brains tutorials that I hope everyone can use.

I will say that I'm not sure what your are doing with Outputs 9 & 10 in your brain. Those outputs (as you have addressed them) refer to "Mach" outputs that would normally be mapped in the "Ports and Pins" configuration section in Mach which doesn't apply to the outputs on the Ajax hardware (GPIO4D or DC3IOB). To refer to the actual physical outputs on the Ajax hardware, use the Modbus addressing.

For example: To a reference output14 on the Ajax hardware the address should be MOD:14-D0-MAC-0:, not "OUTPUT14"
In Mach Brains editor you would select: Modbus->Output->Bit Only-> Bit 0 [Bit0-15]-> MacroModbus Emulation-> CFG# 0 -as shown below
modbus.gif


I will be posting more along these lines in this topic. When I have enough content I will create a new "Sticky" on Brains/Macro programming as well as a manual.

For now, please see my next post to learn how to write a macro to move to a tool change position.
diycncscott

Writing a Macro to move to a tool change position

Post by diycncscott »

Create a Macro to move an axis to a tool change position

In this example, you will create a simple macro that will move an axis (or axes) to a tool change position and then set a Mach "LED" to indicate that the move is complete. G53 (move to an absolute machine position) is used for positioning to prevent G92 or G52 offsets from affecting the tool change position.

For more detailed information on VB Script programming in Mach, please see http://www.machsupport.com. Reference materials that you may find helpful include the Mach Wiki, http://www.machsupport.com/MachCustomizeWiki/ and The Macro Programmers Reference, http://www.machsupport.com/docs/Mach3_V ... og_Ref.pdf

1. Open the VB script editor in Mach ("Operator->VB Script Editor")

2. This will open a blank VB script
blankvb.gif
blankvb.gif (9.23 KiB) Viewed 5656 times
3. Use the code below to command the move - Use a "While" loop and the built in function "IsMoving()" to force the macro to wait for the move to complete before continuing.

Code("G53 Z0") 'commands a move to Z0 in "absolute machine position"*
Sleep 100 'wait 100 milliseconds to insure move has started
While IsMoving() 'wait until the move has completed
Sleep 10
Wend


4. Set a Mach "LED" (could be used in a Brain to trigger "ToolRelease" output)

SetUserLED(1000, 1) 'Set User LED #1000 to a "1" (On)

*All text/code following the ' character is treated as a comment and is ignored by the compiler/interpreter. As seen below, the VB Script Editor supplied with Mach displays all comments in green.


5.Save the finished macro in c:\mach3\macros\mach3mill as M25.m1s
m25.gif
6. Use M25 in your program or from MDI when a move to the tool change position
is required.

NOTE: Although this example is written as a "discrete" macro which simply commands a move to a toolchange position (called using M25), the code created below could easily be extended to also unclamp the tool when the move is complete and/or inserted directly into your exisitng M6 tool change macro.
diycncscott

Using a Macro to read and act on I/O states in Mach

Post by diycncscott »

Using a Macro to read and act on the states of I/O in Mach

In this example, you will create a simple macro that reads the state of a UserLED, an Input and an Output and then turns on an output if the appropriate conditions are met.

NOTE: Although this example is written as a "discrete" macro (called using M15), the code created below could easily be extended to orient the spindle and send the machine to the tool change position prior to unclamping the tool and/or inserted directly into your exisitng M6 tool change macro.

For more detailed information on VB Script programming in Mach, please see http://www.machsupport.com. Reference material that you may find helpful include the Mach Wiki, http://www.machsupport.com/MachCustomizeWiki/ and The Macro Programmers Reference, http://www.machsupport.com/docs/Mach3_V ... og_Ref.pdf

For the purposes of this example the following I/O will be assumed:

Spindle Enable output is Output13, Unclamp Tool output is Output15
Tool Unclamped input is Input 14 and the state of UserLED #1000 reflects whether or not the the machine is at the tool change position.


1. Open the VB script editor in Mach ("Operator->VB Script Editor")

2. This will open a blank VB script
blankvb.gif
blankvb.gif (9.23 KiB) Viewed 5650 times
3.Declare a few variables to make the program easier to read:

Dim At_TC_Position As Integer 'used to store state of UserLED #1000
Dim Spindle_Is_Off As Integer 'used to store state of Output13
Dim Tool_Unclamped As Integer 'used to store state of Input14

4.Set variables = to current states of I/O

Machine_At_TC_Position = GetUserLED(1000) 'Get state of UserLED
Spindle_Is_Off = GetMasterOutput(13) 'Get state of Spindle Output

5. If Machine is at tool change position and spindle is off, turn on Tool Unclamp output.

If At_TC_Position And Spindle_Is_Off Then
SetMasterOutput(15, 1) 'Turn on Unclamp Tool Output15
End if

6. Wait until tool is unclamped before continuing

Sleep 100 'wait 100 milliseconds before checking Tool_Unclamped
While Not Tool_UnClamped
Sleep 10
Tool_Unclamped = GetMasterInput(14) 'Update Tool_Unclamped variable
Wend

7. Save the finished macro in c:\mach3\macros\mach3mill as M15.m1s
m15.gif
*All text/code following the ' character is treated as a comment and is ignored by the compiler/interpreter. As seen below, the VB Script Editor supplied with Mach displays all comments in green.
please no smoke
Posts: 103
Joined: Mon Mar 29, 2010 10:17 pm

Re: Writing Brains For Spindle and TC?

Post by please no smoke »

If I want to use the action of a modbus output as an input event to trigger something in brains, can I call it the same way (mod, output, bit only 0, gfc #0) or is that a modbus input? For example I want to look at mod:803 to see if it's a 0, or 1 for spindle direction?

I tried to terminate a lobe with a local variable V0. Can I do that. I want to use this variable to compare as an input in another brain?

I am using DRO "True Spindle RPM". Is this the speed given by mach? Can I use this to control my spindle?

Thanks
please no smoke
Posts: 103
Joined: Mon Mar 29, 2010 10:17 pm

Re: Writing Brains For Spindle and TC?

Post by please no smoke »

1. In brains if I write a lobe with input "Spindle On" LED, Invert flip signal, terminate with Mod:10. Will this keep MOD:10 from initializing when the spindle is on??

2. If I want to use a high mod output as an input can I just pass the signal or do I have to compare immediate =1????

Thanks
diycncscott

Re: Writing Brains For Spindle and TC?

Post by diycncscott »

Hello No Smoke,

I'm not sure what a "high mod output" is but yes, you can use any Ajax "modbus" output as an "input" for a rung in a Brain.

The inputs and outputs from 768-817 are mapped to the pendant so, unless you have a pendant (I didn't think you did), you won't want to use the I/O in that range. Well, technically you could write your own Brains to look at the LED's for spindle CW/CCW, auto/man etc... but I'd suggest reading the Ajax "modbus" spindle enable and direction outputs instead (read the state of the actual relays that turn on/off the spindle contactors)

I wouldn't use a "variable" in a Brain to test for or to represent an On or Off condition, use a UserLED (bit) instead. (See previous posts for examples)

Also, I'm in the process of writing a "Brains Vs. Macro" writeup that attempts to help clarify when to use a Brain and when to use a Macro to accomplish a task. In general, use a Brain when you want something to always act on a specific input or output and you are positive that no other Brains or Macros will also act on the I/O being acted on in that Brain. Use a Macro when the I/O is being acted on for a specific application or at a specific location in the G code program such as during a tool change. Although Brains and Macros can both conflict with both other Brains and Macros, Brains always act on I/O when enabled while Macros will only act on I/O when explicitly called by a program or button push, I'd suggest using Macros whenever possible to reduce the possibility of conflicts.

Please see the previous two posts in this topic to see the direction I'm taking for a tool changer. Although I've written the tutorials in a modular fashion using explicit Macros to accomplish different tasks, I expect that in the end most of the tool change functionality will be implemented in the M6 macro (or macros)
please no smoke
Posts: 103
Joined: Mon Mar 29, 2010 10:17 pm

Re: Writing Brains For Spindle and TC?

Post by please no smoke »

The macro code was helpful I think, but after fighting for weeks to get where I can kind of write a brain I don't want to spend another month to try and learn VB which I sucked at ten years ago. I have three brains written, that if I could get help with a few specific details would probably get my machine going. Without specific help or a good manual I am pissin in the wind at this point.

What will it take to get this stuff worked out? I guess I can pay you guys, right? It would realistically take 15 minutes of your time I think. This hit and miss tech eats up weeks, especially when you are out.

Let me know.

Thanks

Matt
diycncscott

Re: Writing Brains For Spindle and TC?

Post by diycncscott »

Matt,

I understand that you would rather not re-work what you have.

If you want move forward using your Brains, I'd again suggest replacing V0 with the actual spindle enable and/or direction outputs. Also, if you are going to use Brains to implement the majority of the functionality, I'd suggest using the M6 to at least set a UserLED that indicates when a tool change has been called (and reset when complete) this way your TC Brains can be interlocked to only act on the I/O when a tool change is being performed.

If you want us to write them, we can but it will take considerably more than 15 minutes... you're looking at a $375 minimum+ . Please keep in mind that this fee represents programming time, plus time for application definition (reviewing list of I/O, tool change sequence, required interlocks etc...)

You may also want to try the machsupport forums for advice at http://www.machsupport.com

Below, I have provided a link to Brains manual written by "poppabear" from the machsupport site. He is a Mach systems integrator that also provides fee based custom Brains development.
http://www.ajaxcnc.com/tech/downloads/m ... x_specific

Please ignore the sections on Modbus addressing -it doesn't apply to the Ajax system. All Ajax addressing is handled as I've previously described in this topic
please no smoke
Posts: 103
Joined: Mon Mar 29, 2010 10:17 pm

How do you set a user led in brains??

Post by please no smoke »

How do you set a user led in brains??
Locked