Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
An array is one of the types of TRIK Studio language that stores a set of values (array elements) identified by an index. The numbering of indices in the array starts at 0.
Arrays can be created explicitly using the following expressions (the next lines are equivalent):
Or with explicit indices:
You can use arrays without creating them. For example, like this:
In this case, "empty spaces" in the array (indices that did not have an explicit assignment) will be filled with default values:
0
— for real and integer;
false
— for boolean;
empty lines for arrays of strings.
Array values can also be used without curly braces if used as the return value. For example, this expression will return an array of numbers 1
and 2
:
This is implemented in order to interpret the enumerations of values (for example, the ports of motors in the block "Motors forward") as arrays. Therefore, wherever you use a comma-separated value notation, you can use an array.
Title
Title
Title
+
Addition
Applicable to real and integer values. The result is an integer if both arguments are integer, otherwise real.
-
Subtraction
Applicable to real and integer values. The result is an integer if both arguments are integer, otherwise real.
*
Multiplication
Applicable to real and integer values. The result is an integer if both arguments are integer, otherwise real.
/
Division
Applicable to real and integer values. The result is real.
//
Integer division
Applicable to integer values. The result is an integer.
^
Power
Applicable to real and integer values. The result is real.
%
Remainder of the division
Applicable to integer values. The result is an integer.
&
Bitwise "and"
Applicable to integer values. The result is an integer.
|
Bitwise "or"
Applicable to integer values. The result is an integer.
>>, <<
Bitwise left and right shift
Applicable to integer values. The result is an integer.
..
Concatenation
Applicable to string values. The result is a string.
>=, >, <, <=
Comparison operations
Applicable to integer and real values. The result is boolean.
==
Equality check
Applicable to any type of value. The result is boolean.
~=, !=, '~=', '!='
Inequality check
Applicable to any type of value. The result is boolean. All notations are equal.
and, &&
Logical "and"
Applicable to integer, real and boolean types. The result is boolean. All notations are equal.
or, ||
Logical "or"
Applicable to integer, real and boolean types. The result is boolean. All notations are equal.
Title
Title
Title
-
Arithmetic unary minus
Applicable to integer and real values. The result is an integer or real (depending on the type of argument).
~
Bitwise "not"
Applicable to integer values. The result is an integer.
not
Logical "not"
Applies to boolean, integer, real, and string values, the result is boolean (0 or an empty string is considered false, everything else is true).
#
Length operator
Applicable to string values. The result is an integer.
It has the following form:
variable1, variable2, …, variableN = expression1, expression2, …, expressionN
In its simplest form variable = expression
.
It is written as an expression and should be at the end of the statement block.
Written as ;
.
A statement block with two assignment operators and a return operator:
Besides constants, in TRIK Studio reserved variables are available that store the values of the readings of sensors connected to the corresponding ports.
These values can be assigned to variables and used in mathematical expressions.
Variables have the form
For example, sensorA1
for TRIK or sensor1
for Lego NXT.
A complete list of sensor variables is provided in sections for specific platforms:
TRIK.
TRIK Studio has only one built-in constant. It can be used in the same way as sensor variables, but its value cannot be changed.
pi
3.14159265358979
Represents the ratio of the circumference of a circle to its diameter, determined by the constant π.
In mathematical expressions, you can use the functions available for any platform.
Function
Description
time()
Returns the time in milliseconds since the program started.
sin(angle)
The sine of the angle, where "angle" is the angle in degrees.
cos(angle)
The cosine of the angle, where "angle" is the angle in degrees.
ln(a)
The logarithm, where "a" is a number.
exp(a)
Exponent ("e" in the degree of argument "a").
asin(a)
Arcsine, where "a" is a number.
acos(a)
Arccosine, where "a" is a number.
atan(a)
Arctangent, where "a" is a number.
atan2(a1, a2)
The arctangent of a1 / a2 with division check by 0.
sgn(a)
Sign. Returns 1 if the argument “a” is positive, -1 if it is negative, and 0 if the argument is zero.
sqrt(a)
The square root of the argument "a". If the argument is negative, the variable will be assigned the value “NaN” (Not A Number).
abs(a)
The absolute value of number "a".
ceil(a)
Rounds up the passed argument "a" to the nearest integer.
floor(a)
Rounds down the passed argument "a" to the nearest integer.
random(a)
A random number between 0 and the passed argument “a”.
The language uses spaces, tabs, and line breaks outside of string literals only as separators between tokens — they do not affect the interpretation of expressions.
The language has the following keywords:
and
false
nil
not
or
true
And the following operators:
String literals are written in either single or double-quotes. For example,
Integers are written either in decimal, octal, or hexadecimal. Hexadecimal numbers begin with the prefix 0x
, octal numbers begin with the prefix 0
. For example,
3
, 345
— decimal number
0xff
, 0xBEBADA
— hexadecimal number
07654321
— octal number
Real numbers are written either in conventional or exponential form. For example,
Comments begin with --
and continue to the end of the line. For example,
See the article about the syntax of expressions in the blocks:
To declare variables and set certain values for them, the “Variable Initialization” block is used.
For mathematical expressions — "Expression" block.
Also, mathematical expressions, including those that change the values of variables, can be used almost everywhere where you can specify a value.
Blocks and their properties that do not allow the use of mathematical expressions are described in the section "Common blocks".
All variables in the program are global, i.e. their values can be used in any block in the program.
The language used inside the blocks is based on Lua 5.3 and largely follows its syntax. Nevertheless, there are significant differences, so a full description of the language used in TRIK Studio is given here.
Declaration of several variables in one block "Expression":
The same using "Variables Initialization" blocks:
Proportional controller for driving along the line using two light sensors for the TRIK platform:
An example of using arrays to set the ports of the “Motors forward” block. An array is created with the name a
, the port M3
is assigned to the zero element, the first is M1
, then the contents of the first element of the array are changed to M4, then the resulting array is transferred to the “Ports” property of the “Motors forward” block:
Links between blocks in TRIK Studio indicate the control flow of interpretation between blocks.
Let it be necessary that after the delay the program ends immediately. To do this, connect the Timer and End blocks with a link pointing from the "Timer" block to the program end block.
Links can be created in two ways:
Hover over a block, hold down the right mouse button and draw a line to the second block. The line shape can be arbitrary. It is important that it starts strictly on one block and ends on the second.
If you move the mouse cursor over the link, gray markers are displayed at its ends. By pulling on one of these markers, you can control the link. To attach one of the ends of the connection to the block, you need to pull the corresponding gray marker and release it on the block of interest.
If you drop this relationship on an existing element, these elements will be connected.
If you release the left mouse button when the cursor is on an empty section of the diagram, a menu with the following items will appear:
Delete
Create new element
When you select the "Delete" menu item, the created link will be deleted.
When you hover over the menu item "Create a new element" a new menu appears, listing all the possible elements to create. When you select one of these items on the diagram, the corresponding element will be created and join the current link.
Links are removed in the same way as blocks.
If you need to add a new block between two linked blocks, drag a block from the Palette panel to the link. Release the mouse button when you hover over a link (not a block).
Links in TRIK Studio can be broken lines. To add a breakpoint, move the mouse cursor over the link, click the left mouse button and drag the gray marker that appears.
If the breakpoint of the connection is positioned so that it and the two nearest to it will be located approximately on one straight line, this will lead to the destruction of this breakpoint and smoothing of the broken line in this place.
A program in the TRIK Studio is represented as a sequence of the blocks connected by the links.
Each program corresponds to the main diagram, which may contain other diagrams (subprograms). Diagrams are packaged in projects stored on the disk.
The main diagram is created when the project is created. About adding and removing blocks to the scene, read the article:
The diagrams with subprograms are created automatically when you add the block "Subprogram" to the scene. In this case, the subprogram is displayed by double-clicking on the "Subprogram" block on the scene.
Read more about subprograms in the article:
In TRIK Studio, there are two ways to edit property values of blocks and links between them:
Attention! Editing the properties of the block Subprogram is carried out only using the context menu.
When a block, link, or element is selected, all the properties of the current element are displayed on the Property Editor panel.
The property editor is a table. In the left column, the property name of the element is displayed, in the right - its value.
You can change the value of any property by clicking on the corresponding cell in the right column and entering the desired value.
For properties that allow only a specific set of values, for example, the “Port” property of the "Wait for IR distance sensor" block, when you try to edit them, a drop-down menu will appear where the desired value is selected:
To edit properties directly on the diagram:
Hover over the value of the desired property.
Double-click the left mouse button to activate editing properties.
Enter the desired value.
Click on any place in the scene.
Attention! This approach can serve as a source of errors, because it allows you to enter an arbitrary text value of the property, including the incorrect one. Be careful.
Any program in TRIK Studio can be saved as a subprogram and used in another program.
Subprograms can be saved to a local collection or exported to a separate file for transfer to other computers.
To work with the collection of subprograms, use the menu item Tools → Subprograms
:
Use the export of subprograms to a file to transfer them to other computers. If you plan to use the subprograms on your computer, then use the option Save to collection.
To export subprograms from an open project to a separate qrs file, select Tools → Subprograms → Export to file
in the main menu.
All subprograms from the current project will be exported to this file.
To load previously-stored subprograms, select Tools → Subprograms → Import from file
in the main menu.
Attention! If the imported file contains subprograms with the same names as in the current project, then the subprograms from the project will be replaced by imported ones.
To transfer subprograms to other computers, use the export function.
To save routines from the current project, select Tools → Routines → Save to Collection
from the main menu.
Then select the subprograms you want to save and click OK.
Attention! If there are subprograms with the same names in the collection, they will be overwritten.
To load subprograms from the collection, select Tools → Subprograms → Download
from the collection from the main menu.
Then select the subprograms that you want to import into the current project, and click OK.
To delete all subprograms saved in the collection, select Tools → Subprograms → Clear
collection in the main menu.
The collection of subprograms is stored in the user directory and is not lost when uninstalling or reinstalling TRIK Studio.
Unlike Lua, the TRIK Studio language is statically-typed, that is, the type of each expression and each variable must be known at compile time. Moreover, the language does not require (and does not even allow!) to explicitly write the types of variables. It uses automatic type inference for the use of variables.
For example, environment "understands" from the expression a = 1
that type of a
is integer.
Type
Description
Boolean (logic) type
Can be one of two values: true or false.
Real
Uses IEEE 754 64-bit binary64 representation (allows to store values up to 1.7E+308).
Integer
Uses 32-bit signed representation (allows to store values in a range from -2 147 483 648 to 2 147 483 647).
String
Allows storing character strings of arbitrary length in UTF-8 encoding.
Null type
It has only a one-nil value and means the absence of any other value type.
Allows storing an arbitrary number of values of an arbitrary (but for each value in the same array of the same) type, including other arrays, and access values by index.
See the article about the syntax of expressions in blocks:
You can add blocks to the scene in TRIK Studio in three ways:
Drag and drop the corresponding icons from the palette of elements onto the diagram.
When creating a new connection between blocks using a linker.
Left-click on the necessary block located in the Palette panel. Without releasing the mouse button, move the block onto the scene.
Draw on the scene a special image of the block with the Right mouse button. The block appears in the center of the drawn image.
Gestures can be drawn with a few strokes. The gesture input ends if the strokes have not been drawn for some time (you can set the time in the settings window on the Behavior tab).
Available conditional images can be found in two ways:
1. In the "Mouse Gestures" window, which opens through the main menuTools → Mouse gestures
.
2. In the tooltip that appears when you hover over a block in the Palette panel.
Start creating a connection using the linker (a colored circle to the right of the block that appears after the block is selected) and release the left mouse button when the cursor is on an empty section of the diagram.
In the menu that appears, select "Create new element". A new menu with blocks will appear.
Select the block you need.
Deleting a block from the scene is possible in two ways:
Select the block with the left mouse button and then click the "Delete" button on the keyboard.
Right-click on the block and select "Delete" in the menu that appears.
1. Select the necessary blocks in one of the following ways.
1.1. Hold down the "Ctrl" button and right-click the necessary blocks.
1.2. Right-click on an area in the scene with the necessary blocks.
2. Delete the selected blocks in one of the following ways.
2.1. Press the “Delete” button on the keyboard.
2.2. Right-click on any selected block and select "Delete" from the menu that appears.
To replace the block on the scene:
1. Right-click on the block and select "Replace by..." in the menu that appears.
2. Select the block that you want to put instead of from the list.
The list of available blocks depends on the chosen robotics kit and on the robot model (real robot or 2D model simulation). Blocks unavailable for the current kit are not shown at all, and blocks inaccessible for this model within the same platform are shown in gray and are not available for dragging onto the scene.
Common blocks for all platforms are presented below. A program using only these blocks will be executed on any platform without any changes.
A list of blocks specific to a particular robotics kit can be found in the relevant sections:
Icon
Name
Description
The starting point for program execution.
Each diagram should have only one such block. There should not be any incoming links in it, and there should be only one outgoing link from this element.
The process of diagram interpretation begins with this block.
End of the program.
If the program consists of several parallel execution sections, reaching this block completes the corresponding execution section.
This block cannot have outgoing links.
A block for declaring a new variable and setting a value for it.
Separation of program execution in accordance with a given condition.
Indicates merging of two branches of a conditional statement. It does not perform any actions but is useful for ensuring the structure of the program.
A loop that is executing so far some condition is true, indicated before it begins. This condition is checked before the loop body is executed, so the body may not be satisfied even once (if the condition is false from the very beginning).
Block that provides the execution of a sequence of blocks several times.
A condition with several alternatives.
Counts the value of the specified expression. Initialization of variables is also allowed.
Subprogram execution.
Block divides program execution into several threads.
Block merging parallel tasks.
Finishes the task with the identifier specified in the "Task" property. Must be applied from another task.
A block for assigning a specified variable to a random integer from a given interval.
Block for adding arbitrary text to the diagram as a comment.
Block for setting the delay. The delay time is set in the Delay parameter in milliseconds.
Start drawing with a marker of a given color on the floor. When the robot moves in a two-dimensional model, a colored line will remain behind it.
Finish drawing with a marker.
The starting point for program execution.
Each diagram should have only one such block. There should not be any incoming links in it, and there should be only one outgoing link from this element.
The process of diagram interpretation begins with this block.
End of the program.
If the program consists of several parallel execution sections, reaching this block completes the corresponding execution section.
This block cannot have outgoing links.
A block for declaring a new variable and setting a value for it. The same operation can be performed using the Expression block, but this block makes the program more clear.
Property
Description
Value
An expression is specified that defines the initial value of the variable.
Variable
The variable name is specified.
Separation of program execution in accordance with a given condition.
This block must have two outgoing connections, at least one of which must have the value of the Condition parameter set: true or false.
Property
Description
Condition
Indicates merging of two branches of a conditional statement. It does not perform any actions but is useful for ensuring the structure of the program.
It does not perform any actions but is useful for ensuring the structure of the program. If you adhere to the rule that all branches of the "Condition" or "Switch" operators converge on such a block, this will significantly increase the chances that the generator will be able to generate code in text language without goto
statements.
A loop with a precondition is a loop that is true so far for some condition specified before it starts. This condition is checked before the loop body is executed, so the body may not be satisfied even once (if the condition is false from the very beginning).
Property
Description
Condition
Block that provides the execution of a sequence of blocks several times.
The number of repetitions is set by the value of the Iteration parameter. The block must have two outgoing connections, one of which must be marked with the value “body” (that is, the value of the “Condition” parameter the connection must have “body”). Another connection coming from the “Cycle” block should remain unmarked: it will go through when the program passes through the “Loop” block the specified number of times.
Infinite loops and loops of the form while / do
and while
are organized without using this block, looping the control flow using links. An exit from such a loop is carried out using the “Condition” block.
A condition with several alternatives.
In the "Expression" parameter, you can specify an arbitrary expression (for more details, see the section "Syntax of expressions"), based on the value of which the further path of the diagram interpretation will be selected.
This block must have several outgoing links. All relations, except one, should be marked with an elementary value (string, number, etc.), which can take an expression (the value is simply written in the Condition property of the connection). One of the links should not be marked: it jumps if the expression is not equal to any of the listed values.
Evaluate the value of the specified expression. Initialization of variables is also allowed.
For more information about the syntax of valid expressions for the Expression parameter, see the section "Expression syntax".
Subprogram execution. Subprograms are used to keep repeating program fragments on a separate diagram. When adding this block to the diagram, you will be prompted to enter the name of the subprogram, after which double-clicking on the block will be able to go to the diagram corresponding to this subprogram. An additional palette with all the subprograms will also appear. Subprograms from it can be dragged onto the scene and used as normal blocks. The appearance, name, and properties of the block can be changed using the context menu.
Changing the properties of this block does not perform in the "Properties Editor" panel, but using the "Change Properties" item in the context menu. To call the context menu, right-click on the block "Subprogram".
In the window that opens, you can:
Change subprogram name.
Add and change subprogram parameters by specifying a name, type, and value.
Change the picture on the icon of your subprogram.
Change subprogram icon background.
A block divides program execution into several threads. For example, you can simultaneously wait for the sensor to trigger and the time interval to expire.
A block must have at least two outgoing connections.
In order to be able to further refer to parallel tasks generated by this block (for example, in the "Kill thread" block or in the "Join" block), you need to give the names of the tasks. This is done on outgoing connections, in the Condition property. The name of the task can be any string, but one of the names should be the name of the task that is included in this block. The name of the main program is main
.
Block for merging parallel tasks.
It blocks the execution of the program until the execution of all parallel tasks included in this block reaches this block.
A block must have at least two incoming links. On the outgoing connection (in the “Condition” property) there must be an identifier for the task, which will continue after the block has completed.
Finishes the task with the identifier specified in the "Task" property. Must be applied from another task.
A block for assigning a specified variable to a random integer from a specified interval using the From and To properties.
Block for adding arbitrary text to the diagram as a comment.
Used to explain a specific block or section of a diagram. May be associated with the block, which he explains.
When the program is executed, the block is not taken into account.
Block for setting the delay. The delay time is set in the Delay parameter in milliseconds.
Start drawing with a marker of a given color on the floor. When the robot moves in a two-dimensional model, a colored line will remain behind it.
The block is available only in the two-dimensional model mode.
Finish drawing with a marker.
The block is available only in the two-dimensional model mode.
The Linker is a colored circle to the right of the block that appears after the block is selected. When you click on this circle and move the mouse with the left button pressed, the link begins to stretch out of the element.
A logical expression is indicated (for more details, see the article ""), based on the value of which the further path of the diagram execution will be selected.
The logical expression is specified (for more details, see the article ""), based on the value of which the further path of the diagram interpretation will be selected.