[Home]ClassicLadderExamples

EmcKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org

Search:

Here are some Classicladder examples and concept ideas.
Please note these programs were built using Classicladder version 7,100
and may need adjustment for version 7.124 ( EMC 2.3.X )
especially if using s32 input / output pins. or old timers

If you have a common/interesting ladder program please add it.
if you need help adding it or help creating a special ladder program
Contact me Chris Morley c/o the EMC users maillist-I'll try to help

1. Ladder samples
1.1. Basic ladder
1.2. Turret indexing counter
1.3. ATC tool changer program
1.4. Single button probe/touchoff
1.5. plasma torch control
2. Sequential samples
2.1. Stepper controller tool turret


1. Ladder samples


They may or may not be actually tested with hardware.

1.1. Basic ladder

Some basic concepts
The first line shows a latching output that uses momentary switches to turn it on and off. When the 'normally open' B1 contact is momentarily on, It allows 'power' to coil Q0. This in turn closes contact Q0, which jumps 'power' across the B1 contact essentially removing it's influence and 'latching' the output coil. To turn the coil off one must momentarily open the 'normally closed' B0 contact which supplies 'power' to the whole line.
If you are a logic kinda guy the line says If B0 is off AND either B1 OR Q0 is on then coil Q0 is on.
The second, third, and fourth line are examples of using variables in compare and operate elements. The second line starts with a 'rising-edge' contact, B2 which supplies 'power' to an operate element. A rising edge contact allows power thru it only as it changes from off to on. The operate block adds 1 to the current value in variable W0, then stores it back in variable W0. The third line uses a compare element to preform a math function 'modulus'. The element takes the number stored in W0 divides it by two then compares if the remainder is NOT equal to 0. It breaks down like this: %W0 is a variable, % means modulus, 2 is the number to divide, <> is NOT equal , 0 is the number we want to compare to. If the compare element is true (meaning the modulus of W0 is not = 0) then the Q1 coil is turned on. Using the modulus math, this line checks to see if the number stored in W0 is odd.The fourth line is essentially the same, though it uses the = sign and if the compare is true it will turn Q2 on. This line checks to see if W0 is even. If you programmed this ladder program and turned B2 on and off a bunch of times (by clicking on the B0 checkbox in the variable window) Q1 and Q2 would turn on and off alternately and if you displayed the signed variable window you would see the count of variable W0.
upload:EMC.clp.png

1.2. Turret indexing counter

This is a program for a tool turret.
The turret has a home switch at tool position 1 and another another switch to tell you when the turret is in a lockable position. To keep track of the actual tool number one must count how many positions past home you are. We will use Classicladder's counter block '$CO'.The counter is preset to 1 when RESET is true. The counter is increased by one on the rising edge of INDEX. We then 'COMPARE' the counter value (%C0.V) to the tool we want (in the example only checks for tool 1 and 2 are shown). We also 'OPERATE' the counter value to a word variable (%W0) that (you can assume) is mapped on to a S32 out HAL pin so you can let some other HAL component know what the current tool number is. In the real world another S32 (in) pin would be used to get the requested tool number from EMC.You would have to load Classicladder's realtime module specifying that you want S32 in and out pins. See 'loading options' above.
upload:counter_sample.png

1.3. ATC tool changer program

This program is being developed for a 16 toll ATC for a production milling machine
It actually moves the whole carousel of tools to the spindle to change the current tool.
<the process is like this:
1) tool change call- stop spindle, orientated for tool change.
2) move carousel horizontally to spindle and unclamp current tool. 3) move down and index to requested tool
4) move up and clamp requested tool
5) move horizontally away from spindle
here are the input/outputs
Ins
 
spindle orient complete
magazine in 
spindle unclamp
magazine down
magazine up
spindle clamped
magazine out
counter switch
tool 1 position switch(for homing purposes)
 
Outs
 
orient spindle
magazine in   (remove power and the magazine will move out)
unclamp spindle   (remove power and the spindle will clamp)
lower magazine    (remove power and the magazine will go up)
rotate magazine cw
rotate ccw

1.4. Single button probe/touchoff

This is a program to do tool probing / touch-off in MDI mode by pressing a single button
%I0 connects to a PYVCP button
%I1 connects to "halui.mode.is_mdi' pin
%I2 connects to 'motion.motion-inpos' pin
%Q0, %Q1, and %Q2 each connect to 'halui.mdi-command-XX' where XX is 00, 01, and 02 respectively.
upload:Touch_off.clp.png

In your ini file under [HALUI] you add MDI_COMMAND = G38.2 Z-3 F16 and MDI_COMMAND = G92 z .250 and MDI_COMMAND -G0 z 1
The logic goes like this when the PYVCP button is on and emc is in MDI mode and %B0 and %B1 are not on set %B0 output on. %B0 and %B1 outputs represent procedure steps.
Next line when B0 turns on a monostable holds the signal on for 500 ms which turns on Q0 (which connects to HALUI MDI command 0-G38.2 z-3 f16 -probe down in z at feed rate 16 till contact is made)
Next line: When %B0 is on (step 0 is active) and %I2 (in position signal-means probe is done.) goes off-to-on then set %B1 (step 1) on.
Next line: When %B1 is on, turn on a monostable for 500 ms that holds %Q1 on (%Q1 controls MDI command G92 .250 set offset so z = zero at the bottom of the .250 thick plate )also a timer is set to run.
When the timer is done use a monostable to hold %Q2 on for 500 ms (MDI command Go z 1 -rapid away from plate) and reset %B1 (step1 done)& %B0 (step0 done).
The timer is used to make sure the last rapid command is actually last-there isn't a pin to tell you when the G92 command has finished.
Here is a link to the thread http://www.cnczone.com/forums/showthread.php?t=62423 Below is what one user used for a touch-off plate. Here is the Video...http://www.youtube.com/watch?v=QYBAH6E8IZs
If used on EMC 2.3.X a pin name needs to be changed: moton.motion-inpos to motion.in-position
Also, The timer block has changed in 2.3. The block has 4 pins labled E,C,D,R. Pins C and E must be connected together as noted here: http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?UPDATING#Classicladder_changes
upload:touch_off.jpg

1.5. plasma torch control

This is the ladder program for the THC plasma config example in EMC2
It was created using Trunk from circa pre EMC 2.1/classicladder 7.100
(text and drawing snipped/borrowed from another wiki page)
see: http://wiki.linuxcnc.org/uploads/dallur-thc-design.txt for full txt
upload:dallur-classicladder.png
		There are 3 rungs in this ladder, the first one is the state-aware estop with external triggers, this circuit
		is just a slightly modified example from the classicladder example, see:
			http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Sample_HAL_And_ClassicLadder

		Rung 1
			The only difference from the example is the addition of B0 which is a signal to enable rung 3 to trigger an estop

		Rung 2 is used to control the LockPierceHeight? (Q7) and MoveZtoPierceHeight?(Q8), the first circuit is activated
			by the SpindleON/TorchON? (I5) request from the user or gcode, next we check if the FloatSwitch? is on because the
			only time we want to LockPierceHeight? and MoveZtoPierceHeight? is when the float switch has been triggered.
			If LockPierceHeight? is already active we know that the FloatSwitch? has been triggered since SpindleON/TorchON?(I5)
			was last set so we can bypass the FloatSwitch? (I3) check.
			However we only want to do this for the first time the FloatSwitch? is triggered so we put in a timer which is not
			reset until the I5 or I3 signals are reset with a bypass that retains the circuit for as long as MoveZtoPierceHeight? (Q8)
			is active, MoveZtoPierceHeight? is disconnected as soon as TorchIsAtPierceHeight? (I7) is true, TorchIsAtPierceHeight?
			is external to the ladder but it is a compare (comp) which is true if the CurrentPosition? is >= PierceHeight?.
			LockPierceHeight? (Q7) is set to active every time the circuit is activated, the second circuit then deactivates
			LockPierceHeight? (Q7) when ever SpindleON/TorchON? I5 is turned off.

				To recap, If TorchON? requested and FloatSwitch? Active or LockPierceHeight? active MoveZtoPierceHeight? 
				until TorchIsAtPierceHeight? then LockPierceHeight? stays active until TorchOFF? at which time it is tuned off.

		Rung 3 is used to control moveZtoFloat? (Q3), moveZtoSafe? (Q4), feed-hold (Q6) and turn_torch_on (Q5).
			The first circuit is used to determine if the mode is manual or auto, if automatic mode is on 
			it means we are running gcode and in that scenario we want to move the Z torch to a safe location
			when SpindleON/TorchON? (I5) is not being requested, the main purpose of this is to keep the torch safe when moving it
			around so it will not run into uneven surfaces.
			The second circuit is a bit complex due to the nature of the initialization sequence.

				Branch 1 
					If SpindleON/TorchON? (I5) is requested and ArcOK?(I4) activate feed-hold (Q6) until the PierceDelay?(I8)* timer is up.
					We want to hold the gcode execution until the pierce timer is elapsed and we have pierced through the material.

				Branch 2
					If SpindleON/TorchON? (I5) on requested and If ArcOK? is is false we activate feed-hold(Q6), reset moveZtoSafe? (Q4)
					to disable it, and activate moveZtoFloat? (Q3) until float-switch (I3) is on activated.
					If TorchIsAtPierceHeight? (I7) becomes true it will activate turn_torch_on (Q5) which will open up an alternative
					path so it will remain open until SpindleON/TorchON? (I5) turns off.

				Branch 3

					If SpindleON/TorchON? (I5) is requested and if turn_torch_on (Q5) is active we start a timer set by the 
					ArcStartTimeout?(I9)*, if at any point ArcOK?(I4) turns off after the time is up we activate B0 which 
					causes an ESTOp in Rung1.

				* Impossible to implement at this time due to limitations in classicladder, has to be edit manually in ladder

2. Sequential samples


2.1. Stepper controller tool turret

Here is a program for a turret controlled by a stepper motor
This example is not complete as it does not index to a specific tool -it only indexes to the next tool.The physical idea:The stepper motor turns the turret forward past the park spot then backs up against a stop. It uses HAL component STEPGEN to control a stepper motor to move the turret. This is the sequential program's flow chart. Step 1 is the start-it does nothing but waits. When a tool index request is called, %B0 will go true. That would make step 2 active, which tells the ladder program to signal STEPGEN to step forward and call subroutine # 0 ( SR0 ) which checks when STEPGEN is done . When that is done %B1 will be true bringing step 3 active. Step 3 tells ladder to signal STEPGEN to move backwards and calls subroutine # 0 ( SR0 ) which checks when STEPGEN is done . When that is done %B2 is true and control jumps to step 1 again.
upload:seq3.png
upload:seq1.png upload:seq2.png

These two panels show the main ladder program the one on the left sends the signals (through HAL s32 pins ) to STEPGEN for forward and backward depending on which sequential step is active.
The %X bit inputs tell you when a step is active or not.The tool number is output to a word memory variable 'TOOL#' ( %W11 ). The %B10 switch is a momentary switch to start the index process.
The one on the right shows a counter to keep track of the current tool number. When the tool number = 4 the counter is reset to 0 again (so tool numbers are 0-3)

upload:seq4.png upload:seq5.png

On the left is the subroutine. This checks to see if the commanded move is the same as the current position, if it is then sets the temporary holding register to the current position and finally lets the next step become active depending on what step was currently active.
On the right is the signed integers window, showing the current, commanded , hold register and the current tool number. The 'current' position is imported from STEPGEN through a s32 input pin. The 'commanded' is exported through a s32 out pin which is converted to a float signal and sent to STEPGEN. The 'hold register' and 'tool number' are held in temporary internal memory.

upload:seq6.png upload:seq7.png

On the left shows how I filled out the SYMBOLS window to get named variables. It also shows the HAL signals connected to them.
On The right shows the HAL file used to test this program which didn't use EMC . One thing to Note was that STEPGEN's commanded position information is on a FLOAT pin and Classicladder cannot write (or read) them, so it has to be converted first, using HAL's conv_s32_float component.


EmcKnowledgeBase | RecentChanges | PageIndex | Preferences | LinuxCNC.org
This page is read-only. Follow the BasicSteps to edit pages. | View other revisions
Last edited July 1, 2009 2:12 pm by Chester (diff)Published under a Creative Commons License