The repository is the Matlab code for controlling a robot made with Lego Mindstorms EV3 and controlled with Matlab over a USB cable/Bluetooth dongle. Right now, the code uses a single ultrasonic sensor from the EV3 brick. The support and code for arduino is included, but was commented out while getting the results posted in the video below.
The above video is the result of the matlab code and moving the robot in real time. It can also be seen at my youtube channel
The following hardware are required for use
- 1x LEGO EV3
- 2x Lego Large Motors (EV3)
- 1x Lego Ultrasonic Transeiver (EV3)
- 1x Webcam (Logitech C270 used)
- 1x Arduino MEGAADK
- 5x HC-SR04 Ultrasonic Sensors
- Tested on Matlab 2016a and later
The QR code used for testing is given below.
The design was based on the Ultrasonic sensor driving base design from lego. The PDF design instructions can be downloaded from Lego Website
The code flow can be generalized as follows:
-
Get Deviation from center and Direction from KLT tracking
(a) Find Region of Interest and its center (4x Red Circles in a square)
(b) Find SURF Feature points (QR Code with 4x Red Circles at the corners)
(c) Match SURF features with QR Code template in file
(d)Continue if QR code found else stop moving -
Get Values of 5x Ultrasonic sensors from Arduino
-
Get value from 1x front LEGO ultrasonic sensor
-
Calculate Direction to turn based on the position of QR code in the field of view
-
Calculate speed of turn for both motors using PID feedback control
-
Save values to pass on to cartTurn function to execute the values
-
Check if the main window is open. If its closed; exit the program.