summaryrefslogtreecommitdiff
path: root/docs/src/ladder/ladder_examples_es.txt
blob: c1f2bdb068492820c015c9308e844062d950615d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
= Classicladder Examples

[[cha:classicladder-examples]] (((Classicladder Examples)))

////
ATTENTION TRANSLATORS before translating this document copy the base document
into this copy to get the latest version. Untranslated documents are not kept
up to date with the English documents. 

Do not translate anchors or links, translate only the text of a link after the
comma.
Anchor [[anchor-name]]
Link <<anchor-name,text after the comma can be translated>>

Make sure the documents build after translating.
////

== Wrapping Counter

To have a counter that 'wraps around' you have to use the preset pin
and the reset pin. When you create the counter set the preset at the
number you wish to reach before wrapping around to 0. The logic is if
the counter value is over the preset then reset the counter and if the
underflow is on then set the counter value to the preset value. As you
can see in the example when the counter value is greater than the
counter preset the counter reset is triggered and the value is now 0.
The underflow output %Q2 will set the counter value at the preset when
counting backwards.

.Wrapping Counter[[fig:Wrapping-Counter]]

image::images/wrapping-counter.png[align="center"]

== Reject Extra Pulses

This example shows you how to reject extra pulses from an input.
Suppose the input pulse %I0 has an annoying habit of giving an extra
pulse that spoils our logic. The TOF (Timer Off Delay) prevents the
extra pulse from reaching our cleaned up output %Q0. How this works is
when the timer gets an input the output of the timer is on for the
duration of the time setting. Using a normally closed contact %TM0.Q
the output of the timer blocks any further inputs from reaching our
output until it times out.

.Reject Extra Pulse[[fig:Reject-Extra-Pulse]]

image::images/extra-pulse-reject.png[align="center"]

== External E-Stop

The External E-Stop example is in the /config/classicladder/cl-estop
folder. It uses a pyVCP panel to simulate the external components.

To interface an external E-Stop to LinuxCNC and have the external E-Stop
work together with the internal E-Stop requires a couple of connections
through Classic Ladder.

First we have to open the E-Stop loop in the main HAL file by
commenting out by adding the pound sign as shown or removing the
following lines.

----
# net estop-out <= iocontrol.0.user-enable-out 
# net estop-out => iocontrol.0.emc-enable-in
----

Next we add Classic Ladder to our custom.hal file by adding these two
lines:

----
loadrt classicladder_rt 
addf classicladder.0.refresh servo-thread
----

Next we run our config and build the ladder as shown here.

.E-Stop Section Display[[cap:E-Stop-Section-Display]]

image::images/EStop_Section_Display.png[align="center"]

After building the ladder select Save As and save the ladder as
estop.clp

Now add the following line to your custom.hal file.

----
# Load the ladder 
loadusr classicladder --nogui estop.clp
----

I/O assignments

 - %I0 = Input from the pyVCP panel simulated E-Stop (the checkbox)
 - %I1 = Input from LinuxCNC's E-Stop
 - %I2 = Input from LinuxCNC's E-Stop Reset Pulse
 - %I3 = Input from the pyVCP panel reset button
 - %Q0 = Ouput to LinuxCNC to enable
 - %Q1 = Output to external driver board enable pin (use a N/C output if
   your board had a disable pin)

Next we add the following lines to the custom_postgui.hal file

----
# E-Stop example using pyVCP buttons to simulate external components

# The pyVCP checkbutton simulates a normally closed external E-Stop 
net ext-estop classicladder.0.in-00 <= pyvcp.py-estop

# Request E-Stop Enable from LinuxCNC 
net estop-all-ok iocontrol.0.emc-enable-in <= classicladder.0.out-00

# Request E-Stop Enable from pyVCP or external source 
net ext-estop-reset classicladder.0.in-03 <= pyvcp.py-reset

# This line resets the E-Stop from LinuxCNC 
 net emc-reset-estop iocontrol.0.user-request-enable =>
classicladder.0.in-02

# This line enables LinuxCNC to unlatch the E-Stop in Classic Ladder 
net emc-estop iocontrol.0.user-enable-out => classicladder.0.in-01

# This line turns on the green indicator when out of E-Stop 
net estop-all-ok => pyvcp.py-es-status
----

Next we add the following lines to the panel.xml file. Note you have
to open it with the text editor not the default html viewer.

[source,xml]
----
<pyvcp> 
<vbox> 
<label><text>"E-Stop Demo"</text></label> 
<led> 
<halpin>"py-es-status"</halpin> 
<size>50</size> 
<on_color>"green"</on_color> 
<off_color>"red"</off_color> 
</led> 
<checkbutton> 
<halpin>"py-estop"</halpin> 
<text>"E-Stop"</text> 
</checkbutton> 
</vbox> 
<button> 
<halpin>"py-reset"</halpin> 
<text>"Reset"</text> 
</button> 
</pyvcp>
----

Now start up your config and it should look like this.

.AXIS E-Stop[[cap:AXIS-E-Stop]]

image::images/axis_cl-estop.png[align="center"]

Note that in this example like in real life you must clear the remote
E-Stop (simulated by the checkbox) before the AXIS E-Stop or the
external Reset will put you in OFF mode. If the E-Stop in the AXIS
screen was pressed, you must press it again to clear it. You cannot
reset from the external after you do an E-Stop in AXIS.

== Timer/Operate Example

In this example we are using the Operate block to assign a value to
the timer preset based on if an input is on or off.

.Timer/Operate Example[[cap:Timer/Operate-Example]]

image::images/Tmr_Section_Display.png[align="center"]

In this case %I0 is true so the timer preset value is 10. If %I0 was
false the timer preset would be 5.

///////////////////////////////////////////////////////////////////////////////
== Tool Turret

 - This Example is not complete yet.

This is a program for one type of tool turret. The turret has a home
switch at tool position 1 and 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
Classic Ladder'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 number
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 LinuxCNC.You would have to load Classic Ladder's real time module
specifying that you want s32 in and out pins. See 'loading options'
above. [display turret sample]

== Sequential Example

 - This Example is not complete yet.

This is a sequential program.
When the program is first started step one is active.
Then when %B0 is true, steps 2 and 3 are then active
and step one is inactive.
Then when %B1 and/or %B2 are true, step 4 and/or 5
are active and step 2 and/or 3 are inactive.
Then when either %B3 OR %B4 are true, step 6 is true and
steps 4 and 5 are inactive.
Then when %B5 is true step 1 is active and step 6 is
inactive and it all starts again. 

As shown, the sequence has been:
%B0 was true making step 2 and 3 active, then %B1 became true
(and still is-see the pink line through %B1)
making step 4 active and step 2 inactive.
Step 3 is active and waiting for %B2 to be true.
Step 4 is active and is waiting for %B3 to be true.
WOW, that was quite a mouthful!!
///////////////////////////////////////////////////////////////////////////////