# Robot control from the remote control

{% hint style="info" %}
This article is automatically translated from Russian by Google Translator.
{% endhint %}

To control the robot with the [remote control](https://help.trikset.com/en/gamepad/about) you need to write a program and run it on the robot.

## Example of interaction with the remote control

1. Write [an algorithm](#program-algorithm) to use the controller in TRIK Studio.
2. [Connect](https://help.trikset.com/en/trik/wi-fi) the controller to the computer and [upload](https://help.trikset.com/en/trik/run-upload-programs) the written program to the robot.
3. Connect your smartphone to the controller by selecting the controller's network.
4. Open the [TRIK Gamepad](https://help.trikset.com/en/gamepad/about/app) app on your smartphone.
5. Execute the algorithm on the controller.

## Program algorithm

1\. Enter variables for gamepad touch coordinates - `x` and `y` - and initialize them by assigning zero values to them 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-MSkrV8RlGSfEz-Om3Oy%2F-MSkriMZXSuzOft8LXet%2FB3%201%20En%20Gamepad1.png?alt=media\&token=3e843db9-e0d2-4408-829a-40ec46d7d170)

2\. Add the "[Wait for Gamepad Connect](https://help.trikset.com/en/trik/programming-visual/blocks#wait-for-gamepad-connect)" block:

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSkrlqM10Vs4W2IT6Qq%2FB3%202%20En%20Gamepad2.png?alt=media\&token=2911486a-3603-4302-aea7-2416a00c7d96)

3\. To check if the gamepad clicks on the left area (Pad1), add a "[Condition](https://help.trikset.com/en/studio/programming-visual/blocks#condition)" block with the condition [`gamepadPad1Pressed`](https://help.trikset.com/en/trik/programming-visual/sensory-variables#gamepadpad-1-pressed-gamepadpad-2-pressed)`> 0`:

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSkrpsmBpCdWZIbyqPi%2FB3%203%20En%20Gamepad3.png?alt=media\&token=ba382500-e4d8-4fa7-a6df-53265c5d0530)

4\. In case there is no touch, it is necessary to stop the motors. To do this, add a block "[Stop motors](https://help.trikset.com/en/trik/programming-visual/blocks#stop-motors)":

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSkrtxleIe9Zw-Nzo3t%2FB3%204%20En%20Gamepad4.png?alt=media\&token=107c81f5-4b13-469a-aaa5-5525bfc9aa19)

5\. If the [Pad1](https://help.trikset.com/en/gamepad/about/app) area is pressed on the gamepad, you need to get the coordinates of the touch. To do this, use the [`gamepadPad1`](https://help.trikset.com/en/trik/programming-visual/sensory-variables#gamepadpad-1-gamepadpad2) array 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-MSkrV8RlGSfEz-Om3Oy%2F-MSks4S67RfcXPOFs7sG%2FB3%205%20En%20Gamepad5.png?alt=media\&token=fc693298-415e-4faf-a0c1-47ec74100a32)

6\. After getting the coordinates, add a simple controller with the "[Motor Forward](https://help.trikset.com/en/trik/programming-visual/blocks#motors-forward)" blocks. The Y coordinate offset is responsible for the speed of the robot and the X coordinate offset is responsible for the rotation.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSks9jn7gXiwTph39UK%2FB3%206%20En%20Gamepad6.png?alt=media\&token=f3ae68d4-d53d-430d-9cac-247192491a85)

7\. To close the condition, add a "[Timer](https://help.trikset.com/en/studio/programming-visual/blocks#timer)" block with a value of `100 ms` (in the program this is the time for a new call to the remote control).

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSksFI6C6HB1lDHy9DU%2FB3%207%20En%20Gamepad6.png?alt=media\&token=adb169e0-39c4-4a0e-8414-78bf38a63b2e)

8\. Close the loop on the "Condition" block with a link from the "Timer" block.

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSksJbFmzY1gwIshaWV%2FB3%208%20En%20Gamepad8.png?alt=media\&token=0188ba96-2cfe-4190-a83b-c4ec64e53b60)

9\. If you have a video camera, add the "[Enable Video Streaming](https://help.trikset.com/en/trik/programming-visual/blocks#camera-on)" block to the beginning of the program:

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSksQQLNyALYHYJkl_K%2FB3%209%20En%20Gamepad9.png?alt=media\&token=f1407bba-7df7-41d2-956c-a3e13dbd7756)

### General view of the algorithm

![](https://2483351831-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-9YMGCK0ySSnTAiseS%2F-MSkrV8RlGSfEz-Om3Oy%2F-MSksTiruXVWt_IWcm1Z%2FB3%20A%20En%20Gamepad10.png?alt=media\&token=20c7b3da-cbb6-4b80-9755-6a911b92da5f)

{% hint style="info" %}
You can find the finished program in the root folder of TRIK Studio `/examples/trik/remoteContro`l or download it [here](https://dl.trikset.com/trikset-help/remoteControl.qrs).
{% endhint %}
