Mastodon

Controlling Motors and Read Sensors of LEGO MINDSTORMS with MATLAB

The second MATLAB/LEGO MINDSTORMS exercise is intended to help students to understand how to control motors and to read sensors such as the sonic sensor using MATLAB.

To work on the advanced exercises within the course, it is important to understand how to control the LEGO MINDSTORMS motors with MATLAB. Some of the experiments use motors for controlling vehicles of various types, e.g. models of moving satellites, or devices for scanning of two- and three-dimensional objects. In this exercise #2, a simple vehicle is driven with two motors.

The vehicle is equipped with a LEGO MINDSTORMS sonic sensor, which continuously determines the distance to objects in the direction of movement. A while loop is used to change direction of the vehicle as soon it is less than 0.3 meters away from an object. During operation the distance and the rotation of the motors in degrees is recorded per time and display in a plotyy diagram.