Skip to content

Use with AI

Use with AI

General Hints ​

The following image shows the standard view as soon as a new textual program has been created.

The red box shows the program name and the current TCP position of the robot. There are also buttons that can be used to insert the corresponding values (in a specific format) directly into the text editor. Clicking on the i button at the top right opens a help window in which all textual commands are briefly described. The last line in the red box contains a quick editing option for the program code. However, this is primarily only advantageous and recommended for small changes if no (physical) keyboard is available or can be connected.

There are three buttons in the yellow box:

  • Export (left): Export the current program as a ZIP file together with all its existing configurations and required files
  • Save (centre): Saves the current program
  • Execute (right): Open the Execute program menu to start an execution

The illustration referenced by the source is no longer available. The explanation is retained below.

Illustration: General Hints

Configuration block

Every horstSCRIPT program has a configuration block, which can be seen in the blue box. This is created automatically when a program is created. Normally nothing needs to be changed in the configuration block. The two curly brackets '{' and '}' define this configuration block. Everything within these curly brackets is therefore part of the configuration.

There are individual 'config(...);' lines within the configuration. These define/configure various attributes of a program. The first value specifies what is configured (name/description of the attribute). The second value specifies which value is assigned to the attribute.

config("robot.horstproto", "Horst900S4Fast");

Describes the robot model for which this program was written or designed. As the kinematics are different for the versions, not every robot can move to every point. The robot type is therefore entered here. In this case Horst900S4Fast.

config("tool", "No Tool");

config("world", "EMPTY_WORLD");

Describes which tool and which 3D world is stored in the program. In this case, no tool and the empty standard 3D world are stored.

config("scripttype", "textual");

Describes whether the program is a graphical or textual program.

config("tcp.weight", "2.5")

Describes how heavy the tool is, including the object in/on the tool. Any value from 0.0 kg up to a certain upper limit can be entered here, which varies depending on the robot model. The higher the value, the slower the robot moves in order to avoid step losses with a high weight.

config("version", "2022.04");

Describes which horstFX version was used to create the program.

config("io.config.file", "standard_name.io");

config("io.config.checksum", "f4779a85");

Describes the I/O configuration file associated with the program and a corresponding checksum.

Adding commands ​

Various commands can be added via the respective command window using the Add command button in the command area (green box). This is done in the same way as in graphical programming, except that the added command is added to the text editor in text form.


Defining variables and functions ​

To define a variable in JavaScript, a corresponding name is passed to the var command. In the program sequence, variables are declared as follows:

var Approachheight= 0.05;

var Approachheight= 0.05;

var OffsetX = 0.04;

var OffsetY = 0.06;

The variables can be assigned a value directly, as shown in the example above. This assignment can also be made later in the program and is not absolutely necessary during initialisation.

The identifier function is used to define functions. As shown in the example below, a function name is assigned and the function is defined in the method body. The method body is characterised by two curly brackets.

function GripperInit(){
setOutput

The variables can be assigned a value directly, as shown in the example above. This assignment can also be made later in the program and is not absolutely necessary during initialisation.

The identifier function is used to define functions. As shown in the example below, a function name is assigned and the function is defined in the method body. The method body is characterised by two curly brackets.

Example:

////////////////////////////////////functions/////////////////////////////////////////////

function GripperInit(){
setOutput("TOOL_OUTPUT_1", 1.0);
sleep(100);
setOutput("TOOL_OUTPUT_2", 0.0);
}

In the example above, the function GripperInit is defined. The method body contains methods to set the signals of the tool outputs and a wait function.


IF-Conditions, For-loop, While-loop, Switch-Case ​

To implement an IF-condition in the program, an If-else block is added to the program. Basically, this command is structured as follows:

if(CONDITION_1){

iF CONDITION 1 is fulfilled, then this code is executed

} else if (CONDITION _2){

If CONDITION_2 is fulfilled, then this code is executed

} else {

else

}

Example:

var i = 12;
if (i < 0.5) {
    moveJoint(0.62100, 0.00000, 0.69726, 0.70711, 0.00000, 0.70711, 0.00000, 0.5);
} else if (i > 10) {
    showInfo("i is greater than 10");
} else {
    sleep(500);
}

To implement a repeat loop that runs until a certain condition changes, the while loop can be used. As long as the condition is fulfilled (=true), the method body is executed.

while(CONDITION){

...CODE...

}

Example:

var speed = 0.50;
while (speed <= 1) {    
    moveJoint(0.10432, 0.61218, 0.69726, 0.54037, -0.45607, 0.54037, 0.45607,speed);
    sleep(500);
    moveJoint(0.62100, 0.00000, 0.69726, 0.70711, 0.00000, 0.70711, 0.00000,speed);
    speed+=0.050;
}

To intercept special cases, i.e. to execute a method based on a specific variable value, the switch case statement can be implemented. Each case is ended with a break-command.

switch(case_variable){

case(1): ....CODE... break;

case(2): ...CODE... break;

case(3): ...CODE... break;

}

Example:

var season = 1;
switch (season) {
            case (1):
                  showInfo("Spring.");
                  break;
            case (2):
                  showInfo("Summer.");
                  break;
            case (3):
                  showInfo("Autumn.");
                  break;                  
            case (4):
                  showInfo("Winter.");
                  break;
}

Operators JavaScript ​

General assignment operators ​

Illustration: General assignment operators

Comparison operators ​

Comparison operators can be used to compare two variables/values etc. The result is the value TRUE/False. Illustration: Comparison operators

Arithmetic operators ​

Illustration: Arithmetic operators

Logical operators ​

Logical operators


Further information and cheat sheets ​

For further information on programming with JavaScript, please refer to the various cheat sheets:

https://websitesetup.org/javascript-cheat-sheet/

https://htmlcheatsheet.com/js/

https://www.codecademy.com/learn/introduction-to-javascript/modules/learn-javascript-introduction/cheatsheet

For specific questions about the implementation of JavaScript code, you can also refer to the information provided by the stackoverflow community: https://stackoverflow.com/questions/tagged/javascript