This project tries to provide a starting point to implement any MATLAB code as a standalone program on Raspberry PI board to easily allow MATLAB implementation in Robotics applications. The implemented application is color detection and line-following using the PI camera, the final prototype is shown in this video.
MATLAB 8.5 (R2015a)
Raspberry Pi 2, PI Camera, power bank, USB and LAN cables, robot chassis and motors
I will explain the methodology in 4 steps:
A) MATLAB and Simulink installation
B) Code and algorithm
C) GPIO control
D) Developing Simulink model and standalone program
A) MATLAB and Simulink installation:
1- As a start, I installed MATLAB on my PC together with the Raspberry PI support Package.
2- I followed the instruction in the step-by-step guide to prepare Raspberry PI to run MATLAB and Simulink programs.
3- for PI-camera basic operation I followed the instructions in the following MathWorks link.
B) Code and algorithm:
1- the algorithm for color detection is explained in my element14 blogpost, together with some of my codes attached.
2- the line following algorithm is basically trying to calculate the mid pixel in the filtered and color detected image, and tries to centralize the mid pixel, the field of vision is limited to avoid any noise, this is shown on my YouTube video.
C) GPIO control:
The robot motor control is done using Raspberry PI GPIO pins as explained in my blogpost here.
D) Standalone implementation:
To implement the normal MATLAB code as a standalone program on Raspberry PI, it needs to be changed to Simulink model.
1- to read the camera images in Simulink, some preparation should be made as explained in this link.
2- for the whole steps of implementation please refer to this YouTube video, and my blog post attached.
3- to run the program without the need of uploading your code again, please refer to this blogpost, if you face some problems, I have also included my finalized codes and some problems I faced and how to solve them.
The design has a lot of possible enhancements and room for development:
1- replacing the relay circuits with motor drivers to decrease the response time
2- using Raspberry Pi PWM pin, and software PWM to control the motor speeds independently from each other, this allows modification of movement direction using the two motors differential speeds; this gives much more accuracy and much better response time compared to the ON/OFF approach.
3- making use of MATLAB control systems to control the motors speeds and the robot direction for better response and accuracy; such as PID controllers.
4- enhancing the main function code processing time by:
a- using mex functions (C-language)
b- vectorizing the code
c- using more toolbox functions as opposed to written scripts
Mohaned Essam is a Graduate Research Assistant at the University of Technology PETRONAS, focusing on Neuromorphic systems. Prior to this, he completed his engineering degree in Embedded systems with a focus on Image Processing and Robotics applications.