/ docs / src / ladder / ladder_examples_fr.txt
ladder_examples_fr.txt
  1  == Ladder Examples 
  2  
  3  [[cha:classicladder-examples]]
  4  
  5  === Wrapping Counter
  6  
  7  To have a counter that "wraps around" you have to use the preset pin
  8  and the reset pin. When you create the counter set the preset at the
  9  number you wish to reach before wrapping around to 0. The logic is if
 10  the counter value is over the preset then reset the counter and if the
 11  underflow is on then set the counter value to the preset value. As you
 12  can see in the example when the counter value is greater than the
 13  counter preset the counter reset is triggered and the value is now 0.
 14  The underflow output %Q2 will set the counter value at the preset when
 15  counting backwards.
 16  
 17  .Wrapping Counter[[fig:Wrapping-Counter]]
 18  
 19  image::images/wrapping-counter.png[alt="Wrapping Counter"]
 20  
 21  === Reject Extra Pulses
 22  
 23  This example shows you how to reject extra pulses from an input.
 24  Suppose the input pulse %I0 has an annoying habit of giving an extra
 25  pulse that spoils our logic. The TOF (Timer Off Delay) prevents the
 26  extra pulse from reaching our cleaned up output %Q0. How this works is
 27  when the timer gets an input the output of the timer is on for the
 28  duration of the time setting. Using a normally closed contact %TM0.Q
 29  the output of the timer blocks any further inputs from reaching our
 30  output until it times out.
 31  
 32  .Reject Extra Pulse[[fig:Reject-Extra-Pulse]]
 33  
 34  image::images/extra-pulse-reject.png[alt="Reject Extra Pulse"]
 35  
 36  === External E-Stop
 37  
 38  The External E-Stop example is in the /config/classicladder/cl-estop
 39  folder. It uses a pyVCP panel to simulate the external components.
 40  
 41  To interface an external E-Stop to LinuxCNC and have the external E-Stop
 42  work together with the internal E-Stop requires a couple of connections
 43  through Classic Ladder.
 44  
 45  First we have to open the E-Stop loop in the main HAL file by
 46  commenting out by adding the pound sign as shown or removing the
 47  following lines.
 48  
 49      # net estop-out <= iocontrol.0.user-enable-out 
 50      # net estop-out => iocontrol.0.emc-enable-in
 51  
 52  Next we add Classic Ladder to our custom.hal file by adding these two
 53  lines:
 54  
 55      loadrt classicladder_rt 
 56      addf classicladder.0.refresh servo-thread
 57  
 58  Next we run our config and build the ladder as shown here.
 59  
 60  .E-Stop Section Display[[cap:E-Stop-Section-Display]]
 61  
 62  image::images/EStop_Section_Display.png[alt="E-Stop Section Display"]
 63  
 64  After building the ladder select Save As and save the ladder as
 65  estop.clp
 66  
 67  Now add the following line to your custom.hal file.
 68  
 69      # Load the ladder 
 70      loadusr classicladder --nogui estop.clp
 71  
 72  I/O assignments
 73  
 74   - %I0 = Input from the pyVCP panel simulated E-Stop (the checkbox)
 75   - %I1 = Input from LinuxCNC's E-Stop
 76   - %I2 = Input from LinuxCNC's E-Stop Reset Pulse
 77   - %I3 = Input from the pyVCP panel reset button
 78   - %Q0 = Ouput to LinuxCNC to enable
 79   - %Q1 = Output to external driver board enable pin (use a N/C output if
 80     your board had a disable pin)
 81  
 82  Next we add the following lines to the custom_postgui.hal file
 83  
 84      # E-Stop example using pyVCP buttons to simulate external components
 85  
 86      # The pyVCP checkbutton simulates a normally closed external E-Stop 
 87      net ext-estop classicladder.0.in-00 <= pyvcp.py-estop
 88  
 89      # Request E-Stop Enable from LinuxCNC 
 90      net estop-all-ok iocontrol.0.emc-enable-in <= classicladder.0.out-00
 91  
 92      # Request E-Stop Enable from pyVCP or external source 
 93      net ext-estop-reset classicladder.0.in-03 <= pyvcp.py-reset
 94  
 95      # This line resets the E-Stop from LinuxCNC 
 96       net emc-reset-estop iocontrol.0.user-request-enable =>
 97      classicladder.0.in-02
 98  
 99      # This line enables LinuxCNC to unlatch the E-Stop in Classic Ladder 
100      net emc-estop iocontrol.0.user-enable-out => classicladder.0.in-01
101  
102      # This line turns on the green indicator when out of E-Stop 
103      net estop-all-ok => pyvcp.py-es-status
104  
105  Next we add the following lines to the panel.xml file. Note you have
106  to open it with the text editor not the default html viewer.
107  
108  [source,xml]
109  -------------------------------------------------
110      <pyvcp> 
111      <vbox> 
112      <label><text>"E-Stop Demo"</text></label> 
113      <led> 
114      <halpin>"py-es-status"</halpin> 
115      <size>50</size> 
116      <on_color>"green"</on_color> 
117      <off_color>"red"</off_color> 
118      </led> 
119      <checkbutton> 
120      <halpin>"py-estop"</halpin> 
121      <text>"E-Stop"</text> 
122      </checkbutton> 
123      </vbox> 
124      <button> 
125      <halpin>"py-reset"</halpin> 
126      <text>"Reset"</text> 
127      </button> 
128      </pyvcp>
129  -------------------------------------------------
130  
131  Now start up your config and it should look like this.
132  
133  .AXIS E-Stop[[cap:AXIS-E-Stop]]
134  
135  image::images/axis_cl-estop.png[alt="AXIS E-Stop"]
136  
137  Note that in this example like in real life you must clear the remote
138  E-Stop (simulated by the checkbox) before the AXIS E-Stop or the
139  external Reset will put you in OFF mode. If the E-Stop in the AXIS
140  screen was pressed, you must press it again to clear it. You cannot
141  reset from the external after you do an E-Stop in AXIS.
142  
143  === Timer/Operate Example
144  
145  In this example we are using the Operate block to assign a value to
146  the timer preset based on if an input is on or off.
147  
148  .Timer/Operate Example[[cap:Timer/Operate-Example]]
149  
150  image::images/Tmr_Section_Display.png[alt="Timer/Operate Example"]
151  
152  In this case %I0 is true so the timer preset value is 10. If %I0 was
153  false the timer preset would be 5.
154  
155  === Tool Turret
156  
157   - This Example is not complete yet.
158  
159  This is a program for one type of tool turret. The turret has a home
160  switch at tool position 1 and another switch to tell you when the
161  turret is in a lockable position. To keep track of the actual tool
162  number one must count how many positions past home you are. We will use
163  Classic Ladder's counter block '$CO'.The counter is preset to 1 when
164  RESET is true. The counter is increased by one on the rising edge of
165  INDEX. We then 'COMPARE' the counter value (%C0.V) to the tool number
166  we want (in the example only checks for tool 1 and 2 are shown). We
167  also 'OPERATE' the counter value to a word variable (%W0) that (you can
168  assume) is mapped on to a s32 out HAL pin so you can let some other HAL
169  component know what the current tool number is. In the real world
170  another s32 (in) pin would be used to get the requested tool number
171  from LinuxCNC.You would have to load Classic Ladder's real time module
172  specifying that you want s32 in and out pins. See 'loading options'
173  above. [display turret sample]
174  
175  === Sequential Example
176  
177   - This Example is not complete yet.
178  
179  This is a sequential program. +
180  When the program is first started step one is active. +
181  Then when %B0 is true, steps 2 and 3 are then active and step one is inactive. +
182  Then when %B1 and/or %B2 are true, step 4 and/or 5 are active and step 2 and/or 3 are inactive. +
183  Then when either %B3 OR %B4 are true, step 6 is true and steps 4 and 5 are inactive. +
184  Then when %B5 is true step 1 is active and step 6 is inactive and it all starts again. 
185  
186  As shown, the sequence has been: +
187  %B0 was true making step 2 and 3 active, then %B1 became true +
188  (and still is-see the pink line through %B1) +
189  making step 4 active and step 2 inactive. +
190  Step 3 is active and waiting for %B2 to be true. +
191  Step 4 is active and is waiting for %B3 to be true. +
192  WOW, that was quite a mouthful!! +
193  
194