NEWS
emc2_2.2.6 Release
A fresh bugfix release (2.2.6) - (Changelog).
You can get it: as a source package from sourceforge , from CVS , or as a precompiled package which works on Ubuntu as described here.
 
Ubuntu 8.04&EMC2 Live CD
The EMC2 team now has a brand new custom Live-CD (EU mirror) based on Ubuntu 8.04 with emc 2.2.x included, that will let you try out EMC2 before installing, and it's also the easiest way to install Ubuntu and EMC2 together. (more)
 
emc2_2.2.5 Release
A fresh bugfix release (2.2.5) - (Changelog).
You can get it: as a source package from sourceforge , from CVS , or as a precompiled package which works on Ubuntu as described here.
 
Language
Site Search
Google
Web LinuxCNC
Polls
EMC Version you are using
 
What type of machine do you run with EMC? Vote once for each machine
 

Table of Contents

List of figures

  • ClassicLadder Var window
  • ClassicLadder Section Display window
  • ClassicLadder Section Manager window
  • ClassicLadder Editor window

List of tables

  • ClassicLadder realtime component options

1 ClassicLadder

1.1 Introduction

ClassicLadder is a free implementation of a ladder interpreter, released under the LGPL. It has been written by Marc Le Douarain.

He describes the beginning of the project on his website:

“I decided to program a ladder language only for test purposes at the start, in february 2001. It was planned, that I would have to participate to a new product after leaving the enterprise in which I was working at that time. And I was thinking that to have a ladder language in thoses products could be a nice option to considerate. And so I started to code the first lines for calculating a rung with minimal elements and displaying dynamically it under Gtk, to see if my first idea to realise all this works.

And as quickly I've found that it advanced quite well, I've continued with more complex elements : timer, multiples rungs, etc...

Voila, here is this work... and more : I've continued to add features since then.”

ClassicLadder has been adapted to work with emc2's HAL, and is currently beeing distributed along with emc2. If there are issues/problems/bugs please report them to the Enhanced Machine Controller project.

1.2 Languages

The most common language used when working with ClassicLadder is 'ladder'. ClassicLadder allows one to use other variants (like sequential function chart - Grafcet) too, however those aren't covered by the current documentation.

In the next chapters the main components of ClassicLadder will be described.

1.3 Starting ClassicLadder

There are 2 components belonging to ClassicLadder: a realtime part, and a userspace part (along with a GUI).

1.3.1 Loading the ClassicLadder realtime module

Loading the ClassicLadder realtime module (classicladder_rt) is possible from a halfile, or directly using a halcmd instruction.

It is possible to configure the number of each ladder object while loading the classicladder realtime module

Object name: variable name: Default value:
Number of rungs (numRungs) 100
Number of bits (numBits) 500
Number of word variables (numWords) 100
Number of timers (numTimers) 10
Number of monostables (numMonostables) 10
Number of counters (numCounters) 10
Number of hal inputs bit pins (numPhysInputs) 15
Number of hal output bit pins (numPhysOuputs) 15
Number of arithmetic expressions (numArithmExpr) 50
Number of sections (numSections) 10
Number of symbols (numSymbols) 100
Number of S32 inputs (numS32in) 0
Number of S32 outputs (numS32out) 0
Table: ClassicLadder realtime component options

If you do not configure the number of ladder objects classicladder will use the default values. Objects of most interest are numPhysInputs and numPhysOutputs.

Changing these numbers will change the number of HAL bit pins available.

For example:

loadrt classicladder_rt numRungs=12 numBits=100 numWords=10 numTimers=10 
numMonostables=10 numCounters=10 numPhysInputs=10 numPhysOutputs=10
numArithmExpr=100 numSections=4 numSymbols=200

1.3.2 Loading the ClassicLadder user module

There are options while loading the user module:

  • --help \menuseparator displays basically this list then exits
  • --version \menuseparator displays the... version ...surprise!! then exits
  • --nogui \menuseparator starts classicladder (while loading a ladder program if specified) with no GUI.
  • --modbus_port=port \menuseparator sets up the modbus port number (EMC doesn't use it)
  • --config=file \menuseparator sets up the number of the each ladder object ( only if there is no realtime support.In EMC you load this with the realtime module-I'll get to this in a minute)

Unfortunately as of EMC 2.1.x, --version and --help do not exit HAL properly. Really only --nogui is any use to you. Use the GUI when setting up your system then change it to --nogui when running. The only other thing you can do while loading the user module is specify a ladder program to load. ladder programs are specified by the .clp ending.

for examples:

  • loadusr -w classicladder --nogui myladder.clp

    loads the classicladder user module, ladder program myladder and displays nothing.

  • loadusr -w classicladder myladder.clp

    loads the classicladder user module, ladder program myladder and starts the classicladder GUI.

  • loadusr -w classicladder

    loads the classicladder user module, starts the GUI but loads no laddder program.

*** you can only use this after loading a ladder program previously ***

1.4 ClassicLadder GUI

If you load classicladder with the GUI it will display three windows: vars, section display, and section manager.

1.4.1 The Variables window

It displays some of the variable data and variable names. Notice all variable start with the % sign.

The three edit areas at the top allow you to select what 15 variable will be displayed in each column. For instance if there were 30 %I variable and you entered 10 at the top of the column, variable %I10 to %I25 would be displayed.

The check boxes allow you to set and un set variables but when classicladder is running hal will update the pins and change them.

Near the bottom are the %W variables. These are called word variable and represent positive and negative (signed) numbers and are used with compare and operate. By clicking on the variable, you can edit the number to display which ever you want.The edit box beside it is the number stored in the variable -you can change it- and the drop-down box beside that allow you to choose whether the number to be displayed is in hex, decimal or binary.

The %I variable represents HAL input bit pins. The %Q represents the relay coil and HAL output bit pins. The %B represents an internal relay coil or internal contact.

There is a quirk that the word variables list will not display the symbols unless the check-box in the section manager is checked and you miss-edit the coresponding variable. Meaning erase the numbers after the %W and press return-if there is a symbol for that number you erased and the display symbols check-box in the section display is checked it will show it.

Figure: ClassicLadder Var window

1.4.2 The Section Display window

Most of the buttons are self explanitory:

The config button is not used in EMC.

The symbols button will display an editable list of symbols for the variables (eg you can name the inputs, outputs, coils etc).

The quit button will only shut down the display-the ladder program will still run in the back ground.

The check box at the top right allows you to select whether variable names or symbol names are displayed

Figure: ClassicLadder Section Display window

1.4.3 The Section Manager window

This window allows you to name, create or delete sections. This is also how you name a subroutine for call coils.

Figure: ClassicLadder Section Manager window

1.4.4 The Editor window

Starting from the top left image:

  1. SELECTOR ARROW, ERASER
  2. N.O., N.C. , RISING-EDGE ,FALLING-EDGE CONTACTS.
  3. HORIZONTAL, VERTICAL , HORIZONTAL RUNNING-CONNECTIONS
  4. TIMER, MONOSTABLE, COUNTER, COMPARE
  5. N.O. COIL, N.C. COIL, SET COIL, RESET COIL
  6. JUMP COIL, CALL COIL, OPERATE

Figure: ClassicLadder Editor window

A short description of each of the buttons:

  • The SELECTOR ARROW button allows you to select existing objects and modify the information.
  • The ERASER erases an object.
  • The N.O. CONTACT is a normally open contact. It can be an extenal HAL-pin (%I) input contact, an internal-bit coil (%B) contact or a external coil (%Q) contact. The Hal-pin input contact is closed when the HAL-pin is true. The coil contacts are closed when the coresponding coil is active (%Q2 contact closes when %Q2 coil is active).
  • The N.C. CONTACT is a normally closed contact. It is the same as the n.o. contact except that the contact is open when the hal-pin is true or the coil is active.
  • The RISING-EDGE CONTACT is a contact that is closed when the HAL-pin goes from False to true, or the coil from not-active to active.
  • The FALLING-EDGE CONTACT is a contact that is closed when the HAL-pin goes from true to false or the coil from active to not.
  • The HORIZONTAL CONNECTION connects the 'signal' to objects horizontally.
  • The VERTICAL CONNECTION connects the 'signal' to objects vertically.
  • The HORIZONTAL-RUNNING CONNECTION is a quick way to connect a long run of 'signal wire' horizontally.
  • The TIMER is a Timer Module.
  • The MONOSTABLE is monostable module (one-shot)
  • The COUNTER is a counter module.
  • The COMPARE button allows you to compare variable to values or other variables. (eg %W1<=5 or %W1=%W2)
    The variable you can use are: W-words,T-timers,M-monostables,C-counters,X-sequential and their attributes D-done, E-empty, F-full, P-preset, R-running, and V-value (not all atributes are available to all variables) eg %T2.D.
    The math symbols are +,-,*,/,=,<,>,<=,>=,(,),^ (exponent),% (modulas),& (and),| (or),! (not).
    Math function are ABS (absolute), MOY (average). eg ABS(%W2)=1, MOY(%W1,%W2)<3 .
    Compare cannot be placed in the right most side of the section display.
  • The OPERATE button allows you to assign values to variables. (eg %W2=7 or %W1=%W2) there are two math funtions MINI and MAXI that check a variable for maximum (0x80000000) and minimum values (0x05FFFFFFF) (think signed values) and keeps them from going beyond.
    You may use all the math symbols and functions from above. OPERATE funtions can only be placed at the right most side of the section display.

1.5 ClassicLadder Variables

List of known variables :

Bxxx
: Bit memory xxx (boolean)
Wxxx
: Word memory xxx (32 bits integer)
Txx,R
: Timer xx running (boolean, user read only)
Txx,D
: Timer xx done (boolean, user read only)
Txx,V
: Timer xx current value (integer, user read only)
Txx,P
: Timer xx preset (integer)
Mxx,R
: Monostable xx running (boolean)
Mxx,V
: Monostable xx current value (integer, user read only)
Mxx,P
: Monostable xx preset (integer)
Cxx,D
: Counter xx done (boolean, user read only)
Cxx,E
: Counter xx empty overflow (boolean, user read only)
Cxx,F
: Counter xx full overflow (boolean, user read only)
Cxx,V
: Counter xx current value (integer, user read only)
Cxx,P
: Counter xx preset (integer)
Ixxx
: Physical input xxx (boolean) - HAL input bit -
Qxxx
: Physical output xxx (boolean) - HAL output bit -
Xxxx
: Activity of step xxx (sequential language)
Xxxx,V
: Time of activity in seconds of step xxx (sequential language)

1.6 Using JUMP COILs

JUMP COILs are used to 'JUMP' to another section-like a goto in BASIC programming language.

If you look at the top left of the sections display window you will see a small lable box and a longer comment box beside it. Now go to Editor->Modify then go back to the little box, type in a name.

Go ahead and add a comment in the comment section. This lable name is the name of this rung only and is used by the JUMP COIL to identify where to go.

When placing a JUMP COIL add it in the right most position and change the lable to the rung you want to JUMP to.

JUMP COILs should be placed as the last coil of a rung because of a bug. If there are coils after the JUMP COIL (in the same rung) they will be updated even if the JUMP COIL is true.1

1.7 Using CALL COILs

CALL COILs are used to go to a subroutine section then return-like a gosub in BASIC programming language.

If you go to the sections manager window hit the add section button. You can name this section, select what language it will use (ladder or sequential), and select what type (main or subroutine).

Select a subroutine number (SR0 for exampe). An empty section will be displayed and you can build your subroutine.

When your done that, go back to the section manager and click on the your 'main' section (default name prog1).

Now you can add a CALL COIL to your program. CALL COILs are to be placed at the right most position in the rung.

Remember to change the lable to the subroutine number you choose before.

There can only be one CALL COIL per rung-the rest wil not be called.

Index

Footnotes

1   If the JUMP COIL is true it should JUMP to the new rung right away and not update the rest of the coils of the current rung back

© 2008 LinuxCNC.org
Joomla! is Free Software released under the GNU/GPL License.