Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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.
An array is one of 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 ) as arrays. Therefore, wherever you use a comma-separated value notation, you can use an array.
.
.
.
.
.
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 , 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:
.
.
.
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.
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. |
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. |
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:
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.
See the article about the syntax of expressions in blocks:
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.
In mathematical expressions, you can use the functions available for any platform.
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:
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.
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.
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).
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