2.2 Description of Robot Inventor Kit
The LEGO Robot Inventor 5in1 Mindstorms kit is a
flexible and educational robotics set that allows users
to build and program five different robots (LEGO
Group, 2023). It offers a wide range of components,
including motors, sensors, and a programmable hub,
enabling users to create robots capable of various
tasks. With the help of the intuitive LEGO Mind-
storms software, users can code their robots to per-
form actions, follow commands, and even respond to
sensors. This kit is designed to teach programming,
engineering, and problem-solving skills in a fun and
hands-on way, making it suitable for both beginners
and more experienced robotics enthusiasts.
2.3 Competitive Solutions
There are many robotics platforms that can provide
an excellent environment to practice artificial intelli-
gence and robotics algorithms. Among these we have,
for example, the Aduino and the Raspberry Pi. The
advantage of Lego robots over other solutions is that
they have a closed, safe design, are very fault-tolerant
and have good quality sensors and servomotors in re-
lation to their price. In addition, by controlling Lego
robots in a semi autonomous way, serious robotics al-
gorithms can be tested at university level. For these
two reasons alone, we ourselves use these robots in
the process of educating students and decided to use
one of them in our work.
Next, let’s demonstrate how to use our library to
control robots with lego 5in1 robot inventor kits and
gesture recognition system.
2.4 Robot Control Using the Python
Library le mind controller
The library, named le mind controller and avail-
able at the following address as open source soft-
ware: github.com/wcyb/le mind controller, enables
communication and control of the hub, a key com-
ponent of the Lego Mindstorms set numbered 51515.
In addition, it should also work with the hub from the
Lego Spike Prime set numbered 45678, due to the fact
that the hubs in the two sets differ only in external ap-
pearance, but tests have not been conducted on the
hub from the 45678 set. Connection to the hub can
be made via a USB cable as well as via Bluetooth.
The type of connection does not affect the operation
and use of the library. The library is divided into four
modules:
1. Helpers.py - contains helper functions, respon-
sible for listing the serial ports available on
the system and for establishing a connection
through the selected port. The open source py-
Serial library, available at the following address:
github.com/pyserial/pyserial, is responsible for
the technical, operating system-dependent aspects
of handling serial ports.
2. MindComm.py - is responsible for formatting and
sending control commands to the hub. It also re-
ceives responses and data sent by the hub, and
then directs them to a parsing function in another
module. When sending commands, it is important
to remember that each must contain an individual
identifier. It is randomly generated, has a length of
four characters and consists of uppercase and low-
ercase letters, numbers and ”- ” characters. When
the hub executes a command, it sends back a mes-
sage with the same identifier as the command sent.
This makes it easy to control the status of com-
mand execution.
3. MindData.py - processes the data received from
the hub, as well as contains the definition of con-
stant values used by the modules connected to the
hub and the hub itself, such as the color seen by
the sensor or the type of module connected. The
functions contained in this module allow to eas-
ily obtain the information of interest from the hub
itself as well as the modules connected to it.
4. SerComm.py - it is used to handle events related
to the connection with the hub. Here one can find,
among others, functions called in case of connec-
tion loss or receiving a new line of data from the
hub.
2.5 Gesture Recognition Based on Leap
Motion
The code snippet in Figure 2 is an implementation for
handling data from the Leap Motion device in Python.
In brief, this code analyzes data related to hand and
wrist movements provided by the device and identi-
fies certain gestures based on that data.
The rotation angles (roll) and directions (yaw,
pitch) are transformed from radians to degrees. Then,
the code checks the type of hand (left or right) and
performs different conditional checks based on the
range of the hand’s rotation angle.
The main gestures identified by the code include
wrist movements, hand tilt angles, and the detection
of a fist by analyzing the finger angle. The results are
then sent to the console and logged to a file named
”log.txt” in the form of gesture labels and angle val-
ues.
Prototyping Educational and Scientific Devices with a Custom Python Library for Lego Robot Inventor 5in1 Mindstorms Kit: A Leap
Motion Integration Case Study
545