# An example of solving a problem on the interaction of two robots

## The task

Send message "5" from one robot and receive it on another.

{% hint style="warning" %}
Please note that the task can only be solved in real robot mode.
{% endhint %}

## Solution

To solve the problem, you have to:

1. Write a [message transmission algorithm](#message-transmission-algorithm) for the leading robot.
2. Write a [message reception algorithm](#message-reception-algorithm) for the second robot.
3. [Connect](https://help.trikset.com/en/trik/wi-fi/interaction) robots to a single network.
4. Run programs on robots.

### Message transmission algorithm

1\. Switch TRIK Studio to the [real robot mode](https://help.trikset.com/en/studio/interface#panel-interpreter).

2\. Enter a `message` variable for the message and initialize it by assigning it the number `5` in the "[Expression](https://help.trikset.com/en/studio/programming-visual/blocks#expression)" block.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSiwNB4lDvOY61hDA8G%2F-MSiwWpAYqhPzZBMn2zr%2F79%201%20En%20sendMes1.png?alt=media\&token=062beaa3-db44-4657-8269-145b92d55f29)

3\. Add "[Send message](https://help.trikset.com/en/programming-visual/blocks#send-message)" and "[End](https://help.trikset.com/en/studio/programming-visual/blocks#final)" blocks. In the properties of the "Send message" block, specify the onboard number of the robot to which you want to send the message and the variable containing the message.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSiwNB4lDvOY61hDA8G%2F-MSiw_vsgUJOLzpM7r1H%2F79%202%20En%20sendMes2.png?alt=media\&token=bbccb408-6981-4ef6-bb6a-5245b180a68a)

#### The complete algorithm

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSiwNB4lDvOY61hDA8G%2F-MSiwd_hskl87uZ8IAbs%2F79%203%20En%20sendMes3.png?alt=media\&token=1dcdd243-b630-4980-b98a-be7ce53460d1)

### Message reception algorithm

1\. Switch TRIK Studio to the [real robot mode](https://help.trikset.com/en/studio/interface#panel-interpreter).

2\. Add the "[Receive message](https://help.trikset.com/en/programming-visual/blocks#wait-for-message)" block.\
\
In the block properties, specify the variable in which you want to write a message sent from another robot. The variable can be named whatever you want.\
\
Set the "Wait for message" property to `true`.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSiwNB4lDvOY61hDA8G%2F-MSiwntQhMicbewmAij-%2F79%204%20En%20receiveMes1.png?alt=media\&token=4ba77062-1dbc-44e0-8d6c-c1646b4d7d00)

3\. After the message has arrived, display it on the robot's screen for 3 seconds, and then finish the algorithm. To do this, add blocks "[Print Text](https://help.trikset.com/en/programming-visual/blocks#print-text)", "[Timer](https://help.trikset.com/en/studio/programming-visual/blocks#timer)" and "[End](https://help.trikset.com/en/studio/programming-visual/blocks#final)".\
\
In the properties of the "Print text" block, check the `Calculate` box and specify `true` in the "Update image" field.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSiwNB4lDvOY61hDA8G%2F-MSiwrtoIF9Y1swoOabn%2F79%205%20En%20receiveMes2.png?alt=media\&token=56d2a2aa-5f21-436d-ba5b-c6529bd8a8e5)

#### The complete algorithm

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSiwNB4lDvOY61hDA8G%2F-MSiwx4mLIY5rf0PIsPX%2F79%206%20En%20receiveMes3.png?alt=media\&token=5ed93175-5539-4f51-b5fb-350874c27d9a)
