Interaction with the robot based on the Lego Mindstorms EV3 constructor via RCML
The article describes the experience of using the Lego Mindstorms EV3 designer to create a prototype of a robot with its subsequent program and manual control using Robot Control Meta Language (RCML).
The following key points will be considered: ')
Building a robot prototype based on the Lego Mindstorms EV3 designer
Quick installation and configuration of RCML for Windows
Software control robot based on the EV3 controller
Manual control of the periphery of the robot using the keyboard and gamepad
Looking ahead a bit, I’ll add that in order to implement Lego-robot control using the keyboard, you need to create a program containing only 3 lines of program code. Details on how to do this are written under the cut. 1. To begin with, a prototype robot was created from the Lego Mindstorms EV3 designer, which will be used for programming and manual piloting.
Description of the prototype of the robot
The robot has a design similar to a car chassis. Two motors mounted on the frame have one common axis of rotation, which is connected to the rear wheels through a gearbox. The gearbox converts torque by increasing the angular velocity of the rear axle. The steering system is assembled on the base of a bevel gearbox.
2. The next step is to prepare RCML to work with the Lego Mindstorms EV3 designer.
The following describes the process of performing a quick start for the interaction of RCML and Lego of a robot controlled by an EV3 controller.
The downloaded archives must be extracted into a directory with an arbitrary name, but you should avoid Russian letters in the name.
Directory contents after unpacking archives
Next, you need to create a config.ini configuration file, which must be located in the same directory. To implement the ability to control the EV3 controller using the keyboard and gamepad, you need to connect the modules lego_ev3, keyboard and gamepad.
Listing of the config.ini configuration file for RCML
Next, you should pair the EV3 controller and adapter.
Instructions for pairing the EV3 controller and Bluetooth adapter
The manual contains an example of pairing a Lego Ev3 controller and a PC running the Windows 7 operating system.
1. Go to the settings section of the Ev3 controller, then go to the menu item “Bluetooth”.
2. Make sure the configuration settings are correct. The checkboxes against “Visibility” and “Bluetooth” should be checked.
3. You need to go to the "Control Panel", then "Devices and Printers", then "Bluetooth Devices".
4. You must click the "Add Device" button. A window will open to select available Bluetooth devices.
5. Select the “EV3” device and click the “Next” button.
6. The “Connect?” Dialog box will be displayed on the EV3 controller screen. You need to select the checkmark option, and confirm your choice by pressing the central key.
7. Next, the “PASSKEY” dialog box will appear, the digits “1234” should be indicated in the input line, then you should confirm the key phrase for pairing devices by pressing the central key on the position with a check mark.
8. A form for entering the key for pairing devices will appear in the device pairing wizard. You need to enter the code "1234" and press the "Next" button.
9. Next, a window will appear, with successful connection of the device. Press the "Close" button.
10. On the PC, you need to return to the “Control Panel”, then “Devices and Printers”, then “Bluetooth Devices”. The list of available devices will display the device with which the pairing was made.
11. Double-tap to go to the “EV3” connection properties.
12. Next, go to the tab "Equipment".
13. Next, double-click to go to the properties of the connection "Standard serial port via Bluetooth connection".
14. The COM port index specified in the properties should be used in the config.ini configuration file of the lego_ev3 module. The example shows the Bluetooth properties of the Lego EV3 controller using the standard COM14 serial port.
Further configuration of the module is reduced to the fact that it is necessary to write in the configuration file of the lego_ev3 module the address of the COM port through which communication with the Lego robot takes place.
Listing of the config.ini configuration file for the lego_ev3 module
Now you need to configure the keyboard module. The module is located in the control_modules directory, then the keyboard. You should create a config.ini configuration file next to the keyboard_module.dll file. Before you create a configuration file, you must determine which actions should be performed by pressing the keys.
The keyboard module allows you to use keys that have a certain numeric code. Table of virtual key codes can be found here .
As an example, I will use the following key presses:
The up / down arrows are used to rotate the rear wheel motor forward / backward.
Left / right arrows turn wheels left / right
The keyboard module configuration file describes which axes are available to the programmer to interact with the robot in manual control mode. Thus, in the example we have two control groups - these are the keyboard axes. To add a new axis, follow the following axis description rules.
Rules for describing axes for the keyboard module
1. When adding a new axis, you need to add a property in the [mapped_axis] section, the name of which is the name of the axis, and assign it the value of the keyboard button in the HEX format, and a similar entry is added to each button, i.e. axis name can be used several times. In general, an entry in the [mapped_axis] section will look like this:
_ = ____HEX_
2. It is necessary to set the maximum and minimum value that can be stored on this axis. To do this, you need to add a section in the config.ini configuration file, the same name as the axis name, and set the upper_value and lower_value properties that correspond to the maximum and minimum axes, respectively. In general, this section looks like this:
[_] upper_value = __ lower_value = __
3. Next, determine what value the axis will have if you press a button on the keyboard that was previously attached to it. Definition of values ​​occurs by creating a section, the name of which consists of the axis name and the value of the keyboard button in HEX format, separated by an underscore. To set the default value (in the non- depressed) and depressed state, the unpressed_value and pressed_value properties are used, respectively, to which the values ​​are passed. The general view of the section in this case is as follows:
The spoiler text is copied from the RCML documentation for easy viewing.
To implement the robot prototype control, a keyboard configuration file was created that includes the go and rotate axes. The go axis is used to set the direction of movement of the robot. When you press the up arrow, the axis will receive a value of 100, and when you press the down arrow, the axis will take a value of -50. The rotate axis is used to set the angle of rotation of the front wheels. If you press the left-arrow key, the axis value will be -5; when you press the right arrow, the axis will take the value 5.
Listing of the config.ini configuration file for the keyboard module
Next, to implement the control using the gamepad, you need to configure the gamepad module. Configuring the module involves creating a config.ini configuration file next to gamepad_module.dll, located in the control_modules directory, then gamepad.
Universal configuration file of the module for interacting with the gamepad
Additional information about the features of the gamepad module configuration is displayed in the RCML reference manual .
3. The next step is to write a program in the RCML language.
In the root of the created directory, you must create a program file. The file name of the program and its extension can be any, but you should avoid Russian letters in the name. In the example, the file name is used - hello.rcml.
For the lego_ev3 module, the robot reservation code is the following:
@tr = robot_lego_ev3;
On the connection page of the lego_ev3 module , most of the functions supported by the controller are described. As a test example, a program was created to automatically enter the robot into a skid.
The program algorithm is as follows:
After reserving the first free robot, a connection is established between two engines for subsequent work with them, as with one. Then the robot starts to drift. Program description of the actions of the robot allows you to accurately set the angles of rotation of the front wheels and the speed of rotation of the rear. Using this technique allows you to achieve results that are difficult to repeat during manual piloting from a keyboard or gamepad.
To compile the program, you must use the command line window. First you need to move to the created directory with executable files rcml_compiler.exe and rcml_intepreter.exe. Next you need to enter the following commands.
The command to compile the hello.rcml file is:
rcml_compiler.exehello.rcmlhello.rcml.pc
As a result of compiling, a new file hello.rcml.pc will appear in the created directory.
Screenshot command line after successful compiling
Now you need to make sure that the EV3 controller is on, paired with a Bluetooth adapter. Gamepad must be connected to PC. After that, you need to execute the command to execute the program file:
rcml_intepreter.exehello.rcml
The appearance of the command line in the program
A video showing the robot movement program is located at the bottom of the article.
4. The next step is to control the robot in manual mode using the keyboard.
Further, the process of software communication between the engines of the robot and the keyboard will be demonstrated.
Using the keyboard, you can control any engine of the robot. Within the framework of the example, the following mechanisms are implemented:
Angle of rotation of the front wheels
The direction of rotation of the rear wheels
Listing of the program of interaction between the keyboard and the Lego robot based on the EV3 controller
Next you should compile the program and execute it. The result of the manual control of the Lego robot using the keyboard is shown in the video at the bottom of the page.
5. In addition to the keyboard, a gamepad module is available that allows you to manipulate the robot using a gamepad. To implement the control of the robot using a gamepad, it is necessary to describe at the program level which axes of the robot will assume the values ​​of the gamepad axes.
Program listing of gamepad and Lego robot interaction
Next, you should repeat the process of compiling the program and then execute it. The following shows the result of the manual control of the Lego robot using a gamepad, and all previously connected methods:
The article briefly demonstrated only some of the features of RCML. The most detailed description is in the reference manual.