3.3 Calling Robot Function
05 May 2016
After receiving the robot of the required class, the programmer can make him perform the requested action, i.e., cause the execution of a certain robot function. Robot functions are programmed by the robot developer together with robot module and are described in the documentation to robot module.
Calling a function is visually similar to the object method call in C-like programming languages. Robot class must be specified, and then through the pointer character “->” the required function is specified, and then goes the list of arguments to this function in parentheses.
Robot function call syntax:
For example, you should call do_something function with one argument 1000 from test class robot:
Reaching such structure, the interpreter will reserve a robot of this class, waits until the real physical robot is engaged and then sends a command of robot representation of the execution of the specified function with the specified parameters. After function execution, the robot will be automatically released and transferred to free status.
It should be noted that when robot function call is specified this way, the interpreter waits for confirmation of the function from robot representation, and only then continues executing the rest of the program. Read more information about flags of function execution in Section "Specifying Function Execution Modes".
Depending on how and where the execution of robot functions is described, they (functions) can be divided into three types:
- User-defined functions – the functions described in RCML language in the current file of the source program code or in the included files with the source code in RCML. The code of these functions is within the current program and will be compiled into an executable file of the current program;
- Library functions – the functions of RCML libraries already compiled, linked to the current program, i.e., the code of these functions is outside the current program in RCML;
- System functions – the functions that are provided to RCML environment by robot module. The execution code of these functions is in robot module or in robot software.
System function can be re-defined by user-defined and library function. Library function can be re-defined by user-defined function only. User-defined function can not be re-defined. When you create two user-defined functions with the same name, the compiler will generate an error. This mechanism allows you to re-define inefficient functions of the level, where it is more difficult to do, to the functions of the level, where it is easier to do. For example, it may be difficult to recompile robot module or library due to the absence of source codes, however, it is easy to re-define the required function in the text of your program.
Thus, in a function call, the specified robot function is first searched among user-defined functions. In case the required function is not found among user-defined functions, the search continues among library functions. Each library is searched for the required function in the order it is included in the source program code. It should be noted that different libraries may include th same function for the same robot, so the first function found will be selected. If the required function is also not found among library functions, the search continues among system functions. There may be multiple system functions with the same name as part of robot module, but the first function found is always selected. If the required function is not found among system functions, then an error is generated.
The function is searched only by its name without taking into account the number of its parameters. If the function found has a number of parameters other than the number of arguments sent in the function call, an error is generated.
Based on this search algorithm, it can be concluded that user-defined functions have a highest priority in the search, followed by library and then system functions.
However, sometimes a programmer faces the need to use system function, which is re-defined by library function. This case is possible when library function implementation is inefficient, the source code of the library is absent, and there is the need to use this library because it includes other functions. It is possible to directly access system function if you include a dot character “.” before the function name. Function call syntax is as follows:
the above example is as follows: