Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
This article is automatically translated from Russian by Google Translator.
Provides access to the display of the robot.
Screen size: 240*320 pixels.
Print the specified text on the screen, starting from the specified coordinate. If there was already text in the specified coordinates, it will be replaced by the new text.
The changes on the display will occur only after calling the method "redraw".
Parameters:
text
— display text,
x
, y
— screen coordinates.
Clear the drawing window.
Draw an arc of an ellipse inscribed into a rectangle with the upper left corner at specified coordinates and having a given width and height. The changes on the display will occur only after calling the method "redraw".
Parameters:
x
, y
— the coordinates of the upper left corner of the rectangle on the screen,
l
— rectangle width,
h
— rectangle height,
from
— initial angle bounding the arc,
to
— finite angle bounding the arc.
Draw an ellipse inscribed into a rectangle with the upper left corner at specified coordinates and having a given width and height. The changes on the display will occur only after calling the method "redraw".
Parameters:
x
, y
— coordinates of the upper left corner of the rectangle,
l
— rectangle width,
h
— rectangle height.
Draw a line with the beginning and the end at the given coordinates. The changes on the display will occur only after calling the method "redraw".
Parameters:
x0
, y0
— line origin coordinates,
x1
, y1
— line end coordinates.
Draw a point at given coordinates. The changes on the display will occur only after calling the method "redraw".
Parameters:
point coordinates x
, y
.
Draw a rectangle with the upper left corner at the specified coordinates and having the specified width and height. The changes on the display will occur only after calling the method "redraw".
Parameters:
x
, y
— coordinates of the upper left corner of the rectangle,
l
— rectangle width,
h
— rectangle height.
Close and clear the drawing window.
Redraw the window to draw. The changes to the display will only happen after this method is called.
Remove from the screen all text added to it by calls to the "addLabel" method.
Set the screen background to the color you specify.
Available colors:
white,
red, darkRed,
green, darkGreen,
blue, darkBlue,
cyan, darkCyan,
magenta, darkMagenta,
yellow, darkYellow,
gray, darkGray, lightGray,
black.
As a parameter, you must specify the color.
Set the color of the brush used to draw the graphical primitives.
Available colors:
white,
red, darkRed,
green, darkGreen,
blue, darkBlue,
cyan, darkCyan,
magenta, darkMagenta,
yellow, darkYellow,
gray, darkGray, lightGray,
black.
As a parameter, you must specify the color.
Set the thickness of the brush used to draw the graphical primitives, in pixels.
As a parameter, you must specify the thickness d
.
Display the image generated in the one-dimensional array on the controller.
Parameters:
array
— a one-dimensional integer array with dimensions width
×height
width
и height
— the width and height of the image, respectively
The format in which each element of the array is represented should be passed as the format parameter. The formats currently supported are: «rgb32», «grayscale8», «rgb888».
Examples of using show()
on an image taken withgetPhoto()
.
Display the image previously loaded on the robot.
The name of the image file (in BMP, GIF, JPG, JPEG, PNG, PBM, PGM, PPM, TIFF, XBM, XPM formats) must be specified as a parameter, the path is specified either as absolute or relative to the trik
folder.
This article is automatically translated from Russian by Google Translator.
Represents power motor encoders connected to ports E1, E2, E3, E4.
Returns the current encoder reading in degrees on the specified port.
As a parameter, you must specify the port.
Resets the current encoder reading to 0.
As a parameter, you must specify the port.
Returns the current encoder reading in "ticks" on the specified port.
This article is automatically translated from Russian by Google Translator.
Represents the gyroscope of the TRIK controller. At rest, the average value of the gyroscope output is not zero and is called a bias
or bias error
.
The parameter is determined by many factors and can vary, for example, depending on the ambient temperature.
In order for the gyroscope to work properly it is necessary to subtract the zero offset from the incoming values. This can be calculated using the "calibrate" method.
Since calibration takes a long time, if you run the model frequently, you can do it once, then store the value in a variable with "getCalibrationVaules", and call "setCalibrationValues" instead of calibration when you run the program.
Calculates a zero offset within a specified time and initializes the gyroscope with this parameter, resets the current tilt angles. The recommended calibration time is 10-20 seconds.
Parameter:
msec
— time in milliseconds.
The signal sent by the sensor after the end of the calibration.
Returns an object that contains the necessary zero-offset data.
Returns true
if calibration is complete, false
otherwise.
The signal sent by the sensor when it has new data ready.
Returns an array of seven elements:
0−2 — angular velocities on the three axes (in milligrades/seconds),
3 — a time of the last measurement (in microseconds),
4−6 — tilt angles on the three axes (in milligrads).
Returns an array of three elements with angular velocities on the three axes.
Sets the object containing the necessary parameters about the zero offset.
Since calibration takes a long time, if you run the model frequently, you can do it once, then store the value in a variable with "getCalibrationVaules", and call "setCalibrationValues" instead of calibration when you run the program.
Parameter:
values
— object containing bias data.
This article is automatically translated from Russian by Google Translator.
Read the article about creating a new text program and generating a diagram to code:
The functionality of the runtime environment is accessed through predefined objects and functions.
This article is automatically translated from Russian by Google Translator.
The object "brick" represents the TRIK controller and provides access to the robot devices.
Provides access to the accelerometer (class "Accelerometer").
Provides access to battery information (class "Battery").
Provides access to the color sensor by the camera (class "ColorSensor").
Provides access to the display of the robot (class "Display").
Provides access to the encoder on the specified port (class "Encoder").
As a parameter, you must specify the port.
Get a photo from the camera as an array of bytes.
Provides access to the gyroscope (class "Gyroscope").
Provides access to the buttons on the robot body (class "Keys").
Provides access to the LED on the robot body (class "Led").
Provides access to the line sensor by the camera (class "LineSensor").
Provides access to the motor (power or servomotor) on the specified port (class "Motor").
As a parameter, you must specify the port.
Provides access to the object sensor by the camera (class "ObjectSensor").
Play the audio file.
As a parameter, you must specify the name of the file with an absolute path or the path relative to the folder trik
on the controller.
Warning! The file must be pre-loaded on the controller.
Say the line (in Russian or English).
As a parameter, you must specify a string in English or Russian.
Provides access to the sensor on the specified port (class "Sensor").
As a parameter, you must specify the port.
Stops all motors and active sensors, and removes what is drawn on the display.
This article is automatically translated from Russian by Google Translator.
Represents the accelerometer of the TRIK controller.
Returns the current sensor reading as an array of three elements corresponding to the sensor readings along each axis.
The signal sent by the sensor when new data is ready.
This article is automatically translated from Russian by Google Translator.
The camera in color sensor mode.
Turns the camera on and initializes it in color sensor mode.
The boolean parameter defines whether to display the image from the camera:
true
— output,
false
— do not output
Returns an array with the coordinates of the dominant color in the RGB color scale in the specified area of the frame.
The frame is divided into squares by a grid, by default 3 by 3, the dimensionality of the grid can be set in model-config.xml
on the robot. Squares are indexed from 1. That is, (1, 1) is the upper-left edge of the frame, (2, 2) is its center.
The return value is an array of three elements from 0 to 255, indexed from 0. The zero element contains the intensity of red (0 - none at all, 255 - very much), the first - the intensity of green, the second - the intensity of blue. For example, (0, 0, 0) is black, (255, 255, 255) is white, (255, 0, 0) is red.
As a parameter, it is necessary to specify the indices of the square x
and y
.
Turns off the camera and stops the sensor.
This article is automatically translated from Russian by Google Translator.
Provides control of the robot motor (power or servo motor) connected to ports M1, ..., M4, S1, ..., S6.
Blocking of motors for braking for a specified time in milliseconds.
As a parameter, you must specify the time in milliseconds.
Returns the current motor power (-100 to 100).
Turns the motor off.
Turns on the motor with the specified power.
As a parameter, you must specify the power. The power is set in the range from -100 ("full reverse") to 100 ("full forward"). 0 corresponds to a force break
, i.e. the motor stops, it is blocked and remains energized.
This article is automatically translated from Russian by Google Translator.
Camera in object sensor mode. Captures a contrasting object in the center of the frame and returns its coordinates and size in the frame.
Detects the dominant color in the center of the frame and remembers it as the color of the object. After that, the "" method starts to return data for the object.
Switches the camcorder on and initializes it in object sensor mode. The boolean parameter determines whether to display the image from the camera (true
— display).
The boolean parameter defines whether to display the image from the camera:
true
— output,
false
— don't output.
Returns an array that contains the following data in its cells:
In the zero cell, the X-axis coordinate of the object center relative to the center of the frame (-100 to 100, -100 is the center of the object on the edge of the frame on the left);
The Y-coordinate of the object's center relative to the frame center (from -100 to 100, -100 is the center of the object on the frame edge at the top);
The second cell is the relative size of the object, a number from 0 to 100 (100 - the object occupies almost the entire frame, 0 - the object is not on the frame).
Turns off the camera and stops the sensor.
This article is automatically translated from Russian by Google Translator.
Serves to work with the programmable control panel "".
Sent when the user has pressed one of the five buttons at the bottom of the remote control.
Returns true
if a button with the specified number was pressed on the remote control. Resets the memorized press for this button.
As a parameter, you must specify the number of the button - from 1 to 5.
Sent when the remote control is connected to the robot.
It is sent when the remote control is turned off.
Returns whether the control area on the remote control is currently pressed. The control areas are numbered 0 and 1.
As a parameter, you must specify the number of the control area - 0 or 1.
Sent when the user taps or moves their finger over the control area on the remote.
If the specified control area on the remote is pressed, returns the current x-coordinate of the press.
As a parameter, you must specify the number of the padId
control area.
If the specified control area on the remote is pressed, returns the current y-coordinate of the press.
As a parameter, you must specify the number of the padId
control area.
Sent when the user moves his finger away from the control area with the specified number.
Parameters:
padId
— control area number.
x
, y
— the coordinates of the last known click from -100 to 100. The coordinate (-100, -100) corresponds to the upper left corner of the control area.
Resets the memorized events from the remote control.
If "steering" (events from the device's accelerometer) is enabled on the remote control, it returns the current remote control tilt.
Tilt is coded from -100 to 100, with -100 being the leftmost "rudder" position and 100 being the rightmost position.
Sent when the remote control has the "steering wheel" (events from the device's accelerometer) on and the user has turned the device.
As a parameter it is necessary to specify a number from -100 to 100, -100 corresponds to the leftmost position of the "rudder", 100 - to the rightmost position.
This article is automatically translated from Russian by Google Translator.
Represents methods of controlling script execution and accessing operating system functions.
Sets the end-of-run flag for an event-driven program. As soon as the current event handler completes, the script execution will end.
Returns a random number from the specified range.
The range boundaries must be specified as parameters.
Reads the entire contents of the specified file into a string array.
As a parameter, you must specify the name of the file with the extension.
Deletes the specified file.
As a parameter, you must specify the name of the file with the extension.
Executes the command transmitted.
As a parameter, you must specify the operating system console command.
Returns the time stamp - the number of milliseconds elapsed since the beginning of January 1, 1970 GMT.
Creates and returns a timer (class QTimer
) that sends a timeout
signal every n milliseconds.
n
is passed as a parameter.
Suspends script execution for the number of milliseconds passed.
The number of milliseconds is passed as a parameter.
Writes a string to a file.
The file name and the line to be written should be specified as parameters.
This article is automatically translated from Russian by Google Translator.
Represents a sensor (analog or digital) connected to ports A1, ..., A6, D1, D2.
Returns the current reading of the sensor (digital or analog) connected to this port. The present value is returned, depending on the port configuration, which is described in the file model-config.xml
in the trik
folder on the robot.
For example, the IR distance sensor returns a value in centimeters.
Returns the current raw reading of the sensor (digital or analog) connected to this port. The range of values depends on the specific sensor and does not take into account the configuration of the robot (the physical readings of the sensor are returned, e.g. the delay of the received ultrasonic signal).
This article is automatically translated from Russian by Google Translator.
It implements communication between robots in the network by means of the mailbox mechanism.
Connects to the robot with a given IP address on a given port (or default port), gives it its on-board number, and registers with the "mailbox" network.
As parameters, you must specify the IP address of the robot and the port. If no port is specified, the default port is used.
Returns true
if the robot received a new message.
Returns the onboard number of the robot.
Sends a message after receiving a message.
The first parameter is the sender's onboard number, the second is the message itself.
Gets a new message or blocks script execution until the message arrives.
Sends the specified message to the robot with the specified board number (or all robots).
As a parameter, you must specify the on-board number of the robot to which you want to send the message and the message. If no on-board number is specified, the message is sent to all robots registered in the network.
This article is automatically translated from Russian by Google Translator.
Used to operate the buttons on the robot's remote control.
Sent when the button with the specified code is pressed or released.
The first parameter is the code of the button, the second - 1 if the button is pressed, 0 if released.
Returns true
if the button with the specified code is currently pressed.
Possible options:
KeysEnum.Left
(code105),
KeysEnum.Up
(code 103),
KeysEnum.Down
(code 108),
KeysEnum.Enter
(code 28),
KeysEnum.Right
(code 106),
KeysEnum.Power
(code 116),
KeysEnum.Esc
(code 1).
Resets memorized button presses.
Returns whether or not a button with the specified code was pressed, reset the remembered presses for that button. Possible options:
KeysEnum.Left
(code 105),
KeysEnum.Up
(code 103),
KeysEnum.Down
(code 108),
KeysEnum.Enter
(code 28),
KeysEnum.Right
(code 106),
KeysEnum.Power
(code 116),
KeysEnum.Esc
(code 1).
This article is automatically translated from Russian by Google Translator.
Camera in line sensor mode.
Detects the dominant color in the vertical bar in the center of the frame and remembers it as a line color. Then the "" method starts returning data for that line.
Turns the camera on and initializes it inline sensor mode. The boolean parameter determines whether to display the image from the camera (true
- display).
The boolean parameter defines whether to display the image from the camera:
true
— output,
false
— don't output.
Returns an array with the following data in its cells:
the zero cell is the X coordinate of the line center relative to the center of the frame (from -100 to 100, -100 is the center of the line on the edge of the frame on the left);
in the first cell - the probability of crossing (the number from 0 to 100, showing how many points of the line color are in the horizontal stripe in the frame center);
the second cell - the relative size of the line, a number from 0 to 100 (100 - the line occupies almost the whole frame, 0 - the line is absent in the frame).
Turns off the video camera and stops the sensor.
Sets the event-oriented program flag. When the script finishes, it is not unloaded from memory but continues to wait for events to occur until one of the handlers calls the "" method.
Method
Description
Print the specified text on the screen, starting from the specified coordinate.
Clear the drawing window.
Draw an arc of an ellipse inscribed into a rectangle with the upper left corner at specified coordinates and having a given width and height.
Draw an ellipse inscribed into a rectangle with the upper left corner at specified coordinates and having a given width and height.
Draw a line with the beginning and the end at the given coordinates.
Draw a point at given coordinates.
Draw a rectangle with the upper left corner at the specified coordinates and having the specified width and height.
Close and clear the drawing window.
Redraw the window to draw. The changes to the display will only happen after this method is called.
Remove from the screen all text added to it by calls to the "addLabel" method.
Set the screen background to the color you specify.
Set the color of the brush used to draw the graphical primitives.
Set the thickness of the brush used to draw the graphical primitives, in pixels.
Display the image generated in the one-dimensional array on the controller.
Display the image previously loaded on the robot.
Method
Description
Returns the current encoder reading in degrees on the specified port.
Resets the current encoder reading to 0.
Returns the current encoder reading in "ticks" on the specified port.
Method
Description
Calculates a zero offset within a specified time and initializes the gyroscope with this parameter, resets the current tilt angles.
Returns an object that contains the necessary zero-offset data.
Returns true if calibration is complete, false otherwise.
Returns an array of seven elements: angular velocities on the three axes, time of the last measurement, tilt angles on the three axes.
Returns an array of three elements with angular velocities on the three axes.
Sets the object containing the necessary parameters about the zero offset.
Сигнал
Описание
The signal sent by the sensor after the end of the calibration.
The signal sent by the sensor when it has new data ready.
Method
Description
Provides access to the accelerometer.
Provides access to battery information.
Provides access to the color sensor by the camera.
Provides access to the display of the robot.
Provides access to the encoder on the specified port.
Get a photo from the camera as an array of bytes.
Provides access to the gyroscope.
Provides access to the buttons on the body of the robot.
Play the audio file.
Provides access to the LED on the body of the robot.
Provides access to the line sensor by the camera.
Provides access to the motor on the specified port.
Provides access to the object sensor by the camera.
Pronounce the string passed as a parameter (in Russian or English).
Provides access to the sensor on the specified port.
Stops all motors and active sensors, and removes what is drawn on the display.
Method
Description
Returns the current sensor reading as an array of three elements corresponding to the sensor readings along each axis.
Signal
Description
The signal sent by the sensor when new data is ready.
Method
Description
Turns the camera on and initializes it in color sensor mode.
Returns an array with the coordinates of the dominant color in the RGB color scale in the specified area of the frame.
Turns off the camera and stops the sensor.
Object
Description
Represents the TRIK controller and provides access to the robot's devices.
Represents methods of controlling the execution of the script and provides access to operating system functions.
It implements communication between robots in the network by means of the mailbox mechanism.
Serves to work with the remote control.
Provides management of parallel threads.
Function
Description
Returns a one-dimensional array of bytes containing the pixels of the rgb32-formatted image taken from the camera.
Allows you to use functions implemented by the user in other files. It is assumed for writing your own libraries. As a passed parameter you must specify the full system path to the file with the required functions.
This article is automatically translated from Russian by Google Translator.
Allows you to use functions implemented by the user in other files. It is supposed to write your own libraries.
As a passed parameter you must specify the full system path to the file with the required functions or the name of the file. In the second case, the file for a connection must be in the same directory as the main file in which include
is called.
Method | Description |
Blocking of motors for braking for a specified time. |
Returns the current motor power. |
Turns the motor off. |
Turns on the motor with the specified power. |
Method | Description |
Detects the dominant color in the center of the frame and remembers it as the color of the object. |
Switches the camcorder on and initializes it in object sensor mode. |
Returns an array with the X coordinate of the object center relative to the center of the frame, the Y coordinate of the object center relative to the center of the frame, and the relative size of the object. |
Turns off the camera and stops the sensor. |
Method | Description |
Turns the LED on in "red" mode. |
Turns the LED on in the "green" mode. |
Turns the LED on in the "orange" mode. |
Turns off the LED. |
Method | Description |
Returns |
Returns whether the control area on the remote control is currently pressed. |
If the specified control area on the remote is pressed, returns the current x-coordinate of the press. |
If the specified control area on the remote is pressed, returns the current y-coordinate of the press. |
Sent when the user moves his finger away from the control area with the specified number. |
Resets the memorized events from the remote control. |
If "steering" (events from the device's accelerometer) is enabled on the remote control, it returns the current remote control tilt. |
Sent when the remote control has the "steering wheel" (events from the device's accelerometer) on and the user has turned the device. |
Signal | Description |
Sent when the user has pressed one of the five buttons at the bottom of the remote control. |
Sent when the remote control is connected to the robot. |
It is sent when the remote control is turned off. |
Sent when the user taps or moves their finger over the control area on the remote. |
Method | Description |
Sets the end-of-run flag for an event-driven program. |
Returns a random number from the specified range. |
Считывает всё содержимое указанного файла в массив строк. |
Deletes the specified file. |
Sets the event-oriented program flag. |
Выполняет переданную в качестве параметра команду консоли операционной системы. |
Returns the time stamp - the number of milliseconds elapsed since the beginning of January 1, 1970 GMT. |
Creates and returns a timer. |
Suspends script execution for the number of milliseconds passed. |
Writes a string to a file. |
Method | Description |
Returns the current reading of the sensor (digital or analog) connected to this port. |
Returns the current raw reading of the sensor (digital or analog) connected to this port. |
Method | Description |
Connects to the robot with a given IP address on a given port (or default port), gives it its on-board number, and registers with the "mailbox" network. |
Returns |
Returns the onboard number of the robot. |
Sends a message after receiving a message. |
Gets a new message or blocks script execution until the message arrives. |
Sends the specified message to the robot with the specified board number (or all robots). |
Method | Description |
Sent when the button with the specified code is pressed or released. |
Returns |
Сбрасывает запомненные нажатия кнопок. |
Returns whether or not a button with the specified code was pressed, reset the remembered presses for that button. |
Method | Description |
Detects the dominant color in the vertical bar in the center of the frame and remembers it as a line color. |
Turns the camera on and initializes it inline sensor mode. |
Returns an array with the X coordinate of the center of the line relative to the center of the frame, the probability of a crossover, and the relative size of the line. |
Turns off the video camera and stops the sensor. |
This article is automatically translated from Russian by Google Translator.
The function returns a one-dimensional array of bytes containing the pixels of an rgb32-formatted image taken from the camera (image size 160x120). This function can be used to solve marker recognition problems.
Let's look at an example of converting a frame taken with a camera to grayscale and black-and-white color formats.
Take a picture and display the result with the show function.
Rwsult:
Converts the image to black and white and outputs it to the display:
Result:
Translates the image to black and white and outputs it to the display:
Result:
This article is automatically translated from Russian by Google Translator.
Provides management of parallel threads.
Waiting for the specified flow to complete.
As a parameter, it is necessary to specify thread id.
Finishes the execution of the specified flow.
The thread id must be specified as a parameter.
Queries the received message.
If wait
is true
, it waits until a message arrives.
Sends a message to the specified stream.
As parameters, it is necessary to specify thread id and message.
Runs the function passed as a parameter in a separate thread.
Warning! This creates a new copy for all global variables. So if the value of a variable change in one thread, it stays the same in another thread.
As parameters, it is necessary to specify thread id and function.
Method
Description
Waiting for the specified flow to complete.
Finishes the execution of the specified flow.
Queries the received message.
Sends a message to the specified stream.
Runs the function passed as a parameter in a separate thread.