Simple "bang-bang' line follower

[From Bruce Abbott (2018.02.30.1630 EST)]

Matlab offers a free “hardware” add-on to allow a Lego Mindstorms EV3 to be controlled by a Matlab script. I downloaded the add-on and found that I couldn’t get it to establish a communication link to my EV3. It turns out that updates to the EV3 firmware broke the hardware add-on’s ability to establish a link. However, in the past week or two, updated versions of both the firmware and the add-on were released, and these seem to have rectified the problem although establishing a link via WiFi is stlll rather “iffy” and often requires several tries before it works.

As a test I created a simple “bang-bang” controller for the EV3 that serves as a line follower. The EV3 has been configured as a two-wheeled car (with a castor ball supporting the rear), each wheel being driven independently. An EV3 color sensor set to reflected light mode is mounted in front of the right wheel, looking down at the floor. If the light reflected from the floor is brighter than 20%, the left wheel turns, otherwise the right wheel turns.

I placed the EV3 on our kitchen floor to the immediate left of a small rug that has a black border. Initially the light is brighter than 20%, so the left wheel turns on and steers the sensor toward the rug’s border. As the sensor crosses the black border, the intensity falls below 20%, turning off the left motor and turning on the right. This causes the EV3 to move left until the sensor Is over the floor again. In this way the EV3 wiggles along the border. I’ve posted a video of this action on my YouTube site at https://www.youtube.com/watch?v=PDVoYtsD7Fg .

Below is a Matlab figure created by the line-follower script after the run shown in the video, using the data from that run. The top subplot shows the reflected light intensity in percent, the second one the readings from the on-board gyro sensor (which resets to zero at the start of the script), and the bottom two subplots the motor speeds of the left and right motors, respectively.

image001193.jpgAlthough this illustration is based on the simplest of control systems, it does demonstrate how it is possible to program the EV3 via Matlab scripts and save data generated during each experimental run. Matlab has some sophisticated capabilities including such things as filtering (e.g., low-pass to remove high-frequency noise) and performing Fourier transforms that make it a great tool for investigating real-world control systems, and it far more convenient for implementing complex control systems than the block-based Lego Mindstorms software is. However, at present it does not appear that the hardware add-on will work with non-Lego sensors such as my HiTechnic angle sensor.

Matlab also has a hardware add-on for using the EV3 with Simulink. Simulink was designed for running simulations, and although it is block-based, the system is far more flexible and capable than the Mindstorms software. I will be investigating that add-on as time permits.

Bruce