This exercise is intended to help students to understand how to scan the relative distance of a 3D object from a infrared sensor.
- Build a four-wheeled vehicle on rails with a sensor facing to the side moving up and down.
 - Scan the relative distance of a 3D object in front of the moving infrared sensor. For this purpose, the vehicle drives along a vertical wall in front of which a 3D object is standing halfway away from the vehicle.
 - Display the relative distance measures graphically and discuss the result with respect to the spatial resolution of the sensor.
 
Solution
- First you have to build the vehicle according to the LEGO building instructions. The building instructions are in a LXF file which can be opened with the free LEGO Digital Designer software, which is available for Computers running macOS or Windows. After launching the software you can use the view menue to switch from the construction mode to the building instructions mode.
 - Your MATLAB script creates connections to the motor and the infrared sensor, moves the vehicle and the sensor in small steps and measures the relative distance. It then displays the distance in a 2D graphics using a coordinate grid that you need to define. As you can see the sensor integrates over a relatively large area and therefore smooths the result. See the LEGO Developer Kit for the specs of the sensor.
 
LEGO building instructions and MATLAB script to run the experiment
Download the building instructions and MATLAB script. The LXF file contains the building instructions to be used with the free LEGO Digital Designer software available for macOS and Windows.

