• No results found

Operating Safety Precautions

Chapter 1 KAREL LANGUAGE OVERVIEW

1.2 KAREL PROGRAMMING LANGUAGE

1.2.1 Overview

A KAREL program is made up of declarations and executable statements stored in a source code file.

The variable data values associated with a program are stored in a variable file.

MARRC75KR07091E Rev H 1. KAREL LANGUAGE OVERVIEW

KAREL programs are created and edited using ROBOGUIDE’s Advanced Development Tools, or another editor such as Word Pad.

The KAREL language translator turns the source code into an internal format called p-code and generates a p-code file. The translator is provided with ROBOGUIDE’s Advanced Development Tools. After being translated, the resulting p-code program can be loaded onto the controller using the KAREL Command Language (KCL) or the FILE menu.

During loading, the system will create any required variables that are not in RAM and set them uninitialized. When you run the program, the KAREL interpreter executes the loaded p-code instructions.

A KAREL program is composed of the program logic and the program data. Program logic defines a sequence of steps to be taken to perform a specific task. Program data is the task-related information that the program logic uses. In KAREL the program logic is separate from the program data.

Program logic is defined by KAREL executable statements between the BEGIN and the END statements in a KAREL program. Program data includes variables that are identified in the VAR declaration section of a KAREL program by name, data type and storage area in RAM.

Values for program data can be taught using the teach pendant to jog the robot, computed by the program, read from data files, set from within the CRT/KB or teach pendant menu structure, or accepted as input to the program during execution. The data values can change from one execution to the next, but the same program logic is used to manipulate the data.

Program logic and program data are separate in a KAREL program for the following reasons:

To allow data to be referenced from several places in the same program

To allow more than one program to reference or share the same data

To allow a program to use alternative data

To facilitate the building of data files by an off-line computer-aided design (CAD) system The executable section of the program contains the data manipulation statements, I/O statements, and routine calls.

The program development cycle is described briefly in the following list. Section 1.2.2-Section 1.2.6that follow provide details on each phase.

Create a program source code file

Translate the program file.

Load the program logic and data.

Execute the program.

Maintain the execution history of the program.

1. KAREL LANGUAGE OVERVIEW MARRC75KR07091E Rev H

A log or history of programs that have been executed is maintained by the controller and can be viewed.

1.2.2 Creating a Program

You can create a KAREL program using the editor provided with ROBOGUIDE’s Advanced Development Tools, or any text editor such as WordPad. The resulting file is called the source file or source code.

1.2.3 Translating a Program

KAREL source files must be translated into internal code, called p-code, before they are executed.

The KAREL language translator performs this function and also checks for errors in the source code.

The KAREL language translator starts at the first line of the source code and continues until it encounters an error or translates the program successfully. If an error is encountered, the translator tries to continue checking the program, but no p-code will be generated.

You can invoke the translator from within a ROBOGUIDE workcell or using the KTRANS command utility, and the source code you were editing will be translated. After a successful translation, the translator displays a successful translation message and creates a p-code file. The p-code file will use the source code file name and a .pc file type. This file contains an internal representation of the source code and information the system needs to link the program to variable data and routines.

If you invoke the translator from within a ROBOGUIDE workcell and no errors are detected, the resulting p-code will automatically be loaded on the virtual controller.

If the translator detects any errors, it displays the error messages and the source lines that were being translated. After you have corrected the errors, you can translate the program again.

1.2.4 Loading Program Logic and Data

Note For R-30iB and R-30iB Mate controllers, the KAREL option must be installed on the robot controller in order to load KAREL programs.

The p-code for a program is loaded onto a controller where it can be executed. When a program is

MARRC75KR07091E Rev H 1. KAREL LANGUAGE OVERVIEW

variable data table contains the program identifier, all of the variable identifiers, and the name of the storage area in RAM where the variables are located.

Loading a program also establishes the links between statements and variables. Initially, the values in the variable data table will be uninitialized. If a variable file (.vr) is loaded successfully, the values of any variables will be stored in the variable data storage area (CMOS, DRAM, SHADOW).

Multiple programs are often used to break a large application or problem into smaller pieces that can be developed and tested separately. The KAREL system permits loading of multiple programs. Each program that is loaded has its own p-code structure.

Variable data can be shared among multiple programs. In this case, the KAREL language FROM clause must be specified in the VAR declaration so that the system can perform the link when the program is loaded. This saves the storage required to include multiple copies of the data.

The following limits apply to the number and size of KAREL programs that can be loaded:

Number of programs is limited to 2704 or available RAM.

Number of variables per program is limited to 2704 or available RAM.

1.2.5 Executing a Program

After you have selected a program from the program list and the p-code and variable files are loaded into RAM, test and debug the program to make sure that it operates as intended.

Program execution begins at the first executable line. A stack of 300 words is allocated unless you specify a stack size. The stack is allocated from available user RAM. Stack usage is described inSection 5.1.6.

1.2.6 Execution History

Each time a program is executed, a log of the nested routines and the line numbers that have been executed can be displayed from KCL with the SHOW HISTORY command.

This is useful when a program has paused or been aborted unexpectedly. Execution history displays the sequence of events that led to the disruption.

1.2.7 Program Structure

A KAREL program is composed of declaration and executable sections made up of KAREL language statements, as shown inStructure of a KAREL Program.

1. KAREL LANGUAGE OVERVIEW MARRC75KR07091E Rev H

Structure of a KAREL Program PROGRAM prog_name

Translator Directives

CONST, TYPE, and/or VAR Declarations ROUTINE Declarations

BEGIN

Executable Statements END prog_name

ROUTINE Declarations

InStructure of a KAREL Program, the words shown in uppercase letters are KAREL reserved words, which have dedicated meanings. PROGRAM, CONST, TYPE, VAR, and ROUTINE indicate declaration sections of the program. BEGIN and END mark the executable section. Reserved words are described inSection 2.1.3.

The PROGRAM statement, which identifies the program, must be the first statement in any KAREL program. The PROGRAM statement consists of the reserved word PROGRAM and an identifier of your choice (prog_name inStructure of a KAREL Program). Identifiers are described inSection 2.1.4.

NoteYour program must reside in a file. The file can, but does not have to, have the same name as the program. This distinction is important because you invoke the translator and load programs with the name of the file containing your program, but you initiate execution of the program and clear the program with the program name.

For example, if a program named mover was contained in a file named transfer , you would reference the file by transfer to translate it, but would use the program name mover to execute the program.

If both the program and the file were named mover , you could use mover to translate the file and also to execute the program.

A task is created to execute the program and the task name is the name of the program you initiate.

The program can call a routine in another program, but the task name does not change.

The identifier used to name the program cannot be used in the program for any other purpose, such as to identify a variable or constant.

The CONST (constant), TYPE (type), and VAR (variable) declaration sections come after the PROGRAM statement. A program can contain any number of CONST, TYPE, and VAR sections.

Each section can also contain any number of individual declaration statements. Also, multiple CONST, TYPE, and VAR sections can appear in any order. The number of CONST, TYPE, and VAR sections, and declaration statements are limited only by the amount of memory available.

ROUTINE declarations can follow the CONST, TYPE, and VAR sections. Each routine begins with the reserved word ROUTINE and is similar in syntax to a program. ROUTINE declarations can also

MARRC75KR07091E Rev H 1. KAREL LANGUAGE OVERVIEW

The executable section must be marked by BEGIN at the beginning and END, followed by the program identifier (prog_name inStructure of a KAREL Program), at the end. The same program identifier must be used in the END statement as in the PROGRAM statement. The executable section can contain any number of executable statements, limited only by the amount of memory available.

See Also: Chapter 2 LANGUAGE ELEMENTS,Chapter 3 USE OF OPERATORS, andChapter 5 ROUTINES.